Skip to content

Commit

Permalink
SC-683 Lease and LeaseCancel actions (#3319)
Browse files Browse the repository at this point in the history
* Add RIDE V5 context

* Support DApp ScriptResult for V5

* Support DocSource for V5

* Adapt OverdraftTest for V5

* Correct extracting data functions docs for V5

* Adapt issuing V5 script suites

* Set recent defined function complexity as default

* Adapt context functions test

* Adapt FunctionComplexityTest

* Remove empty file

* SC-683 Lease action

* Correct ambiguous import

* Correct LeaseCancel validation

* Remove unused BaseFunction field

* Refactor DiffsCommon

* Provide calculating unique id for Lease action

* Support script results

* Add nonce field for Lease action constructor

This reverts commit 4e37ff3.

* Adapt tests

* Unify resolving alias

* Add related functions

* Improve calculateLeaseId test

* Check LeaseCancel actions

* Add Lease action tests

* Adapt new PB format

* Correct definition of LeaseAction

* Improve LeaseCancel error messages

* Improve LeaseCancel error message

* Support lease details for CompositeBlockchain in case of Lease action

* Add LeaseCancel tests

* Better naming

* Test Lease action cancelled by LeaseCancelTransaction

* Add multiple action tests

* Check duplicate lease action and add test

* Refactor DiffsCommon

* Clarify activation test

* Add balance tests for active leases

* Add balance tests for cancelled leases

* Provide exhaustiveness

* Adapt json results

* Test json results

* Clean-up imports

* Add leaseId field to Lease action

* Implement store and rollback of lease action details

* Support rollback for LeaseCancel

* Assert lease details height is invariable

* Keep lease details previous height when replacing

* Refactor RollbackSpec

* Correct test

* Improve activation test

* Support active leases API

* Correct callableReturnType after merge

* Correct WavesContext after merge

* Add ContinuationTransaction blockchain feature to implemented

* Correct read of active leases

* Correct LeaseActionSuite

* Don't use fork parameter for GRPC API

* Use actual height in LeaseActionSuite

* Remove unxpected node config from LeaseActionSuite

* Adapt LeasingTransactionsGrpcSuite

* Use different lease amounts for tx and action in LeaseActionSuite

* Add LeaseActionGrpcSuite

* Update protobuf version

* Adapt with new LeaseResponse protobuf model

* Adapt tests

* Remove duplicate ByteStr json format

* Fill invokeId in ContinuationTransactionDiff script result

* Add continuations mock for lease API test

* Adapt LeaseActionDiffTest

* Adapt RollbackSpec

* Adapt statuses for TransactionsRouteSpec

* Correct DebugApiRouteSpec
  • Loading branch information
xrtm000 authored Dec 29, 2020
1 parent 40bda67 commit 474e6da
Show file tree
Hide file tree
Showing 58 changed files with 2,494 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import java.util.concurrent.TimeUnit

import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.lang.v1.CalculateAssetIdBenchmark._
import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.{curve25519, randomBytes}
import com.wavesplatform.lang.v1.traits.domain.Issue
import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.{curve25519, randomAddress, randomBytes}
import com.wavesplatform.lang.v1.traits.domain.Recipient.{Address, Alias}
import com.wavesplatform.lang.v1.traits.domain.{Issue, Lease}
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import scorex.crypto.hash.{Blake2b256, Keccak256, Sha256}
Expand Down Expand Up @@ -79,7 +80,25 @@ class CalculateAssetIdBenchmark {

@Benchmark
def calculateAssetId(st: CalculateAssetIdSt, bh: Blackhole): Unit =
bh.consume(Issue.calculateId(Int.MaxValue, st.MaxAssetDescription, isReissuable = true, st.MaxAssetName, Long.MaxValue, Long.MaxValue, ByteStr(new Array[Byte](64))))
bh.consume(
Issue.calculateId(
Int.MaxValue,
st.MaxAssetDescription,
isReissuable = true,
st.MaxAssetName,
Long.MaxValue,
Long.MaxValue,
ByteStr(new Array[Byte](64))
)
)

@Benchmark
def calculateLeaseIdWithAddress(st: CalculateLeaseIdSt, bh: Blackhole): Unit =
bh.consume(Lease.calculateId(Lease(st.address, Long.MaxValue, Long.MaxValue), st.txId))

@Benchmark
def calculateLeaseIdWithAlias(st: CalculateLeaseIdSt, bh: Blackhole): Unit =
bh.consume(Lease.calculateId(Lease(st.maxAlias, Long.MaxValue, Long.MaxValue), st.txId))
}

object CalculateAssetIdBenchmark {
Expand Down Expand Up @@ -111,4 +130,11 @@ object CalculateAssetIdBenchmark {
val MaxAssetName: String = "a" * 16
val MaxAssetDescription: String = "a" * 1000
}

@State(Scope.Benchmark)
class CalculateLeaseIdSt {
val address: Address = Address(randomAddress)
val maxAlias: Alias = Alias("a" * 30)
val txId: ByteStr = ByteStr(randomBytes(32))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import com.google.protobuf.ByteString
import com.google.protobuf.wrappers.{BytesValue, StringValue}
import com.wavesplatform.account.{Address, Alias}
import com.wavesplatform.api.common.CommonAccountsApi
import com.wavesplatform.api.common.CommonAccountsApi.LeaseInfo
import com.wavesplatform.protobuf._
import com.wavesplatform.protobuf.transaction.PBTransactions
import com.wavesplatform.protobuf.transaction.{PBRecipients, PBTransactions}
import com.wavesplatform.protobuf.utils.PBImplicitConversions.fromAssetIdAndAmount
import com.wavesplatform.transaction.Asset
import io.grpc.stub.StreamObserver
Expand Down Expand Up @@ -63,12 +64,22 @@ class AccountsApiGrpcImpl(commonApi: CommonAccountsApi)(implicit sc: Scheduler)
}
}

override def getActiveLeases(request: AccountRequest, responseObserver: StreamObserver[TransactionResponse]): Unit =
override def getActiveLeases(request: AccountRequest, responseObserver: StreamObserver[LeaseResponse]): Unit =
responseObserver.interceptErrors {
val transactions = commonApi.activeLeases(request.address.toAddress)
val result = transactions.map {
case (height, transaction) => TransactionResponse(transaction.id().toByteString, height, Some(transaction.toPB))
}
val result =
commonApi
.activeLeases(request.address.toAddress)
.map {
case LeaseInfo(leaseId, originTransactionId, sender, recipient, amount, height) =>
LeaseResponse(
leaseId.toByteString,
originTransactionId.toByteString,
ByteString.copyFrom(sender.bytes),
Some(PBRecipients.create(recipient)),
amount,
height
)
}
responseObserver.completeWith(result)
}

Expand Down
7 changes: 7 additions & 0 deletions lang/doc/v5/funcs/blockchain-functions.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
paramsDoc: [ "Structure of a token issue." ]
complexity: 10
}
{
name: "calculateLeaseId"
params: [ "Lease" ]
doc: "Calculates ID of lease obtained by invoke script transaction's call of the Lease structure."
paramsDoc: [ "Structure of a lease action." ]
complexity: 1
}
{
name: "transactionHeightById"
params: [ "ByteVector" ]
Expand Down
18 changes: 16 additions & 2 deletions lang/doc/v5/funcs/internal-functions.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@
doc: "Issue action detailed constructor"
paramsDoc: [ "Token name", "Token description", "Amount of the token", "Number of digits in decimal part", "Reissue ability flag", "Smart asset script (optional)", "Sequential number"]
complexity: 1
},
}
{
name: "Issue"
params: [ "String", "String", "Int", "Int", "Boolean" ]
doc: "Issue action simplified constructor"
paramsDoc: [ "Token name", "Token description", "Amount of the token", "Number of digits in decimal part", "Reissue ability flag" ]
complexity: 1
}
{
name: "Lease"
params: [ "Address|Alias", "Int", "Int" ]
doc: "Lease action detailed constructor"
paramsDoc: [ "Recipient", "Amount of Waves", "Nonce to distinguish" ]
complexity: 1
}
{
name: "Lease"
params: [ "Address|Alias", "Int" ]
doc: "Lease action simplified constructor"
paramsDoc: [ "Recipient", "Amount of Waves" ]
complexity: 1
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ package object utils {

private val Global: BaseGlobal = com.wavesplatform.lang.Global // Hack for IDEA

val environment = new Environment[Id] {
val environment = buildEnvironment(ByteStr.empty)

def buildEnvironment(txIdParam: ByteStr) = new Environment[Id] {
override def height: Long = 0
override def chainId: Byte = 1: Byte
override def inputEntity: Environment.InputEntity = null
override val txId: ByteStr = ByteStr.empty
override val txId: ByteStr = txIdParam
override def transactionById(id: Array[Byte]): Option[Tx] = ???
override def transferTransactionById(id: Array[Byte]): Option[Tx.Transfer] = ???
override def transactionHeightById(id: Array[Byte]): Option[Long] = ???
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ object FunctionIds {
val TRANSFER_TRANSACTION_FROM_PROTO: Short = 1070

val CALCULATE_ASSET_ID: Short = 1080
val CALCULATE_LEASE_ID: Short = 1081

val SIMPLIFIED_ISSUE_ACTION_CONSTRUCTOR: Short = 1090
val DETAILED_ISSUE_ACTION_CONSTRUCTOR: Short = 1091
val SIMPLIFIED_LEASE_ACTION_CONSTRUCTOR: Short = 1092
val DETAILED_LEASE_ACTION_CONSTRUCTOR: Short = 1093

val ExternalFunctionIds =
Set(
Expand Down
Loading

0 comments on commit 474e6da

Please sign in to comment.