From e6e3c0343dfc39790ce67d8d2340db36f3b219e9 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Tue, 19 Oct 2021 14:51:34 +0300 Subject: [PATCH] NODE-2337: Ethereum transaction support (#3519) --- .gitattributes | 3 + .../v1/AddressFromPublicKeyBenchmark.scala | 38 + .../v1/EnvironmentFunctionsBenchmark.scala | 14 +- build-with-docker.sh | 7 +- build.sbt | 14 +- .../wavesplatform/api/grpc/GRPCErrors.scala | 2 +- .../api/grpc/GRPCServerExtension.scala | 6 +- .../api/grpc/TransactionsApiGrpcImpl.scala | 33 +- .../com/wavesplatform/api/grpc/package.scala | 2 +- .../com/wavesplatform/events/events.scala | 77 +- .../api/grpc/test/GRPCBroadcastSpec.scala | 127 ++++ .../events/BlockchainUpdatesSpec.scala | 43 +- lang/doc/v6/funcs/converting-functions.hjson | 2 +- .../wavesplatform/common/state/ByteStr.scala | 18 +- .../wavesplatform/lang/utils/package.scala | 1 + .../com/wavesplatform/lang/v1/Serde.scala | 13 +- .../lang/v1/evaluator/FunctionIds.scala | 7 +- .../v1/evaluator/ctx/impl/PureContext.scala | 6 +- .../evaluator/ctx/impl/waves/Functions.scala | 24 +- .../ctx/impl/waves/WavesContext.scala | 4 +- .../wavesplatform/lang/v1/parser/Parser.scala | 7 +- .../lang/v1/traits/Environment.scala | 1 + .../scala/com/wavesplatform/lang/Common.scala | 1 + .../lang/evaluator/EvaluatorV1V2Test.scala | 2 +- node-generator/devnet.conf | 25 - .../src/main/resources/application.conf | 2 +- .../NarrowTransactionGenerator.scala | 158 ++-- .../generator/TransactionsGeneratorApp.scala | 28 +- .../generator/config/FicusImplicits.scala | 19 +- .../com/wavesplatform/it/ExternalNode.scala | 4 +- ...GrpcIntegrationSuiteWithThreeAddress.scala | 14 +- .../scala/com/wavesplatform/it/Node.scala | 9 +- .../wavesplatform/it/TransferSending.scala | 8 +- .../wavesplatform/it/api/AsyncGrpcApi.scala | 82 +- .../wavesplatform/it/api/SyncGrpcApi.scala | 2 +- .../wavesplatform/it/api/SyncHttpApi.scala | 13 +- .../GrpcIssueReissueBurnAssetSuite.scala | 2 +- .../it/asset/IssueReissueBurnAssetSuite.scala | 10 +- .../it/sync/AddressApiSuite.scala | 6 +- .../it/sync/AssetDistributionSuite.scala | 6 +- .../MicroblocksSponsoredFeeTestSuite.scala | 2 + .../com/wavesplatform/it/sync/UtxSuite.scala | 20 +- .../sync/grpc/BurnTransactionGrpcSuite.scala | 15 +- .../sync/grpc/DataTransactionGrpcSuite.scala | 4 +- .../grpc/ExchangeTransactionGrpcSuite.scala | 4 +- .../grpc/FailedTransactionGrpcSuite.scala | 4 +- .../sync/grpc/GetTransactionGrpcSuite.scala | 15 +- .../grpc/InvokeScriptErrorMsgGrpcSuite.scala | 3 +- ...keScriptPayAndTransferAssetGrpcSuite.scala | 11 +- .../sync/grpc/IssueTransactionGrpcSuite.scala | 12 +- .../grpc/LeasingTransactionsGrpcSuite.scala | 10 +- .../MassTransferTransactionGrpcSuite.scala | 2 +- .../grpc/ReissueTransactionGrpcSuite.scala | 10 +- .../sync/grpc/SetAssetScriptGrpcSuite.scala | 18 +- .../grpc/SetScriptTransactionGrpcSuite.scala | 69 +- .../grpc/SponsorFeeTransactionGrpcSuite.scala | 140 +++- .../grpc/TransferTransactionGrpcSuite.scala | 4 +- .../UpdateAssetInfoTransactionGrpcSuite.scala | 9 +- .../network/SimpleTransactionsSuite.scala | 4 +- .../smartcontract/EstimatorTestSuite.scala | 40 +- .../PseudoTransactionSuite.scala | 85 ++- .../RideReplBlockchainFunctionsSuite.scala | 18 +- .../freecall/InvokeExpressionSuite.scala | 6 +- .../transactions/DataTransactionSuite.scala | 2 +- .../MassTransferTransactionSuite.scala | 2 +- .../SignAndBroadcastApiSuite.scala | 4 +- .../TransactionsStatusSuite.scala | 14 +- .../UpdateAssetInfoTransactionSuite.scala | 15 +- .../utils/TransactionSerializeSuite.scala | 9 +- .../scala/com/wavesplatform/test/Signed.scala | 24 + node/build.sbt | 4 - node/src/main/protobuf/waves/database.proto | 19 +- .../scala/com/wavesplatform/Application.scala | 41 +- .../scala/com/wavesplatform/Explorer.scala | 57 +- .../wavesplatform/GenesisBlockGenerator.scala | 10 +- .../com/wavesplatform/MetamaskBootstrap.scala | 141 ++++ .../wavesplatform/ResponsivenessLogs.scala | 8 +- .../com/wavesplatform/account/Address.scala | 121 --- .../account/AddressOrAlias.scala | 68 -- .../com/wavesplatform/account/Alias.scala | 69 -- .../com/wavesplatform/account/KeyPair.scala | 4 +- .../com/wavesplatform/account/PublicKey.scala | 13 +- .../com/wavesplatform/account/Recipient.scala | 218 ++++++ .../com/wavesplatform/account/package.scala | 3 + .../api/common/AddressTransactions.scala | 35 +- .../api/common/CommonAccountsApi.scala | 33 +- .../api/common/CommonTransactionsApi.scala | 57 +- .../api/common/TransactionMeta.scala | 50 ++ .../wavesplatform/api/common/package.scala | 31 +- .../api/http/AddressApiRoute.scala | 14 +- .../com/wavesplatform/api/http/ApiError.scala | 24 +- .../api/http/ApiMarshallers.scala | 32 +- .../api/http/CompositeHttpService.scala | 10 +- .../api/http/CustomDirectives.scala | 30 +- .../api/http/DebugApiRoute.scala | 6 +- .../wavesplatform/api/http/JsonFormats.scala | 38 + .../api/http/TransactionsApiRoute.scala | 76 +- .../api/http/UtilsApiRoute.scala | 59 +- .../api/http/alias/AliasApiRoute.scala | 4 +- .../api/http/assets/AssetsApiRoute.scala | 4 +- .../api/http/eth/EthRpcRoute.scala | 220 ++++++ .../com/wavesplatform/api/http/eth/Type.scala | 16 + .../com/wavesplatform/api/http/package.scala | 58 +- .../http/requests/InvokeScriptRequest.scala | 13 +- .../http/requests/LeaseCancelRequest.scala | 2 +- .../requests/SignedMassTransferRequest.scala | 2 +- .../api/http/requests/TransferRequest.scala | 4 +- .../com/wavesplatform/block/package.scala | 10 +- .../block/serialization/BlockSerializer.scala | 2 +- .../block/serialization/package.scala | 42 +- .../consensus/TransactionsOrdering.scala | 10 +- .../nxt/api/http/NxtConsensusApiRoute.scala | 0 .../com/wavesplatform/crypto/package.scala | 11 +- .../com/wavesplatform/database/Caches.scala | 7 +- .../wavesplatform/database/DBResource.scala | 4 +- .../com/wavesplatform/database/KeyTags.scala | 3 +- .../com/wavesplatform/database/Keys.scala | 14 +- .../database/LevelDBWriter.scala | 348 ++++----- .../scala/com/wavesplatform/database/RW.scala | 6 +- .../database/jna/LevelDBJNADB.scala | 6 +- .../com/wavesplatform/database/package.scala | 79 +- .../features/BlockchainFeature.scala | 2 + .../wavesplatform/metrics/BlockStats.scala | 2 +- .../metrics/TxProcessingStats.scala | 22 +- .../com/wavesplatform/mining/Miner.scala | 8 +- .../mining/microblocks/MicroBlockMiner.scala | 3 + .../microblocks/MicroBlockMinerImpl.scala | 6 +- .../network/BasicMessagesRepo.scala | 22 +- .../network/LegacyFrameCodec.scala | 6 +- .../wavesplatform/network/NetworkServer.scala | 5 +- .../client/LegacyChannelInitializer.scala | 2 +- .../com/wavesplatform/network/messages.scala | 15 +- .../com/wavesplatform/network/package.scala | 18 +- .../protobuf/block/PBBlocks.scala | 23 +- .../protobuf/block/PBMicroBlocks.scala | 4 +- .../protobuf/transaction/PBOrders.scala | 9 +- .../protobuf/transaction/PBRecipients.scala | 23 +- .../protobuf/transaction/PBTransactions.scala | 151 ++-- .../protobuf/transaction/transaction.scala | 2 - .../utils/PBImplicitConversions.scala | 17 +- .../wavesplatform/serialization/package.scala | 4 +- .../settings/BlockchainSettings.scala | 6 +- .../com/wavesplatform/state/Blockchain.scala | 24 +- .../state/BlockchainUpdaterImpl.scala | 8 +- .../scala/com/wavesplatform/state/Diff.scala | 17 +- .../state/InvokeScriptResult.scala | 10 +- .../state/diffs/AssetTransactionsDiff.scala | 8 +- .../state/diffs/BlockDiffer.scala | 10 +- .../state/diffs/CommonValidation.scala | 18 +- .../state/diffs/DiffsCommon.scala | 8 +- .../state/diffs/EthereumTransactionDiff.scala | 56 ++ .../state/diffs/ExchangeTransactionDiff.scala | 16 +- .../state/diffs/FeeValidation.scala | 68 +- .../diffs/MassTransferTransactionDiff.scala | 8 +- .../state/diffs/PaymentTransactionDiff.scala | 2 +- .../state/diffs/TransactionDiffer.scala | 49 +- .../state/diffs/TransferDiff.scala | 93 +++ .../state/diffs/TransferTransactionDiff.scala | 87 --- .../diffs/invoke/InvokeDiffsCommon.scala | 91 ++- .../state/diffs/invoke/InvokeScript.scala | 50 +- .../state/diffs/invoke/InvokeScriptDiff.scala | 37 +- .../invoke/InvokeScriptTransactionDiff.scala | 35 +- .../com/wavesplatform/state/package.scala | 4 +- .../state/patch/CancelLeaseOverflow.scala | 2 +- .../patch/CancelLeasesToDisabledAliases.scala | 2 +- .../state/reader/CompositeBlockchain.scala | 14 +- .../transaction/ABIConverter.scala | 230 ++++++ .../transaction/CreateAliasTransaction.scala | 26 +- .../transaction/DataTransaction.scala | 22 +- .../transaction/EthereumTransaction.scala | 214 ++++++ .../transaction/FastHashId.scala | 10 +- .../transaction/GenesisTransaction.scala | 17 +- .../{LegacyPBSwitch.scala => PBSince.scala} | 12 +- .../transaction/PaymentTransaction.scala | 27 +- .../transaction/ProtobufOnly.scala | 3 - .../transaction/ProvenTransaction.scala | 17 +- .../transaction/SigProofsSwitch.scala | 2 +- .../transaction/SignedTransaction.scala | 20 - .../transaction/Transaction.scala | 28 +- .../transaction/TransactionFactory.scala | 116 +-- .../transaction/TransactionParsers.scala | 1 - .../transaction/TransactionType.scala | 28 + .../transaction/TxValidationError.scala | 1 - .../transaction/VersionedTransaction.scala | 6 + .../transaction/assets/BurnTransaction.scala | 8 +- .../transaction/assets/IssueTransaction.scala | 20 +- .../assets/ReissueTransaction.scala | 20 +- .../assets/SetAssetScriptTransaction.scala | 16 +- .../assets/SponsorFeeTransaction.scala | 18 +- .../assets/UpdateAssetInfoTransaction.scala | 26 +- .../assets/exchange/AssetPair.scala | 18 +- .../assets/exchange/EthOrders.scala | 162 ++++ .../assets/exchange/ExchangeTransaction.scala | 22 +- .../transaction/assets/exchange/Order.scala | 50 +- .../assets/exchange/OrderJson.scala | 38 +- .../lease/LeaseCancelTransaction.scala | 6 +- .../transaction/lease/LeaseTransaction.scala | 17 +- .../wavesplatform/transaction/package.scala | 21 +- .../serialization/impl/BaseTxJson.scala | 38 +- .../serialization/impl/BurnTxSerializer.scala | 4 +- .../impl/CreateAliasTxSerializer.scala | 4 +- .../serialization/impl/DataTxSerializer.scala | 2 +- .../impl/ExchangeTxSerializer.scala | 4 +- .../impl/GenesisTxSerializer.scala | 6 +- .../impl/InvokeScriptTxSerializer.scala | 29 +- .../impl/IssueTxSerializer.scala | 6 +- .../impl/LeaseCancelTxSerializer.scala | 4 +- .../impl/LeaseTxSerializer.scala | 6 +- .../impl/MassTransferTxSerializer.scala | 9 +- .../serialization/impl/OrderSerializer.scala | 10 +- .../impl/PBTransactionSerializer.scala | 2 +- .../impl/PaymentTxSerializer.scala | 6 +- .../impl/ReissueTxSerializer.scala | 6 +- .../impl/SetAssetScriptTxSerializer.scala | 2 +- .../impl/SetScriptTxSerializer.scala | 2 +- .../impl/SponsorFeeTxSerializer.scala | 4 +- .../impl/TransferTxSerializer.scala | 22 +- .../smart/InvokeExpressionTransaction.scala | 19 +- .../smart/InvokeScriptTransaction.scala | 63 +- .../transaction/smart/InvokeTransaction.scala | 16 +- .../smart/RealTransactionWrapper.scala | 96 ++- .../smart/SetScriptTransaction.scala | 16 +- .../transaction/smart/Verifier.scala | 37 +- .../transaction/smart/WavesEnvironment.scala | 41 +- .../smart/script/trace/TraceStep.scala | 10 +- .../transfer/MassTransferTransaction.scala | 48 +- .../transfer/TransferTransaction.scala | 38 +- .../transaction/utils/EthConverters.scala | 27 + .../transaction/utils/EthTxGenerator.scala | 200 +++++ .../transaction/utils/Signed.scala | 24 + .../validation/TxConstraints.scala | 6 +- .../impl/InvokeScriptTxValidator.scala | 4 +- .../impl/MassTransferTxValidator.scala | 6 +- .../impl/UpdateAssetInfoTxValidator.scala | 3 +- .../com/wavesplatform/utils/EthEncoding.scala | 10 + .../com/wavesplatform/utx/UtxPoolImpl.scala | 8 +- .../com/wavesplatform/wallet/Wallet.scala | 2 +- .../scala/com/wavesplatform/BlockGen.scala | 4 +- .../wavesplatform/BlockchainStubHelpers.scala | 118 ++- .../BlocksTransactionsHelpers.scala | 14 +- .../scala/com/wavesplatform/RequestGen.scala | 4 +- .../scala/com/wavesplatform/TestHelpers.scala | 2 +- .../com/wavesplatform/TransactionGen.scala | 31 +- .../account/AccountOrAliasSpecification.scala | 6 +- .../api/eth/EthRpcRouteSpec.scala | 193 +++++ .../api/http/CustomJsonMarshallerSpec.scala | 11 +- .../api/http/TraceResultJsonTest.scala | 15 +- .../api/http/requests/RequestsSpec.scala | 2 +- .../TransactionsOrderingSpecification.scala | 2 +- .../database/LevelDBWriterSpec.scala | 4 +- .../com/wavesplatform/db/WithState.scala | 3 +- .../features/FeatureProviderTest.scala | 1 + .../features/RideV5LimitsChangeTest.scala | 1 - .../BlockchainUpdaterBadReferencesTest.scala | 2 +- ...roblockSequencesSameTransactionsTest.scala | 2 +- .../BlockchainUpdaterBlockOnlyTest.scala | 2 +- .../history/BlockchainUpdaterBurnTest.scala | 4 +- ...eneratorFeeNextBlockOrMicroBlockTest.scala | 2 +- ...hainUpdaterGeneratorFeeSameBlockTest.scala | 2 +- .../BlockchainUpdaterInMemoryDiffTest.scala | 2 +- ...nUpdaterKeyAndMicroBlockConflictTest.scala | 4 +- .../BlockchainUpdaterLiquidBlockTest.scala | 2 +- ...inUpdaterMicroblockBadSignaturesTest.scala | 2 +- ...ckchainUpdaterMicroblockSunnyDayTest.scala | 2 +- ...ockchainUpdaterSponsoredFeeBlockTest.scala | 6 +- .../com/wavesplatform/history/Domain.scala | 61 +- .../history/LeasingExpirySpec.scala | 3 +- .../wavesplatform/http/AddressRouteSpec.scala | 9 +- .../http/AssetsBroadcastRouteSpec.scala | 4 +- .../wavesplatform/http/AssetsRouteSpec.scala | 12 +- .../http/DebugApiRouteSpec.scala | 18 +- .../wavesplatform/http/LeaseRouteSpec.scala | 115 ++- .../http/ProtoVersionTransactionsSpec.scala | 5 +- .../http/TransactionBroadcastSpec.scala | 347 +++++++++ .../http/TransactionsRouteSpec.scala | 713 ++++++++---------- .../wavesplatform/http/UtilsRouteSpec.scala | 13 +- .../com/wavesplatform/http/package.scala | 4 +- .../lagonaki/unit/BlockSpecification.scala | 3 +- .../unit/MicroBlockSpecification.scala | 6 +- .../wavesplatform/mining/BlockV5Test.scala | 25 +- .../mining/BlockWithMaxBaseTargetTest.scala | 3 +- .../mining/MicroBlockMinerSpec.scala | 2 + .../mining/MiningFailuresSuite.scala | 4 +- .../mining/MiningWithRewardSuite.scala | 3 +- .../network/BasicMessagesRepoSpec.scala | 2 +- .../network/LegacyFrameCodecSpec.scala | 10 +- .../network/MessageCodecSpec.scala | 10 +- .../network/MicroBlockResponseSpec.scala | 15 + .../state/BlockchainUpdaterImplSpec.scala | 19 +- .../com/wavesplatform/state/CommonSpec.scala | 3 +- .../com/wavesplatform/state/NgStateTest.scala | 2 +- .../wavesplatform/state/RollbackSpec.scala | 11 +- .../state/TransactionsByAddressSpec.scala | 2 +- .../appender/ExtensionAppenderSpec.scala | 3 +- .../diffs/AssetTransactionsDiffTest.scala | 4 +- .../diffs/BalanceDiffValidationTest.scala | 2 +- .../diffs/BlockDifferDetailedDiffTest.scala | 6 +- .../state/diffs/BlockDifferTest.scala | 4 +- .../state/diffs/CommonValidationTest.scala | 2 +- .../diffs/CommonValidationTimeTest.scala | 2 +- .../CreateAliasTransactionDiffTest.scala | 6 +- .../state/diffs/DataTransactionDiffTest.scala | 2 +- .../diffs/ExchangeTransactionDiffTest.scala | 9 +- .../diffs/GenesisTransactionDiffTest.scala | 2 +- .../MassTransferTransactionDiffTest.scala | 2 +- .../diffs/PaymentTransactionDiffTest.scala | 2 +- .../diffs/ReissueTransactionDiffTest.scala | 2 +- .../state/diffs/ScriptsCountTest.scala | 2 +- .../diffs/SetScriptTransactionDiffTest.scala | 4 +- .../state/diffs/SponsorshipDiffTest.scala | 4 +- .../TransactionValidationErrorPrintTest.scala | 2 +- ...nDiffTest.scala => TransferDiffTest.scala} | 6 +- .../state/diffs/ci/BigIntInvokeTest.scala | 17 +- .../state/diffs/ci/CallableV4DiffTest.scala | 54 +- .../state/diffs/ci/CallableV5LimitTest.scala | 11 +- .../diffs/ci/DAppDataEntryTypeTest.scala | 13 +- .../diffs/ci/IllegalAddressChainIdTest.scala | 17 +- .../ci/InvokeActionsAvailabilityTest.scala | 8 +- .../state/diffs/ci/InvokeActionsFeeTest.scala | 31 +- .../diffs/ci/InvokeAssetChecksTest.scala | 40 +- .../diffs/ci/InvokeDataEntriesBytesTest.scala | 7 +- .../diffs/ci/InvokeFeeMultiplierTest.scala | 21 +- .../ci/InvokePaymentsAvailabilityTest.scala | 8 +- .../diffs/ci/InvokePaymentsLimitTest.scala | 10 +- .../ci/InvokeScriptTransactionDiffTest.scala | 257 +++---- .../diffs/ci/InvokeScriptV5LimitsTest.scala | 97 +-- .../state/diffs/ci/LeaseActionDiffTest.scala | 14 +- .../state/diffs/ci/ListParamInvokeTest.scala | 40 +- .../diffs/ci/MultiPaymentInvokeDiffTest.scala | 9 +- .../state/diffs/ci/OverdraftTest.scala | 19 +- .../diffs/ci/ScriptTransferByAliasTest.scala | 8 +- .../state/diffs/ci/package.scala | 13 +- ...ansactionCrosscontractInvokeDiffTest.scala | 30 +- .../ci/sync/SyncDAppBalanceCheckTest.scala | 9 +- .../ci/sync/SyncDAppComplexityCountTest.scala | 20 +- .../sync/SyncDAppForbidOldVersionsTest.scala | 10 +- .../ci/sync/SyncDAppMultiVersionTest.scala | 8 +- .../diffs/ci/sync/SyncDAppRecursionTest.scala | 61 +- .../diffs/freecall/InvokeExpressionTest.scala | 12 +- .../wavesplatform/state/diffs/package.scala | 2 +- .../diffs/smart/DiffComplexityCountTest.scala | 8 +- .../diffs/smart/SmartAccountFeeTest.scala | 30 +- .../diffs/smart/SmartAssetEvalTest.scala | 2 +- .../diffs/smart/eth/EthereumInvokeTest.scala | 104 +++ .../smart/eth/EthereumTransferSmartTest.scala | 119 +++ .../SigVerifyPerformanceTest.scala | 2 +- .../diffs/smart/predef/AddressTest.scala | 3 +- .../smart/predef/BrokenUnicodeTest.scala | 19 +- .../smart/predef/CommonFunctionsTest.scala | 11 +- .../smart/predef/ContextFunctionsTest.scala | 72 +- .../predef/DAppVerifierRestrictionsTest.scala | 1 - .../predef/GenericRideActivationTest.scala | 14 +- .../predef/IsDataStorageUntouchedTest.scala | 18 +- .../ObsoleteTransactionBindingsTest.scala | 8 +- .../smart/predef/ScriptVersionsTest.scala | 3 +- .../predef/TransactionBindingsTest.scala | 39 +- .../state/diffs/smart/predef/package.scala | 41 +- .../AddressFromRecipientScenarioTest.scala | 4 +- .../smart/scenarios/BalancesV4Test.scala | 16 +- .../smart/scenarios/MultiSig2of3Test.scala | 4 +- ...NotaryControlledTransferScenarioTest.scala | 2 +- .../OneProofForNonScriptedAccountTest.scala | 4 +- .../scenarios/OnlyTransferIsAllowedTest.scala | 3 +- .../smart/scenarios/OracleDataTest.scala | 2 +- .../smart/scenarios/ScriptedSponsorTest.scala | 2 +- .../TransactionFieldAccessTest.scala | 3 +- ...teReaderEffectiveBalancePropertyTest.scala | 2 +- .../EthereumTransactionRollbackSpec.scala | 71 ++ .../wavesplatform/{ => test}/TestTime.scala | 4 +- .../BurnTransactionSpecification.scala | 5 +- .../transaction/ChainIdSpecification.scala | 2 +- .../CreateAliasTransactionSpecification.scala | 3 +- .../DataTransactionSpecification.scala | 3 +- .../ExchangeTransactionSpecification.scala | 5 +- .../GenesisTransactionSpecification.scala | 2 +- .../InvokeScriptComplexitySpec.scala | 7 +- ...InvokeScriptTransactionSpecification.scala | 104 +-- .../IssueTransactionV1Specification.scala | 5 +- .../IssueTransactionV2Specification.scala | 3 +- .../LeaseCancelTransactionSpecification.scala | 2 +- .../LeaseTransactionSpecification.scala | 9 +- ...MassTransferTransactionSpecification.scala | 3 +- .../transaction/OrderSpecification.scala | 5 +- .../ProtoVersionTransactionsSpec.scala | 11 +- .../ReissueTransactionV1Specification.scala | 5 +- .../SponsorFeeTransactionSpecification.scala | 7 +- .../TransferTransactionV1Specification.scala | 8 +- .../TransferTransactionV2Specification.scala | 3 +- .../wavesplatform/transaction/TxHelpers.scala | 35 +- .../assets/Erc20NoConflictIssueTest.scala | 43 ++ .../assets/exchange/EthOrderSpec.scala | 255 +++++++ .../smart/EthereumTransactionSpec.scala | 539 +++++++++++++ .../smart/VerifierSpecification.scala | 1 - .../smart/script/ScriptCompilerV1Test.scala | 3 +- .../smart/script/ScriptReaderTest.scala | 2 +- .../smart/script/ScriptV1Test.scala | 3 +- .../wavesplatform/utils/DiffMatchers.scala | 25 + .../wavesplatform/utils/EmptyBlockchain.scala | 8 +- .../com/wavesplatform/utils/EthHelpers.scala | 86 +++ .../wavesplatform/utx/UtxFailedTxsSpec.scala | 3 +- .../utx/UtxPoolSpecification.scala | 39 +- .../utx/UtxPriorityPoolSpecification.scala | 1 + project/Dependencies.scala | 35 +- .../repl/node/ErrorMessageEnvironment.scala | 1 + .../v1/repl/node/http/WebEnvironment.scala | 64 +- .../http/response/ChainDependentMapper.scala | 2 +- .../node/http/response/ImplicitMappings.scala | 4 + .../http/response/TransferTxSerializer.scala | 4 +- 408 files changed, 7628 insertions(+), 3787 deletions(-) create mode 100644 benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala create mode 100644 grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/GRPCBroadcastSpec.scala delete mode 100644 node-generator/devnet.conf create mode 100644 node-it/src/test/scala/com/wavesplatform/test/Signed.scala create mode 100644 node/src/main/scala/com/wavesplatform/MetamaskBootstrap.scala delete mode 100644 node/src/main/scala/com/wavesplatform/account/Address.scala delete mode 100644 node/src/main/scala/com/wavesplatform/account/AddressOrAlias.scala delete mode 100644 node/src/main/scala/com/wavesplatform/account/Alias.scala create mode 100644 node/src/main/scala/com/wavesplatform/account/Recipient.scala create mode 100644 node/src/main/scala/com/wavesplatform/api/common/TransactionMeta.scala create mode 100644 node/src/main/scala/com/wavesplatform/api/http/JsonFormats.scala create mode 100644 node/src/main/scala/com/wavesplatform/api/http/eth/EthRpcRoute.scala create mode 100644 node/src/main/scala/com/wavesplatform/api/http/eth/Type.scala create mode 100644 node/src/main/scala/com/wavesplatform/consensus/nxt/api/http/NxtConsensusApiRoute.scala create mode 100644 node/src/main/scala/com/wavesplatform/state/diffs/EthereumTransactionDiff.scala create mode 100644 node/src/main/scala/com/wavesplatform/state/diffs/TransferDiff.scala delete mode 100644 node/src/main/scala/com/wavesplatform/state/diffs/TransferTransactionDiff.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/ABIConverter.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/EthereumTransaction.scala rename node/src/main/scala/com/wavesplatform/transaction/{LegacyPBSwitch.scala => PBSince.scala} (55%) delete mode 100644 node/src/main/scala/com/wavesplatform/transaction/ProtobufOnly.scala delete mode 100644 node/src/main/scala/com/wavesplatform/transaction/SignedTransaction.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/TransactionType.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/assets/exchange/EthOrders.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/utils/EthConverters.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/utils/EthTxGenerator.scala create mode 100644 node/src/main/scala/com/wavesplatform/transaction/utils/Signed.scala create mode 100644 node/src/main/scala/com/wavesplatform/utils/EthEncoding.scala create mode 100644 node/src/test/scala/com/wavesplatform/api/eth/EthRpcRouteSpec.scala create mode 100644 node/src/test/scala/com/wavesplatform/http/TransactionBroadcastSpec.scala create mode 100644 node/src/test/scala/com/wavesplatform/network/MicroBlockResponseSpec.scala rename node/src/test/scala/com/wavesplatform/state/diffs/{TransferTransactionDiffTest.scala => TransferDiffTest.scala} (95%) create mode 100644 node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumInvokeTest.scala create mode 100644 node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumTransferSmartTest.scala create mode 100644 node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala rename node/src/test/scala/com/wavesplatform/{ => test}/TestTime.scala (74%) create mode 100644 node/src/test/scala/com/wavesplatform/transaction/assets/Erc20NoConflictIssueTest.scala create mode 100644 node/src/test/scala/com/wavesplatform/transaction/assets/exchange/EthOrderSpec.scala create mode 100644 node/src/test/scala/com/wavesplatform/transaction/smart/EthereumTransactionSpec.scala create mode 100644 node/src/test/scala/com/wavesplatform/utils/DiffMatchers.scala create mode 100644 node/src/test/scala/com/wavesplatform/utils/EthHelpers.scala diff --git a/.gitattributes b/.gitattributes index 217cc08e29b..ef36eaeb07a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,4 @@ +*.sh text eol=lf +*.scala text eol=lf +* text=auto node/src/main/resources/swagger-ui/* linguist-vendored diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala new file mode 100644 index 00000000000..385d0a94019 --- /dev/null +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/AddressFromPublicKeyBenchmark.scala @@ -0,0 +1,38 @@ +package com.wavesplatform.lang.v1 +import java.util.concurrent.TimeUnit + +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.lang.directives.DirectiveSet +import com.wavesplatform.lang.directives.values.{Account, Expression, V6} +import com.wavesplatform.lang.utils.lazyContexts +import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.curve25519 +import com.wavesplatform.lang.v1.compiler.Terms.EXPR +import com.wavesplatform.lang.v1.compiler.TestCompiler +import com.wavesplatform.lang.v1.evaluator.EvaluatorV2 +import com.wavesplatform.utils.EthHelpers +import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.infra.Blackhole + +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@BenchmarkMode(Array(Mode.AverageTime)) +@Threads(1) +@Fork(1) +@Warmup(iterations = 10, time = 1) +@Measurement(iterations = 10, time = 1) +class AddressFromPublicKeyBenchmark { + @Benchmark + def addressFromPublicKeyWaves(s: PkSt, bh: Blackhole): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.exprWaves, V6)) + + @Benchmark + def addressFromPublicKeyEth(s: PkSt, bh: Blackhole): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.exprEth, V6)) +} + +@State(Scope.Benchmark) +class PkSt extends EthHelpers { + val ds = DirectiveSet(V6, Account, Expression).fold(null, identity) + val ctx = lazyContexts(ds).value().evaluationContext(EnvironmentFunctionsBenchmark.environment) + + val wavesPk = ByteStr(curve25519.generateKeypair._2) + val exprWaves = TestCompiler(V6).compileExpression(s"addressFromPublicKey(base58'$wavesPk')").expr.asInstanceOf[EXPR] + val exprEth = TestCompiler(V6).compileExpression(s"addressFromPublicKey(base58'$TestEthPublicKey')").expr.asInstanceOf[EXPR] +} diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala index 14545236229..8d603802592 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala @@ -6,6 +6,7 @@ import java.util.concurrent.{ThreadLocalRandom, TimeUnit} import cats.Id import cats.syntax.bifunctor._ import com.wavesplatform.account +import com.wavesplatform.account.PublicKey import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.crypto.Curve25519 @@ -85,9 +86,6 @@ class EnvironmentFunctionsBenchmark { Curve25519.verify(signature, message, publicKey) } - @Benchmark - def addressFromPublicKey_test(): ByteStr = randomAddress - @Benchmark def addressFromString(st: AddressFromString, bh: Blackhole): Unit = { val i = Random.nextInt(100) @@ -102,7 +100,7 @@ object EnvironmentFunctionsBenchmark { val DataBytesLength = 512 val SeedBytesLength = 128 - val defaultEnvironment: Environment[Id] = new Environment[Id] { + val environment: Environment[Id] = new Environment[Id] { override def height: Long = 1 override def chainId: Byte = ChainId override def inputEntity: Environment.InputEntity = ??? @@ -128,6 +126,10 @@ object EnvironmentFunctionsBenchmark { _.toString, address => Address(ByteStr(address.bytes)) ) + + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = + Right(Address(ByteStr(PublicKey(publicKey).toAddress.bytes))) + override def accountScript(addressOrAlias: Recipient): Option[Script] = ??? override def callScript( dApp: Address, @@ -139,7 +141,7 @@ object EnvironmentFunctionsBenchmark { ): Coeval[(Either[ValidationError, EVALUATED], Int)] = ??? } - val environmentFunctions = new EnvironmentFunctions(defaultEnvironment) + val environmentFunctions = new EnvironmentFunctions(environment) val string32Kb: String = "FEDCBA9876543210" * (32 * 1024 / 16) @@ -167,7 +169,7 @@ class AddressFromString { val ctx: EvaluationContext[Environment, Id] = WavesContext .build(Global, DirectiveSet(V4, Account, DApp).explicitGet()) - .evaluationContext(defaultEnvironment) + .evaluationContext(environment) val expr: Array[EXPR] = (1 to 100).map { _ => diff --git a/build-with-docker.sh b/build-with-docker.sh index c2760061c4b..6f33e4d9c71 100755 --- a/build-with-docker.sh +++ b/build-with-docker.sh @@ -11,8 +11,7 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" USER=$(id -u) GROUP=$(id -g) -docker run --mount type=bind,source="$DIR",target=/src -i mozilla/sbt:8u232_1.3.8 /bin/sh -c " +docker run --mount type=bind,source="$DIR",target=/src -it --rm wavesplatform/sbt:8u302-b08_1.5.5_2.13.6 /bin/sh -c " cd /src && - COURSIER_CACHE=\"$DIR/target/docker/coursier\" sbt \"-Dsbt.boot.directory=$DIR/target/docker/sbt_cache\" \"set ThisBuild/network := $NETWORK\" packageAll && - chown -R $USER:$GROUP . -" + COURSIER_CACHE=/src/target/docker/coursier sbt -Dsbt.boot.directory=/src/target/docker/sbt_cache -Dsbt.server.forcestart=true --batch \"set ThisBuild/network := $NETWORK\" packageAll && + chown -R $USER:$GROUP ." diff --git a/build.sbt b/build.sbt index ce39e83ba71..820314db4b5 100644 --- a/build.sbt +++ b/build.sbt @@ -61,7 +61,7 @@ lazy val `lang-doc` = project .dependsOn(`lang-jvm`) .settings( Compile / sourceGenerators += Tasks.docSource, - libraryDependencies ++= Seq("com.github.spullara.mustache.java" % "compiler" % "0.9.5") ++ Dependencies.test + libraryDependencies ++= Seq("com.github.spullara.mustache.java" % "compiler" % "0.9.10") ++ Dependencies.test ) lazy val node = project.dependsOn(`lang-jvm`, `lang-testkit` % "test") @@ -111,7 +111,9 @@ lazy val root = (project in file(".")) node, `node-it`, `node-generator`, - benchmark + benchmark, + `repl-js`, + `repl-jvm` ) inScope(Global)( @@ -131,8 +133,6 @@ inScope(Global)( "-language:postfixOps", "-Ywarn-unused:-implicits", "-Xlint", - "-opt:l:inline", - "-opt-inline-from:**", "-Wconf:cat=deprecation&site=com.wavesplatform.api.grpc.*:s", // Ignore gRPC warnings "-Wconf:cat=deprecation&site=com.wavesplatform.protobuf.transaction.InvokeScriptResult.*:s", // Ignore deprecated argsBytes "-Wconf:cat=deprecation&site=com.wavesplatform.state.InvokeScriptResult.*:s" @@ -153,7 +153,10 @@ inScope(Global)( testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"), testOptions += Tests.Setup(_ => sys.props("sbt-testing") = "true"), network := Network(sys.props.get("network")), - resolvers += Resolver.sonatypeRepo("snapshots"), + resolvers ++= Seq( + Resolver.sonatypeRepo("snapshots"), + Resolver.mavenLocal + ), Compile / doc / sources := Seq.empty, Compile / packageDoc / publishArtifact := false ) @@ -184,6 +187,7 @@ checkPRRaw := Def (`grpc-server` / Test / test).value (node / Test / test).value (`repl-js` / Compile / fastOptJS).value + (`node-it` / Test / compile).value } ) .value diff --git a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCErrors.scala b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCErrors.scala index b5dd4847ca3..57403b46a04 100644 --- a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCErrors.scala +++ b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCErrors.scala @@ -15,7 +15,7 @@ object GRPCErrors { def toStatusException(api: ApiError): StatusException = { val code = api match { - case TransactionDoesNotExist | AliasDoesNotExist(_) | BlockDoesNotExist | MissingSenderPrivateKey | DataKeyDoesNotExist => + case TransactionDoesNotExist | BlockDoesNotExist | MissingSenderPrivateKey | DataKeyDoesNotExist => Status.NOT_FOUND case _ => Status.INVALID_ARGUMENT } diff --git a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCServerExtension.scala b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCServerExtension.scala index 74e78901e95..fc508dbd6ce 100644 --- a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCServerExtension.scala +++ b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/GRPCServerExtension.scala @@ -2,6 +2,8 @@ package com.wavesplatform.api.grpc import java.net.InetSocketAddress +import scala.concurrent.Future + import com.wavesplatform.extensions.{Extension, Context => ExtensionContext} import com.wavesplatform.settings.GRPCSettings import com.wavesplatform.utils.ScorexLogging @@ -11,15 +13,13 @@ import monix.execution.Scheduler import net.ceedubs.ficus.Ficus._ import net.ceedubs.ficus.readers.ArbitraryTypeReader._ -import scala.concurrent.Future - class GRPCServerExtension(context: ExtensionContext) extends Extension with ScorexLogging { private implicit val apiScheduler: Scheduler = Scheduler(context.actorSystem.dispatcher) private val settings = context.settings.config.as[GRPCSettings]("waves.grpc") private val bindAddress = new InetSocketAddress(settings.host, settings.port) private val server: Server = NettyServerBuilder .forAddress(bindAddress) - .addService(TransactionsApiGrpc.bindService(new TransactionsApiGrpcImpl(context.transactionsApi), apiScheduler)) + .addService(TransactionsApiGrpc.bindService(new TransactionsApiGrpcImpl(context.blockchain, context.transactionsApi), apiScheduler)) .addService(BlocksApiGrpc.bindService(new BlocksApiGrpcImpl(context.blocksApi), apiScheduler)) .addService(AccountsApiGrpc.bindService(new AccountsApiGrpcImpl(context.accountsApi), apiScheduler)) .addService(AssetsApiGrpc.bindService(new AssetsApiGrpcImpl(context.assetsApi, context.accountsApi), apiScheduler)) diff --git a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/TransactionsApiGrpcImpl.scala b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/TransactionsApiGrpcImpl.scala index f40ad901f5a..d00969ba138 100644 --- a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/TransactionsApiGrpcImpl.scala +++ b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/TransactionsApiGrpcImpl.scala @@ -1,21 +1,22 @@ package com.wavesplatform.api.grpc +import scala.concurrent.Future + import com.wavesplatform.account.AddressScheme -import com.wavesplatform.api.common.CommonTransactionsApi -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} import com.wavesplatform.protobuf._ import com.wavesplatform.protobuf.transaction._ import com.wavesplatform.protobuf.utils.PBImplicitConversions.PBRecipientImplicitConversionOps -import com.wavesplatform.state.{InvokeScriptResult => VISR} -import com.wavesplatform.transaction.Authorized -import io.grpc.stub.StreamObserver +import com.wavesplatform.state.{Blockchain, InvokeScriptResult => VISR} +import com.wavesplatform.transaction.{Authorized, EthereumTransaction} +import com.wavesplatform.transaction.TxValidationError.GenericError import io.grpc.{Status, StatusRuntimeException} +import io.grpc.stub.StreamObserver import monix.execution.Scheduler import monix.reactive.Observable -import scala.concurrent.Future - -class TransactionsApiGrpcImpl(commonApi: CommonTransactionsApi)(implicit sc: Scheduler) extends TransactionsApiGrpc.TransactionsApi { +class TransactionsApiGrpcImpl(blockchain: Blockchain, commonApi: CommonTransactionsApi)(implicit sc: Scheduler) + extends TransactionsApiGrpc.TransactionsApi { override def getTransactions(request: TransactionsRequest, responseObserver: StreamObserver[TransactionResponse]): Unit = responseObserver.interceptErrors { @@ -25,6 +26,7 @@ class TransactionsApiGrpcImpl(commonApi: CommonTransactionsApi)(implicit sc: Sch case Some(subject) => val recipientAddrOrAlias = subject .toAddressOrAlias(AddressScheme.current.chainId) + .flatMap(blockchain.resolveAlias(_)) .fold(e => throw new IllegalArgumentException(e.toString), identity) val maybeSender = Option(request.sender) @@ -83,7 +85,7 @@ class TransactionsApiGrpcImpl(commonApi: CommonTransactionsApi)(implicit sc: Sch val result = Observable(request.transactionIds: _*) .flatMap(txId => Observable.fromIterable(commonApi.transactionById(txId.toByteStr))) .collect { - case CommonTransactionsApi.TransactionMeta.Invoke(_, transaction, _, invokeScriptResult) => + case TransactionMeta.Invoke(_, transaction, _, invokeScriptResult) => InvokeScriptResultResponse.of(Some(PBTransactions.protobuf(transaction)), invokeScriptResult.map(VISR.toPB)) } @@ -113,17 +115,18 @@ class TransactionsApiGrpcImpl(commonApi: CommonTransactionsApi)(implicit sc: Sch override def broadcast(tx: PBSignedTransaction): Future[PBSignedTransaction] = (for { - maybeTx <- Future(tx.toVanilla) - vtx <- maybeTx.toFuture - result <- commonApi.broadcastTransaction(vtx) - _ <- result.resultE.toFuture + vtxEither <- Future(tx.toVanilla) // Intercept runtime errors + vtx <- vtxEither.toFuture + _ <- Either.cond(!vtx.isInstanceOf[EthereumTransaction], (), GenericError("ETH transactions should not be broadcasted over gRPC")).toFuture + result <- commonApi.broadcastTransaction(vtx) + _ <- result.resultE.toFuture // Check for success } yield tx).wrapErrors } private object TransactionsApiGrpcImpl { def toTransactionResponse(meta: TransactionMeta): TransactionResponse = { - val transactionId = meta.transaction.id().toByteString - val status = if (meta.succeeded) ApplicationStatus.SUCCEEDED else ApplicationStatus.SCRIPT_EXECUTION_FAILED + val transactionId = meta.transaction.id().toByteString + val status = if (meta.succeeded) ApplicationStatus.SUCCEEDED else ApplicationStatus.SCRIPT_EXECUTION_FAILED val invokeScriptResult = meta match { case TransactionMeta.Invoke(_, _, _, r) => r.map(VISR.toPB) case _ => None diff --git a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/package.scala b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/package.scala index a7d2a40bb63..f9029540577 100644 --- a/grpc-server/src/main/scala/com/wavesplatform/api/grpc/package.scala +++ b/grpc-server/src/main/scala/com/wavesplatform/api/grpc/package.scala @@ -22,7 +22,7 @@ package object grpc extends ScorexLogging { } implicit class PBSignedTransactionConversions(val tx: PBSignedTransaction) extends AnyVal { - def toVanilla: Either[ValidationError, VanillaTransaction] = PBTransactions.vanilla(tx) + def toVanilla: Either[ValidationError, VanillaTransaction] = PBTransactions.vanilla(tx, unsafe = false) } implicit class VanillaHeaderConversionOps(val header: vb.BlockHeader) extends AnyVal { diff --git a/grpc-server/src/main/scala/com/wavesplatform/events/events.scala b/grpc-server/src/main/scala/com/wavesplatform/events/events.scala index 40314d39bbd..112125107fe 100644 --- a/grpc-server/src/main/scala/com/wavesplatform/events/events.scala +++ b/grpc-server/src/main/scala/com/wavesplatform/events/events.scala @@ -1,8 +1,5 @@ package com.wavesplatform.events -import scala.collection.mutable -import scala.collection.mutable.ArrayBuffer - import cats.Monoid import cats.syntax.monoid._ import com.google.protobuf.ByteString @@ -10,20 +7,27 @@ import com.wavesplatform.account.{Address, AddressOrAlias, Alias, PublicKey} import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ -import com.wavesplatform.events.StateUpdate.{AssetStateUpdate, BalanceUpdate, DataEntryUpdate, LeaseUpdate, LeasingBalanceUpdate} import com.wavesplatform.events.StateUpdate.LeaseUpdate.LeaseStatus +import com.wavesplatform.events.StateUpdate.{AssetStateUpdate, BalanceUpdate, DataEntryUpdate, LeaseUpdate, LeasingBalanceUpdate} import com.wavesplatform.events.protobuf.TransactionMetadata +import com.wavesplatform.events.protobuf.TransactionMetadata.{EthereumMetadata, TransferMetadata} +import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.protobuf._ -import com.wavesplatform.protobuf.transaction.{PBAmounts, PBTransactions} -import com.wavesplatform.state.{AccountDataInfo, AssetDescription, AssetScriptInfo, Blockchain, DataEntry, Diff, DiffToStateApplier, EmptyDataEntry, Height, InvokeScriptResult, LeaseBalance} +import com.wavesplatform.protobuf.transaction.InvokeScriptResult.Call.Argument +import com.wavesplatform.protobuf.transaction.{PBAmounts, PBTransactions, InvokeScriptResult => PBInvokeScriptResult} import com.wavesplatform.state.DiffToStateApplier.PortfolioUpdates import com.wavesplatform.state.diffs.BlockDiffer.DetailedDiff +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike import com.wavesplatform.state.reader.CompositeBlockchain -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxAmount} +import com.wavesplatform.state._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.lease.LeaseTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} +import com.wavesplatform.transaction.{Asset, EthereumTransaction, GenesisTransaction, TxAmount} + +import scala.collection.mutable +import scala.collection.mutable.ArrayBuffer final case class StateUpdate( balances: Seq[BalanceUpdate], @@ -138,8 +142,8 @@ object StateUpdate { case object Inactive extends LeaseStatus } - import com.wavesplatform.events.protobuf.StateUpdate.{LeaseUpdate => PBLeaseUpdate} import com.wavesplatform.events.protobuf.StateUpdate.LeaseUpdate.{LeaseStatus => PBLeaseStatus} + import com.wavesplatform.events.protobuf.StateUpdate.{LeaseUpdate => PBLeaseUpdate} def fromPB(v: PBLeaseUpdate): LeaseUpdate = { LeaseUpdate( @@ -183,8 +187,8 @@ object StateUpdate { object AssetStateUpdate { final case class AssetDetails(assetId: ByteStr, desc: AssetDescription) - import com.wavesplatform.events.protobuf.StateUpdate.{AssetDetails => PBAssetDetails, AssetStateUpdate => PBAssetStateUpdate} import com.wavesplatform.events.protobuf.StateUpdate.AssetDetails.{AssetScriptInfo => PBAssetScriptInfo} + import com.wavesplatform.events.protobuf.StateUpdate.{AssetDetails => PBAssetDetails, AssetStateUpdate => PBAssetStateUpdate} def fromPB(self: PBAssetStateUpdate): AssetStateUpdate = { @@ -400,12 +404,32 @@ object StateUpdate { } private[this] def transactionsMetadata(blockchain: Blockchain, diff: Diff): Seq[TransactionMetadata] = { + implicit class AddressResolver(addr: AddressOrAlias) { + def resolve: Address = blockchain.resolveAlias(addr).explicitGet() + } + + def invokeScriptLikeToMetadata(ist: InvokeScriptTransactionLike) = { + + def argumentToPB(arg: Terms.EXPR): Argument.Value = arg match { + case Terms.CONST_LONG(t) => Argument.Value.IntegerValue(t) + case bs: Terms.CONST_BYTESTR => Argument.Value.BinaryValue(bs.bs.toByteString) + case str: Terms.CONST_STRING => Argument.Value.StringValue(str.s) + case Terms.CONST_BOOLEAN(b) => Argument.Value.BooleanValue(b) + case Terms.ARR(xs) => Argument.Value.List(Argument.List(xs.map(x => Argument(argumentToPB(x))))) + case _ => Argument.Value.Empty + } + + TransactionMetadata.InvokeScriptMetadata( + ist.dApp.resolve.toByteString, + ist.funcCall.function.funcName, + ist.funcCall.args.map(x => PBInvokeScriptResult.Call.Argument(argumentToPB(x))), + ist.payments.map(p => Amount(PBAmounts.toPBAssetId(p.assetId), p.amount)), + diff.scriptResults.get(ist.id()).map(InvokeScriptResult.toPB) + ) + } + diff.transactions.values .map[TransactionMetadata.Metadata] { tx => - implicit class AddressResolver(addr: AddressOrAlias) { - def resolve: Address = blockchain.resolveAlias(addr).explicitGet() - } - tx.transaction match { case tt: TransferTransaction => TransactionMetadata.Metadata.Transfer(TransactionMetadata.TransferMetadata(tt.recipient.resolve.toByteString)) @@ -414,19 +438,24 @@ object StateUpdate { TransactionMetadata.Metadata.MassTransfer(TransactionMetadata.MassTransferMetadata(mtt.transfers.map(_.address.resolve.toByteString))) case lt: LeaseTransaction => - TransactionMetadata.Metadata.LeaseMeta(TransactionMetadata.LeaseMetadata(lt.recipient.resolve.toByteString)) + TransactionMetadata.Metadata.Lease(TransactionMetadata.LeaseMetadata(lt.recipient.resolve.toByteString)) case ist: InvokeScriptTransaction => - import com.wavesplatform.protobuf.transaction.InvokeScriptResult.Call.Argument - TransactionMetadata.Metadata.InvokeScript( - TransactionMetadata.InvokeScriptMetadata( - ist.dAppAddressOrAlias.resolve.toByteString, - ist.funcCall.function.funcName, - ist.funcCall.args.map(x => Argument(InvokeScriptResult.rideExprToPB(x))), - ist.payments.map(p => Amount(PBAmounts.toPBAssetId(p.assetId), p.amount)), - diff.scriptResults.get(ist.id()).map(InvokeScriptResult.toPB) - ) - ) + TransactionMetadata.Metadata.InvokeScript(invokeScriptLikeToMetadata(ist)) + + case et: EthereumTransaction => + val metadataOpt: Option[EthereumMetadata] = et.payload match { + case EthereumTransaction.Transfer(_, _, recipient) => + Some(EthereumMetadata(et.senderAddress().toByteString, EthereumMetadata.Action.Transfer(TransferMetadata(recipient.toByteString)))) + + case inv @ EthereumTransaction.Invocation(_, _) => + for { + invoke <- inv.toInvokeScriptLike(et, blockchain).toOption + } yield EthereumMetadata(et.senderAddress().toByteString, EthereumMetadata.Action.Invoke(invokeScriptLikeToMetadata(invoke))) + } + metadataOpt + .map(TransactionMetadata.Metadata.Ethereum) + .getOrElse(TransactionMetadata.Metadata.Empty) case _ => TransactionMetadata.Metadata.Empty diff --git a/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/GRPCBroadcastSpec.scala b/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/GRPCBroadcastSpec.scala new file mode 100644 index 00000000000..b062a1d1ef0 --- /dev/null +++ b/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/GRPCBroadcastSpec.scala @@ -0,0 +1,127 @@ +package com.wavesplatform.api.grpc.test + +import scala.concurrent.{Await, Future} +import scala.concurrent.duration.Duration + +import com.wavesplatform.account.Address +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.test.{FlatSpec, TestTime} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.BlockchainStubHelpers +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} +import com.wavesplatform.api.grpc.TransactionsApiGrpcImpl +import com.wavesplatform.block.Block +import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.lang.ValidationError +import com.wavesplatform.protobuf.transaction.PBTransactions +import com.wavesplatform.state.{Blockchain, Height} +import com.wavesplatform.transaction.{Asset, CreateAliasTransaction, Transaction, TxHelpers, TxVersion} +import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} +import com.wavesplatform.transaction.smart.script.trace.TracedResult +import com.wavesplatform.transaction.TransactionType.TransactionType +import com.wavesplatform.transaction.utils.EthTxGenerator +import com.wavesplatform.utils.{DiffMatchers, EthHelpers, EthSetChainId} +import io.grpc.StatusException +import monix.execution.Scheduler +import monix.reactive.Observable +import org.scalamock.scalatest.PathMockFactory +import org.scalatest.BeforeAndAfterAll + +class GRPCBroadcastSpec + extends FlatSpec + with BeforeAndAfterAll + with PathMockFactory + with BlockchainStubHelpers + with EthHelpers + with EthSetChainId + with DiffMatchers { + // Fake NTP time + val FakeTime: TestTime = TestTime(100) + + "GRPC broadcast" should "accept Exchange with ETH orders" in { + val ethBuyOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xe5ff562bfb0296e95b631365599c87f1c5002597bf56a131f289765275d2580f5344c62999404c37cd858ea037328ac91eca16ad1ce69c345ebb52fde70b66251c" + ) + ) + + val ethSellOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.SELL, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xc8ba2bdafd27742546b3be34883efc51d6cdffbb235798d7b51876c6854791f019b0522d7a39b6f2087cba46ae86919b71a2d9d7920dfc8e00246d8f02a258f21b" + ) + ) + + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + } + + val transaction = TxHelpers.exchange(ethBuyOrder, ethSellOrder, TxVersion.V3, 100) + FakeTime.setTime(transaction.timestamp) + blockchain.assertBroadcast(transaction) + } + + it should "reject eth transactions" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.defaultEthAddress, Waves) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.SynchronousCalls) + } + + val transaction = EthTxGenerator.generateEthTransfer(TxHelpers.defaultEthSigner, TxHelpers.secondAddress, 10, Waves) + FakeTime.setTime(transaction.timestamp) + intercept[Exception](blockchain.assertBroadcast(transaction)).toString should include("ETH transactions should not be broadcasted over gRPC") + } + + //noinspection NotImplementedCode + implicit class BlockchainBroadcastExt(blockchain: Blockchain) { + def grpcTxApi: TransactionsApiGrpcImpl = + new TransactionsApiGrpcImpl(blockchain, new CommonTransactionsApi { + def aliasesOfAddress(address: Address): Observable[(Height, CreateAliasTransaction)] = ??? + def transactionById(txId: ByteStr): Option[TransactionMeta] = ??? + def unconfirmedTransactions: Seq[Transaction] = ??? + def unconfirmedTransactionById(txId: ByteStr): Option[Transaction] = ??? + def calculateFee(tx: Transaction): Either[ValidationError, (Asset, Long, Long)] = ??? + def transactionsByAddress( + subject: Address, + sender: Option[Address], + transactionTypes: Set[TransactionType], + fromId: Option[ByteStr] + ): Observable[TransactionMeta] = ??? + def transactionProofs(transactionIds: List[ByteStr]): List[Block.TransactionProof] = ??? + def broadcastTransaction(tx: Transaction): Future[TracedResult[ValidationError, Boolean]] = { + val differ = blockchain.stub.transactionDiffer(FakeTime) + Future.successful(differ(tx).map(_ => true)) + } + })(Scheduler.global) + + @throws[StatusException]("on failed broadcast") + def assertBroadcast(tx: Transaction): Unit = { + Await.result(grpcTxApi.broadcast(PBTransactions.protobuf(tx)), Duration.Inf) + } + } +} diff --git a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala index 5ca391f71cc..02d7fad61d5 100644 --- a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala +++ b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala @@ -2,10 +2,6 @@ package com.wavesplatform.events import java.nio.file.Files -import scala.concurrent.{Await, Promise} -import scala.concurrent.duration._ -import scala.util.Random - import com.google.common.primitives.Longs import com.google.protobuf.ByteString import com.wavesplatform.account.{Address, KeyPair} @@ -13,13 +9,13 @@ import com.wavesplatform.api.common.CommonBlocksApi import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ import com.wavesplatform.db.WithDomain -import com.wavesplatform.events.StateUpdate.{AssetInfo, AssetStateUpdate, BalanceUpdate, DataEntryUpdate, LeaseUpdate, LeasingBalanceUpdate} import com.wavesplatform.events.StateUpdate.LeaseUpdate.LeaseStatus +import com.wavesplatform.events.StateUpdate.{AssetInfo, AssetStateUpdate, BalanceUpdate, DataEntryUpdate, LeaseUpdate, LeasingBalanceUpdate} import com.wavesplatform.events.api.grpc.protobuf.{GetBlockUpdatesRangeRequest, SubscribeEvent, SubscribeRequest} -import com.wavesplatform.events.protobuf.{BlockchainUpdated => PBBlockchainUpdated} import com.wavesplatform.events.protobuf.BlockchainUpdated.Rollback.RollbackType import com.wavesplatform.events.protobuf.BlockchainUpdated.Update import com.wavesplatform.events.protobuf.serde._ +import com.wavesplatform.events.protobuf.{BlockchainUpdated => PBBlockchainUpdated} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain import com.wavesplatform.lang.v1.FunctionHeader @@ -28,15 +24,16 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.protobuf._ import com.wavesplatform.protobuf.block.PBBlocks import com.wavesplatform.protobuf.transaction.DataTransactionData.DataEntry -import com.wavesplatform.protobuf.transaction.InvokeScriptResult.{Call, Invocation} import com.wavesplatform.protobuf.transaction.InvokeScriptResult +import com.wavesplatform.protobuf.transaction.InvokeScriptResult.{Call, Invocation} import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings, WavesSettings} import com.wavesplatform.state.{AssetDescription, EmptyDataEntry, Height, LeaseBalance, StringDataEntry} -import com.wavesplatform.test.{FreeSpec, _} -import com.wavesplatform.transaction.{Asset, GenesisTransaction, PaymentTransaction, TxHelpers} +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler +import com.wavesplatform.transaction.utils.Signed +import com.wavesplatform.transaction.{Asset, GenesisTransaction, PaymentTransaction, TxHelpers} import io.grpc.StatusException import io.grpc.stub.{CallStreamObserver, StreamObserver} import monix.execution.CancelableFuture @@ -45,6 +42,10 @@ import org.scalactic.source.Position import org.scalamock.scalatest.PathMockFactory import org.scalatest.concurrent.ScalaFutures +import scala.concurrent.duration._ +import scala.concurrent.{Await, Promise} +import scala.util.Random + class BlockchainUpdatesSpec extends FreeSpec with WithDomain with ScalaFutures with PathMockFactory { var currentSettings: WavesSettings = domainSettingsWithFS( TestFunctionalitySettings.withFeatures( @@ -482,18 +483,16 @@ class BlockchainUpdatesSpec extends FreeSpec with WithDomain with ScalaFutures w ScriptEstimatorV3 ) .explicitGet() - val invoke = InvokeScriptTransaction - .selfSigned( - 2.toByte, - invoker, - issuer.toAddress, - Some(FUNCTION_CALL(FunctionHeader.User("issue"), Nil)), - Seq.empty, - 2.waves, - Asset.Waves, - ntpTime.getTimestamp() - ) - .explicitGet() + val invoke = Signed.invokeScript( + 2.toByte, + invoker, + issuer.toAddress, + Some(FUNCTION_CALL(FunctionHeader.User("issue"), Nil)), + Seq.empty, + 2.waves, + Asset.Waves, + ntpTime.getTimestamp() + ) d.appendBlock( GenesisTransaction.create(issuerAddress, 1000.waves, ntpTime.getTimestamp()).explicitGet(), GenesisTransaction.create(invoker.toAddress, 1000.waves, ntpTime.getTimestamp()).explicitGet(), diff --git a/lang/doc/v6/funcs/converting-functions.hjson b/lang/doc/v6/funcs/converting-functions.hjson index ae4c7444418..d49ee9763f7 100644 --- a/lang/doc/v6/funcs/converting-functions.hjson +++ b/lang/doc/v6/funcs/converting-functions.hjson @@ -5,7 +5,7 @@ params: [ "ByteVector" ] doc: "Converts account public key to [address](blockhain/address.md)." paramsDoc: [ "The public key to convert." ] - complexity: 63 + complexity: 1 } { name: "addressFromRecipient" diff --git a/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala b/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala index c2f39b0d75d..3e9ce704631 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala @@ -1,10 +1,10 @@ package com.wavesplatform.common.state -import com.wavesplatform.common.utils.{Base58, Base64} -import com.wavesplatform.common._ - import scala.util.Try +import com.wavesplatform.common._ +import com.wavesplatform.common.utils.{Base58, Base64} + case class ByteStr(arr: Array[Byte]) { private[this] lazy val base58: String = Base58.encode(arr) lazy val base64Raw: String = Base64.encode(arr) @@ -30,25 +30,25 @@ case class ByteStr(arr: Array[Byte]) { def ++(other: ByteStr): ByteStr = if (this.isEmpty) other else ByteStr(this.arr ++ other.arr) - def take(n: Long): ByteStr = { + def take(n: Int): ByteStr = { val n1 = n min arr.length max 0 if (n1 == arr.length) this else if (n1 == 0) ByteStr.empty - else ByteStr(arr.take(n1.toInt)) + else ByteStr(arr.take(n1)) } - def drop(n: Long): ByteStr = { + def drop(n: Int): ByteStr = { val n1 = n min arr.length max 0 if (n1 == arr.length) ByteStr.empty else if (n1 == 0) this - else ByteStr(arr.drop(n1.toInt)) + else ByteStr(arr.drop(n1)) } - def takeRight(n: Long): ByteStr = drop(arr.length.toLong - n) + def takeRight(n: Int): ByteStr = drop(arr.length - n) - def dropRight(n: Long): ByteStr = take(arr.length.toLong - n.max(0)) + def dropRight(n: Int): ByteStr = take(arr.length - n.max(0)) override def equals(a: Any): Boolean = a match { case other: ByteStr => java.util.Arrays.equals(arr, other.arr) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala index 79275365a1c..a3c1ce59ad7 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala @@ -50,6 +50,7 @@ package object utils { override def multiPaymentAllowed: Boolean = true override def transferTransactionFromProto(b: Array[Byte]): Option[Tx.Transfer] = ??? override def addressFromString(address: String): Either[String, Recipient.Address] = ??? + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = ??? override def accountScript(addressOrAlias: Recipient): Option[Script] = ??? override def callScript( dApp: Address, diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/Serde.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/Serde.scala index 149f2f0d547..031dffae178 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/Serde.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/Serde.scala @@ -3,6 +3,8 @@ package com.wavesplatform.lang.v1 import java.io.ByteArrayOutputStream import java.nio.ByteBuffer +import scala.util.Try + import cats.instances.lazyList._ import cats.instances.list._ import cats.syntax.apply._ @@ -14,8 +16,6 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.compiler.Types.CASETYPEREF import monix.eval.Coeval -import scala.util.Try - object Serde { val E_LONG: Byte = 0 val E_BYTES: Byte = 1 @@ -174,6 +174,15 @@ object Serde { def deserialize(bb: ByteBuffer): Either[String, EXPR] = Try(desAux(bb).value()).toEither.left.map(_.getMessage) + def deserializeFunctionCall(bb: ByteBuffer): Either[Throwable, FUNCTION_CALL] = + Try(desAux(bb).value()).toEither.flatMap { + case fc: FUNCTION_CALL => Right(fc) + case other => Left(new RuntimeException(s"Not a function call: $other")) + } + + def deserializeFunctionCall(bb: Array[Byte]): Either[Throwable, FUNCTION_CALL] = + deserializeFunctionCall(ByteBuffer.wrap(bb)) + def serAux(out: ByteArrayOutputStream, acc: Coeval[Unit], expr: EXPR, allowObjects: Boolean = false): Coeval[Unit] = acc.flatMap { _ => expr match { case CONST_LONG(n) => diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/FunctionIds.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/FunctionIds.scala index ba0603209ae..1a2b4847d8f 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/FunctionIds.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/FunctionIds.scala @@ -155,9 +155,10 @@ object FunctionIds { val DATA_BYTES_FROM_STATE_SELF: Short = 1057 val DATA_STRING_FROM_STATE_SELF: Short = 1058 - val ADDRESSFROMRECIPIENT: Short = 1060 - val ADDRESSTOSTRING: Short = 1061 - val ADDRESSFROMSTRING_NATIVE: Short = 1062 + val ADDRESSFROMRECIPIENT: Short = 1060 + val ADDRESSTOSTRING: Short = 1061 + val ADDRESSFROMSTRING_NATIVE: Short = 1062 + val ADDRESSFROMPUBLICKEY_NATIVE: Short = 1063 val TRANSFER_TRANSACTION_FROM_PROTO: Short = 1070 diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala index 3c30467641b..68e0b3eb29b 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala @@ -9,7 +9,6 @@ import cats.{Id, Monad} import com.google.common.annotations.VisibleForTesting import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.lang.{CoevalF, ExecutionError} import com.wavesplatform.lang.directives.DirectiveDictionary import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.utils.getDecompilerContext @@ -25,6 +24,7 @@ import com.wavesplatform.lang.v1.evaluator.{ContextfulNativeFunction, Contextful import com.wavesplatform.lang.v1.parser.BinaryOperation import com.wavesplatform.lang.v1.parser.BinaryOperation._ import com.wavesplatform.lang.v1.{BaseGlobal, CTX, FunctionHeader} +import com.wavesplatform.lang.{CoevalF, ExecutionError} import monix.eval.Coeval import scala.annotation.tailrec @@ -511,7 +511,7 @@ object PureContext { ("xs", BYTESTR), ("number", LONG) ) { - case CONST_BYTESTR(xs) :: CONST_LONG(number) :: Nil => CONST_BYTESTR(xs.take(number)) + case CONST_BYTESTR(xs) :: CONST_LONG(number) :: Nil => CONST_BYTESTR(xs.take(number.toInt)) case xs => notImplemented[Id, EVALUATED]("take(xs: ByteVector, number: Int)", xs) } @@ -524,7 +524,7 @@ object PureContext { ("xs", BYTESTR), ("number", LONG) ) { - case CONST_BYTESTR(xs) :: CONST_LONG(number) :: Nil => CONST_BYTESTR(xs.drop(number)) + case CONST_BYTESTR(xs) :: CONST_LONG(number) :: Nil => CONST_BYTESTR(xs.drop(number.toInt)) case xs => notImplemented[Id, EVALUATED]("drop(xs: ByteVector, number: Int)", xs) } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Functions.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Functions.scala index 2e682db803a..38e028f24ad 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Functions.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Functions.scala @@ -227,6 +227,28 @@ object Functions { } ) + val addressFromPublicKeyNative: BaseFunction[Environment] = + NativeFunction.withEnvironment[Environment]( + "addressFromPublicKey", + Map[StdLibVersion, Long](V6 -> 1L), + ADDRESSFROMPUBLICKEY_NATIVE, + addressType, + ("publicKey", BYTESTR) + ) { + new ContextfulNativeFunction.Simple[Environment]("addressFromPublicKey", addressType, Seq(("AddressOrAlias", addressOrAliasType))) { + override def evaluate[F[_]: Monad](env: Environment[F], args: List[EVALUATED]): F[Either[ExecutionError, EVALUATED]] = { + (env, args) match { + case (env, CONST_BYTESTR(publicKey) :: Nil) => + env + .addressFromPublicKey(publicKey) + .map(address => CaseObj(addressType, Map("bytes" -> CONST_BYTESTR(address.bytes).explicitGet())): EVALUATED) + .pure[F] + case (_, xs) => notImplemented[F, EVALUATED](s"addressFromPublicKey(publicKey: ByteVector)", xs) + } + } + } + } + private def removePrefixExpr(str: EXPR, prefix: String): EXPR = IF( FUNCTION_CALL( PureContext.eq, @@ -455,7 +477,7 @@ object Functions { "generating" -> CONST_LONG(b.generating), "effective" -> CONST_LONG(b.effective) ) - ) + ) ) ) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala index 14225bd5948..a2a5041e763 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala @@ -115,8 +115,8 @@ object WavesContext { getBooleanByIndexF(version), getBinaryByIndexF(version), getStringByIndexF(version), - addressFromPublicKeyF(version), - if (version >= V4) addressFromStringV4 else addressFromStringF(version) + if (version >= V4) addressFromStringV4 else addressFromStringF(version), + if (version >= V6) addressFromPublicKeyNative else addressFromPublicKeyF(version) ) ++ (if (version >= V5) Array(accountScriptHashF(global)) else Array()) val versionSpecificFuncs = diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/Parser.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/Parser.scala index 6646bb7eddf..570836e976a 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/Parser.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/Parser.scala @@ -588,12 +588,12 @@ object Parser { def parseExpr(str: String): Parsed[EXPR] = { def expr[_: P] = P(Start ~ unusedText ~ (baseExpr | invalid) ~ End) - parse(str, expr(_)) + parse(str, expr(_), verboseFailures = true) } def parseExprOrDecl(str: String): Parsed[EXPR] = { def e[_: P] = P(Start ~ unusedText ~ (baseExprOrDecl | invalid) ~ End) - parse(str, e(_)) + parse(str, e(_), verboseFailures = true) } def parseContract(str: String): Parsed[DAPP] = { @@ -602,7 +602,8 @@ object Parser { .map { case (ds, fs, t, end) => (DAPP(Pos(0, end), ds.flatten.toList, fs.toList), t) } - parse(str, contract(_)) match { + + parse(str, contract(_), verboseFailures = true) match { case Parsed.Success((s, t), _) if (t.nonEmpty) => def contract[_: P] = P(Start ~ unusedText ~ (declaration.rep) ~ comment ~ (annotatedFunc.rep) ~ !declaration.rep(1) ~ End ~~ Index) parse(str, contract(_)) match { diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/traits/Environment.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/traits/Environment.scala index dacc9da0642..da675ba7c4c 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/traits/Environment.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/traits/Environment.scala @@ -38,6 +38,7 @@ trait Environment[F[_]] { def txId: ByteStr def transferTransactionFromProto(b: Array[Byte]): F[Option[Tx.Transfer]] def addressFromString(address: String): Either[String, Address] + def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] def dAppAlias: Boolean = false def accountScript(addressOrAlias: Recipient): F[Option[Script]] def callScript( diff --git a/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala b/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala index aa4577e2c48..5f9245735cb 100644 --- a/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala +++ b/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala @@ -91,6 +91,7 @@ object Common { override def txId: ByteStr = ??? override def transferTransactionFromProto(b: Array[Byte]): Option[Tx.Transfer] = ??? override def addressFromString(address: String): Either[String, Recipient.Address] = ??? + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = ??? def accountScript(addressOrAlias: Recipient): Option[Script] = ??? override def callScript(dApp: Address, func: String, args: List[EVALUATED], payments: Seq[(Option[Array[Byte]], Long)], remainingComplexity: Int, reentrant: Boolean): Coeval[(Either[ValidationError, EVALUATED], Int)] = ??? } diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala index c25c2df2c5c..c3141df465c 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala @@ -465,7 +465,7 @@ class EvaluatorV1V2Test extends PropSpec with EitherValues { } } - property("dropRightBytes(ByteStr, Long) works as the native one") { + ignore("dropRightBytes(ByteStr, Long) works as the native one") { forAll(genBytesAndNumber) { case (xs, number) => val expr = FUNCTION_CALL(PureContext.dropRightBytes.header, List(CONST_BYTESTR(xs).explicitGet(), CONST_LONG(number))) diff --git a/node-generator/devnet.conf b/node-generator/devnet.conf deleted file mode 100644 index 8cc645f16dc..00000000000 --- a/node-generator/devnet.conf +++ /dev/null @@ -1,25 +0,0 @@ -generator { - chainId = D - accounts = [ - "EB52Qiw82RE1mtQpVu73d92t6CcpT8FtXGeWigidJCET", - "788h8WCsVet6sMceHT8vn9VqRy3Ms929BwdW24eFp1r7", - "8UhM36mbnGFS2tRWDqtEX2tReVKq6Ww6jyMCekFjqoDQ", - ] - n = 100 - every = 500 ms - send-to { - address = 34.251.200.245 - port = 6864 - } - probabilities { - payment: 0.1 - issue: 0.1 - transfer: 0.3 - reissue: 0.05 - burn: 0.075 - exchange: 0.1 - lease: 0.1 - lease-cancel: 0.075 - create-alias: 0.1 - } -} diff --git a/node-generator/src/main/resources/application.conf b/node-generator/src/main/resources/application.conf index 9b35fe5d4db..98148cf59f2 100644 --- a/node-generator/src/main/resources/application.conf +++ b/node-generator/src/main/resources/application.conf @@ -2,7 +2,7 @@ waves.network.traffic-logger { ignore-tx-messages = [] } -generator { +waves.generator { chain-id = D accounts = [ "FfPr7UvxLRaDDY37nU1Hj9hCswSG6yg1cXw5ooYcVyg5", diff --git a/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala b/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala index 89ecfc9f17f..4313c34c4e9 100644 --- a/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala +++ b/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala @@ -4,32 +4,35 @@ import java.nio.file.{Files, Paths} import java.util.UUID import java.util.concurrent.ThreadLocalRandom +import scala.concurrent.duration._ +import scala.util.Random +import scala.util.Random._ + import cats.Show import com.wavesplatform.account.{Alias, KeyPair} import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.common.utils.{Base58, EitherExt2} import com.wavesplatform.generator.utils.{Gen, Universe} import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.estimator.ScriptEstimator -import com.wavesplatform.state.DataEntry.{MaxValueSize, Type} import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, IntegerDataEntry, StringDataEntry} -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.state.DataEntry.{MaxValueSize, Type} import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange._ import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} -import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer +import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer +import com.wavesplatform.transaction.utils.{EthTxGenerator, Signed} +import com.wavesplatform.transaction.TransactionType.TransactionType import com.wavesplatform.utils.{LoggerFacade, NTP} import org.slf4j.LoggerFactory - -import scala.concurrent.duration._ -import scala.util.Random -import scala.util.Random._ +import org.web3j.crypto.Bip32ECKeyPair //noinspection ScalaStyle, TypeAnnotation class NarrowTransactionGenerator( @@ -67,7 +70,7 @@ class NarrowTransactionGenerator( val timestamp = now + i val tx: Option[Transaction] = typeGen.getRandom match { - case IssueTransaction => + case TransactionType.Issue => val sender = randomFrom(accounts).get val name = random.nextString(5) val description = random.nextString(5) @@ -89,7 +92,7 @@ class NarrowTransactionGenerator( ) ) - case TransferTransaction => + case TransactionType.Transfer => ( for { (sender, asset) <- randomSenderAndAsset(validIssueTxs) @@ -112,7 +115,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no issued assets, may be you need to increase issue transaction's probability or pre-configure them") - case ReissueTransaction => + case TransactionType.Reissue => ( for { assetTx <- randomFrom(reissuableIssueTxs) orElse randomFrom(Universe.IssuedAssets.filter(_.reissuable)) @@ -132,7 +135,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no reissuable assets, may be you need to increase issue transaction's probability or pre-configure them") - case BurnTransaction => + case TransactionType.Burn => ( for { assetTx <- randomFrom(validIssueTxs).orElse(randomFrom(Universe.IssuedAssets)) @@ -150,15 +153,25 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no issued assets, may be you need to increase issue transaction's probability or pre-configure them") - case ExchangeTransaction => + case TransactionType.Exchange => ( for { matcher <- randomFrom(Universe.Accounts).map(_.keyPair) seller <- randomFrom(Universe.Accounts).map(_.keyPair) buyer <- randomFrom(Universe.Accounts).map(_.keyPair) pair <- preconditions.tradeAsset.map(a => AssetPair(Waves, IssuedAsset(a.id()))) - delta = random.nextLong(10000) - sellOrder = Order.sell(Order.V2, seller, matcher.publicKey, pair, 10000000 + delta, 10, timestamp, timestamp + 30.days.toMillis, 300000L) + delta = random.nextLong(10000) + sellOrder = Order.sell( + Order.V2, + seller, + matcher.publicKey, + pair, + 10000000 + delta, + 10, + timestamp, + timestamp + 30.days.toMillis, + 300000L + ) buyOrder = Order.buy( Order.V2, buyer, @@ -187,7 +200,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("Can't define seller/matcher/buyer of transaction, check your configuration") - case LeaseTransaction => + case TransactionType.Lease => ( for { sender <- randomFrom(accounts) @@ -200,7 +213,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("Can't define recipient of transaction, check your configuration") - case LeaseCancelTransaction => + case TransactionType.LeaseCancel => ( for { lease <- activeLeaseTransactions.headOption @@ -209,14 +222,14 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no active lease transactions, may be you need to increase lease transaction's probability") - case CreateAliasTransaction => + case TransactionType.CreateAlias => val sender = randomFrom(accounts).get val aliasString = NarrowTransactionGenerator.generateAlias() logOption( CreateAliasTransaction.selfSigned(correctVersion(TxVersion.V2), sender, Alias.create(aliasString).explicitGet(), 500000L, timestamp) ) - case MassTransferTransaction => + case TransactionType.MassTransfer => ( for { (sender, asset) <- randomSenderAndAsset(validIssueTxs) @@ -242,7 +255,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no issued assets, may be you need to increase issue transaction's probability or pre-configure them") - case DataTransaction => + case TransactionType.Data => val sender = randomFrom(accounts).get val count = random.nextInt(10) @@ -263,7 +276,7 @@ class NarrowTransactionGenerator( val fee = 500000L * (size / 1024 + 1) logOption(DataTransaction.selfSigned(correctVersion(TxVersion.V1), sender, data.toList, fee, timestamp)) - case SponsorFeeTransaction => + case TransactionType.SponsorFee => ( for { assetTx <- randomFrom(validIssueTxs).orElse(randomFrom(Universe.IssuedAssets)) @@ -281,7 +294,7 @@ class NarrowTransactionGenerator( } yield tx ).logNone("There is no issued assets, may be you need to increase issue transaction's probability or pre-configure them") - case InvokeScriptTransaction => + case TransactionType.InvokeScript => val script = randomFrom(settings.scripts).get val function = randomFrom(script.functions).get val sender = randomFrom(accounts).get @@ -302,19 +315,46 @@ class NarrowTransactionGenerator( .fold(Waves: Asset)(tx => IssuedAsset(tx.id())) logOption( - InvokeScriptTransaction.selfSigned( - correctVersion(TxVersion.V1), - sender, - GeneratorSettings.toKeyPair(script.dappAccount).toAddress, - maybeFunctionCall, - Seq(InvokeScriptTransaction.Payment(random.nextInt(5000), asset)), - 5300000L, - Waves, - timestamp + Right( + Signed.invokeScript( + correctVersion(TxVersion.V1), + sender, + GeneratorSettings.toKeyPair(script.dappAccount).toAddress, + maybeFunctionCall, + Seq(InvokeScriptTransaction.Payment(random.nextInt(5000), asset)), + 5300000L, + Waves, + timestamp + ) + ) + ) + + case TransactionType.Ethereum => + import EthTxGenerator.Arg + + val script = randomFrom(settings.scripts).get + val function = randomFrom(script.functions).get + val sender = randomFrom(accounts).get + val ethArgs = for { + ScriptSettings.Function.Arg(argType, value) <- function.args + } yield argType.toLowerCase match { + case "integer" | "int" | "long" | "int64" | "uint64" => Arg.Integer(value.toLong) + case "bigint" | "int256" | "uint256" => Arg.BigInteger(BigInt(Base58.decode(value))) + case "string" => Arg.Str(value) + case "boolean" | "bool" => Arg.Bool(value.toBoolean) + case "binary" => Arg.Bytes(ByteStr(Base58.decode(value))) + } + + val asset = randomFrom(Universe.IssuedAssets.filter(a => script.paymentAssets.contains(a.name.toStringUtf8))) + .fold(Waves: Asset)(tx => IssuedAsset(tx.id())) + + logOption( + Right( + EthTxGenerator.generateEthInvoke(Bip32ECKeyPair.generateKeyPair(sender.seed), GeneratorSettings.toKeyPair(script.dappAccount).toAddress, function.name, ethArgs, Seq(InvokeScriptTransaction.Payment(random.nextInt(5000), asset))) ) ) - case SetScriptTransaction => + case TransactionType.SetScript => for { sender <- randomFrom(preconditions.setScriptAccounts) script = Gen.script(complexity = false, estimator) @@ -329,7 +369,7 @@ class NarrowTransactionGenerator( ) } yield tx - case SetAssetScriptTransaction => + case TransactionType.SetAssetScript => ( for { assetTx <- randomFrom(preconditions.setScriptAssets) @@ -347,6 +387,8 @@ class NarrowTransactionGenerator( ) } yield tx ).logNone("There is no issued smart assets, may be you need to increase issue transaction's probability or pre-configure them") + + case _ => ??? } (tx.fold(allTxsWithValid)(tx => allTxsWithValid :+ tx), tx match { @@ -413,7 +455,15 @@ class NarrowTransactionGenerator( object NarrowTransactionGenerator { - final case class ScriptSettings(dappAccount: String, paymentAssets: Set[String], functions: Seq[ScriptSettings.Function]) + final case class ScriptSettings( + dappAccount: String, + paymentAssets: Set[String], + functions: Seq[ScriptSettings.Function], + scriptFile: Option[String] + ) { + def dappAccountKP = GeneratorSettings.toKeyPair(dappAccount) + def dappAddress = dappAccountKP.toAddress + } object ScriptSettings { final case class Function(name: String, args: Seq[Function.Arg]) object Function { @@ -434,7 +484,7 @@ object NarrowTransactionGenerator { final case class Settings( transactions: Int, - probabilities: Map[TransactionParser, Double], + probabilities: Map[TransactionType, Double], scripts: Seq[ScriptSettings], setScript: Option[SetScriptSettings], protobuf: Boolean @@ -472,7 +522,9 @@ object NarrowTransactionGenerator { def apply(settings: Settings, accounts: Seq[KeyPair], time: NTP, estimator: ScriptEstimator): NarrowTransactionGenerator = { val (setScriptInitTxs, setScriptTailInitTxs, setScriptAccounts, setScriptAssets) = - if (settings.probabilities.get(SetScriptTransaction).exists(_ > 0) || settings.probabilities.get(SetAssetScriptTransaction).exists(_ > 0)) { + if (settings.probabilities + .get(TransactionType.SetScript) + .exists(_ > 0) || settings.probabilities.get(TransactionType.SetAssetScript).exists(_ > 0)) { require(settings.setScript.isDefined, "SetScript and SetAssetScript generations require additional settings [set-script]") val accountsSettings = settings.setScript.get.accounts @@ -496,19 +548,19 @@ object NarrowTransactionGenerator { .selfSigned(2.toByte, richAccount, account.toAddress, Waves, balance, Waves, fee, ByteStr.empty, time.correctedTime()) .explicitGet() - val script = ScriptCompiler.compile(new String(Files.readAllBytes(Paths.get(scriptFile))), estimator).explicitGet()._1 - val scriptTx = SetScriptTransaction.selfSigned(TxVersion.V1, account, Some(script), fee, time.correctedTime()).explicitGet() + val script = ScriptCompiler.compile(new String(Files.readAllBytes(Paths.get(scriptFile))), estimator).explicitGet()._1 + val scriptTx = SetScriptTransaction.selfSigned(TxVersion.V1, account, Some(script), fee, time.correctedTime()).explicitGet() (initTxs :+ transferTx, tailInitTxs :+ scriptTx, accounts :+ account) } val assetTailInitTxs = - if (settings.probabilities.keySet.contains(SetAssetScriptTransaction)) + if (settings.probabilities.keySet.contains(TransactionType.SetAssetScript)) ((1 to assetsSettings.repeat) foldLeft Seq.empty[IssueTransaction]) { case (txs, i) => import assetsSettings._ - val issuer = randomFrom(accounts).get + val issuer = randomFrom(accounts).get val script = ScriptCompiler.compile(new String(Files.readAllBytes(Paths.get(scriptFile))), estimator).explicitGet()._1 val tx = IssueTransaction @@ -531,7 +583,7 @@ object NarrowTransactionGenerator { (accountInitTxs, accountTailInitTxs ++ assetTailInitTxs, accounts, assetTailInitTxs) } else (Seq(), Seq(), Seq(), Seq()) - val (tradeAsset, tradeTailInitTxs) = if (settings.probabilities.keySet.contains(ExchangeTransaction)) { + val (tradeAsset, tradeTailInitTxs) = if (settings.probabilities.keySet.contains(TransactionType.Exchange)) { val trader = randomFrom(accounts).get @@ -573,7 +625,27 @@ object NarrowTransactionGenerator { val leaseRecipient = GeneratorSettings.toKeyPair("lease recipient") - val initialTxs = tradeAsset.fold(Seq.empty[Transaction])(Seq(_)) ++ setScriptInitTxs + val fundEthereumAddresses = accounts.map { kp => + import com.wavesplatform.transaction.utils.EthConverters._ + val ethAccount = kp.toEthWavesAddress + TransferTransaction + .selfSigned(TxVersion.V1, accounts.head, ethAccount, Waves, 100_0000_0000L, Waves, 500000L, ByteStr.empty, System.currentTimeMillis()) + .explicitGet() + } + + val setPredefScripts = settings.scripts.collect { + case s if s.scriptFile.nonEmpty => + val transferTx = TransferTransaction + .selfSigned(2.toByte, accounts.head, s.dappAddress, Waves, 1_0000_000L, Waves, 500000L, ByteStr.empty, time.correctedTime()) + .explicitGet() + + val script = ScriptCompiler.compile(new String(Files.readAllBytes(Paths.get(s.scriptFile.get))), estimator).explicitGet()._1 + val scriptTx = SetScriptTransaction.selfSigned(TxVersion.V1, s.dappAccountKP, Some(script), 500000L, time.correctedTime()).explicitGet() + + Seq(transferTx, scriptTx) + }.flatten + + val initialTxs = fundEthereumAddresses ++ setPredefScripts ++ tradeAsset.fold(Seq.empty[Transaction])(Seq(_)) ++ setScriptInitTxs val tailInitialTxs = tradeTailInitTxs ++ setScriptTailInitTxs val preconditions = Preconditions(leaseRecipient, tradeAsset, setScriptAccounts, setScriptAssets) diff --git a/node-generator/src/main/scala/com/wavesplatform/generator/TransactionsGeneratorApp.scala b/node-generator/src/main/scala/com/wavesplatform/generator/TransactionsGeneratorApp.scala index 3157223a62a..d239ad0c4f2 100644 --- a/node-generator/src/main/scala/com/wavesplatform/generator/TransactionsGeneratorApp.scala +++ b/node-generator/src/main/scala/com/wavesplatform/generator/TransactionsGeneratorApp.scala @@ -1,34 +1,35 @@ package com.wavesplatform.generator +import java.io.File import java.net.InetSocketAddress import java.util.concurrent.Executors +import scala.concurrent._ +import scala.concurrent.duration._ +import scala.util.{Failure, Random, Success} + import cats.implicits.showInterpolator import com.typesafe.config.ConfigFactory import com.wavesplatform.account.AddressScheme +import com.wavesplatform.features.EstimatorProvider._ import com.wavesplatform.generator.GeneratorSettings.NodeAddress import com.wavesplatform.generator.Preconditions.{PGenSettings, UniverseHolder} import com.wavesplatform.generator.cli.ScoptImplicits import com.wavesplatform.generator.config.FicusImplicits import com.wavesplatform.generator.utils.Universe import com.wavesplatform.network.client.NetworkSender -import com.wavesplatform.settings.WavesSettings import com.wavesplatform.transaction.Transaction -import com.wavesplatform.features.EstimatorProvider._ import com.wavesplatform.utils.{LoggerFacade, NTP} +import com.wavesplatform.Application import monix.execution.Scheduler import net.ceedubs.ficus.Ficus._ -import net.ceedubs.ficus.readers.ArbitraryTypeReader._ import net.ceedubs.ficus.readers.{EnumerationReader, NameMapper, ValueReader} +import net.ceedubs.ficus.readers.ArbitraryTypeReader._ import org.asynchttpclient.AsyncHttpClient import org.asynchttpclient.Dsl.asyncHttpClient import org.slf4j.LoggerFactory import scopt.OptionParser -import scala.concurrent._ -import scala.concurrent.duration._ -import scala.util.{Failure, Random, Success} - object TransactionsGeneratorApp extends App with ScoptImplicits with FicusImplicits with EnumerationReader { // IDEA bugs @@ -142,12 +143,12 @@ object TransactionsGeneratorApp extends App with ScoptImplicits with FicusImplic ) } - val defaultConfig = - ConfigFactory - .load() - .as[GeneratorSettings]("generator") + val externalConf = new File("generator.local.conf") + val wavesSettings = Application.loadApplicationConfig(if (externalConf.isFile) Some(externalConf) else None) - val wavesSettings = WavesSettings.default() + val defaultConfig = + wavesSettings.config + .as[GeneratorSettings]("waves.generator") parser.parse(args, defaultConfig) match { case None => parser.failure("Failed to parse command line parameters") @@ -181,6 +182,7 @@ object TransactionsGeneratorApp extends App with ScoptImplicits with FicusImplic case Mode.MULTISIG => new MultisigTransactionGenerator(finalConfig.multisig, finalConfig.privateKeyAccounts, estimator) case Mode.ORACLE => new OracleTransactionGenerator(finalConfig.oracle, finalConfig.privateKeyAccounts, estimator) case Mode.SWARM => new SmartGenerator(finalConfig.swarm, finalConfig.privateKeyAccounts, estimator) + case _ => ??? } val threadPool = Executors.newFixedThreadPool(Math.max(1, finalConfig.sendTo.size)) @@ -227,7 +229,7 @@ object TransactionsGeneratorApp extends App with ScoptImplicits with FicusImplic nodeRestUrl, () => canContinue, initialUniTransactions ++ initialGenTransactions, - finalConfig.privateKeyAccounts.map(_.toAddress.stringRepr), + finalConfig.privateKeyAccounts.map(_.toAddress.toString), initialTailTransactions ++ initialGenTailTransactions ) } diff --git a/node-generator/src/main/scala/com/wavesplatform/generator/config/FicusImplicits.scala b/node-generator/src/main/scala/com/wavesplatform/generator/config/FicusImplicits.scala index ed44804d3f6..98ee50c9176 100644 --- a/node-generator/src/main/scala/com/wavesplatform/generator/config/FicusImplicits.scala +++ b/node-generator/src/main/scala/com/wavesplatform/generator/config/FicusImplicits.scala @@ -1,16 +1,17 @@ package com.wavesplatform.generator.config +import scala.concurrent.duration.{Duration, FiniteDuration} + import com.google.common.base.CaseFormat import com.typesafe.config.{Config, ConfigRenderOptions} import com.wavesplatform.generator.Worker import com.wavesplatform.state.DataEntry -import com.wavesplatform.transaction.{TransactionParser, TransactionParsers} +import com.wavesplatform.transaction.{TransactionParser, TransactionParsers, TransactionType} +import com.wavesplatform.transaction.TransactionType.TransactionType import net.ceedubs.ficus.Ficus._ import net.ceedubs.ficus.readers.{CollectionReaders, ValueReader} import play.api.libs.json._ -import scala.concurrent.duration.{Duration, FiniteDuration} - trait FicusImplicits { private[this] val byName: Map[String, TransactionParser] = TransactionParsers.all.map { @@ -31,6 +32,18 @@ trait FicusImplicits { } } + implicit val newDistributionsReader: ValueReader[Map[TransactionType, Double]] = { + val converter = CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.UPPER_CAMEL) + def toTxType(key: String): TransactionType = TransactionType.withName(converter.convert(key).replace("Transaction", "")) + + CollectionReaders.mapValueReader[Double].map { xs => + xs.map { + case (k, v) => + toTxType(k) -> v + } + } + } + implicit val dataEntryReader: ValueReader[DataEntry[_]] = (config: Config, path: String) => Json.parse(config.getConfig(path).root().render(ConfigRenderOptions.concise())).as[DataEntry[_]] diff --git a/node-it/src/test/scala/com/wavesplatform/it/ExternalNode.scala b/node-it/src/test/scala/com/wavesplatform/it/ExternalNode.scala index b8d8920d494..2b09f5ab9db 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/ExternalNode.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/ExternalNode.scala @@ -12,8 +12,8 @@ class ExternalNode(config: Config) extends Node(config) { override def apiKey: String = config.getString("api-key") override def networkAddress: InetSocketAddress = { - val hostAndPort = "([^:]+)\\:([\\d+])+".r - @unchecked val hostAndPort(host, port) = config.getString("network-address") + val hostAndPort = "([^:]+):([\\d+])+".r + val hostAndPort(host, port) = (config.getString("network-address"): @unchecked) new InetSocketAddress(host, port.toInt) } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/GrpcIntegrationSuiteWithThreeAddress.scala b/node-it/src/test/scala/com/wavesplatform/it/GrpcIntegrationSuiteWithThreeAddress.scala index b759d554f6c..abf589da496 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/GrpcIntegrationSuiteWithThreeAddress.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/GrpcIntegrationSuiteWithThreeAddress.scala @@ -4,19 +4,14 @@ import com.google.protobuf.ByteString import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.it.api.SyncGrpcApi._ -import com.wavesplatform.test.NumericExt import com.wavesplatform.protobuf.transaction.{PBRecipients, PBTransactions, Recipient} +import com.wavesplatform.test.NumericExt import com.wavesplatform.transaction.transfer.TransferTransaction import com.wavesplatform.utils.ScorexLogging -import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures} import org.scalatest._ +import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures} -trait GrpcIntegrationSuiteWithThreeAddress - extends BaseSuite - with ScalaFutures - with IntegrationPatience - with RecoverMethods - with ScorexLogging { +trait GrpcIntegrationSuiteWithThreeAddress extends BaseSuite with ScalaFutures with IntegrationPatience with RecoverMethods with ScorexLogging { this: TestSuite with Nodes => protected lazy val firstAcc: KeyPair = KeyPair("first_acc".getBytes("UTF-8")) @@ -54,7 +49,8 @@ trait GrpcIntegrationSuiteWithThreeAddress def makeTransfers(accounts: Seq[ByteString]): Seq[String] = accounts.map { acc => PBTransactions .vanilla( - sender.broadcastTransfer(sender.keyPair, Recipient().withPublicKeyHash(acc), defaultBalance, sender.fee(TransferTransaction.typeId)) + sender.broadcastTransfer(sender.keyPair, Recipient().withPublicKeyHash(acc), defaultBalance, sender.fee(TransferTransaction.typeId)), + unsafe = false ) .explicitGet() .id() diff --git a/node-it/src/test/scala/com/wavesplatform/it/Node.scala b/node-it/src/test/scala/com/wavesplatform/it/Node.scala index 0d5de3ad1ae..1ebdfc536dd 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/Node.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/Node.scala @@ -2,21 +2,22 @@ package com.wavesplatform.it import java.net.{InetSocketAddress, URL} +import scala.concurrent.duration.FiniteDuration + import com.typesafe.config.Config import com.wavesplatform.account.{KeyPair, PublicKey} import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.it.util.GlobalTimer import com.wavesplatform.settings.WavesSettings import com.wavesplatform.state.diffs.FeeValidation +import com.wavesplatform.transaction.TransactionType import com.wavesplatform.utils.LoggerFacade import com.wavesplatform.wallet.Wallet import io.grpc.{ManagedChannel, ManagedChannelBuilder} -import org.asynchttpclient.Dsl.{config => clientConfig, _} import org.asynchttpclient._ +import org.asynchttpclient.Dsl.{config => clientConfig, _} import org.slf4j.LoggerFactory -import scala.concurrent.duration.FiniteDuration - abstract class Node(val config: Config) extends AutoCloseable { lazy val log: LoggerFacade = LoggerFacade(LoggerFactory.getLogger(s"${getClass.getCanonicalName}.${this.name}")) @@ -56,7 +57,7 @@ object Node { implicit class NodeExt(val n: Node) extends AnyVal { def name: String = n.settings.networkSettings.nodeName def publicKeyStr: String = n.publicKey.toString - def fee(txTypeId: Byte): Long = FeeValidation.FeeConstants(txTypeId) * FeeValidation.FeeUnit + def fee(txTypeId: Byte): Long = FeeValidation.FeeConstants(TransactionType(txTypeId)) * FeeValidation.FeeUnit def blockDelay: FiniteDuration = n.settings.blockchainSettings.genesisSettings.averageBlockDelay } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/TransferSending.scala b/node-it/src/test/scala/com/wavesplatform/it/TransferSending.scala index 8f5ae825459..a6c914e6313 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/TransferSending.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/TransferSending.scala @@ -42,7 +42,7 @@ trait TransferSending extends ScorexLogging { val sourceAndDest = (1 to n).map { _ => val destPk = Array.fill[Byte](seedSize)(Random.nextInt(Byte.MaxValue).toByte) - Address.fromPublicKey(PublicKey(destPk)).stringRepr + Address.fromPublicKey(PublicKey(destPk)).toString } val requests = sourceAndDest.foldLeft(List.empty[Req]) { @@ -63,7 +63,7 @@ trait TransferSending extends ScorexLogging { } val sourceAndDest = (1 to n).map { _ => - val Seq((srcConfig, _), (_, destPrivateKey)) = Random.shuffle(srcDest).take(2) + val Seq((srcConfig, _), (_, destPrivateKey)) = (Random.shuffle(srcDest).take(2): @unchecked) (srcConfig, destPrivateKey.toAddress.toString) } @@ -91,7 +91,7 @@ trait TransferSending extends ScorexLogging { val sourceAndDest = (1 to n).map { id => val srcSeed = Random.shuffle(seeds).head val destPk = prefix ++ Ints.toByteArray(id) ++ new Array[Byte](24) - val destAddr = Address.fromPublicKey(PublicKey(destPk)).stringRepr + val destAddr = Address.fromPublicKey(PublicKey(destPk)).toString (srcSeed, destAddr) } @@ -145,7 +145,7 @@ trait TransferSending extends ScorexLogging { Some(2.toByte), None, Some(tx.sender.toString), - recipient.stringRepr, + recipient.toString, Some(assetId), amount, Some(feeAssetId), diff --git a/node-it/src/test/scala/com/wavesplatform/it/api/AsyncGrpcApi.scala b/node-it/src/test/scala/com/wavesplatform/it/api/AsyncGrpcApi.scala index 32fd42e64e2..2cc5c95d713 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/api/AsyncGrpcApi.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/api/AsyncGrpcApi.scala @@ -95,11 +95,11 @@ object AsyncGrpcApi { ) script match { - case Left(_) => transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + case Left(_) => transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) case _ => val proofs = - crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } } @@ -129,10 +129,10 @@ object AsyncGrpcApi { ) ) try { - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } catch { - case _: IllegalArgumentException => transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + case _: IllegalArgumentException => transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) } } @@ -158,8 +158,8 @@ object AsyncGrpcApi { ) ) - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - val transaction = SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).explicitGet().bodyBytes()) + val transaction = SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr))) transactions.broadcast(transaction) } @@ -174,10 +174,10 @@ object AsyncGrpcApi { PBTransaction.Data.CreateAlias(CreateAliasTransactionData(alias)) ) if (Alias.create(alias).isLeft) { - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) } else { - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } } @@ -196,11 +196,11 @@ object AsyncGrpcApi { version, PBTransaction.Data.DataTransaction(DataTransactionData.of(data)) ) - if (PBTransactions.vanilla(SignedTransaction(Some(unsigned))).isLeft) { - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + if (PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).isLeft) { + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) } else { - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } } @@ -235,8 +235,8 @@ object AsyncGrpcApi { ) ) - val proofs = crypto.sign(matcher.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - val transaction = SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr))) + val proofs = crypto.sign(matcher.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false).explicitGet().bodyBytes()) + val transaction = SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr))) transactions.broadcast(transaction) } @@ -264,11 +264,11 @@ object AsyncGrpcApi { ) script match { - case Left(_) => transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + case Left(_) => transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) case _ => val proofs = - crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } } @@ -301,7 +301,7 @@ object AsyncGrpcApi { _.getTransaction(txId) .map(Option(_)) .recover { case _: NoSuchElementException => None }, - tOpt => tOpt.exists(t => PBTransactions.vanilla(t).explicitGet().id().toString == txId), + tOpt => tOpt.exists(t => PBTransactions.vanilla(t, unsafe = false).explicitGet().id().toString == txId), retryInterval ).map(_.get) @@ -335,13 +335,13 @@ object AsyncGrpcApi { ) ) - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - val transaction = SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + val transaction = SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr))) transactions.broadcast(transaction) } def broadcast(unsignedTx: PBTransaction, proofs: Seq[ByteString]): Future[PBSignedTransaction] = - transactions.broadcast(SignedTransaction(Some(unsignedTx), proofs)) + transactions.broadcast(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsignedTx), proofs)) def broadcastSponsorFee(sender: KeyPair, minFee: Option[Amount], fee: Long, version: Int = 1): Future[PBSignedTransaction] = { val unsigned = PBTransaction( @@ -352,8 +352,8 @@ object AsyncGrpcApi { version, PBTransaction.Data.SponsorFee(SponsorFeeTransactionData.of(minFee)) ) - val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def broadcastMassTransfer( @@ -378,8 +378,8 @@ object AsyncGrpcApi { ) ) ) - val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def broadcastInvokeScript( @@ -405,8 +405,8 @@ object AsyncGrpcApi { ) ) ) - val proofs = crypto.sign(caller.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(caller.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def broadcastInvokeExpression( @@ -424,8 +424,8 @@ object AsyncGrpcApi { version, PBTransaction.Data.InvokeExpression(InvokeExpressionTransactionData(ByteString.copyFrom(expression.bytes.value().arr))) ) - val proofs = crypto.sign(caller.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(caller.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def broadcastLease(source: KeyPair, recipient: Recipient, amount: Long, fee: Long, version: Int = 2): Future[PBSignedTransaction] = { @@ -437,8 +437,8 @@ object AsyncGrpcApi { version, PBTransaction.Data.Lease(LeaseTransactionData.of(Some(recipient), amount)) ) - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def broadcastLeaseCancel(source: KeyPair, leaseId: String, fee: Long, version: Int = 2): Future[PBSignedTransaction] = { @@ -450,8 +450,8 @@ object AsyncGrpcApi { version, PBTransaction.Data.LeaseCancel(LeaseCancelTransactionData.of(ByteString.copyFrom(Base58.decode(leaseId)))) ) - val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + val proofs = crypto.sign(source.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } def setAssetScript( @@ -472,11 +472,11 @@ object AsyncGrpcApi { ) script match { - case Left(_) => transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.EMPTY))) + case Left(_) => transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.EMPTY))) case _ => val proofs = - crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - transactions.broadcast(SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) + crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + transactions.broadcast(SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr)))) } } @@ -504,8 +504,8 @@ object AsyncGrpcApi { ) ) - val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsigned)), unsafe = true).explicitGet().bodyBytes()) - val transaction = SignedTransaction.of(Some(unsigned), Seq(ByteString.copyFrom(proofs.arr))) + val proofs = crypto.sign(sender.privateKey, PBTransactions.vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = true).explicitGet().bodyBytes()) + val transaction = SignedTransaction.of(SignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proofs.arr))) transactions.broadcast(transaction) } diff --git a/node-it/src/test/scala/com/wavesplatform/it/api/SyncGrpcApi.scala b/node-it/src/test/scala/com/wavesplatform/it/api/SyncGrpcApi.scala index 8de17529982..121c2c4e8f8 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/api/SyncGrpcApi.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/api/SyncGrpcApi.scala @@ -303,7 +303,7 @@ object SyncGrpcApi extends Assertions { } def signedBroadcast(tx: PBSignedTransaction, waitForTx: Boolean = false): PBSignedTransaction = { - maybeWaitForTransaction(sync(async(n).broadcast(tx.getTransaction, tx.proofs)), waitForTx) + maybeWaitForTransaction(sync(async(n).broadcast(tx.getWavesTransaction, tx.proofs)), waitForTx) } def broadcast(tx: PBTransaction, proofs: Seq[ByteString], waitForTx: Boolean = false): PBSignedTransaction = { diff --git a/node-it/src/test/scala/com/wavesplatform/it/api/SyncHttpApi.scala b/node-it/src/test/scala/com/wavesplatform/it/api/SyncHttpApi.scala index 96c5ded54ad..cce03df0544 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/api/SyncHttpApi.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/api/SyncHttpApi.scala @@ -1,6 +1,7 @@ package com.wavesplatform.it.api import java.net.InetSocketAddress + import akka.http.scaladsl.model.StatusCodes.BadRequest import akka.http.scaladsl.model.{StatusCode, StatusCodes} import com.wavesplatform.account.{AddressOrAlias, KeyPair} @@ -14,7 +15,7 @@ import com.wavesplatform.it.Node import com.wavesplatform.it.sync._ import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.compiler.Terms -import com.wavesplatform.state.{AssetDistribution, AssetDistributionPage, DataEntry, Portfolio} +import com.wavesplatform.state.{AssetDistribution, AssetDistributionPage, DataEntry} import com.wavesplatform.transaction.assets.exchange.Order import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.InvokeScriptTransaction @@ -56,6 +57,13 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers { )((id, message, json) => GenericApiError(id, message, StatusCodes.BadRequest.intValue, json)) } + /** + * + * @param id Expected API error code + * @param message Expected API error full message or regex template + * @param code Expected HTTP status code, 400/Bad Request by default + * @param matchMessage When true, uses `message` as regular expression to find it in response. When false, fully tests `message` equality with received error message. + */ case class AssertiveApiError(id: Int, message: String, code: StatusCode = StatusCodes.BadRequest, matchMessage: Boolean = false) implicit class ApiErrorOps(error: ApiError) { @@ -66,8 +74,7 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers { def assertBadRequestAndResponse[R](f: => R, errorRegex: String): Assertion = Try(f) match { case Failure(ApiCallException(UnexpectedStatusCodeException(_, _, statusCode, responseBody))) => Assertions.assert( - statusCode == BadRequest.intValue && responseBody.replace("\n", "").matches(s".*$errorRegex.*"), - s"\nexpected '$errorRegex'\nactual '$responseBody'" + statusCode == BadRequest.intValue && responseBody.replace("\n", "").matches(s".*$errorRegex.*"), s"\nexpected '$errorRegex'\nactual '$responseBody'" ) case Failure(e) => Assertions.fail(e) case _ => Assertions.fail("Expecting bad request") diff --git a/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcIssueReissueBurnAssetSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcIssueReissueBurnAssetSuite.scala index 12ab8ba7a04..fc16ce9be5d 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcIssueReissueBurnAssetSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcIssueReissueBurnAssetSuite.scala @@ -405,7 +405,7 @@ class GrpcIssueReissueBurnAssetSuite extends AnyFreeSpec with GrpcBaseTransactio case CallableMethod => val tx = invokeScript(account, "issueAsset", fee = fee) assertStateChanges(tx) { sd => - sd.issues match { + (sd.issues: @unchecked) match { case Seq(issue) => validateIssue(issue, data) } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/asset/IssueReissueBurnAssetSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/asset/IssueReissueBurnAssetSuite.scala index a8a9d440874..6b75d4aca92 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/asset/IssueReissueBurnAssetSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/asset/IssueReissueBurnAssetSuite.scala @@ -286,16 +286,16 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec { val asset = issueValidated(acc, simpleReissuableAsset) invokeScript(acc, "transferAndBurn", assetId = asset, count = 100) nodes.waitForHeightArise() - sender.assetDistribution(asset).map { case (a, v) => a.stringRepr -> v } shouldBe Map( + sender.assetDistribution(asset).map { case (a, v) => a.toString -> v } shouldBe Map( miner.address -> 100L, - acc.toAddress.stringRepr -> (simpleReissuableAsset.quantity - 200) + acc.toAddress.toString -> (simpleReissuableAsset.quantity - 200) ) reissue(acc, CallableMethod, asset, 400, reissuable = false) invokeScript(acc, "transferAndBurn", assetId = asset, count = 100) nodes.waitForHeightArise() - sender.assetDistribution(asset).map { case (a, v) => a.stringRepr -> v } shouldBe Map( + sender.assetDistribution(asset).map { case (a, v) => a.toString -> v } shouldBe Map( miner.address -> 200L, - acc.toAddress.stringRepr -> simpleReissuableAsset.quantity + acc.toAddress.toString -> simpleReissuableAsset.quantity ) } @@ -491,7 +491,7 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec { case CallableMethod => val tx = invokeScript(account, "issueAsset", fee = fee) assertStateChanges(tx) { sd => - sd.issues match { + (sd.issues: @unchecked) match { case Seq(issue) => validateIssue(issue, data) } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/AddressApiSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/AddressApiSuite.scala index 22639fee56d..338e46b8702 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/AddressApiSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/AddressApiSuite.scala @@ -15,7 +15,7 @@ import scala.util.Random class AddressApiSuite extends BaseTransactionSuite with NTPTime { test("balance at height") { - val address = sender.createKeyPair().toAddress.stringRepr + val address = sender.createKeyPair().toAddress.toString sender.transfer(sender.keyPair, address, 1, waitForTx = true) nodes.waitForHeightArise() sender.transfer(sender.keyPair, address, 1, waitForTx = true) @@ -23,8 +23,8 @@ class AddressApiSuite extends BaseTransactionSuite with NTPTime { sender.transfer(sender.keyPair, address, 1, waitForTx = true) nodes.waitForHeightArise() - val Seq(_, h2, _) = sender.debugBalanceHistory(address) - val Seq((_, balance)) = sender.accountsBalances(Some(h2.height), Seq(address)) + val Seq(_, h2, _) = sender.debugBalanceHistory(address): @unchecked + val Seq((_, balance)) = sender.accountsBalances(Some(h2.height), Seq(address)): @unchecked balance shouldBe 2 } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/AssetDistributionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/AssetDistributionSuite.scala index c88110bff49..fb4d9b5d167 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/AssetDistributionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/AssetDistributionSuite.scala @@ -29,7 +29,7 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur node.massTransfer( issuer, - addresses.map(addr => MassTransferTransaction.Transfer(addr.stringRepr, transferAmount)), + addresses.map(addr => MassTransferTransaction.Transfer(addr.toString, transferAmount)), minFee + (minFee * addresses.size), assetId = Some(issueTx), waitForTx = true @@ -130,7 +130,7 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur val assetId = node.issue(issuer, "TestCoin#2", "no description", issueAmount, 8, false, issueFee, waitForTx = true).id receivers.foreach { receiver => - node.transfer(issuer, receiver.toAddress.stringRepr, 10, assetId = Some(assetId)) + node.transfer(issuer, receiver.toAddress.toString, 10, assetId = Some(assetId)) } @@ -145,7 +145,7 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur def distributionPages(asset: String, height: Int, limit: Int): List[AssetDistributionPage] = { def _load(acc: List[AssetDistributionPage], maybeAfter: Option[String]): List[AssetDistributionPage] = { val page = node.assetDistributionAtHeight(asset, height, limit, maybeAfter) - if (page.hasNext) _load(page :: acc, page.lastItem.map(_.stringRepr)) + if (page.hasNext) _load(page :: acc, page.lastItem.map(_.toString)) else page :: acc } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/MicroblocksSponsoredFeeTestSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/MicroblocksSponsoredFeeTestSuite.scala index 3aaf38a90b4..9d1e30af18a 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/MicroblocksSponsoredFeeTestSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/MicroblocksSponsoredFeeTestSuite.scala @@ -54,6 +54,8 @@ class MicroblocksSponsoredFeeTestSuite extends BaseFreeSpec with ScorexLogging { minerBalances.zip(filteredBlocksFee).sliding(2).foreach { case Seq((minerBalance1, blockFee1), (minerBalance2, blockFee2)) => minerBalance2 should be(minerBalance1 + blockFee1 * 6 / 10 + blockFee2 * 4 / 10) + + case _ => ??? } val block = notMiner.blockAt(height) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/UtxSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/UtxSuite.scala index b394974f691..0c7b45fd1ce 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/UtxSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/UtxSuite.scala @@ -1,21 +1,21 @@ package com.wavesplatform.it.sync +import scala.util.{Random, Try} + import com.typesafe.config.{Config, ConfigFactory} import com.wavesplatform.account.KeyPair import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.it.{BaseFunSuite, Node} import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.TransactionInfo -import com.wavesplatform.it.{BaseFunSuite, Node} import com.wavesplatform.lang.v1.estimator.ScriptEstimatorV1 +import com.wavesplatform.transaction.{utils, TxVersion} import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.TxVersion +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import scala.util.{Random, Try} - class UtxSuite extends BaseFunSuite { private var whitelistedAccount: KeyPair = _ private var whitelistedDAppAccount: KeyPair = _ @@ -154,11 +154,9 @@ class UtxSuite extends BaseFunSuite { .selfSigned(TxVersion.V1, whitelistedAccount, UtxSuite.createAccount.toAddress, Waves, 1L, Waves, minTransferFee, ByteStr.empty, time) .explicitGet() } - val byDApp = (1 to 5).map { _ => - InvokeScriptTransaction - .selfSigned(TxVersion.V1, invokeAccount, whitelistedDAppAccount.toAddress, None, Seq.empty, minInvokeFee, Waves, time) - .explicitGet() - } + val byDApp = Seq.fill(5)( + utils.Signed.invokeScript(TxVersion.V1, invokeAccount, whitelistedDAppAccount.toAddress, None, Seq.empty, minInvokeFee, Waves, time) + ) Random.shuffle(bySender ++ byDApp) } @@ -184,7 +182,7 @@ class UtxSuite extends BaseFunSuite { whitelistedAccount = createAccount whitelistedDAppAccount = createAccount - val whitelist = Seq(whitelistedAccount, whitelistedDAppAccount).map(_.toAddress.stringRepr) + val whitelist = Seq(whitelistedAccount, whitelistedDAppAccount).map(_.toAddress.toString) val minerConfig = ConfigFactory.parseString(UtxSuite.minerConfigPredef(whitelist)) val notMinerConfig = ConfigFactory.parseString(UtxSuite.notMinerConfigPredef(whitelist)) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/BurnTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/BurnTransactionGrpcSuite.scala index 79fcb3b0e6e..b6223b7ddfa 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/BurnTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/BurnTransactionGrpcSuite.scala @@ -13,7 +13,8 @@ class BurnTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("burning assets changes issuer's asset balance; issuer's waves balance is decreased by fee") { for (v <- burnTxSupportedVersions) { val issuedAssetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, s"name+$v", issueAmount, decimals, reissuable = false, fee = issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, s"name+$v", issueAmount, decimals, reissuable = false, fee = issueFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString sender.assetsBalance(firstAddress, Seq(issuedAssetId))(issuedAssetId) shouldBe issueAmount @@ -39,7 +40,8 @@ class BurnTransactionGrpcSuite extends GrpcBaseTransactionSuite { val transferredQuantity = issuedQuantity / 2 val issuedAssetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString sender.broadcastTransfer(firstAcc, Recipient().withPublicKeyHash(secondAddress), transferredQuantity, minFee, assetId = issuedAssetId, waitForTx = true) @@ -62,7 +64,8 @@ class BurnTransactionGrpcSuite extends GrpcBaseTransactionSuite { val burnedQuantity = issuedQuantity + 1 val issuedAssetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString sender.waitForHeightArise() @@ -82,7 +85,8 @@ class BurnTransactionGrpcSuite extends GrpcBaseTransactionSuite { val burnedQuantity = transferredQuantity + 1 val issuedAssetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = false, issueFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString sender.broadcastTransfer(firstAcc, Recipient().withPublicKeyHash(secondAddress), transferredQuantity, minFee, assetId = issuedAssetId, waitForTx = true) @@ -100,7 +104,8 @@ class BurnTransactionGrpcSuite extends GrpcBaseTransactionSuite { val transferredQuantity = issuedQuantity / 2 val issuedAssetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = true, issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, s"name+$v", issuedQuantity, decimals, reissuable = true, issueFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString sender.broadcastTransfer(firstAcc, Recipient().withPublicKeyHash(secondAddress), transferredQuantity, minFee, assetId = issuedAssetId, waitForTx = true) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/DataTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/DataTransactionGrpcSuite.scala index d71e34dc18a..27826cea5b0 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/DataTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/DataTransactionGrpcSuite.scala @@ -56,7 +56,7 @@ class DataTransactionGrpcSuite extends GrpcBaseTransactionSuite { assertGrpcError( sender.broadcast( - dataTx.getTransaction, + dataTx.getWavesTransaction, dataTx.proofs :+ ByteString.copyFrom(new Array[Byte](65)), waitForTx = true ), @@ -297,7 +297,7 @@ class DataTransactionGrpcSuite extends GrpcBaseTransactionSuite { val txIds = dataSet .grouped(100) .map(_.toList) - .map(data => PBTransactions.vanilla(sender.putData(fourthAcc, data, calcDataFee(data, v), version = v)).explicitGet().id().toString) + .map(data => PBTransactions.vanilla(sender.putData(fourthAcc, data, calcDataFee(data, v), version = v), unsafe = false).explicitGet().id().toString) txIds.foreach(tx => sender.waitForTransaction(tx)) val r = scala.util.Random.nextInt(199) sender.getDataByKey(fourthAddress, s"int$r") shouldBe List(DataEntry(s"int$r", DataEntry.Value.IntValue(1000 + r))) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ExchangeTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ExchangeTransactionGrpcSuite.scala index 982ad9af9d0..0b2ff8ea776 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ExchangeTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ExchangeTransactionGrpcSuite.scala @@ -32,7 +32,7 @@ class ExchangeTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime test("exchange tx with orders v1,v2") { val exchAsset = sender.broadcastIssue(buyer, Base64.encode("exchAsset".utf8Bytes), someAssetAmount, 8, reissuable = true, 1.waves, waitForTx = true) - val exchAssetId = PBTransactions.vanilla(exchAsset).explicitGet().id().toString + val exchAssetId = PBTransactions.vanilla(exchAsset, unsafe = false).explicitGet().id().toString val price = 500000L val amount = 40000000L val priceAssetSpending = amount * price / 100000000L @@ -58,7 +58,7 @@ class ExchangeTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime test("exchange tx with orders v3") { val feeAsset = sender.broadcastIssue(buyer, "feeAsset", someAssetAmount, 8, reissuable = true, 1.waves, waitForTx = true) - val feeAssetId = PBTransactions.vanilla(feeAsset).explicitGet().id() + val feeAssetId = PBTransactions.vanilla(feeAsset, unsafe = false).explicitGet().id() val price = 500000L val amount = 40000000L val priceAssetSpending = price * amount / 100000000L diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/FailedTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/FailedTransactionGrpcSuite.scala index ca0565a653c..bc44e3e9995 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/FailedTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/FailedTransactionGrpcSuite.scala @@ -449,7 +449,7 @@ class FailedTransactionGrpcSuite extends GrpcBaseTransactionSuite with FailedTra val tx = PBTransactions.protobuf( mkExchange(buyer, seller, matcher, assetPair, fee, buyMatcherFeeAssetId, sellMatcherFeeAssetId, buyMatcherFee, sellMatcherFee) ) - sender.broadcast(tx.transaction.get, tx.proofs) + sender.broadcast(tx.getWavesTransaction, tx.proofs) } overflowBlock() sendTxsAndThenPriorityTx( @@ -515,7 +515,7 @@ class FailedTransactionGrpcSuite extends GrpcBaseTransactionSuite with FailedTra val tx = PBTransactions.protobuf( mkExchange(buyer, seller, matcher, assetPair, fee, buyMatcherFeeAssetId, sellMatcherFeeAssetId, buyMatcherFee, sellMatcherFee) ) - sender.broadcast(tx.transaction.get, tx.proofs) + sender.broadcast(tx.getWavesTransaction, tx.proofs) } overflowBlock() diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/GetTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/GetTransactionGrpcSuite.scala index 3490df5426c..981d45cbd9e 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/GetTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/GetTransactionGrpcSuite.scala @@ -10,11 +10,12 @@ class GetTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("get transaction by sender, by recipient, by sender&recipient and id") { val txId = PBTransactions.vanilla( - sender.broadcastTransfer(firstAcc, Recipient().withPublicKeyHash(secondAddress), transferAmount, minFee, waitForTx = true) + sender.broadcastTransfer(firstAcc, Recipient().withPublicKeyHash(secondAddress), transferAmount, minFee, waitForTx = true), + unsafe = false ).explicitGet().id().toString - val transactionBySenderAndId = sender.getTransaction(sender = firstAddress, id = txId).getTransaction - val transactionByRecipientAndId = sender.getTransaction(recipient = Some(Recipient().withPublicKeyHash(secondAddress)), id = txId).getTransaction - val transactionBySenderRecipientAndId = sender.getTransaction(sender = firstAddress, recipient = Some(Recipient().withPublicKeyHash(secondAddress)), id = txId).getTransaction + val transactionBySenderAndId = sender.getTransaction(sender = firstAddress, id = txId).getWavesTransaction + val transactionByRecipientAndId = sender.getTransaction(recipient = Some(Recipient().withPublicKeyHash(secondAddress)), id = txId).getWavesTransaction + val transactionBySenderRecipientAndId = sender.getTransaction(sender = firstAddress, recipient = Some(Recipient().withPublicKeyHash(secondAddress)), id = txId).getWavesTransaction transactionBySenderAndId.senderPublicKey shouldBe ByteString.copyFrom(Base58.decode(firstAcc.publicKey.toString)) transactionByRecipientAndId.getTransfer.getRecipient shouldBe PBRecipients.create(secondAcc.toAddress) @@ -24,13 +25,13 @@ class GetTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("get multiple transactions") { val txs = List.fill(10)(sender.broadcastTransfer(thirdAcc, Recipient().withPublicKeyHash(secondAddress), transferAmount / 10, minFee, waitForTx = true)) - val txsIds = txs.map(tx => PBTransactions.vanilla(tx).explicitGet().id().toString) + val txsIds = txs.map(tx => PBTransactions.vanilla(tx, unsafe = false).explicitGet().id().toString) val transactionsByIds = sender.getTransactionSeq(txsIds, sender = thirdAddress, recipient = Some(Recipient().withPublicKeyHash(secondAddress))) transactionsByIds.size shouldBe 10 for(tx <- transactionsByIds) { - tx.getTransaction.getTransaction.senderPublicKey shouldBe ByteString.copyFrom(thirdAcc.publicKey.arr) - tx.getTransaction.getTransaction.getTransfer.getRecipient shouldBe PBRecipients.create(secondAcc.toAddress) + tx.getTransaction.getWavesTransaction.senderPublicKey shouldBe ByteString.copyFrom(thirdAcc.publicKey.arr) + tx.getTransaction.getWavesTransaction.getTransfer.getRecipient shouldBe PBRecipients.create(secondAcc.toAddress) } } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptErrorMsgGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptErrorMsgGrpcSuite.scala index 8367c9fb062..43aae5e456e 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptErrorMsgGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptErrorMsgGrpcSuite.scala @@ -55,7 +55,8 @@ class InvokeScriptErrorMsgGrpcSuite extends GrpcBaseTransactionSuite { fee = issueFee + smartFee, script = Right(Some(script)), waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptPayAndTransferAssetGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptPayAndTransferAssetGrpcSuite.scala index 62a326b32f1..a10189e0dd9 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptPayAndTransferAssetGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/InvokeScriptPayAndTransferAssetGrpcSuite.scala @@ -26,7 +26,8 @@ class InvokeScriptPayAndTransferAssetGrpcSuite extends GrpcBaseTransactionSuite test("issue and transfer asset") { assetId = PBTransactions .vanilla( - sender.broadcastIssue(caller, "Asset", assetQuantity, 2, reissuable = true, fee = issueFee, waitForTx = true) + sender.broadcastIssue(caller, "Asset", assetQuantity, 2, reissuable = true, fee = issueFee, waitForTx = true), + unsafe = false ) .explicitGet() .id() @@ -35,7 +36,8 @@ class InvokeScriptPayAndTransferAssetGrpcSuite extends GrpcBaseTransactionSuite val script = Right(Some(ScriptCompiler.compile("true", estimator).explicitGet()._1)) smartAssetId = PBTransactions .vanilla( - sender.broadcastIssue(caller, "Smart", assetQuantity, 2, reissuable = true, fee = issueFee, script = script, waitForTx = true) + sender.broadcastIssue(caller, "Smart", assetQuantity, 2, reissuable = true, fee = issueFee, script = script, waitForTx = true), + unsafe = false ) .explicitGet() .id() @@ -45,7 +47,8 @@ class InvokeScriptPayAndTransferAssetGrpcSuite extends GrpcBaseTransactionSuite val smartScript = Right(Some(ScriptCompiler.compile(scriptText, estimator).explicitGet()._1)) rejAssetId = PBTransactions .vanilla( - sender.broadcastIssue(caller, "Reject", assetQuantity, 2, reissuable = true, fee = issueFee, script = smartScript, waitForTx = true) + sender.broadcastIssue(caller, "Reject", assetQuantity, 2, reissuable = true, fee = issueFee, script = smartScript, waitForTx = true), + unsafe = false ) .explicitGet() .id() @@ -68,7 +71,7 @@ class InvokeScriptPayAndTransferAssetGrpcSuite extends GrpcBaseTransactionSuite |{-# STDLIB_VERSION 3 #-} |{-# CONTENT_TYPE DAPP #-} | - |let receiver = Address(base58'${receiver.toAddress.stringRepr}') + |let receiver = Address(base58'${receiver.toAddress.toString}') | |@Callable(i) |func resendPayment() = { diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/IssueTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/IssueTransactionGrpcSuite.scala index ae0bd771cbe..f106fe4801a 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/IssueTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/IssueTransactionGrpcSuite.scala @@ -36,13 +36,13 @@ class IssueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime wi script = scriptText(v), waitForTx = true ) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString sender.wavesBalance(issuerAddress).available shouldBe issuerBalance - issueFee sender.wavesBalance(issuerAddress).effective shouldBe issuerEffBalance - issueFee sender.assetsBalance(issuerAddress, Seq(issuedAssetId)).getOrElse(issuedAssetId, 0L) shouldBe someAssetAmount - val assetInfo = sender.getTransaction(issuedAssetId).getTransaction.getIssue + val assetInfo = sender.getTransaction(issuedAssetId).getWavesTransaction.getIssue assetInfo.decimals shouldBe 8 assetInfo.amount shouldBe someAssetAmount @@ -94,7 +94,7 @@ class IssueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime wi script = scriptText(v), waitForTx = true ) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString val issuedAssetTx2 = sender.broadcastIssue( issuer, @@ -108,13 +108,13 @@ class IssueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime wi script = scriptText(v), waitForTx = true ) - val issuedAssetId2 = PBTransactions.vanilla(issuedAssetTx2).explicitGet().id().toString + val issuedAssetId2 = PBTransactions.vanilla(issuedAssetTx2, unsafe = false).explicitGet().id().toString sender.assetsBalance(issuerAddress, Seq(issuedAssetId)).getOrElse(issuedAssetId, 0L) shouldBe someAssetAmount sender.assetsBalance(issuerAddress, Seq(issuedAssetId2)).getOrElse(issuedAssetId2, 0L) shouldBe someAssetAmount - sender.getTransaction(issuedAssetId).getTransaction.getIssue.name shouldBe assetName - sender.getTransaction(issuedAssetId2).getTransaction.getIssue.name shouldBe assetName + sender.getTransaction(issuedAssetId).getWavesTransaction.getIssue.name shouldBe assetName + sender.getTransaction(issuedAssetId2).getWavesTransaction.getIssue.name shouldBe assetName } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/LeasingTransactionsGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/LeasingTransactionsGrpcSuite.scala index 5c3c23b721b..113f92028a1 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/LeasingTransactionsGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/LeasingTransactionsGrpcSuite.scala @@ -20,7 +20,7 @@ class LeasingTransactionsGrpcSuite extends GrpcBaseTransactionSuite { val secondBalance = sender.wavesBalance(secondAddress) val leaseTx = sender.broadcastLease(firstAcc, PBRecipients.create(secondAcc.toAddress), leasingAmount, minFee, version = v, waitForTx = true) - val vanillaTx = PBTransactions.vanilla(leaseTx).explicitGet() + val vanillaTx = PBTransactions.vanilla(leaseTx, unsafe = false).explicitGet() val leaseTxId = vanillaTx.id().toString val height = sender.getStatus(leaseTxId).height @@ -40,7 +40,7 @@ class LeasingTransactionsGrpcSuite extends GrpcBaseTransactionSuite { test("cannot lease non-own waves") { for (v <- leaseTxSupportedVersions) { val leaseTx = sender.broadcastLease(firstAcc, PBRecipients.create(secondAcc.toAddress), leasingAmount, minFee, version = v, waitForTx = true) - val vanillaTx = PBTransactions.vanilla(leaseTx).explicitGet() + val vanillaTx = PBTransactions.vanilla(leaseTx, unsafe = false).explicitGet() val leaseTxId = vanillaTx.id().toString val height = sender.getStatus(leaseTxId).height @@ -101,7 +101,7 @@ class LeasingTransactionsGrpcSuite extends GrpcBaseTransactionSuite { val secondBalance = sender.wavesBalance(secondAddress) val leaseTx = sender.broadcastLease(firstAcc, PBRecipients.create(secondAcc.toAddress), leasingAmount, minFee, version = v, waitForTx = true) - val leaseTxId = PBTransactions.vanilla(leaseTx).explicitGet().id().toString + val leaseTxId = PBTransactions.vanilla(leaseTx, unsafe = false).explicitGet().id().toString sender.broadcastLeaseCancel(firstAcc, leaseTxId, minFee, waitForTx = true) @@ -120,7 +120,7 @@ class LeasingTransactionsGrpcSuite extends GrpcBaseTransactionSuite { val secondBalance = sender.wavesBalance(secondAddress) val leaseTx = sender.broadcastLease(firstAcc, PBRecipients.create(secondAcc.toAddress), leasingAmount, minFee, version = v, waitForTx = true) - val leaseTxId = PBTransactions.vanilla(leaseTx).explicitGet().id().toString + val leaseTxId = PBTransactions.vanilla(leaseTx, unsafe = false).explicitGet().id().toString sender.broadcastLeaseCancel(firstAcc, leaseTxId, minFee, waitForTx = true) @@ -145,7 +145,7 @@ class LeasingTransactionsGrpcSuite extends GrpcBaseTransactionSuite { val secondBalance = sender.wavesBalance(secondAddress) val leaseTx = sender.broadcastLease(firstAcc, PBRecipients.create(secondAcc.toAddress), leasingAmount, minFee, version = v, waitForTx = true) - val vanillaTx = PBTransactions.vanilla(leaseTx).explicitGet() + val vanillaTx = PBTransactions.vanilla(leaseTx, unsafe = false).explicitGet() val leaseTxId = vanillaTx.id().toString val height = sender.getStatus(leaseTxId).height diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/MassTransferTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/MassTransferTransactionGrpcSuite.scala index 2acce3d88cb..d092db05820 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/MassTransferTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/MassTransferTransactionGrpcSuite.scala @@ -20,7 +20,7 @@ class MassTransferTransactionGrpcSuite extends GrpcBaseTransactionSuite { val transfers = List(Transfer(Some(Recipient().withPublicKeyHash(secondAddress)), transferAmount)) val assetId = PBTransactions.vanilla( - sender.broadcastIssue(firstAcc, "name", issueAmount, 8, reissuable = false, issueFee, waitForTx = true) + sender.broadcastIssue(firstAcc, "name", issueAmount, 8, reissuable = false, issueFee, waitForTx = true), unsafe = false ).explicitGet().id().toString sender.waitForTransaction(assetId) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ReissueTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ReissueTransactionGrpcSuite.scala index c6b28df3f20..9f0fd03baa6 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ReissueTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/ReissueTransactionGrpcSuite.scala @@ -18,7 +18,7 @@ class ReissueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime val reissuerEffBalance = sender.wavesBalance(reissuerAddress).effective val issuedAssetTx = sender.broadcastIssue(reissuer, "assetname", someAssetAmount, decimals = 2, reissuable = true, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString sender.broadcastReissue(reissuer, reissueFee, issuedAssetId, someAssetAmount, reissuable = true, version = v, waitForTx = true) @@ -34,7 +34,7 @@ class ReissueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime val reissuerEffBalance = sender.wavesBalance(reissuerAddress).effective val issuedAssetTx = sender.broadcastIssue(reissuer, "assetname", someAssetAmount, decimals = 2, reissuable = false, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString assertGrpcError(sender.broadcastReissue(reissuer, reissueFee, issuedAssetId, someAssetAmount, version = v, reissuable = true, waitForTx = true), "Asset is not reissuable", @@ -53,7 +53,7 @@ class ReissueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime val hugeReissueFee = reissuerEffBalance + 1.waves val issuedAssetTx = sender.broadcastIssue(reissuer, "assetname", someAssetAmount, decimals = 2, reissuable = true, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString assertGrpcError(sender.broadcastReissue(reissuer, hugeReissueFee, issuedAssetId, someAssetAmount, reissuable = true, version = v, waitForTx = true), "Accounts balance errors", @@ -71,7 +71,7 @@ class ReissueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime val reissuerEffBalance = sender.wavesBalance(reissuerAddress).effective val issuedAssetTx = sender.broadcastIssue(reissuer, "assetname", someAssetAmount, decimals = 2, reissuable = true, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString sender.broadcastReissue(reissuer, reissueFee, issuedAssetId, someAssetAmount, reissuable = false, version = v, waitForTx = true) @@ -91,7 +91,7 @@ class ReissueTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime val reissuerEffBalance = sender.wavesBalance(reissuerAddress).effective val issuedAssetTx = sender.broadcastIssue(reissuer, "assetname", someAssetAmount, decimals = 2, reissuable = true, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAssetTx).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAssetTx, unsafe = false).explicitGet().id().toString sender.broadcastReissue(reissuer, reissueFee, issuedAssetId, someAssetAmount, reissuable = true, version = v, waitForTx = true) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetAssetScriptGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetAssetScriptGrpcSuite.scala index 53cf8872915..5a20efc6f42 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetAssetScriptGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetAssetScriptGrpcSuite.scala @@ -70,7 +70,8 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { ) ), waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() @@ -99,7 +100,7 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { val firstEffBalance = sender.wavesBalance(firstAddress).effective sender.setAssetScript(firstAcc, assetWScript, Right(Some(script2)), setAssetScriptFee, waitForTx = true) - sender.assetInfo(assetWScript).script.flatMap(sd => PBTransactions.toVanillaScript(sd.scriptBytes)) should contain (script2) + sender.assetInfo(assetWScript).script.flatMap(sd => PBTransactions.toVanillaScript(sd.scriptBytes)) should contain(script2) sender.wavesBalance(firstAddress).available shouldBe firstBalance - setAssetScriptFee sender.wavesBalance(firstAddress).effective shouldBe firstEffBalance - setAssetScriptFee @@ -156,7 +157,8 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { issueFee, script = Right(Some(unchangeableScript)), waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() @@ -172,7 +174,8 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { test("try to make SetAssetScript for asset v1") { val assetV1 = PBTransactions .vanilla( - sender.broadcastIssue(thirdAcc, "assetV1", someAssetAmount, 8, reissuable = true, issueFee, waitForTx = true) + sender.broadcastIssue(thirdAcc, "assetV1", someAssetAmount, 8, reissuable = true, issueFee, waitForTx = true), + unsafe = false ) .explicitGet() .id() @@ -192,7 +195,6 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { } - protected override def beforeAll(): Unit = { super.beforeAll() assetWOScript = PBTransactions @@ -205,7 +207,8 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { reissuable = false, fee = issueFee, waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() @@ -222,7 +225,8 @@ class SetAssetScriptGrpcSuite extends GrpcBaseTransactionSuite { fee = issueFee, script = Right(Some(script)), waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetScriptTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetScriptTransactionGrpcSuite.scala index 4602a9e0791..788adcda26e 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetScriptTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SetScriptTransactionGrpcSuite.scala @@ -11,7 +11,14 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.protobuf.Amount -import com.wavesplatform.protobuf.transaction.{PBTransactions, Recipient, SetScriptTransactionData, SignedTransaction, TransferTransactionData, Transaction => PBTransaction} +import com.wavesplatform.protobuf.transaction.{ + PBTransactions, + Recipient, + SetScriptTransactionData, + SignedTransaction, + TransferTransactionData, + Transaction => PBTransaction +} import com.wavesplatform.transaction.smart.script.ScriptCompiler import io.grpc.Status.Code @@ -34,10 +41,12 @@ class SetScriptTransactionGrpcSuite extends GrpcBaseTransactionSuite { } """.stripMargin - val script = ScriptCompiler(scriptText, isAssetScript = false, ScriptEstimatorV2).explicitGet()._1 - val scriptComplexity = Script.estimate(Script.fromBase64String(script.bytes().base64).explicitGet(), ScriptEstimatorV3, fixEstimateOfVerifier = true, useContractVerifierLimit = true).explicitGet() - val setScriptTx = sender.setScript(contract, Right(Some(script)), setScriptFee, waitForTx = true) - val setScriptTxId = PBTransactions.vanilla(setScriptTx).explicitGet().id().toString + val script = ScriptCompiler(scriptText, isAssetScript = false, ScriptEstimatorV2).explicitGet()._1 + val scriptComplexity = Script + .estimate(Script.fromBase64String(script.bytes().base64).explicitGet(), ScriptEstimatorV3, fixEstimateOfVerifier = true, useContractVerifierLimit = true) + .explicitGet() + val setScriptTx = sender.setScript(contract, Right(Some(script)), setScriptFee, waitForTx = true) + val setScriptTxId = PBTransactions.vanilla(setScriptTx, unsafe = false).explicitGet().id().toString val scriptInfo = sender.scriptInfo(contractAddr) @@ -45,7 +54,7 @@ class SetScriptTransactionGrpcSuite extends GrpcBaseTransactionSuite { scriptInfo.scriptText shouldBe script.expr.toString scriptInfo.complexity shouldBe scriptComplexity - sender.getTransaction(setScriptTxId).getTransaction.getSetScript.script shouldBe PBTransactions.toPBScript(Some(script)) + sender.getTransaction(setScriptTxId).getWavesTransaction.getSetScript.script shouldBe PBTransactions.toPBScript(Some(script)) } } @@ -82,9 +91,29 @@ class SetScriptTransactionGrpcSuite extends GrpcBaseTransactionSuite { ) ) val sig1 = - ByteString.copyFrom(crypto.sign(secondAcc.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsignedTransfer))).explicitGet().bodyBytes()).arr) + ByteString.copyFrom( + crypto + .sign( + secondAcc.privateKey, + PBTransactions + .vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsignedTransfer)), unsafe = false) + .explicitGet() + .bodyBytes() + ) + .arr + ) val sig2 = - ByteString.copyFrom(crypto.sign(thirdAcc.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsignedTransfer))).explicitGet().bodyBytes()).arr) + ByteString.copyFrom( + crypto + .sign( + thirdAcc.privateKey, + PBTransactions + .vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsignedTransfer)), unsafe = false) + .explicitGet() + .bodyBytes() + ) + .arr + ) sender.broadcast(unsignedTransfer, Seq(sig1, sig2), waitForTx = true) sender.wavesBalance(contractAddr).available shouldBe firstBalance - transferAmount - transferFee @@ -104,9 +133,29 @@ class SetScriptTransactionGrpcSuite extends GrpcBaseTransactionSuite { data = PBTransaction.Data.SetScript(SetScriptTransactionData()) ) val sig1 = - ByteString.copyFrom(crypto.sign(secondAcc.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsignedSetScript))).explicitGet().bodyBytes()).arr) + ByteString.copyFrom( + crypto + .sign( + secondAcc.privateKey, + PBTransactions + .vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsignedSetScript)), unsafe = false) + .explicitGet() + .bodyBytes() + ) + .arr + ) val sig2 = - ByteString.copyFrom(crypto.sign(thirdAcc.privateKey, PBTransactions.vanilla(SignedTransaction(Some(unsignedSetScript))).explicitGet().bodyBytes()).arr) + ByteString.copyFrom( + crypto + .sign( + thirdAcc.privateKey, + PBTransactions + .vanilla(SignedTransaction(SignedTransaction.Transaction.WavesTransaction(unsignedSetScript)), unsafe = false) + .explicitGet() + .bodyBytes() + ) + .arr + ) sender.broadcast(unsignedSetScript, Seq(sig1, sig2), waitForTx = true) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SponsorFeeTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SponsorFeeTransactionGrpcSuite.scala index 2672befb5e0..652d384ee87 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SponsorFeeTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/SponsorFeeTransactionGrpcSuite.scala @@ -10,39 +10,59 @@ import com.wavesplatform.state.diffs.FeeValidation import io.grpc.Status.Code class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { - val (alice, aliceAddress) = (firstAcc, firstAddress) - val (bob, bobAddress) = (secondAcc, secondAddress) - val (sponsor, sponsorAddress) = (thirdAcc, thirdAddress) - val token = 100L - val sponsorAssetTotal = 100 * token - val minSponsorFee = token - val tinyFee = token / 2 - val smallFee = token + token / 2 - val largeFee = 10 * token + val (alice, aliceAddress) = (firstAcc, firstAddress) + val (bob, bobAddress) = (secondAcc, secondAddress) + val (sponsor, sponsorAddress) = (thirdAcc, thirdAddress) + val token = 100L + val sponsorAssetTotal = 100 * token + val minSponsorFee = token + val tinyFee = token / 2 + val smallFee = token + token / 2 + val largeFee = 10 * token val sponsorFeeTxSupportedVersions: List[Byte] = List(1, 2) test("able to make transfer with sponsored fee") { for (v <- sponsorFeeTxSupportedVersions) { - val minerWavesBalance = sender.wavesBalance(ByteString.copyFrom(Base58.decode(miner.address))) + val minerWavesBalance = sender.wavesBalance(ByteString.copyFrom(Base58.decode(miner.address))) val minerBalanceHeight = sender.height - val sponsoredAssetId = PBTransactions.vanilla( - sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true) - ).explicitGet().id().toString + val sponsoredAssetId = PBTransactions + .vanilla( + sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true), + unsafe = false + ) + .explicitGet() + .id() + .toString val sponsoredAssetMinFee = Some(Amount.of(ByteString.copyFrom(Base58.decode(sponsoredAssetId)), token)) sender.broadcastSponsorFee(sponsor, sponsoredAssetMinFee, fee = sponsorReducedFee, version = v, waitForTx = true) - sender.broadcastTransfer(sponsor, Recipient().withPublicKeyHash(aliceAddress), sponsorAssetTotal / 2, minFee, assetId = sponsoredAssetId, waitForTx = true) + sender.broadcastTransfer( + sponsor, + Recipient().withPublicKeyHash(aliceAddress), + sponsorAssetTotal / 2, + minFee, + assetId = sponsoredAssetId, + waitForTx = true + ) - val aliceWavesBalance = sender.wavesBalance(aliceAddress) - val bobWavesBalance = sender.wavesBalance(bobAddress) + val aliceWavesBalance = sender.wavesBalance(aliceAddress) + val bobWavesBalance = sender.wavesBalance(bobAddress) val sponsorWavesBalance = sender.wavesBalance(sponsorAddress) - val aliceAssetBalance = sender.assetsBalance(aliceAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) - val bobAssetBalance = sender.assetsBalance(bobAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) + val aliceAssetBalance = sender.assetsBalance(aliceAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) + val bobAssetBalance = sender.assetsBalance(bobAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) val sponsorAssetBalance = sender.assetsBalance(sponsorAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) - sender.broadcastTransfer(alice, Recipient().withPublicKeyHash(bobAddress), 10 * token, smallFee, assetId = sponsoredAssetId, feeAssetId = sponsoredAssetId, waitForTx = true) + sender.broadcastTransfer( + alice, + Recipient().withPublicKeyHash(bobAddress), + 10 * token, + smallFee, + assetId = sponsoredAssetId, + feeAssetId = sponsoredAssetId, + waitForTx = true + ) nodes.foreach(n => n.waitForHeight(n.height + 1)) sender.wavesBalance(aliceAddress).available shouldBe aliceWavesBalance.available @@ -60,9 +80,14 @@ class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("only issuer is able to sponsor asset") { for (v <- sponsorFeeTxSupportedVersions) { - val sponsoredAssetId = PBTransactions.vanilla( - sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true) - ).explicitGet().id().toString + val sponsoredAssetId = PBTransactions + .vanilla( + sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true), + unsafe = false + ) + .explicitGet() + .id() + .toString val sponsoredAssetMinFee = Some(Amount.of(ByteString.copyFrom(Base58.decode(sponsoredAssetId)), token)) assertGrpcError( @@ -75,9 +100,14 @@ class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("sponsor is able to cancel sponsorship") { for (v <- sponsorFeeTxSupportedVersions) { - val sponsoredAssetId = PBTransactions.vanilla( - sender.broadcastIssue(alice, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true) - ).explicitGet().id().toString + val sponsoredAssetId = PBTransactions + .vanilla( + sender.broadcastIssue(alice, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true), + unsafe = false + ) + .explicitGet() + .id() + .toString val sponsoredAssetMinFee = Some(Amount.of(ByteString.copyFrom(Base58.decode(sponsoredAssetId)), token)) sender.broadcastSponsorFee(alice, sponsoredAssetMinFee, fee = sponsorReducedFee, version = v, waitForTx = true) @@ -92,7 +122,15 @@ class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { sender.broadcastSponsorFee(alice, sponsoredAssetNullMinFee, fee = sponsorReducedFee, version = v, waitForTx = true) assertGrpcError( - sender.broadcastTransfer(alice, Recipient().withPublicKeyHash(bobAddress), 10 * token, smallFee, assetId = sponsoredAssetId, feeAssetId = sponsoredAssetId, waitForTx = true), + sender.broadcastTransfer( + alice, + Recipient().withPublicKeyHash(bobAddress), + 10 * token, + smallFee, + assetId = sponsoredAssetId, + feeAssetId = sponsoredAssetId, + waitForTx = true + ), s"Asset $sponsoredAssetId is not sponsored, cannot be used to pay fees", Code.INVALID_ARGUMENT ) @@ -101,11 +139,23 @@ class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { test("sponsor is able to update amount of sponsored fee") { for (v <- sponsorFeeTxSupportedVersions) { - val sponsoredAssetId = PBTransactions.vanilla( - sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true) - ).explicitGet().id().toString - - sender.broadcastTransfer(sponsor, Recipient().withPublicKeyHash(aliceAddress), sponsorAssetTotal / 2, minFee, assetId = sponsoredAssetId, waitForTx = true) + val sponsoredAssetId = PBTransactions + .vanilla( + sender.broadcastIssue(sponsor, "SponsoredAsset", sponsorAssetTotal, 2, reissuable = false, issueFee, waitForTx = true), + unsafe = false + ) + .explicitGet() + .id() + .toString + + sender.broadcastTransfer( + sponsor, + Recipient().withPublicKeyHash(aliceAddress), + sponsorAssetTotal / 2, + minFee, + assetId = sponsoredAssetId, + waitForTx = true + ) val sponsoredAssetMinFee = Some(Amount.of(ByteString.copyFrom(Base58.decode(sponsoredAssetId)), token)) sender.broadcastSponsorFee(sponsor, sponsoredAssetMinFee, fee = sponsorReducedFee, version = v, waitForTx = true) @@ -114,18 +164,34 @@ class SponsorFeeTransactionGrpcSuite extends GrpcBaseTransactionSuite { sender.broadcastSponsorFee(sponsor, sponsoredAssetUpdatedMinFee, fee = sponsorReducedFee, version = v, waitForTx = true) assertGrpcError( - sender.broadcastTransfer(alice, Recipient().withPublicKeyHash(bobAddress), 10 * token, smallFee, assetId = sponsoredAssetId, feeAssetId = sponsoredAssetId, waitForTx = true), + sender.broadcastTransfer( + alice, + Recipient().withPublicKeyHash(bobAddress), + 10 * token, + smallFee, + assetId = sponsoredAssetId, + feeAssetId = sponsoredAssetId, + waitForTx = true + ), s"does not exceed minimal value of $minFee WAVES or $largeFee $sponsoredAssetId", Code.INVALID_ARGUMENT ) - val aliceWavesBalance = sender.wavesBalance(aliceAddress) - val bobWavesBalance = sender.wavesBalance(bobAddress) + val aliceWavesBalance = sender.wavesBalance(aliceAddress) + val bobWavesBalance = sender.wavesBalance(bobAddress) val sponsorWavesBalance = sender.wavesBalance(sponsorAddress) - val aliceAssetBalance = sender.assetsBalance(aliceAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) - val bobAssetBalance = sender.assetsBalance(bobAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) + val aliceAssetBalance = sender.assetsBalance(aliceAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) + val bobAssetBalance = sender.assetsBalance(bobAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) val sponsorAssetBalance = sender.assetsBalance(sponsorAddress, Seq(sponsoredAssetId)).getOrElse(sponsoredAssetId, 0L) - sender.broadcastTransfer(alice, Recipient().withPublicKeyHash(bobAddress), 10 * token, largeFee, assetId = sponsoredAssetId, feeAssetId = sponsoredAssetId, waitForTx = true) + sender.broadcastTransfer( + alice, + Recipient().withPublicKeyHash(bobAddress), + 10 * token, + largeFee, + assetId = sponsoredAssetId, + feeAssetId = sponsoredAssetId, + waitForTx = true + ) sender.wavesBalance(aliceAddress).available shouldBe aliceWavesBalance.available sender.wavesBalance(bobAddress).available shouldBe bobWavesBalance.available diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/TransferTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/TransferTransactionGrpcSuite.scala index 19f20939734..efab15e4c8a 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/TransferTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/TransferTransactionGrpcSuite.scala @@ -16,13 +16,13 @@ class TransferTransactionGrpcSuite extends GrpcBaseTransactionSuite with NTPTime super.beforeAll() val issuedAsset = sender.broadcastIssue(firstAcc, "name", someAssetAmount, 8, true, issueFee, waitForTx = true) - issuedAssetId = PBTransactions.vanilla(issuedAsset).explicitGet().id().toString + issuedAssetId = PBTransactions.vanilla(issuedAsset, unsafe = false).explicitGet().id().toString } test("asset transfer changes sender's and recipient's asset balance by transfer amount and waves by fee") { for (v <- transferTxSupportedVersions) { val issuedAsset = sender.broadcastIssue(firstAcc, "name", someAssetAmount, 8, true, issueFee, waitForTx = true) - val issuedAssetId = PBTransactions.vanilla(issuedAsset).explicitGet().id().toString + val issuedAssetId = PBTransactions.vanilla(issuedAsset, unsafe = false).explicitGet().id().toString val firstBalance = sender.wavesBalance(firstAddress).available val firstEffBalance = sender.wavesBalance(firstAddress).effective val secondBalance = sender.wavesBalance(secondAddress).available diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/UpdateAssetInfoTransactionGrpcSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/UpdateAssetInfoTransactionGrpcSuite.scala index de15a6ed47c..c7c01121442 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/UpdateAssetInfoTransactionGrpcSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/grpc/UpdateAssetInfoTransactionGrpcSuite.scala @@ -40,7 +40,8 @@ class UpdateAssetInfoTransactionGrpcSuite extends GrpcBaseTransactionSuite with description = "description", version = 1, waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() @@ -54,7 +55,8 @@ class UpdateAssetInfoTransactionGrpcSuite extends GrpcBaseTransactionSuite with val updateAssetInfoTxId = PBTransactions .vanilla( - sender.updateAssetInfo(issuer, assetId, "updatedName", "updatedDescription", minFee) + sender.updateAssetInfo(issuer, assetId, "updatedName", "updatedDescription", minFee), + unsafe = false ) .explicitGet() .id() @@ -149,7 +151,8 @@ class UpdateAssetInfoTransactionGrpcSuite extends GrpcBaseTransactionSuite with fee = issueFee, script = Right(Some(script)), waitForTx = true - ) + ), + unsafe = false ) .explicitGet() .id() diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/network/SimpleTransactionsSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/network/SimpleTransactionsSuite.scala index 9106f10a609..00bbc531065 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/network/SimpleTransactionsSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/network/SimpleTransactionsSuite.scala @@ -30,7 +30,7 @@ class SimpleTransactionsSuite extends BaseTransactionSuite { val tx = TransferTransaction.selfSigned(1.toByte, node.keyPair, Address.fromString(node.address).explicitGet(), Waves, 1L, Waves, minFee, ByteStr.empty, System.currentTimeMillis()) .explicitGet() - node.sendByNetwork(RawBytes.fromTransaction(tx)) + node.sendByNetwork(RawBytes.fromTransaction(tx, forceProtobuf = false)) node.waitForTransaction(tx.id().toString) } @@ -50,7 +50,7 @@ class SimpleTransactionsSuite extends BaseTransactionSuite { ) .explicitGet() - node.sendByNetwork(RawBytes.fromTransaction(tx)) + node.sendByNetwork(RawBytes.fromTransaction(tx, forceProtobuf = false)) val maxHeight = nodes.map(_.height).max nodes.waitForHeight(maxHeight + 1) node.ensureTxDoesntExist(tx.id().toString) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/EstimatorTestSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/EstimatorTestSuite.scala index 87b4fc3b9b9..1c88e9135c8 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/EstimatorTestSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/EstimatorTestSuite.scala @@ -30,9 +30,11 @@ class EstimatorTestSuite extends BaseTransactionSuite with CancelAfterFailure { private def smartAcc = firstKeyPair private def callerAcc = secondKeyPair - private val accScript = "base64:AAIDAAAAAAAAAAQI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AIFAAAACyRzaXplNTc5NjA0AAAAAAAAAAAvBQAAAAwkYWNjNDc1Nzk2MDQEAAAADCRhY2M0ODU3OTYwNAkBAAAACHZhbGlkYXRlAAAAAgUAAAAMJGFjYzQ3NTc5NjA0CQABkQAAAAIFAAAACyRsaXN0NTc5NjA0AAAAAAAAAAAvCQAAAgAAAAECAAAAE0xpc3Qgc2l6ZSBleGNlZWQgNDcJAABmAAAAAgkAATEAAAABBQAAAARzaWdzAAAAAAAAAAAA69Yzlw==" var issuedAssetId = "" @@ -48,7 +50,7 @@ class EstimatorTestSuite extends BaseTransactionSuite with CancelAfterFailure { amount = 5.waves, fee = minFee, waitForTx = true - ) + ) ) val value = ByteStr(("4djidnqe9lK09le4FvgRD0BTok55nHP8MKFotfUeQOWEfBkp6MV4skCceWgDGBnc" * 512).dropRight(1).getBytes) @@ -105,21 +107,7 @@ class EstimatorTestSuite extends BaseTransactionSuite with CancelAfterFailure { test("can set contract and invoke script before precheck activation") { sender.setScript(smartAcc, Some(accScript), setScriptFee + smartFee, waitForTx = true).id - - sender - .invokeScript( - callerAcc, - smartAcc.toAddress.toString, - Some("default"), - List.empty, - Seq.empty, - smartMinFee, - None, - waitForTx = true - ) - ._1 - .id - + sender.invokeScript(callerAcc, smartAcc.toAddress.toString, waitForTx = true)._1.id sender.setScript(smartAcc, Some(accScript), setScriptFee + smartFee, waitForTx = true).id } @@ -163,21 +151,7 @@ class EstimatorTestSuite extends BaseTransactionSuite with CancelAfterFailure { } test("can still invoke account and asset scripts after estimator v1 precheck activation") { - sender - .invokeScript( - callerAcc, - smartAcc.toAddress.toString, - Some("default"), - List.empty, - Seq.empty, - smartMinFee, - None, - waitForTx = true - ) - ._1 - .id - + sender.invokeScript(callerAcc, smartAcc.toAddress.toString, waitForTx = true)._1.id sender.transfer(smartAcc, callerAcc.toAddress.toString, 1, minFee + 2 * smartFee, Some(issuedAssetId), None, waitForTx = true) } - } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/PseudoTransactionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/PseudoTransactionSuite.scala index 7098c4fb747..07c80d90146 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/PseudoTransactionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/PseudoTransactionSuite.scala @@ -13,6 +13,7 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler +import com.wavesplatform.transaction.utils.Signed class PseudoTransactionSuite extends BaseTransactionSuite { @@ -22,7 +23,7 @@ class PseudoTransactionSuite extends BaseTransactionSuite { private def caller = thirdKeyPair - private var smartAssetId = "" + private var smartAssetId = "" private val recipientAlias = "alias" protected override def beforeAll(): Unit = { @@ -57,9 +58,18 @@ class PseudoTransactionSuite extends BaseTransactionSuite { test("check burn pseudotransaction fields") { val smartAssetQuantityBefore = sender.assetsDetails(smartAssetId).quantity - val burnedQuantity = 100000 - val signedInvoke = invokeScriptTransaction("burnAsset", List(Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_LONG(burnedQuantity))) - sender.setAssetScript(smartAssetId, firstDApp, script = Some(smartAssetScript(signedInvoke.id().toString)), fee = issueFee + smartFee, waitForTx = true) + val burnedQuantity = 100000 + val signedInvoke = invokeScriptTransaction( + "burnAsset", + List(Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_LONG(burnedQuantity)) + ) + sender.setAssetScript( + smartAssetId, + firstDApp, + script = Some(smartAssetScript(signedInvoke.id().toString)), + fee = issueFee + smartFee, + waitForTx = true + ) sender.signedBroadcast(signedInvoke.json(), waitForTx = true) sender.assetsDetails(smartAssetId).quantity shouldBe smartAssetQuantityBefore - burnedQuantity @@ -67,38 +77,63 @@ class PseudoTransactionSuite extends BaseTransactionSuite { test("check reissue pseudotransaction fields") { val smartAssetQuantityBefore = sender.assetsDetails(smartAssetId).quantity - val addedQuantity = 100000 - val signedInvoke = invokeScriptTransaction("reissueAsset", - List(Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_BOOLEAN(true), Terms.CONST_LONG(addedQuantity))) - sender.setAssetScript(smartAssetId, firstDApp, script = Some(smartAssetScript(signedInvoke.id().toString)), fee = issueFee + smartFee, waitForTx = true) + val addedQuantity = 100000 + val signedInvoke = invokeScriptTransaction( + "reissueAsset", + List(Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_BOOLEAN(true), Terms.CONST_LONG(addedQuantity)) + ) + sender.setAssetScript( + smartAssetId, + firstDApp, + script = Some(smartAssetScript(signedInvoke.id().toString)), + fee = issueFee + smartFee, + waitForTx = true + ) sender.signedBroadcast(signedInvoke.json(), waitForTx = true) sender.assetsDetails(smartAssetId).quantity shouldBe smartAssetQuantityBefore + addedQuantity } test("check transfer pseudotransaction fields") { - val signedInvoke = invokeScriptTransaction("transferAsset", + val signedInvoke = invokeScriptTransaction( + "transferAsset", List( Terms.CONST_BYTESTR(ByteStr.decodeBase58(recipient.toAddress.toString).get).explicitGet(), Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_LONG(transferAmount / 2) - )) - sender.setAssetScript(smartAssetId, firstDApp, script = Some(smartAssetScript(signedInvoke.id().toString)), fee = issueFee + smartFee, waitForTx = true) + ) + ) + sender.setAssetScript( + smartAssetId, + firstDApp, + script = Some(smartAssetScript(signedInvoke.id().toString)), + fee = issueFee + smartFee, + waitForTx = true + ) sender.signedBroadcast(signedInvoke.json(), waitForTx = true) sender.createAlias(recipient, recipientAlias, fee = smartMinFee, waitForTx = true) - val signedInvoke2 = invokeScriptTransaction("transferAssetByAlias", + val signedInvoke2 = invokeScriptTransaction( + "transferAssetByAlias", List( Terms.CONST_STRING(recipientAlias).explicitGet(), Terms.CONST_BYTESTR(ByteStr.decodeBase58(smartAssetId).get).explicitGet(), Terms.CONST_LONG(transferAmount / 2) - )) - sender.setAssetScript(smartAssetId, firstDApp, script = Some(smartAssetScript(signedInvoke2.id().toString)), fee = issueFee + smartFee, waitForTx = true) + ) + ) + sender.setAssetScript( + smartAssetId, + firstDApp, + script = Some(smartAssetScript(signedInvoke2.id().toString)), + fee = issueFee + smartFee, + waitForTx = true + ) sender.signedBroadcast(signedInvoke2.json(), waitForTx = true) } - private def smartAssetScript(invokeId: String): String = ScriptCompiler( - s""" + private def smartAssetScript(invokeId: String): String = + ScriptCompiler( + s""" |{-# STDLIB_VERSION 4 #-} |{-# CONTENT_TYPE EXPRESSION #-} |{-# SCRIPT_TYPE ASSET #-} @@ -135,19 +170,19 @@ class PseudoTransactionSuite extends BaseTransactionSuite { | case _ => true | } """.stripMargin, - isAssetScript = true, - ScriptEstimatorV3 - ).explicitGet()._1.bytes().base64 + isAssetScript = true, + ScriptEstimatorV3 + ).explicitGet()._1.bytes().base64 - private def invokeScriptTransaction(func: String, args: List[EXPR]): InvokeScriptTransaction = { - InvokeScriptTransaction.selfSigned( + private def invokeScriptTransaction(func: String, args: List[EXPR]): InvokeScriptTransaction = + Signed.invokeScript( 2.toByte, caller, AddressOrAlias.fromString(firstDApp.toAddress.toString).explicitGet(), - Some(FUNCTION_CALL(FunctionHeader.User(func),args)), + Some(FUNCTION_CALL(FunctionHeader.User(func), args)), Seq.empty, smartMinFee + smartFee, Waves, - System.currentTimeMillis()).explicitGet() - } -} \ No newline at end of file + System.currentTimeMillis() + ) +} diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/RideReplBlockchainFunctionsSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/RideReplBlockchainFunctionsSuite.scala index 6fb76f34310..0e7ff95ddb7 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/RideReplBlockchainFunctionsSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/RideReplBlockchainFunctionsSuite.scala @@ -36,7 +36,7 @@ class RideReplBlockchainFunctionsSuite extends BaseTransactionSuite { private lazy val chainId: Char = miner.settings.blockchainSettings.addressSchemeCharacter - private lazy val settings = NodeConnectionSettings(miner.nodeApiEndpoint.toString, chainId.toByte, alice.toAddress.stringRepr) + private lazy val settings = NodeConnectionSettings(miner.nodeApiEndpoint.toString, chainId.toByte, alice.toAddress.toString) private lazy val repl = Repl(Some(settings)) private var dataTxId = "" @@ -92,7 +92,7 @@ class RideReplBlockchainFunctionsSuite extends BaseTransactionSuite { } test("this") { - assert("this.toString()", s""""${alice.toAddress.stringRepr}"""") + assert("this.toString()", s""""${alice.toAddress}"""") } test("height") { @@ -168,7 +168,7 @@ class RideReplBlockchainFunctionsSuite extends BaseTransactionSuite { test("assetInfo()") { assert( s"assetInfo(base58'$assetId').value().issuer.toString()", - s""""${alice.toAddress.stringRepr}"""" + s""""${alice.toAddress}"""" ) } @@ -250,28 +250,28 @@ class RideReplBlockchainFunctionsSuite extends BaseTransactionSuite { test("addressFromPublicKey()") { assert( s"addressFromPublicKey(base58'${alice.publicKey}').value().toString()", - s""""${alice.toAddress.stringRepr}"""" + s""""${alice.toAddress}"""" ) } test("addressFromRecipient() with alias") { assert( s"""addressFromRecipient(transferTx1.recipient).toString()""", - s""""${bob.toAddress.stringRepr}"""" + s""""${bob.toAddress}"""" ) } test("addressFromString()") { assert( - s"""addressFromString("${alice.toAddress.stringRepr}").value().toString()""", - s""""${alice.toAddress.stringRepr}"""" + s"""addressFromString("${alice.toAddress}").value().toString()""", + s""""${alice.toAddress}"""" ) } test("addressFromStringValue()") { assert( - s"""addressFromStringValue("${alice.toAddress.stringRepr}").toString()""", - s""""${alice.toAddress.stringRepr}"""" + s"""addressFromStringValue("${alice.toAddress}").toString()""", + s""""${alice.toAddress}"""" ) } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/freecall/InvokeExpressionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/freecall/InvokeExpressionSuite.scala index 4093cf8ffea..6acee7153e1 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/freecall/InvokeExpressionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/freecall/InvokeExpressionSuite.scala @@ -1,12 +1,12 @@ package com.wavesplatform.it.sync.smartcontract.freecall import com.typesafe.config.Config import com.wavesplatform.account.AddressScheme -import com.wavesplatform.api.http.ApiError.CustomValidationError +import com.wavesplatform.api.http.ApiError.{CustomValidationError, StateCheckFailed} import com.wavesplatform.features.BlockchainFeatures.RideV6 import com.wavesplatform.it.NodeConfigs import com.wavesplatform.it.NodeConfigs.Default -import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.{PutDataResponse, StateChangesDetails, Transaction, TransactionInfo} +import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.sync.invokeExpressionFee import com.wavesplatform.it.transactions.BaseTransactionSuite import com.wavesplatform.lang.directives.values.StdLibVersion.V6 @@ -58,7 +58,7 @@ class InvokeExpressionSuite extends BaseTransactionSuite with CancelAfterFailure val unsupportedVersion = InvokeExpressionTransaction.supportedVersions.max + 1 assertApiError( sender.invokeExpression(firstKeyPair, expr, version = unsupportedVersion.toByte), - AssertiveApiError(CustomValidationError.Id, s"Bad transaction type (18) and version ($unsupportedVersion)") + AssertiveApiError(StateCheckFailed.Id, s"Transaction version $unsupportedVersion has not been activated yet", matchMessage = true) ) val illegalExpression = TestCompiler(V6).compileExpression("true").asInstanceOf[ExprScript] diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/DataTransactionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/DataTransactionSuite.scala index 5d8cb315364..eca890f6b36 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/DataTransactionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/DataTransactionSuite.scala @@ -46,7 +46,7 @@ class DataTransactionSuite extends BaseTransactionSuite with EitherValues { test("should not put 65-sized proof") { val keyPair = sender.createKeyPair() - sender.transfer(sender.keyPair, keyPair.toAddress.stringRepr, 1.waves, waitForTx = true) + sender.transfer(sender.keyPair, keyPair.toAddress.toString, 1.waves, waitForTx = true) sender.setScript( keyPair, Some( diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/MassTransferTransactionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/MassTransferTransactionSuite.scala index ddef9c5a95e..43ca7a3a5e4 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/MassTransferTransactionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/MassTransferTransactionSuite.scala @@ -324,7 +324,7 @@ class MassTransferTransactionSuite extends BaseTransactionSuite { createAliasTxs.foreach(sender.waitForTransaction(_)) val transfers = aliases.map { alias => - Transfer(Alias.create(alias).explicitGet().stringRepr, 2.waves) + Transfer(Alias.create(alias).explicitGet().toString, 2.waves) } val txId = sender.massTransfer(firstKeyPair, transfers, 300000, version = v).id nodes.waitForHeightAriseAndTxPresent(txId) diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/SignAndBroadcastApiSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/SignAndBroadcastApiSuite.scala index f667065a6e8..27cc3eb31ae 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/SignAndBroadcastApiSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/SignAndBroadcastApiSuite.scala @@ -51,7 +51,7 @@ class SignAndBroadcastApiSuite extends BaseTransactionSuite with NTPTime with Be val json = Json.obj("type" -> CreateAliasTransaction.typeId, "sender" -> firstAddress, "alias" -> "alias", "fee" -> 100000) val js = if (Option(v).isDefined) json ++ Json.obj("version" -> v) else json assertSignBadJson(js - "type", "failed to parse json message") - assertSignBadJson(js + ("type" -> Json.toJson(-100)), "Bad transaction type") + assertSignBadJson(js + ("type" -> JsNumber(-100)), "Bad transaction type") assertSignBadJson(js - "alias", "failed to parse json message") } @@ -321,7 +321,7 @@ class SignAndBroadcastApiSuite extends BaseTransactionSuite with NTPTime with Be } test("/transactions/sign/{signerAddress} should sign a transaction by key of signerAddress") { - val firstAddress = sender.createKeyPairServerSide().toAddress.stringRepr + val firstAddress = sender.createKeyPairServerSide().toAddress.toString val json = Json.obj( "type" -> TransferTransaction.typeId, diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/TransactionsStatusSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/TransactionsStatusSuite.scala index b458924405a..49aebab5ac6 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/TransactionsStatusSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/TransactionsStatusSuite.scala @@ -1,20 +1,20 @@ package com.wavesplatform.it.sync.transactions +import scala.util.Random + import com.wavesplatform.api.http.ApiError.InvalidIds import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.it.NTPTime -import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.{TransactionInfo, TransactionStatus} +import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.sync._ import com.wavesplatform.it.transactions.BaseTransactionSuite +import com.wavesplatform.transaction.{ProvenTransaction, Transaction} import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.ProvenTransaction import com.wavesplatform.transaction.transfer.TransferTransaction import play.api.libs.json._ -import scala.util.Random - class TransactionsStatusSuite extends BaseTransactionSuite with NTPTime { import TransactionsStatusSuite._ @@ -55,7 +55,7 @@ class TransactionsStatusSuite extends BaseTransactionSuite with NTPTime { val maxTxList = (1 to 1000).map(_ => txIds.head).toList val result = notMiner.transactionStatus(maxTxList) result.size shouldBe maxTxList.size - result.forall(_ == result.head) + assert(result.forall(_ == result.head)) assertBadRequestAndMessage(notMiner.transactionStatus(maxTxList :+ txIds.head), "Too big sequence requested") assertBadRequestAndMessage(notMiner.transactionStatus(Seq()), "Empty request") @@ -75,7 +75,7 @@ class TransactionsStatusSuite extends BaseTransactionSuite with NTPTime { notFound should contain theSameElementsAs data.notFound } - private def mkTransactions: List[ProvenTransaction] = + private def mkTransactions: List[Transaction with ProvenTransaction] = (1001 to 1020).map { amount => TransferTransaction .selfSigned( @@ -92,7 +92,7 @@ class TransactionsStatusSuite extends BaseTransactionSuite with NTPTime { .explicitGet() }.toList - private def waitForTransactions(txs: List[ProvenTransaction]): List[TransactionInfo] = + private def waitForTransactions(txs: List[Transaction]): List[TransactionInfo] = txs.map(tx => nodes.waitForTransaction(tx.id().toString)) } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/UpdateAssetInfoTransactionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/UpdateAssetInfoTransactionSuite.scala index b801eeb541b..f530806c1ac 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/UpdateAssetInfoTransactionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/transactions/UpdateAssetInfoTransactionSuite.scala @@ -1,5 +1,8 @@ package com.wavesplatform.it.sync.transactions +import scala.concurrent.duration._ +import scala.util.Random + import com.typesafe.config.{Config, ConfigFactory} import com.wavesplatform.account.AddressScheme import com.wavesplatform.api.http.ApiError.{InvalidName, StateCheckFailed, TooBigArrayAllocation} @@ -7,23 +10,19 @@ import com.wavesplatform.api.http.requests.UpdateAssetInfoRequest import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.it.NodeConfigs.{Miners, NotMiner} -import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.api.{Transaction, TransactionInfo} +import com.wavesplatform.it.api.SyncHttpApi._ import com.wavesplatform.it.sync._ import com.wavesplatform.it.transactions.BaseTransactionSuite import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 -import com.wavesplatform.transaction.TxVersion -import com.wavesplatform.transaction.assets.UpdateAssetInfoTransaction +import com.wavesplatform.transaction.{TransactionType, TxVersion} import com.wavesplatform.transaction.smart.script.ScriptCompiler import org.scalatest.CancelAfterFailure import org.scalatest.prop.TableDrivenPropertyChecks import play.api.libs.json.{JsObject, Json} -import scala.concurrent.duration._ -import scala.util.Random - class UpdateAssetInfoTransactionSuite extends BaseTransactionSuite with CancelAfterFailure with TableDrivenPropertyChecks { import UpdateAssetInfoTransactionSuite._ val updateInterval = 2 @@ -129,7 +128,7 @@ class UpdateAssetInfoTransactionSuite extends BaseTransactionSuite with CancelAf None ) ) - .as[JsObject] ++ Json.obj("type" -> UpdateAssetInfoTransaction.typeId) + .as[JsObject] ++ Json.obj("type" -> TransactionType.UpdateAssetInfo.id) val fee = sender.calculateFee(txJson) fee.feeAmount shouldBe 1e5.toLong @@ -294,7 +293,7 @@ class UpdateAssetInfoTransactionSuite extends BaseTransactionSuite with CancelAf test("not able to update asset info without paying enough fee") { assertApiError(sender.updateAssetInfo(issuer, assetId, "updatedName", "updatedDescription", minFee - 1)) { error => error.id shouldBe StateCheckFailed.Id - error.message shouldBe s"State check failed. Reason: . Fee for UpdateAssetInfoTransaction (${minFee - 1} in WAVES) does not exceed minimal value of $minFee WAVES." + error.message shouldBe s"State check failed. Reason: Fee for UpdateAssetInfoTransaction (${minFee - 1} in WAVES) does not exceed minimal value of $minFee WAVES." } } diff --git a/node-it/src/test/scala/com/wavesplatform/it/sync/utils/TransactionSerializeSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/sync/utils/TransactionSerializeSuite.scala index 4a691d29262..d120cd06050 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/sync/utils/TransactionSerializeSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/sync/utils/TransactionSerializeSuite.scala @@ -1,6 +1,6 @@ package com.wavesplatform.it.sync.utils -import com.wavesplatform.account.{Address, PublicKey} +import com.wavesplatform.account.{Address, AddressScheme, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.it.api.SyncHttpApi._ @@ -12,14 +12,14 @@ import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms.TRUE import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, IntegerDataEntry} import com.wavesplatform.test._ +import com.wavesplatform.transaction.{CreateAliasTransaction, DataTransaction, Proofs, Transaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange._ import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.transfer.MassTransferTransaction.Transfer import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} -import com.wavesplatform.transaction.{CreateAliasTransaction, DataTransaction, Proofs, Transaction, TxVersion} +import com.wavesplatform.transaction.transfer.MassTransferTransaction.Transfer import com.wavesplatform.utils._ import org.scalatest.Informing import org.scalatest.prop.TableDrivenPropertyChecks @@ -362,7 +362,8 @@ class TransactionSerializeSuite extends BaseTransactionSuite with TableDrivenPro smartMinFee, Waves, ts, - Proofs(Seq(ByteStr.decodeBase58("4bfDaqBcnK3hT8ywFEFndxtS1DTSYfncUqd4s5Vyaa66PZHawtC73rDswUur6QZu5RpqM7L9NFgBHT1vhCoox4vi").get)) + Proofs(Seq(ByteStr.decodeBase58("4bfDaqBcnK3hT8ywFEFndxtS1DTSYfncUqd4s5Vyaa66PZHawtC73rDswUur6QZu5RpqM7L9NFgBHT1vhCoox4vi").get)), + AddressScheme.current.chainId ) .explicitGet() diff --git a/node-it/src/test/scala/com/wavesplatform/test/Signed.scala b/node-it/src/test/scala/com/wavesplatform/test/Signed.scala new file mode 100644 index 00000000000..fa9501982bb --- /dev/null +++ b/node-it/src/test/scala/com/wavesplatform/test/Signed.scala @@ -0,0 +1,24 @@ +package com.wavesplatform.test + +import com.wavesplatform.account.{AddressOrAlias, KeyPair} +import com.wavesplatform.common.utils._ +import com.wavesplatform.lang.v1.compiler.Terms +import com.wavesplatform.transaction.{Asset, Proofs, TxAmount, TxTimestamp} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction + +object Signed { + def invokeScript( + version: Byte, + sender: KeyPair, + dApp: AddressOrAlias, + functionCall: Option[Terms.FUNCTION_CALL], + payments: Seq[InvokeScriptTransaction.Payment], + fee: TxAmount, + feeAssetId: Asset, + timestamp: TxTimestamp + ): InvokeScriptTransaction = + InvokeScriptTransaction + .create(version, sender.publicKey, dApp, functionCall, payments, fee, feeAssetId, timestamp, Proofs.empty, dApp.chainId) + .map(_.signWith(sender.privateKey)) + .explicitGet() +} diff --git a/node/build.sbt b/node/build.sbt index 12ccc9047bd..044969ea2d1 100644 --- a/node/build.sbt +++ b/node/build.sbt @@ -1,7 +1,3 @@ -import CommonSettings.autoImport.network -import com.typesafe.sbt.SbtNativePackager.Universal -import sbtassembly.MergeStrategy - name := "waves" maintainer := "com.wavesplatform" diff --git a/node/src/main/protobuf/waves/database.proto b/node/src/main/protobuf/waves/database.proto index 494736cb791..25122943677 100644 --- a/node/src/main/protobuf/waves/database.proto +++ b/node/src/main/protobuf/waves/database.proto @@ -4,6 +4,7 @@ option java_package = "com.wavesplatform.database.protobuf"; import "waves/block.proto"; import "waves/transaction.proto"; +import "waves/amount.proto"; import "waves/recipient.proto"; import "google/protobuf/empty.proto"; @@ -34,10 +35,26 @@ message TransactionMeta { bool failed = 4; } +message EthereumTransactionMeta { + message Invocation { + bytes function_call = 1; + repeated Amount payments = 2; + } + message Transfer { + bytes public_key_hash = 1; + Amount amount = 2; + } + oneof payload { + Invocation invocation = 1; + Transfer transfer = 2; + } +} + message TransactionData { oneof transaction { bytes legacy_bytes = 1; - SignedTransaction new_transaction = 2; + SignedTransaction waves_transaction = 2; + bytes ethereum_transaction = 4; } bool failed = 3; } diff --git a/node/src/main/scala/com/wavesplatform/Application.scala b/node/src/main/scala/com/wavesplatform/Application.scala index da3613b5e66..10282bcd7c7 100644 --- a/node/src/main/scala/com/wavesplatform/Application.scala +++ b/node/src/main/scala/com/wavesplatform/Application.scala @@ -5,11 +5,6 @@ import java.security.Security import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.atomic.AtomicBoolean -import scala.concurrent.{Await, Future} -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.duration._ -import scala.util.{Failure, Success, Try} - import akka.actor.ActorSystem import akka.http.scaladsl.Http import akka.http.scaladsl.Http.ServerBinding @@ -24,12 +19,14 @@ import com.wavesplatform.api.common._ import com.wavesplatform.api.http._ import com.wavesplatform.api.http.alias.AliasApiRoute import com.wavesplatform.api.http.assets.AssetsApiRoute +import com.wavesplatform.api.http.eth.EthRpcRoute import com.wavesplatform.api.http.leasing.LeaseApiRoute import com.wavesplatform.common.state.ByteStr import com.wavesplatform.consensus.PoSSelector -import com.wavesplatform.database.{openDB, DBExt, Keys} +import com.wavesplatform.database.{DBExt, Keys, openDB} import com.wavesplatform.events.{BlockchainUpdateTriggers, UtxEvent} import com.wavesplatform.extensions.{Context, Extension} +import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.EstimatorProvider._ import com.wavesplatform.features.api.ActivationApiRoute import com.wavesplatform.history.{History, StorageFactory} @@ -38,13 +35,13 @@ import com.wavesplatform.metrics.Metrics import com.wavesplatform.mining.{Miner, MinerDebugInfo, MinerImpl} import com.wavesplatform.network._ import com.wavesplatform.settings.WavesSettings -import com.wavesplatform.state.{Blockchain, BlockchainUpdaterImpl, Diff, Height} import com.wavesplatform.state.appender.{BlockAppender, ExtensionAppender, MicroblockAppender} -import com.wavesplatform.transaction.{Asset, DiscardedBlocks, Transaction} -import com.wavesplatform.transaction.smart.script.trace.TracedResult +import com.wavesplatform.state.{Blockchain, BlockchainUpdaterImpl, Diff, Height} import com.wavesplatform.transaction.TxValidationError.GenericError -import com.wavesplatform.utils._ +import com.wavesplatform.transaction.smart.script.trace.TracedResult +import com.wavesplatform.transaction.{Asset, DiscardedBlocks, Transaction} import com.wavesplatform.utils.Schedulers._ +import com.wavesplatform.utils._ import com.wavesplatform.utx.{UtxPool, UtxPoolImpl} import com.wavesplatform.wallet.Wallet import io.netty.channel.Channel @@ -61,6 +58,11 @@ import org.influxdb.dto.Point import org.iq80.leveldb.DB import org.slf4j.LoggerFactory +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} +import scala.util.{Failure, Success, Try} + class Application(val actorSystem: ActorSystem, val settings: WavesSettings, configRoot: ConfigObject, time: NTP) extends ScorexLogging { app => @@ -141,7 +143,10 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con val pos = PoSSelector(blockchainUpdater, settings.synchronizationSettings.maxBaseTarget) if (settings.minerSettings.enable) - miner = new MinerImpl(allChannels, blockchainUpdater, settings, time, utxStorage, wallet, pos, minerScheduler, appenderScheduler) + miner = + new MinerImpl(allChannels, blockchainUpdater, settings, time, utxStorage, wallet, pos, minerScheduler, appenderScheduler, utxEvents.collect { + case _: UtxEvent.TxAdded => () + }) val processBlock = BlockAppender(blockchainUpdater, time, utxStorage, pos, allChannels, peerDatabase, appenderScheduler) _ @@ -238,7 +243,16 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con // Network server should be started only after all extensions initialized val networkServer = - NetworkServer(settings, lastBlockInfo, historyReplier, utxStorage, peerDatabase, allChannels, establishedConnections) + NetworkServer( + settings, + lastBlockInfo, + historyReplier, + utxStorage, + peerDatabase, + allChannels, + establishedConnections, + () => blockchainUpdater.isFeatureActivated(BlockchainFeatures.BlockV5) + ) maybeNetworkServer = Some(networkServer) val (signatures, blocks, blockchainScores, microblockInvs, microblockResponses, transactions) = networkServer.messages @@ -316,6 +330,7 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con ) val apiRoutes = Seq( + new EthRpcRoute(blockchainUpdater, extensionContext.transactionsApi,time), NodeApiRoute(settings.restAPISettings, blockchainUpdater, () => shutdown()), BlocksApiRoute(settings.restAPISettings, extensionContext.blocksApi, time), TransactionsApiRoute( @@ -560,8 +575,8 @@ object Application extends ScorexLogging { Metrics.start(settings.metrics, time) def dumpMinerConfig(): Unit = { - import settings.{minerSettings => miner} import settings.synchronizationSettings.microBlockSynchronizer + import settings.{minerSettings => miner} Metrics.write( Point diff --git a/node/src/main/scala/com/wavesplatform/Explorer.scala b/node/src/main/scala/com/wavesplatform/Explorer.scala index f026ab0d0cb..97af5c7978a 100644 --- a/node/src/main/scala/com/wavesplatform/Explorer.scala +++ b/node/src/main/scala/com/wavesplatform/Explorer.scala @@ -4,25 +4,21 @@ import java.io.File import java.nio.ByteBuffer import java.util -import com.google.common.primitives.{Longs, Shorts} +import com.google.common.primitives.Longs import com.wavesplatform.account.Address import com.wavesplatform.api.common.AddressPortfolio import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, Base64, EitherExt2} -import com.wavesplatform.database.{AddressId, DBExt, KeyTags, Keys, LevelDBWriter, openDB, readTransactionBytes, readTransactionHNSeqAndType} -import com.wavesplatform.protobuf.transaction.{PBSignedTransaction, PBTransactions} +import com.wavesplatform.database.{AddressId, DBExt, KeyTags, Keys, LevelDBWriter, loadTransactions, openDB, readTransactionHNSeqAndType} import com.wavesplatform.settings.Constants -import com.wavesplatform.state.{Blockchain, Diff, Height, Portfolio, TxNum} +import com.wavesplatform.state.{Blockchain, Diff, Height, Portfolio} import com.wavesplatform.transaction.Asset.IssuedAsset -import com.wavesplatform.transaction.{Transaction, TransactionParsers} import com.wavesplatform.utils.ScorexLogging import org.iq80.leveldb.DB import scala.annotation.tailrec import scala.collection.mutable -import scala.collection.mutable.ListBuffer import scala.jdk.CollectionConverters._ -import scala.util.Try //noinspection ScalaStyle object Explorer extends ScorexLogging { @@ -222,35 +218,8 @@ object Explorer extends ScorexLogging { } case "TXBH" => - val txs = new ListBuffer[(TxNum, Transaction)] - val h = Height(argument(1, "height").toInt) - - val prefix = ByteBuffer - .allocate(6) - .put(KeyTags.NthTransactionInfoAtHeight.prefixBytes) - .putInt(h) - .array() - - val iterator = db.iterator - - try { - iterator.seek(prefix) - while (iterator.hasNext && iterator.peekNext().getKey.startsWith(prefix)) { - val entry = iterator.next() - - val k = entry.getKey - println(k.toList.map(_.toInt & 0xff)) - - for { - idx <- Try(Shorts.fromByteArray(k.slice(6, 8))) - tx = readTransactionBytes(entry.getValue) match { - case (_, Left(legacyBytes)) => TransactionParsers.parseBytes(legacyBytes).get - case (_, Right(newBytes)) => PBTransactions.vanilla(PBSignedTransaction.parseFrom(newBytes)).explicitGet() - } - } txs.append((TxNum(idx), tx)) - } - } finally iterator.close() + val txs = db.readOnly(loadTransactions(h, _)).get println(txs.length) txs.foreach(println) @@ -290,6 +259,24 @@ object Explorer extends ScorexLogging { log.info(s"${db.get(Keys.idToAddress(AddressId(id.toLong)))}: $count") } + + case "CSAI" => + val PrefixLength = argument(1, "prefix").toInt + var prevAssetId = Array.emptyByteArray + var assetCounter = 0 + db.iterateOver(KeyTags.AssetStaticInfo) { e => + assetCounter += 1 + val thisAssetId = e.getKey.drop(2) + if (prevAssetId.nonEmpty) { + var counter = 0 + while (counter < PrefixLength && prevAssetId(counter) == thisAssetId(counter)) counter += 1 + if (counter == PrefixLength) { + log.info(s"${Base58.encode(prevAssetId)} ~ ${Base58.encode(thisAssetId)}") + } + } + prevAssetId = thisAssetId + } + log.info(s"Checked $assetCounter asset(s)") } } finally db.close() } diff --git a/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala b/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala index e0acc247037..9cc0071a99e 100644 --- a/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala +++ b/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala @@ -4,13 +4,16 @@ import java.io.{File, FileNotFoundException} import java.nio.file.Files import java.time.Instant +import scala.annotation.tailrec +import scala.concurrent.duration._ + import com.typesafe.config.ConfigFactory import com.wavesplatform.account.{Address, AddressScheme, KeyPair} import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.consensus.PoSCalculator.{generationSignature, hit} import com.wavesplatform.consensus.{FairPoSCalculator, NxtPoSCalculator, PoSCalculator} +import com.wavesplatform.consensus.PoSCalculator.{generationSignature, hit} import com.wavesplatform.crypto._ import com.wavesplatform.features.{BlockchainFeature, BlockchainFeatures} import com.wavesplatform.settings.{FunctionalitySettings, GenesisSettings, GenesisTransactionSettings} @@ -20,9 +23,6 @@ import com.wavesplatform.wallet.Wallet import net.ceedubs.ficus.Ficus._ import net.ceedubs.ficus.readers.ArbitraryTypeReader._ -import scala.annotation.tailrec -import scala.concurrent.duration._ - object GenesisBlockGenerator extends App { private type SeedText = String @@ -204,7 +204,7 @@ object GenesisBlockGenerator extends App { settings.initialBalance, Some(genesis.signature), genesisTxs.map { tx => - GenesisTransactionSettings(tx.recipient.stringRepr, tx.amount) + GenesisTransactionSettings(tx.recipient.toString, tx.amount) }, genesis.header.baseTarget, settings.averageBlockDelay diff --git a/node/src/main/scala/com/wavesplatform/MetamaskBootstrap.scala b/node/src/main/scala/com/wavesplatform/MetamaskBootstrap.scala new file mode 100644 index 00000000000..96243e6aedc --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/MetamaskBootstrap.scala @@ -0,0 +1,141 @@ +package com.wavesplatform + +import scala.annotation.tailrec +import scala.concurrent.Await +import scala.concurrent.duration.{Duration, _} + +import akka.actor.ActorSystem +import akka.http.scaladsl.Http +import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest} +import akka.util.ByteString +import com.google.common.primitives.Longs +import com.wavesplatform.account._ +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 +import com.wavesplatform.settings.WalletSettings +import com.wavesplatform.transaction.{ABIConverter, Asset, Transaction} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.smart.script.ScriptCompiler +import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} +import com.wavesplatform.utils.EthEncoding +import com.wavesplatform.wallet.Wallet +import play.api.libs.json.{JsObject, Json} + +//noinspection ScalaStyle +object MetamaskBootstrap extends App { + AddressScheme.current = new AddressScheme { + override val chainId: Byte = 'E'.toByte + } + + val ethAddressString = args(0) + val ethAddress = Address(EthEncoding.toBytes(ethAddressString)) + val wallet = Wallet(WalletSettings(None, Some("123"), ByteStr.decodeBase58("bQbp").toOption)) + val firstKP = wallet.generateNewAccount().get + + val transferWavesToEthAddress = TransferTransaction + .selfSigned( + 2.toByte, + firstKP, + ethAddress, + Asset.Waves, + 50_0000_0000L, + Asset.Waves, + 10_0000L, + ByteStr.empty, + System.currentTimeMillis() + ) + .explicitGet() + + val massTransfer = MassTransferTransaction + .selfSigned( + 2.toByte, + firstKP, + Asset.Waves, + Seq( + MassTransferTransaction.ParsedTransfer(ethAddress, 15_0000_0000L), + MassTransferTransaction.ParsedTransfer(ethAddress, 16_0000_0000L) + ), + 20_000L, + System.currentTimeMillis(), + ByteStr.empty + ) + .explicitGet() + + val randomRecipient = KeyPair(Longs.toByteArray(System.currentTimeMillis())) + val randomEthAddress = EthEncoding.toHexString(randomRecipient.publicKey.toAddress.publicKeyHash) + + val issue = IssueTransaction + .selfSigned(2.toByte, firstKP, "ERC20_1", "", 10000_000000L, 6, false, None, 1_00000000, System.currentTimeMillis()) + .explicitGet() + + val assetId = if (args.length > 1) IssuedAsset(ByteStr.decodeBase58(args(1)).get) else issue.asset + + val transferAsset = + TransferTransaction + .selfSigned(2.toByte, firstKP, ethAddress, assetId, 50_000000, Waves, 10_000L, ByteStr.empty, System.currentTimeMillis()) + .explicitGet() + + val dAppAccount = wallet.generateNewAccount().get + val (script, _) = ScriptCompiler + .compile( + """ + |{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func deposit(amount: Int) = { + | [ + | ScriptTransfer(i.caller, amount, unit) + | ] + |} + | + |""".stripMargin, + ScriptEstimatorV3 + ) + .explicitGet() + val fundDApp = TransferTransaction + .selfSigned(2.toByte, firstKP, dAppAccount.toAddress, Waves, 1_0000_0000L, Waves, 100000L, ByteStr.empty, System.currentTimeMillis()) + .explicitGet() + val setDAppScript = SetScriptTransaction.selfSigned(1.toByte, dAppAccount, Some(script), 500000L, System.currentTimeMillis()).explicitGet() + + println(s"""Rich account: ${firstKP.toAddress} / ${EthEncoding.toHexString(firstKP.toAddress.publicKeyHash)} (seed = ${ByteStr(firstKP.seed)}) + |Primary account: $ethAddress / $ethAddressString + |Asset ID: ${assetId.id} / ${EthEncoding.toHexString(assetId.id.arr.dropRight(12))} + |DApp: ${dAppAccount.toAddress} / ${EthEncoding.toHexString(dAppAccount.toAddress.publicKeyHash)} (seed = ${ByteStr(dAppAccount.seed)})""".stripMargin) + + println(Json.prettyPrint(ABIConverter(script).jsonABI)) + println(ABIConverter(script).funcByMethodId) + + implicit val actorSystem = ActorSystem() + val http = Http() + + @tailrec + def broadcast(tx: Transaction): JsObject = { + val request = HttpRequest( + HttpMethods.POST, + "http://localhost:6869/transactions/broadcast", + entity = HttpEntity.Strict(ContentTypes.`application/json`, ByteString(tx.json().toString())) + ) + val result = Await.result(http.singleRequest(request), Duration.Inf) + + val response = Await.result(result.entity.toStrict(10 seconds), Duration.Inf).data.utf8String + val json = Json.parse(response).as[JsObject] + if (result.status.isSuccess() && !json.value.contains("error")) json + else { + println(json) + Thread.sleep(1000) + broadcast(tx) + } + } + + println("Funding primary acc: " + broadcast(transferWavesToEthAddress)) + if (assetId == issue.asset) println(broadcast(issue)) + println(broadcast(transferAsset)) + + println("Funding DAPP: " + broadcast(fundDApp)) + println("Setting DAPP script: " + broadcast(setDAppScript)) +} diff --git a/node/src/main/scala/com/wavesplatform/ResponsivenessLogs.scala b/node/src/main/scala/com/wavesplatform/ResponsivenessLogs.scala index f32d12184b5..58b1d0b3039 100644 --- a/node/src/main/scala/com/wavesplatform/ResponsivenessLogs.scala +++ b/node/src/main/scala/com/wavesplatform/ResponsivenessLogs.scala @@ -72,7 +72,7 @@ private class ResponsivenessLogs(csvPrefix: String, metricName: String) extends .measurement(metricName) .tag("id", tx.id().toString) .tag("event", eventType.toString.toLowerCase) - .addField("type", tx.builder.typeId) + .addField("type", tx.tpe.id) .addField("height", height) if (eventType == TxEvent.Mined) { @@ -159,7 +159,7 @@ private class ResponsivenessLogs(csvPrefix: String, metricName: String) extends case Some(err) => escape(err.toString) case None => "" } - val txType = tx.builder.typeId + val txType = tx.tpe.id val timestamp = System.currentTimeMillis() val txJson = if (eventType == TxEvent.Expired || eventType == TxEvent.Invalidated) tx.json().toString() else "" val logLine = s"${tx.id()};$eventType;$height;$txType;$timestamp;$reasonClass;$reasonEscaped;$txJson" @@ -189,7 +189,7 @@ object ResponsivenessLogs { def isNeutrino(tx: Transaction): Boolean = { val txAddrs = tx match { case is: InvokeScriptTransaction => - Seq(is.sender.toAddress) ++ (is.dAppAddressOrAlias match { + Seq(is.senderAddress) ++ (is.dApp match { case a: Address => Seq(a) case _ => Nil }) @@ -205,7 +205,7 @@ object ResponsivenessLogs { "3PNikM6yp4NqcSU8guxQtmR5onr2D4e8yTJ" ) - txAddrs.map(_.stringRepr).exists(neutrinoAddrs) + txAddrs.map(_.toString).exists(neutrinoAddrs) } def writeEvent(height: Int, tx: Transaction, eventType: TxEvent, reason: Option[ValidationError] = None): Unit = diff --git a/node/src/main/scala/com/wavesplatform/account/Address.scala b/node/src/main/scala/com/wavesplatform/account/Address.scala deleted file mode 100644 index e5719d4e888..00000000000 --- a/node/src/main/scala/com/wavesplatform/account/Address.scala +++ /dev/null @@ -1,121 +0,0 @@ -package com.wavesplatform.account - -import java.nio.ByteBuffer - -import com.google.common.cache.{Cache, CacheBuilder} -import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils.Base58 -import com.wavesplatform.crypto -import com.wavesplatform.lang.ValidationError -import com.wavesplatform.transaction.TxValidationError.InvalidAddress -import com.wavesplatform.utils.{ScorexLogging, base58Length} -import play.api.libs.json._ - -sealed trait Address extends AddressOrAlias { - lazy val stringRepr: String = Base58.encode(bytes) -} - -//noinspection ScalaDeprecation -object Address extends ScorexLogging { - val Prefix: String = "address:" - val AddressVersion: Byte = 1 - val ChecksumLength: Int = 4 - val HashLength: Int = 20 - val AddressLength: Int = 1 + 1 + HashLength + ChecksumLength - val AddressStringLength: Int = base58Length(AddressLength) - - private[this] val publicKeyBytesCache: Cache[(ByteStr, Byte), Address] = CacheBuilder - .newBuilder() - .softValues() - .maximumSize(200000) - .build() - - private[this] val bytesCache: Cache[ByteStr, Either[InvalidAddress, Address]] = CacheBuilder - .newBuilder() - .softValues() - .maximumSize(200000) - .build() - - def fromPublicKey(publicKey: PublicKey, chainId: Byte = scheme.chainId): Address = { - publicKeyBytesCache.get( - (publicKey, chainId), { () => - val withoutChecksum = ByteBuffer - .allocate(1 + 1 + HashLength) - .put(AddressVersion) - .put(chainId) - .put(crypto.secureHash(publicKey.arr), 0, HashLength) - .array() - - val bytes = ByteBuffer - .allocate(AddressLength) - .put(withoutChecksum) - .put(calcCheckSum(withoutChecksum), 0, ChecksumLength) - .array() - - createUnsafe(bytes) - } - ) - } - - def fromBytes(addressBytes: Array[Byte], chainId: Byte = scheme.chainId): Either[InvalidAddress, Address] = { - bytesCache.get( - ByteStr(addressBytes), { () => - Either - .cond( - addressBytes.length == Address.AddressLength, - (), - InvalidAddress(s"Wrong addressBytes length: expected: ${Address.AddressLength}, actual: ${addressBytes.length}") - ) - .flatMap { - _ => - val version = addressBytes(0) - val network = addressBytes(1) - - (for { - _ <- Either.cond(version == AddressVersion, (), s"Unknown address version: $version") - _ <- Either.cond( - network == chainId, - (), - s"Address belongs to another network: expected: $chainId(${chainId.toChar}), actual: $network(${network.toChar})" - ) - checkSum = addressBytes.takeRight(ChecksumLength) - checkSumGenerated = calcCheckSum(addressBytes.dropRight(ChecksumLength)) - _ <- Either.cond(java.util.Arrays.equals(checkSum, checkSumGenerated), (), s"Bad address checksum") - } yield createUnsafe(addressBytes)).left.map(err => InvalidAddress(err)) - } - } - ) - } - - def fromString(addressStr: String): Either[ValidationError, Address] = { - val base58String = if (addressStr.startsWith(Prefix)) addressStr.drop(Prefix.length) else addressStr - for { - _ <- Either.cond( - base58String.length <= AddressStringLength, - (), - InvalidAddress(s"Wrong address string length: max=$AddressStringLength, actual: ${base58String.length}") - ) - byteArray <- Base58.tryDecodeWithLimit(base58String).toEither.left.map(ex => InvalidAddress(s"Unable to decode base58: ${ex.getMessage}")) - address <- fromBytes(byteArray) - } yield address - } - - def calcCheckSum(withoutChecksum: Array[Byte]): Array[Byte] = { - val fullHash = crypto.secureHash(withoutChecksum) - fullHash.take(ChecksumLength) - } - - implicit val jsonFormat: Format[Address] = Format[Address]( - Reads(jsValue => fromString(jsValue.as[String]).fold(err => JsError(err.toString), JsSuccess(_))), - Writes(addr => JsString(addr.stringRepr)) - ) - - @inline - private[this] def scheme: AddressScheme = AddressScheme.current - - // Optimization, should not be used externally - private[wavesplatform] def createUnsafe(addressBytes: Array[Byte]): Address = new Address { - override val bytes: Array[Byte] = addressBytes - override val chainId: Byte = addressBytes(1) - } -} diff --git a/node/src/main/scala/com/wavesplatform/account/AddressOrAlias.scala b/node/src/main/scala/com/wavesplatform/account/AddressOrAlias.scala deleted file mode 100644 index 714120240a5..00000000000 --- a/node/src/main/scala/com/wavesplatform/account/AddressOrAlias.scala +++ /dev/null @@ -1,68 +0,0 @@ -package com.wavesplatform.account - -import java.nio.ByteBuffer - -import com.wavesplatform.lang.ValidationError -import com.wavesplatform.lang.v1.traits.domain.Recipient -import com.wavesplatform.serialization.Deser -import com.wavesplatform.transaction.TxValidationError._ - -trait AddressOrAlias { - def stringRepr: String - def bytes: Array[Byte] - def chainId: Byte - - override def toString: String = stringRepr - - override def equals(obj: Any): Boolean = obj match { - case a: AddressOrAlias => java.util.Arrays.equals(bytes, a.bytes) - case _ => false - } - - override def hashCode(): Int = java.util.Arrays.hashCode(bytes) -} - -object AddressOrAlias { - def fromBytes(bytes: Array[Byte], position: Int): Either[ValidationError, (AddressOrAlias, Int)] = { - bytes(position) match { - case Address.AddressVersion => - val addressEnd = position + Address.AddressLength - val addressBytes = bytes.slice(position, addressEnd) - Address.fromBytes(addressBytes).map((_, addressEnd)) - case Alias.AddressVersion => - val (_, aliasEnd) = Deser.parseArrayWithLength(bytes, position + 2) - Alias.fromBytes(bytes.slice(position, aliasEnd)).map((_, aliasEnd)) - case _ => Left(InvalidAddress("Unknown address/alias version")) - } - } - - def fromBytes(buf: ByteBuffer): Either[ValidationError, AddressOrAlias] = { - buf.get match { - case Address.AddressVersion => - buf.position(buf.position() - 1) - val addressBytes = new Array[Byte](Address.AddressLength) - buf.get(addressBytes) - Address.fromBytes(addressBytes) - - case Alias.AddressVersion => - val chainId = buf.get - val aliasBytes = Deser.parseArrayWithLength(buf) - Alias.createWithChainId(new String(aliasBytes, "UTF-8"), chainId) - - case _ => - Left(InvalidAddress("Unknown address/alias version")) - } - } - - def fromString(s: String): Either[ValidationError, AddressOrAlias] = { - if (s.startsWith(Alias.Prefix)) - Alias.fromString(s) - else Address.fromString(s) - } - - def fromRide(r: Recipient): Either[ValidationError, AddressOrAlias] = - r match { - case Recipient.Address(bytes) => Address.fromBytes(bytes.arr) - case Recipient.Alias(name) => Alias.create(name) - } -} diff --git a/node/src/main/scala/com/wavesplatform/account/Alias.scala b/node/src/main/scala/com/wavesplatform/account/Alias.scala deleted file mode 100644 index 72c658b54ab..00000000000 --- a/node/src/main/scala/com/wavesplatform/account/Alias.scala +++ /dev/null @@ -1,69 +0,0 @@ -package com.wavesplatform.account - -import com.google.common.primitives.Bytes -import com.wavesplatform.lang.ValidationError -import com.wavesplatform.serialization.Deser -import com.wavesplatform.transaction.TxValidationError.GenericError -import com.wavesplatform.utils._ - -sealed trait Alias extends AddressOrAlias { - lazy val stringRepr: String = Alias.Prefix + chainId.toChar + ":" + name - lazy val bytes: Array[Byte] = Bytes.concat(Array(Alias.AddressVersion, chainId), Deser.serializeArrayWithLength(name.utf8Bytes)) - - val name: String -} - -object Alias { - val Prefix: String = "alias:" - - val AddressVersion: Byte = 2 - val MinLength = 4 - val MaxLength = 30 - - val AliasAlphabet = "-.0123456789@_abcdefghijklmnopqrstuvwxyz" - - def create(name: String): Either[ValidationError, Alias] = { - createWithChainId(name, AddressScheme.current.chainId) - } - - def fromString(str: String): Either[ValidationError, Alias] = { - val aliasPatternInfo = "Alias string pattern is 'alias::" - - if (!str.startsWith(Prefix)) { - Left(GenericError(aliasPatternInfo)) - } else { - val charSemicolonAlias = str.drop(Prefix.length) - val chainId = charSemicolonAlias(0).toByte - val name = charSemicolonAlias.drop(2) - if (charSemicolonAlias(1) != ':') { - Left(GenericError(aliasPatternInfo)) - } else { - createWithChainId(name, chainId) - } - } - } - - def fromBytes(bytes: Array[Byte]): Either[ValidationError, Alias] = { - bytes match { - case Array(`AddressVersion`, chainId, _, _, rest @ _*) => - createWithChainId(new String(rest.toArray, "UTF-8"), chainId) - - case _ => - Left(GenericError("Bad alias bytes")) - } - } - - private[this] def isValidAliasChar(c: Char): Boolean = - ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || c == '_' || c == '@' || c == '-' || c == '.' - - private[wavesplatform] def createWithChainId(name: String, chainId: Byte): Either[ValidationError, Alias] = { - final case class AliasImpl(chainId: Byte, name: String) extends Alias - - if (name.length < MinLength || MaxLength < name.length) - Left(GenericError(s"Alias '$name' length should be between $MinLength and $MaxLength")) - else if (!name.forall(isValidAliasChar)) - Left(GenericError(s"Alias should contain only following characters: $AliasAlphabet")) - else - Right(AliasImpl(chainId, name)) - } -} diff --git a/node/src/main/scala/com/wavesplatform/account/KeyPair.scala b/node/src/main/scala/com/wavesplatform/account/KeyPair.scala index 663a210cca1..3c1b890106a 100644 --- a/node/src/main/scala/com/wavesplatform/account/KeyPair.scala +++ b/node/src/main/scala/com/wavesplatform/account/KeyPair.scala @@ -2,6 +2,8 @@ package com.wavesplatform.account import java.util +import scala.util.{Failure, Success} + import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto.Curve25519 @@ -9,8 +11,6 @@ import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.utils import play.api.libs.json.{Format, Json, Writes} -import scala.util.{Failure, Success} - final class KeyPair(val seed: Array[Byte]) { lazy val privateKey: PrivateKey = PrivateKey(Curve25519.privateKeyFromSeed(seed)) lazy val publicKey: PublicKey = PublicKey(Curve25519.publicKeyFromPrivateKey(privateKey.arr)) diff --git a/node/src/main/scala/com/wavesplatform/account/PublicKey.scala b/node/src/main/scala/com/wavesplatform/account/PublicKey.scala index ee2cfdef549..ff491655419 100644 --- a/node/src/main/scala/com/wavesplatform/account/PublicKey.scala +++ b/node/src/main/scala/com/wavesplatform/account/PublicKey.scala @@ -6,6 +6,7 @@ import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto._ import com.wavesplatform.transaction.TxValidationError.InvalidAddress import com.wavesplatform.utils.base58Length +import org.web3j.crypto.Keys import play.api.libs.json.{Format, Writes} import supertagged._ import supertagged.postfix._ @@ -15,8 +16,10 @@ object PublicKey extends TaggedType[ByteStr] { val KeyStringLength: Int = base58Length(KeyLength) + def isValidSize(length: Int): Boolean = length == KeyLength || length == EthereumKeyLength + def apply(publicKey: ByteStr): PublicKey = { - require(publicKey.arr.length == KeyLength, s"invalid public key length: ${publicKey.arr.length}") + require(isValidSize(publicKey.size), s"invalid public key length: ${publicKey.arr.length}") interner.intern(publicKey @@ this) } @@ -33,8 +36,12 @@ object PublicKey extends TaggedType[ByteStr] { Some(apply(arg)) implicit class PublicKeyImplicitOps(private val pk: PublicKey) extends AnyVal { - def toAddress: Address = Address.fromPublicKey(pk) - def toAddress(chainId: Byte): Address = Address.fromPublicKey(pk, chainId) + def toAddress: Address = toAddress(AddressScheme.current.chainId) + def toAddress(chainId: Byte): Address = pk.size match { + case KeyLength => Address.fromPublicKey(pk, chainId) + case EthereumKeyLength => Address(Keys.getAddress(pk.arr), chainId) + case other => throw new IllegalArgumentException(s"Unexpected public key length: $other") + } } implicit lazy val jsonFormat: Format[PublicKey] = Format[PublicKey]( diff --git a/node/src/main/scala/com/wavesplatform/account/Recipient.scala b/node/src/main/scala/com/wavesplatform/account/Recipient.scala new file mode 100644 index 00000000000..007cef549c5 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/account/Recipient.scala @@ -0,0 +1,218 @@ +package com.wavesplatform.account + +import java.nio.ByteBuffer + +import com.google.common.cache.{Cache, CacheBuilder} +import com.google.common.primitives.Bytes +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.Base58 +import com.wavesplatform.crypto +import com.wavesplatform.lang.ValidationError +import com.wavesplatform.lang.v1.traits.domain.{Recipient => RideRecipient} +import com.wavesplatform.serialization.Deser +import com.wavesplatform.transaction.TxValidationError.{GenericError, InvalidAddress} +import com.wavesplatform.utils.{base58Length, EthEncoding, StringBytes} +import play.api.libs.json._ + +sealed trait AddressOrAlias { + def chainId: Byte + def bytes: Array[Byte] +} + +final class Address private(val chainId: Byte, val publicKeyHash: Array[Byte], checksum: Array[Byte]) extends AddressOrAlias { + override lazy val bytes: Array[Byte] = Bytes.concat(Array(1.toByte, chainId), publicKeyHash, checksum) + override lazy val toString: String = ByteStr(bytes).toString + + override def equals(obj: Any): Boolean = obj match { + case a: Address => java.util.Arrays.equals(publicKeyHash, a.publicKeyHash) && chainId == a.chainId + case _ => false + } + + override def hashCode(): Int = (ByteStr(publicKeyHash), chainId).hashCode() +} + +final case class Alias(chainId: Byte, name: String) extends AddressOrAlias { + override lazy val bytes: Array[Byte] = Bytes.concat(Array(Alias.AddressVersion, chainId), Deser.serializeArrayWithLength(name.utf8Bytes)) + override lazy val toString: String = s"alias:${chainId.toChar}:$name" +} + +object AddressOrAlias { + def fromRide(r: RideRecipient): Either[ValidationError, AddressOrAlias] = + r match { + case RideRecipient.Address(bytes) => Address.fromBytes(bytes.arr) + case RideRecipient.Alias(name) => Alias.create(name) + } + + def fromString(s: String): Either[ValidationError, AddressOrAlias] = s match { + case alias if alias.startsWith(Alias.Prefix) => Alias.fromString(s) + case address => Address.fromString(address) + } + + def fromBytes(buf: Array[Byte]): Either[ValidationError, AddressOrAlias] = buf.headOption match { + case Some(Address.AddressVersion) => Address.fromBytes(buf) + case Some(Alias.AddressVersion) => Alias.fromBytes(buf) + case _ => throw new IllegalArgumentException(s"Not a valid recipient: ${ByteStr(buf)}") + } +} + +object Address { + val Prefix: String = "address:" + val AddressVersion: Byte = 1 + val ChecksumLength: Int = 4 + val HashLength: Int = 20 + val AddressLength: Int = 1 + 1 + HashLength + ChecksumLength + val AddressStringLength: Int = base58Length(AddressLength) + + private[this] val publicKeyBytesCache: Cache[(ByteStr, Byte), Address] = CacheBuilder + .newBuilder() + .softValues() + .maximumSize(200000) + .build() + + private[this] val bytesCache: Cache[ByteStr, Either[InvalidAddress, Address]] = CacheBuilder + .newBuilder() + .softValues() + .maximumSize(200000) + .build() + + def apply(publicKeyHash: Array[Byte], chainId: Byte = AddressScheme.current.chainId): Address = new Address( + chainId, + publicKeyHash, + crypto.secureHash(Array(1.toByte, AddressScheme.current.chainId) ++ publicKeyHash).take(4) + ) + + def fromHexString(hexString: String): Address = Address(EthEncoding.toBytes(hexString)) + + def fromPublicKey(publicKey: PublicKey, chainId: Byte = scheme.chainId): Address = { + publicKeyBytesCache.get( + (publicKey, chainId), { () => + val withoutChecksum = ByteBuffer + .allocate(1 + 1 + HashLength) + .put(AddressVersion) + .put(chainId) + .put(crypto.secureHash(publicKey.arr), 0, HashLength) + .array() + + val bytes = ByteBuffer + .allocate(AddressLength) + .put(withoutChecksum) + .put(calcCheckSum(withoutChecksum), 0, ChecksumLength) + .array() + + createUnsafe(bytes) + } + ) + } + + def fromBytes(addressBytes: Array[Byte], chainId: Byte = scheme.chainId): Either[InvalidAddress, Address] = { + bytesCache.get( + ByteStr(addressBytes), { () => + Either + .cond( + addressBytes.length == Address.AddressLength, + (), + InvalidAddress(s"Wrong addressBytes length: expected: ${Address.AddressLength}, actual: ${addressBytes.length}") + ) + .flatMap { + _ => + val Array(version, network, _*) = (addressBytes: @unchecked) + + (for { + _ <- Either.cond(version == AddressVersion, (), s"Unknown address version: $version") + _ <- Either.cond( + network == chainId, + (), + s"Address belongs to another network: expected: $chainId(${chainId.toChar}), actual: $network(${network.toChar})" + ) + checkSum = addressBytes.takeRight(ChecksumLength) + checkSumGenerated = calcCheckSum(addressBytes.dropRight(ChecksumLength)) + _ <- Either.cond(java.util.Arrays.equals(checkSum, checkSumGenerated), (), s"Bad address checksum") + } yield createUnsafe(addressBytes)).left.map(err => InvalidAddress(err)) + } + } + ) + } + + def fromString(addressStr: String): Either[ValidationError, Address] = { + val base58String = if (addressStr.startsWith(Prefix)) addressStr.drop(Prefix.length) else addressStr + for { + _ <- Either.cond( + base58String.length <= AddressStringLength, + (), + InvalidAddress(s"Wrong address string length: max=$AddressStringLength, actual: ${base58String.length}") + ) + byteArray <- Base58.tryDecodeWithLimit(base58String).toEither.left.map(ex => InvalidAddress(s"Unable to decode base58: ${ex.getMessage}")) + address <- fromBytes(byteArray) + } yield address + } + + def calcCheckSum(withoutChecksum: Array[Byte]): Array[Byte] = { + val fullHash = crypto.secureHash(withoutChecksum) + fullHash.take(ChecksumLength) + } + + implicit val jsonFormat: Format[Address] = Format[Address]( + Reads(jsValue => fromString(jsValue.as[String]).fold(err => JsError(err.toString), JsSuccess(_))), + Writes(addr => JsString(addr.toString)) + ) + + @inline + private[this] def scheme: AddressScheme = AddressScheme.current + + // Optimization, should not be used externally + private[this] def createUnsafe(addressBytes: Array[Byte]): Address = + new Address(addressBytes(1), addressBytes.drop(2).dropRight(4), addressBytes.takeRight(4)) +} + +object Alias { + val Prefix: String = "alias:" + + val AddressVersion: Byte = 2 + val MinLength = 4 + val MaxLength = 30 + + val AliasAlphabet = "-.0123456789@_abcdefghijklmnopqrstuvwxyz" + + def create(name: String): Either[ValidationError, Alias] = { + createWithChainId(name, AddressScheme.current.chainId) + } + + def fromString(str: String): Either[ValidationError, Alias] = { + val aliasPatternInfo = "Alias string pattern is 'alias::" + + if (!str.startsWith(Prefix)) { + Left(GenericError(aliasPatternInfo)) + } else { + val charSemicolonAlias = str.drop(Prefix.length) + val chainId = charSemicolonAlias(0).toByte + val name = charSemicolonAlias.drop(2) + if (charSemicolonAlias(1) != ':') { + Left(GenericError(aliasPatternInfo)) + } else { + createWithChainId(name, chainId) + } + } + } + + def fromBytes(bytes: Array[Byte]): Either[ValidationError, Alias] = { + bytes match { + case Array(`AddressVersion`, chainId, _, _, rest @ _*) => + createWithChainId(new String(rest.toArray, "UTF-8"), chainId) + + case _ => + Left(GenericError("Bad alias bytes")) + } + } + + private[this] def isValidAliasChar(c: Char): Boolean = + ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || c == '_' || c == '@' || c == '-' || c == '.' + + private[wavesplatform] def createWithChainId(name: String, chainId: Byte): Either[ValidationError, Alias] = { + if (name.length < MinLength || MaxLength < name.length) + Left(GenericError(s"Alias '$name' length should be between $MinLength and $MaxLength")) + else if (!name.forall(isValidAliasChar)) + Left(GenericError(s"Alias should contain only following characters: $AliasAlphabet")) + else + Right(new Alias(chainId, name)) + } +} diff --git a/node/src/main/scala/com/wavesplatform/account/package.scala b/node/src/main/scala/com/wavesplatform/account/package.scala index ef6a8d78cbd..72d30a55491 100644 --- a/node/src/main/scala/com/wavesplatform/account/package.scala +++ b/node/src/main/scala/com/wavesplatform/account/package.scala @@ -1,6 +1,9 @@ package com.wavesplatform +sealed trait PublicKey + package object account { + type PublicKey = PublicKey.Type type PrivateKey = PrivateKey.Type } diff --git a/node/src/main/scala/com/wavesplatform/api/common/AddressTransactions.scala b/node/src/main/scala/com/wavesplatform/api/common/AddressTransactions.scala index 9a7812ed9ec..4fb0cb9b555 100644 --- a/node/src/main/scala/com/wavesplatform/api/common/AddressTransactions.scala +++ b/node/src/main/scala/com/wavesplatform/api/common/AddressTransactions.scala @@ -1,11 +1,11 @@ package com.wavesplatform.api.common import com.wavesplatform.account.Address -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.database.protobuf.EthereumTransactionMeta import com.wavesplatform.database.{DBExt, DBResource, Keys} import com.wavesplatform.state.{Diff, Height, InvokeScriptResult, NewTransactionInfo, TransactionId, TxNum} -import com.wavesplatform.transaction.{Authorized, GenesisTransaction, Transaction} +import com.wavesplatform.transaction.{Authorized, EthereumTransaction, GenesisTransaction, Transaction, TransactionType} import monix.eval.Task import monix.reactive.Observable import org.iq80.leveldb.DB @@ -22,22 +22,20 @@ trait AddressTransactions { fromId: Option[ByteStr] ): Observable[TransactionMeta] = Observable - .fromIterator(Task(allAddressTransactions(db, maybeDiff, subject, sender, types, fromId).map { - case (height, transaction, succeeded) => - TransactionMeta.create(height, transaction, succeeded) { ist => - maybeDiff - .flatMap { case (_, diff) => diff.scriptResults.get(ist.id()) } - .orElse(loadInvokeScriptResult(db, ist.id())) - } - })) + .fromIterator( + Task( + allAddressTransactions(db, maybeDiff, subject, sender, types, fromId).map(loadTransactionMeta(db, maybeDiff)) + ) + ) } object AddressTransactions { private def loadTransaction(db: DB, height: Height, txNum: TxNum, sender: Option[Address]): Option[(Height, Transaction, Boolean)] = db.get(Keys.transactionAt(height, txNum)) match { - case Some((tx: Authorized, status)) if sender.forall(_ == tx.sender.toAddress) => Some((height, tx, status)) - case Some((gt: GenesisTransaction, status)) if sender.isEmpty => Some((height, gt, status)) - case _ => None + case Some((tx: Authorized, status)) if sender.forall(_ == tx.sender.toAddress) => Some((height, tx, status)) + case Some((gt: GenesisTransaction, status)) if sender.isEmpty => Some((height, gt, status)) + case Some((et: EthereumTransaction, status)) if sender.forall(_ == et.senderAddress()) => Some((height, et, status)) + case _ => None } private def loadInvokeScriptResult(resource: DBResource, txId: ByteStr): Option[InvokeScriptResult] = @@ -49,6 +47,13 @@ object AddressTransactions { def loadInvokeScriptResult(db: DB, txId: ByteStr): Option[InvokeScriptResult] = db.withResource(r => loadInvokeScriptResult(r, txId)) + def loadEthereumMetadata(db: DB, txId: ByteStr): Option[EthereumTransactionMeta] = db.withResource { resource => + for { + tm <- resource.get(Keys.transactionMetaById(TransactionId(txId))) + m <- resource.get(Keys.ethereumTransactionMeta(Height(tm.height), TxNum(tm.num.toShort))) + } yield m + } + def allAddressTransactions( db: DB, maybeDiff: Option[(Height, Diff)], @@ -88,7 +93,7 @@ object AddressTransactions { (txType, txNum) <- transactionIds.view } yield (height, txNum, txType)) .dropWhile { case (h, txNum, _) => h > maxHeight || h == maxHeight && txNum >= maxTxNum } - .collect { case (h, txNum, txType) if types.isEmpty || types(txType) => h -> txNum } + .collect { case (h, txNum, txType) if types.isEmpty || types(TransactionType(txType)) => h -> txNum } .flatMap { case (h, txNum) => loadTransaction(db, h, txNum, sender) } } .iterator @@ -107,7 +112,7 @@ object AddressTransactions { } yield (height, tx, succeeded)) .dropWhile { case (_, tx, _) => fromId.isDefined && !fromId.contains(tx.id()) } .dropWhile { case (_, tx, _) => fromId.contains(tx.id()) } - .filter { case (_, tx, _) => types.isEmpty || types.contains(tx.typeId) } + .filter { case (_, tx, _) => types.isEmpty || types.contains(tx.tpe) } .collect { case v @ (_, tx: Authorized, _) if sender.forall(_ == tx.sender.toAddress) => v } .iterator } diff --git a/node/src/main/scala/com/wavesplatform/api/common/CommonAccountsApi.scala b/node/src/main/scala/com/wavesplatform/api/common/CommonAccountsApi.scala index bc9f25e04c9..7470bd0e296 100644 --- a/node/src/main/scala/com/wavesplatform/api/common/CommonAccountsApi.scala +++ b/node/src/main/scala/com/wavesplatform/api/common/CommonAccountsApi.scala @@ -2,20 +2,19 @@ package com.wavesplatform.api.common import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.api.common.AddressPortfolio.{assetBalanceIterator, nftIterator} -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.database -import com.wavesplatform.database.{DBExt, KeyTags, Keys} +import com.wavesplatform.database.{DBExt, Keys, KeyTags} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.ValidationError +import com.wavesplatform.state.{AccountScriptInfo, AssetDescription, Blockchain, DataEntry, Diff, Height, InvokeScriptResult} import com.wavesplatform.state.patch.CancelLeasesToDisabledAliases import com.wavesplatform.state.reader.LeaseDetails.Status -import com.wavesplatform.state.{AccountScriptInfo, AssetDescription, Blockchain, DataEntry, Diff, Height, InvokeScriptResult} import com.wavesplatform.transaction.Asset.IssuedAsset +import com.wavesplatform.transaction.TransactionType import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.lease.LeaseTransaction -import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.utils.ScorexLogging import monix.eval.Task import monix.reactive.Observable @@ -81,18 +80,17 @@ object CommonAccountsApi extends ScorexLogging { override def portfolio(address: Address): Observable[(IssuedAsset, Long)] = { val currentDiff = diff() - db.resourceObservable.flatMap { resource => - Observable.fromIterator(Task(assetBalanceIterator(resource, address, currentDiff, includeNft(blockchain)))) - } + db.resourceObservable.flatMap { resource => + Observable.fromIterator(Task(assetBalanceIterator(resource, address, currentDiff, includeNft(blockchain)))) } + } - override def nftList(address: Address, after: Option[IssuedAsset]): Observable[(IssuedAsset, AssetDescription)] = - { - val currentDiff = diff() - db.resourceObservable.flatMap { resource => - Observable.fromIterator(Task(nftIterator(resource, address, currentDiff, after, blockchain.assetDescription))) - } + override def nftList(address: Address, after: Option[IssuedAsset]): Observable[(IssuedAsset, AssetDescription)] = { + val currentDiff = diff() + db.resourceObservable.flatMap { resource => + Observable.fromIterator(Task(nftIterator(resource, address, currentDiff, after, blockchain.assetDescription))) } + } override def script(address: Address): Option[AccountScriptInfo] = blockchain.accountScript(address) @@ -101,8 +99,7 @@ object CommonAccountsApi extends ScorexLogging { override def dataStream(address: Address, regex: Option[String]): Observable[DataEntry[_]] = Observable.defer { val pattern = regex.map(_.r.pattern) - val entriesFromDiff = diff() - .accountData + val entriesFromDiff = diff().accountData .get(address) .fold[Map[String, DataEntry[_]]](Map.empty)(_.data.filter { case (k, _) => pattern.forall(_.matcher(k).matches()) }) @@ -133,7 +130,7 @@ object CommonAccountsApi extends ScorexLogging { Some(Height(blockchain.height) -> diff()), address, None, - Set(LeaseTransaction.typeId, InvokeScriptTransaction.typeId), + Set(TransactionType.Lease, TransactionType.InvokeScript), None ).flatMapIterable { case TransactionMeta(leaseHeight, lt: LeaseTransaction, true) if leaseIsActive(lt.id()) => @@ -148,7 +145,7 @@ object CommonAccountsApi extends ScorexLogging { LeaseInfo.Status.Active ) ) - case TransactionMeta.Invoke(invokeHeight, originTransaction, true, Some(scriptResult)) => + case inv @ TransactionMeta.Invoke(invokeHeight, originTransaction, true, Some(scriptResult)) => def extractLeases(sender: Address, result: InvokeScriptResult): Seq[LeaseInfo] = result.leases.collect { case lease if leaseIsActive(lease.id) => @@ -165,7 +162,7 @@ object CommonAccountsApi extends ScorexLogging { result.invokes.flatMap(i => extractLeases(i.dApp, i.stateChanges)) } - extractLeases(blockchain.resolveAlias(originTransaction.dAppAddressOrAlias).explicitGet(), scriptResult) + extractLeases(blockchain.resolveAlias(inv.transaction.dApp).explicitGet(), scriptResult) case _ => Seq() } diff --git a/node/src/main/scala/com/wavesplatform/api/common/CommonTransactionsApi.scala b/node/src/main/scala/com/wavesplatform/api/common/CommonTransactionsApi.scala index 48a150443f4..1ee57433953 100644 --- a/node/src/main/scala/com/wavesplatform/api/common/CommonTransactionsApi.scala +++ b/node/src/main/scala/com/wavesplatform/api/common/CommonTransactionsApi.scala @@ -1,6 +1,6 @@ package com.wavesplatform.api.common -import com.wavesplatform.account.{Address, AddressOrAlias} +import com.wavesplatform.account.Address import com.wavesplatform.api.{BlockMeta, common} import com.wavesplatform.block import com.wavesplatform.block.Block @@ -9,7 +9,8 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.state.diffs.FeeValidation import com.wavesplatform.state.diffs.FeeValidation.FeeDetails -import com.wavesplatform.state.{Blockchain, Diff, Height, InvokeScriptResult} +import com.wavesplatform.state.{Blockchain, Diff, Height} +import com.wavesplatform.transaction.TransactionType.TransactionType import com.wavesplatform.transaction.smart.InvokeTransaction import com.wavesplatform.transaction.smart.script.trace.TracedResult import com.wavesplatform.transaction.{Asset, CreateAliasTransaction, Transaction} @@ -21,7 +22,6 @@ import org.iq80.leveldb.DB import scala.concurrent.Future trait CommonTransactionsApi { - import CommonTransactionsApi._ def aliasesOfAddress(address: Address): Observable[(Height, CreateAliasTransaction)] @@ -36,9 +36,9 @@ trait CommonTransactionsApi { def broadcastTransaction(tx: Transaction): Future[TracedResult[ValidationError, Boolean]] def transactionsByAddress( - subject: AddressOrAlias, + subject: Address, sender: Option[Address], - transactionTypes: Set[Byte], + transactionTypes: Set[TransactionType], fromId: Option[ByteStr] = None ): Observable[TransactionMeta] @@ -46,33 +46,6 @@ trait CommonTransactionsApi { } object CommonTransactionsApi { - sealed trait TransactionMeta { - def height: Height - def transaction: Transaction - def succeeded: Boolean - } - - object TransactionMeta { - final case class Default(height: Height, transaction: Transaction, succeeded: Boolean) extends TransactionMeta - - final case class Invoke(height: Height, transaction: InvokeTransaction, succeeded: Boolean, invokeScriptResult: Option[InvokeScriptResult]) - extends TransactionMeta - - def unapply(tm: TransactionMeta): Option[(Height, Transaction, Boolean)] = - Some((tm.height, tm.transaction, tm.succeeded)) - - def create(height: Height, transaction: Transaction, succeeded: Boolean)( - result: InvokeTransaction => Option[InvokeScriptResult] - ): TransactionMeta = - transaction match { - case ist: InvokeTransaction => - Invoke(height, ist, succeeded, result(ist)) - - case _ => - Default(height, transaction, succeeded) - } - } - def apply( maybeDiff: => Option[(Height, Diff)], db: DB, @@ -82,28 +55,18 @@ object CommonTransactionsApi { publishTransaction: Transaction => Future[TracedResult[ValidationError, Boolean]], blockAt: Int => Option[(BlockMeta, Seq[Transaction])] ): CommonTransactionsApi = new CommonTransactionsApi { - private def resolve(subject: AddressOrAlias): Option[Address] = blockchain.resolveAlias(subject).toOption - override def aliasesOfAddress(address: Address): Observable[(Height, CreateAliasTransaction)] = common.aliasesOfAddress(db, maybeDiff, address) override def transactionsByAddress( - subject: AddressOrAlias, + subject: Address, sender: Option[Address], - transactionTypes: Set[Byte], + transactionTypes: Set[TransactionType], fromId: Option[ByteStr] = None - ): Observable[TransactionMeta] = resolve(subject).fold(Observable.empty[TransactionMeta]) { subjectAddress => - common.addressTransactions(db, maybeDiff, subjectAddress, sender, transactionTypes, fromId) - } + ): Observable[TransactionMeta] = + common.addressTransactions(db, maybeDiff, subject, sender, transactionTypes, fromId) override def transactionById(transactionId: ByteStr): Option[TransactionMeta] = - blockchain.transactionInfo(transactionId).map { - case (height, transaction, succeeded) => - TransactionMeta.create(Height(height), transaction, succeeded) { _ => - maybeDiff - .flatMap { case (_, diff) => diff.scriptResults.get(transactionId) } - .orElse(AddressTransactions.loadInvokeScriptResult(db, transactionId)) - } - } + blockchain.transactionInfo(transactionId).map(common.loadTransactionMeta(db, maybeDiff)) override def unconfirmedTransactions: Seq[Transaction] = utx.all diff --git a/node/src/main/scala/com/wavesplatform/api/common/TransactionMeta.scala b/node/src/main/scala/com/wavesplatform/api/common/TransactionMeta.scala new file mode 100644 index 00000000000..3a2ec6d03b7 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/api/common/TransactionMeta.scala @@ -0,0 +1,50 @@ +package com.wavesplatform.api.common + +import com.wavesplatform.database.protobuf.EthereumTransactionMeta +import com.wavesplatform.state.{Height, InvokeScriptResult} +import com.wavesplatform.transaction.{EthereumTransaction, Transaction} +import com.wavesplatform.transaction.smart.InvokeTransaction + +sealed trait TransactionMeta { + def height: Height + def transaction: Transaction + def succeeded: Boolean +} + +object TransactionMeta { + + def unapply(tm: TransactionMeta): Option[(Height, Transaction, Boolean)] = + Some((tm.height, tm.transaction, tm.succeeded)) + + def create( + height: Height, + transaction: Transaction, + succeeded: Boolean, + loadStateChanges: Transaction => Option[InvokeScriptResult], + loadEthereumMetadata: EthereumTransaction => Option[EthereumTransactionMeta] + ): TransactionMeta = + transaction match { + case ist: InvokeTransaction => + Invoke(height, ist, succeeded, loadStateChanges(ist)) + + case et: EthereumTransaction => + Ethereum(height, et, succeeded, loadEthereumMetadata(et), loadStateChanges(et)) + + case _ => + Default(height, transaction, succeeded) + } + + final case class Default(height: Height, transaction: Transaction, succeeded: Boolean) extends TransactionMeta + + final case class Invoke(height: Height, transaction: InvokeTransaction, succeeded: Boolean, invokeScriptResult: Option[InvokeScriptResult]) + extends TransactionMeta + + final case class Ethereum( + height: Height, + transaction: EthereumTransaction, + succeeded: Boolean, + meta: Option[EthereumTransactionMeta], + invokeScriptResult: Option[InvokeScriptResult] + ) extends TransactionMeta + +} diff --git a/node/src/main/scala/com/wavesplatform/api/common/package.scala b/node/src/main/scala/com/wavesplatform/api/common/package.scala index 85e7bc0f688..bf4b71496bc 100644 --- a/node/src/main/scala/com/wavesplatform/api/common/package.scala +++ b/node/src/main/scala/com/wavesplatform/api/common/package.scala @@ -1,29 +1,34 @@ package com.wavesplatform.api + import com.wavesplatform.account.Address -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta -import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.api.common.AddressTransactions._ import com.wavesplatform.database.{DBExt, Keys} import com.wavesplatform.state.{Diff, Height} -import com.wavesplatform.transaction.CreateAliasTransaction -import com.wavesplatform.transaction.lease.LeaseTransaction +import com.wavesplatform.transaction.{CreateAliasTransaction, Transaction, TransactionType} import monix.reactive.Observable import org.iq80.leveldb.DB package object common extends BalanceDistribution with AddressTransactions { def aliasesOfAddress(db: DB, maybeDiff: => Option[(Height, Diff)], address: Address): Observable[(Height, CreateAliasTransaction)] = { val disabledAliases = db.get(Keys.disabledAliases) - addressTransactions(db, maybeDiff, address, Some(address), Set(CreateAliasTransaction.typeId), None) + addressTransactions(db, maybeDiff, address, Some(address), Set(TransactionType.CreateAlias), None) .collect { case TransactionMeta(height, cat: CreateAliasTransaction, true) if disabledAliases.isEmpty || !disabledAliases(cat.alias) => height -> cat } } - def activeLeases( - db: DB, - maybeDiff: Option[(Height, Diff)], - address: Address, - leaseIsActive: ByteStr => Boolean - ): Observable[(Height, LeaseTransaction)] = - addressTransactions(db, maybeDiff, address, None, Set(LeaseTransaction.typeId), None) - .collect { case TransactionMeta(h, lt: LeaseTransaction, true) if leaseIsActive(lt.id()) => h -> lt } + def loadTransactionMeta(db: DB, maybeDiff: => Option[(Int, Diff)])(m: (Int, Transaction, Boolean)): TransactionMeta = + TransactionMeta.create( + Height(m._1), + m._2, + m._3, + ist => + maybeDiff + .flatMap { case (_, diff) => diff.scriptResults.get(ist.id()) } + .orElse(loadInvokeScriptResult(db, ist.id())), + et => + maybeDiff + .flatMap { case (_, diff) => diff.ethereumTransactionMeta.get(et.id()) } + .orElse(loadEthereumMetadata(db, et.id())) + ) } diff --git a/node/src/main/scala/com/wavesplatform/api/http/AddressApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/AddressApiRoute.scala index 5ec905f8877..8e4e8ef83d4 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/AddressApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/AddressApiRoute.scala @@ -74,7 +74,7 @@ case class AddressApiRoute( val maxComplexity = (callableComplexities.values.toSeq :+ verifierComplexity).max Json.obj( - "address" -> address.stringRepr, + "address" -> address, "script" -> scriptInfoOpt.map(_.script.bytes().base64), "scriptText" -> scriptInfoOpt.map(_.script.expr.toString), "version" -> scriptInfoOpt.map(_.script.stdLibVersion.id), @@ -136,7 +136,7 @@ case class AddressApiRoute( val details = commonAccountsApi.balanceDetails(address) import details._ complete( - Json.obj("address" -> address.stringRepr, "regular" -> regular, "generating" -> generating, "available" -> available, "effective" -> effective) + Json.obj("address" -> address, "regular" -> regular, "generating" -> generating, "available" -> available, "effective" -> effective) ) } @@ -243,10 +243,10 @@ case class AddressApiRoute( } private def balanceJson(acc: Address, confirmations: Int) = { - Balance(acc.stringRepr, confirmations, commonAccountsApi.balance(acc, confirmations)) + Balance(acc.toString, confirmations, commonAccountsApi.balance(acc, confirmations)) } - private def balanceJson(acc: Address) = Balance(acc.stringRepr, 0, commonAccountsApi.balance(acc)) + private def balanceJson(acc: Address) = Balance(acc.toString, 0, commonAccountsApi.balance(acc)) private def scriptMetaJson(account: Address): Either[ValidationError.ScriptParseError, AccountScriptMeta] = { val accountScript = blockchain.accountScript(account) @@ -254,11 +254,11 @@ case class AddressApiRoute( accountScript .map(_.script) .traverse(Global.dAppFuncTypes) - .map(AccountScriptMeta(account.stringRepr, _)) + .map(AccountScriptMeta(account.toString, _)) } private def effectiveBalanceJson(acc: Address, confirmations: Int) = { - Balance(acc.stringRepr, confirmations, commonAccountsApi.effectiveBalance(acc, confirmations)) + Balance(acc.toString, confirmations, commonAccountsApi.effectiveBalance(acc, confirmations)) } private[this] def validateBalanceDepth(height: Int): Directive0 = { @@ -322,7 +322,7 @@ case class AddressApiRoute( } def publicKey: Route = (path("publicKey" / PublicKeySegment) & get) { publicKey => - complete(Json.obj("address" -> Address.fromPublicKey(publicKey).stringRepr)) + complete(Json.obj("address" -> Address.fromPublicKey(publicKey).toString)) } } diff --git a/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala b/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala index f30cfd7cf22..8999687e48c 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala @@ -1,13 +1,13 @@ package com.wavesplatform.api.http import akka.http.scaladsl.model.{StatusCode, StatusCodes} -import com.wavesplatform.account.{Address, AddressOrAlias, Alias} +import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.state.diffs.TransactionDiffer.TransactionValidationError -import com.wavesplatform.transaction.{Transaction, _} -import com.wavesplatform.transaction.assets.exchange.Order import com.wavesplatform.transaction.Asset.IssuedAsset +import com.wavesplatform.transaction.assets.exchange.Order +import com.wavesplatform.transaction.{Transaction, _} import play.api.libs.json._ case class ApiErrorResponse(error: Int, message: String) @@ -43,7 +43,7 @@ object ApiError { case TxValidationError.GenericError(ge) => CustomValidationError(ge) case TxValidationError.AlreadyInTheState(tx, txHeight) => AlreadyInState(tx, txHeight) case TxValidationError.AccountBalanceError(errs) => AccountBalanceErrors(errs) - case TxValidationError.AliasDoesNotExist(tx) => AliasDoesNotExist(tx) + case TxValidationError.AliasDoesNotExist(alias) => AliasDoesNotExist(alias) case TxValidationError.OrderValidationError(o, m) => OrderInvalid(o, m) case TxValidationError.UnsupportedTransactionType => UnsupportedTransactionType case TxValidationError.Mistiming(err) => Mistiming(err) @@ -58,7 +58,7 @@ object ApiError { case TxValidationError.Mistiming(errorMessage) => Mistiming(errorMessage) case e: TxValidationError.ScriptExecutionError => ScriptExecutionError(tx, e.error, isTokenScript = e.isAssetScript) case e: TxValidationError.FailedTransactionError if e.isExecutionError => ScriptExecutionError(tx, e.message, e.isAssetScript) - case e: TxValidationError.FailedTransactionError => TransactionNotAllowedByAssetScript(tx) + case _: TxValidationError.FailedTransactionError => TransactionNotAllowedByAssetScript(tx) case err => StateCheckFailed(tx, fromValidationError(err)) } case error => CustomValidationError(error.toString) @@ -204,15 +204,11 @@ object ApiError { override val message: String = "block does not exist" } - final case class AliasDoesNotExist(aoa: AddressOrAlias) extends ApiError { + final case class AliasDoesNotExist(alias: Alias) extends ApiError { override val id: Int = AliasDoesNotExist.Id override val code = StatusCodes.NotFound - private[this] lazy val msgReason = (aoa: @unchecked) match { - case a: Address => s"for address '${a.stringRepr}'" - case a: Alias => s"'${a.stringRepr}'" - } - override lazy val message: String = s"alias $msgReason doesn't exist" + override lazy val message: String = s"alias '$alias' doesn't exist" } case object AliasDoesNotExist { @@ -295,8 +291,8 @@ object ApiError { } case class AssetDoesNotExist(assetId: IssuedAsset) extends ApiError { - val id: Int = 313 - val message: String = s"Asset does not exist: $assetId" + val id: Int = 313 + val message: String = s"Asset does not exist: $assetId" val code: StatusCode = StatusCodes.NotFound } @@ -357,7 +353,7 @@ object ApiError { .toJson( errs .map { - case (addr, err) => addr.stringRepr -> err + case (addr, err) => addr.toString -> err } ) ) diff --git a/node/src/main/scala/com/wavesplatform/api/http/ApiMarshallers.scala b/node/src/main/scala/com/wavesplatform/api/http/ApiMarshallers.scala index 4074cbe471d..19d806cd455 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/ApiMarshallers.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/ApiMarshallers.scala @@ -11,10 +11,7 @@ import akka.stream.scaladsl.{Flow, Source} import akka.util.ByteString import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError -import com.wavesplatform.lang.contract.meta.FunctionSignatures -import com.wavesplatform.transaction.Transaction -import com.wavesplatform.transaction.smart.script.trace.{TraceStep, TracedResult} -import play.api.libs.json.Json.JsValueWrapper +import com.wavesplatform.transaction.smart.script.trace.TracedResult import play.api.libs.json._ import scala.util.control.Exception.nonFatalCatch @@ -26,7 +23,7 @@ case class PlayJsonException( ) extends IllegalArgumentException with NoStackTrace -trait ApiMarshallers { +trait ApiMarshallers extends JsonFormats { import akka.http.scaladsl.marshalling.PredefinedToResponseMarshallers._ implicit lazy val ApiErrorMarshaller: ToResponseMarshaller[ApiError] = @@ -35,10 +32,6 @@ trait ApiMarshallers { implicit lazy val ValidationErrorMarshaller: ToResponseMarshaller[ValidationError] = ApiErrorMarshaller.compose(ve => ApiError.fromValidationError(ve)) - implicit lazy val TransactionJsonWrites: OWrites[Transaction] = OWrites(_.json()) - - implicit lazy val logWrites: Writes[TraceStep] = Writes(_.json) - def tracedResultMarshaller[A](includeTrace: Boolean)(implicit writes: OWrites[A]): ToResponseMarshaller[TracedResult[ApiError, A]] = fromStatusCodeAndValue[StatusCode, JsValue] .compose( @@ -49,27 +42,6 @@ trait ApiMarshallers { ) ) - implicit val functionSignaturesWrites: Writes[FunctionSignatures] = - (o: FunctionSignatures) => - Json.obj( - "version" -> o.version.toString, - "isArrayArguments" -> true, - "callableFuncTypes" -> Json.obj( - o.argsWithFuncName.map { - case (functionName, args) => - val functionArgs: JsValueWrapper = - args.map { - case (argName, argType) => - Json.obj( - "name" -> argName, - "type" -> argType.name - ) - } - functionName -> functionArgs - }: _* - ) - ) - private[this] lazy val jsonStringUnmarshaller = Unmarshaller.byteStringUnmarshaller .forContentTypes(`application/json`) diff --git a/node/src/main/scala/com/wavesplatform/api/http/CompositeHttpService.scala b/node/src/main/scala/com/wavesplatform/api/http/CompositeHttpService.scala index 3b06332c85a..eb232da1a27 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/CompositeHttpService.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/CompositeHttpService.scala @@ -60,17 +60,21 @@ case class CompositeHttpService(routes: Seq[ApiRoute], settings: RestAPISettings private val corsAllowedHeaders = (if (settings.apiKeyDifferentHost) List("api_key", "X-API-Key") else List.empty[String]) ++ Seq("Authorization", "Content-Type", "X-Requested-With", "Timestamp", "Signature") - private def corsAllowAll = if (settings.cors) respondWithHeader(`Access-Control-Allow-Origin`.*) else pass + private def corsAllowAll = + if (settings.cors) respondWithHeaders(`Access-Control-Allow-Credentials`(true), + `Access-Control-Allow-Headers`(corsAllowedHeaders), + `Access-Control-Allow-Methods`(OPTIONS, POST, PUT, GET, DELETE), + `Access-Control-Allow-Origin`(HttpOrigin("http://localhost:8080"))) else pass private def extendRoute(base: Route): Route = handleAllExceptions { if (settings.cors) { ctx => - val extendedRoute = corsAllowAll(base) ~ options { + val extendedRoute = options { respondWithDefaultHeaders( `Access-Control-Allow-Credentials`(true), `Access-Control-Allow-Headers`(corsAllowedHeaders), `Access-Control-Allow-Methods`(OPTIONS, POST, PUT, GET, DELETE) )(corsAllowAll(complete(StatusCodes.OK))) - } + } ~ corsAllowAll(base) extendedRoute(ctx) } else base diff --git a/node/src/main/scala/com/wavesplatform/api/http/CustomDirectives.scala b/node/src/main/scala/com/wavesplatform/api/http/CustomDirectives.scala index 902bd814220..fd038ee29cb 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/CustomDirectives.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/CustomDirectives.scala @@ -1,7 +1,13 @@ package com.wavesplatform.api.http +import scala.util.Try + import akka.http.scaladsl.server._ -import com.wavesplatform.utils.ScorexLogging +import cats.data.{Validated, ValidatedNel} +import cats.instances.vector._ +import cats.syntax.traverse._ +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.utils.{EthEncoding, ScorexLogging} import monix.execution.{Scheduler, UncaughtExceptionReporter} import play.api.libs.json.JsObject @@ -16,11 +22,31 @@ trait CustomDirectives extends Directives with ApiMarshallers with ScorexLogging baseDirective .flatMap { case list if nonEmpty && list.isEmpty => reject(MissingQueryParamRejection(paramName)) - case list if list.size > limit => complete(ApiError.TooBigArrayAllocation(limit)) + case list if list.size > limit => complete(ApiError.TooBigArrayAllocation(limit)) case list => provide(list) } } + implicit class SeqDirectiveValidationExt[Source](dir: Directive1[Iterable[Source]]) { + def massValidate[Result](f: Source => Validated[Source, Result]): Directive1[ValidatedNel[Source, Vector[Result]]] = { + dir.map(vs => vs.map(f(_).toValidatedNel).toVector.sequence) + } + } + + implicit class AnyParamStrDirectiveValidationExt(dir: Directive1[Iterable[String]]) { + def massValidateIds: Directive1[Vector[ByteStr]] = + dir.massValidate(str => Validated.fromTry(ByteStr.decodeBase58(str)).leftMap(_ => str)).flatMap { + case Validated.Valid(a) => provide(a) + case Validated.Invalid(e) => complete(ApiError.InvalidIds(e.toList)) + } + + def massValidateEthereumIds: Directive1[Vector[ByteStr]] = + dir.massValidate(str => Validated.fromTry(Try(ByteStr(EthEncoding.toBytes(str)))).leftMap(_ => str)).flatMap { + case Validated.Valid(a) => provide(a) + case Validated.Invalid(e) => complete(ApiError.InvalidIds(e.toList)) + } + } + def extractScheduler: Directive1[Scheduler] = extractExecutionContext.map(ec => Scheduler(ec, UncaughtExceptionReporter((t: Throwable) => log.debug("Error processing request", t)))) } diff --git a/node/src/main/scala/com/wavesplatform/api/http/DebugApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/DebugApiRoute.scala index 6eeebc220e3..274c67a2151 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/DebugApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/DebugApiRoute.scala @@ -16,7 +16,7 @@ import akka.stream.scaladsl.Source import cats.syntax.either._ import com.typesafe.config.{ConfigObject, ConfigRenderOptions} import com.wavesplatform.account.Address -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.api.common.TransactionMeta import com.wavesplatform.api.common.{CommonAccountsApi, CommonAssetsApi, CommonTransactionsApi} import com.wavesplatform.api.http.TransactionsApiRoute.TransactionJsonSerializer import com.wavesplatform.common.state.ByteStr @@ -162,7 +162,7 @@ case class DebugApiRoute( .collect { case (address, Right(offset)) => AccountMiningInfo( - address.stringRepr, + address.toString, blockchain.effectiveBalance( address, ws.blockchainSettings.functionalitySettings.generatingBalanceDepth(blockchain.height), @@ -338,7 +338,7 @@ object DebugApiRoute { implicit val accountMiningBalanceFormat: Format[AccountMiningInfo] = Json.format - implicit val addressWrites: Writes[Address] = Writes((a: Address) => JsString(a.stringRepr)) + implicit val addressWrites: Writes[Address] = Writes((a: Address) => JsString(a.toString)) implicit val hrCacheSizesFormat: Format[HistoryReplier.CacheSizes] = Json.format implicit val mbsCacheSizesFormat: Format[MicroBlockSynchronizer.CacheSizes] = Json.format diff --git a/node/src/main/scala/com/wavesplatform/api/http/JsonFormats.scala b/node/src/main/scala/com/wavesplatform/api/http/JsonFormats.scala new file mode 100644 index 00000000000..6560a38ebcb --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/api/http/JsonFormats.scala @@ -0,0 +1,38 @@ +package com.wavesplatform.api.http + +import com.wavesplatform.account.Address +import com.wavesplatform.lang.contract.meta.FunctionSignatures +import com.wavesplatform.transaction.Transaction +import com.wavesplatform.transaction.smart.script.trace.TraceStep +import play.api.libs.json.Json.JsValueWrapper +import play.api.libs.json._ + +trait JsonFormats { + implicit lazy val wavesAddressWrites: Writes[Address] = Writes(w => JsString(w.toString)) + + implicit lazy val TransactionJsonWrites: OWrites[Transaction] = OWrites(_.json()) + + implicit lazy val logWrites: Writes[TraceStep] = Writes(_.json) + + implicit lazy val functionSignaturesWrites: Writes[FunctionSignatures] = + (o: FunctionSignatures) => + Json.obj( + "version" -> o.version.toString, + "isArrayArguments" -> true, + "callableFuncTypes" -> Json.obj( + o.argsWithFuncName.map { + case (functionName, args) => + val functionArgs: JsValueWrapper = + args.map { + case (argName, argType) => + Json.obj( + "name" -> argName, + "type" -> argType.name + ) + } + functionName -> functionArgs + }: _* + ) + ) + +} diff --git a/node/src/main/scala/com/wavesplatform/api/http/TransactionsApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/TransactionsApiRoute.scala index 36ca280f8b0..14c6d9613bd 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/TransactionsApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/TransactionsApiRoute.scala @@ -1,8 +1,5 @@ package com.wavesplatform.api.http -import scala.concurrent.Future -import scala.util.Success - import akka.http.scaladsl.marshalling.ToResponseMarshallable import akka.http.scaladsl.server.Route import cats.instances.either._ @@ -11,27 +8,35 @@ import cats.instances.try_._ import cats.syntax.alternative._ import cats.syntax.either._ import cats.syntax.traverse._ -import com.wavesplatform.account.{Address, AddressOrAlias} -import com.wavesplatform.api.common.CommonTransactionsApi -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.account.{Address, Alias} +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} import com.wavesplatform.api.http.ApiError._ import com.wavesplatform.block.Block import com.wavesplatform.block.Block.TransactionProof import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, _} import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.lang.v1.Serde import com.wavesplatform.network.TransactionPublisher +import com.wavesplatform.protobuf.transaction.PBAmounts import com.wavesplatform.settings.RestAPISettings -import com.wavesplatform.state.{Blockchain, InvokeScriptResult} import com.wavesplatform.state.reader.LeaseDetails +import com.wavesplatform.state.{Blockchain, InvokeScriptResult} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.lease._ -import com.wavesplatform.utils.Time +import com.wavesplatform.transaction.serialization.impl.InvokeScriptTxSerializer +import com.wavesplatform.transaction.smart.InvokeScriptTransaction +import com.wavesplatform.utils.{EthEncoding, Time} import com.wavesplatform.wallet.Wallet import monix.eval.Task import monix.execution.Scheduler import play.api.libs.json._ +import scala.concurrent.Future +import scala.util.Success + +import com.wavesplatform.database.protobuf.EthereumTransactionMeta.Payload + case class TransactionsApiRoute( settings: RestAPISettings, commonApi: CommonTransactionsApi, @@ -75,9 +80,9 @@ case class TransactionsApiRoute( complete(commonApi.transactionById(id).toRight(ApiError.TransactionDoesNotExist)) } ~ (pathEndOrSingleSlash & anyParam("id")) { ids => val result = for { - _ <- Either.cond(ids.nonEmpty, (), InvalidTransactionId("Transaction ID was not specified")) - statuses <- ids.map(readTransactionMeta).toList.sequence - } yield statuses + _ <- Either.cond(ids.nonEmpty, (), InvalidTransactionId("Transaction ID was not specified")) + meta <- ids.map(readTransactionMeta).toList.sequence + } yield meta complete(result) } @@ -169,7 +174,7 @@ case class TransactionsApiRoute( } def signWithSigner: Route = path(AddrSegment) { address => - jsonPost[JsObject](TransactionFactory.parseRequestAndSign(wallet, address.stringRepr, time, _)) + jsonPost[JsObject](TransactionFactory.parseRequestAndSign(wallet, address.toString, time, _)) } def signedBroadcast: Route = path("broadcast")(broadcast[JsValue](TransactionFactory.fromSignedRequest)) @@ -196,12 +201,12 @@ case class TransactionsApiRoute( } def transactionsByAddress(address: Address, limitParam: Int, maybeAfter: Option[ByteStr])(implicit sc: Scheduler): Future[List[JsObject]] = { - val aliasesOfAddress: Task[Set[AddressOrAlias]] = + val aliasesOfAddress: Task[Set[Alias]] = commonApi .aliasesOfAddress(address) .collect { case (_, cat) => cat.alias } .toListL - .map(aliases => (address :: aliases).toSet) + .map(aliases => aliases.toSet) .memoize /** @@ -212,7 +217,15 @@ case class TransactionsApiRoute( import com.wavesplatform.transaction.transfer._ meta.transaction match { case mtt: MassTransferTransaction if mtt.sender.toAddress != address => - aliasesOfAddress.map(mtt.compactJson(_) ++ serializer.transactionMetaJson(meta)) + (if (mtt.transfers.exists( + pt => + pt.address match { + case address: Address => false + case a: Alias => true + } + )) aliasesOfAddress.map(aliases => mtt.compactJson(address, aliases)) + else Task.now(mtt.compactJson(address, Set.empty))).map(_ ++ serializer.transactionMetaJson(meta)) + case _ => Task.now(serializer.transactionWithMetaJson(meta)) } } @@ -290,8 +303,37 @@ object TransactionsApiRoute { } val stateChanges = meta match { - case i: TransactionMeta.Invoke => Json.obj("stateChanges" -> i.invokeScriptResult) - case _ => JsObject.empty + case i: TransactionMeta.Invoke => + Json.obj("stateChanges" -> i.invokeScriptResult) + + case e: TransactionMeta.Ethereum => + val payloadJson: JsObject = e.meta + .map(_.payload) + .collect { + case Payload.Invocation(i) => + val functionCallEi = Serde.deserializeFunctionCall(i.functionCall.toByteArray).map(InvokeScriptTxSerializer.functionCallToJson) + val payments = i.payments.map(p => InvokeScriptTransaction.Payment(p.amount, PBAmounts.toVanillaAssetId(p.assetId))) + Json.obj( + "type" -> "invocation", + "dApp" -> Address(EthEncoding.toBytes(e.transaction.underlying.getTo)), + "call" -> functionCallEi.toOption, + "payment" -> payments, + "stateChanges" -> e.invokeScriptResult + ) + + case Payload.Transfer(t) => + val (asset, amount) = PBAmounts.toAssetAndAmount(t.getAmount) + Json.obj( + "type" -> "transfer", + "recipient" -> Address(t.publicKeyHash.toByteArray), + "asset" -> asset, + "amount" -> amount + ) + } + .getOrElse(JsObject.empty) + Json.obj("payload" -> payloadJson) + + case _ => JsObject.empty } Seq( diff --git a/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala index b5dc926208b..736b61f7e7c 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala @@ -5,13 +5,12 @@ import java.security.SecureRandom import akka.http.scaladsl.server.{PathMatcher1, Route} import cats.syntax.either._ import cats.syntax.semigroup._ -import com.wavesplatform.account.{Address, AddressScheme, PublicKey} +import com.wavesplatform.account.{Address, AddressOrAlias, AddressScheme, PublicKey} import com.wavesplatform.api.http.ApiError.{CustomValidationError, ScriptCompilerError, TooBigArrayAllocation} import com.wavesplatform.api.http.requests.{ScriptWithImportsRequest, byteStrFormat} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ import com.wavesplatform.crypto -import com.wavesplatform.crypto.KeyLength import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.BlockchainFeatures.{RideV6, SynchronousCalls} import com.wavesplatform.features.RideVersionProvider.RideVersionBlockchainExt @@ -21,23 +20,26 @@ import com.wavesplatform.lang.directives.values.{DApp => DAppType, _} import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.Script.ComplexityInfo import com.wavesplatform.lang.script.v1.ExprScript -import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.compiler.Terms.{EVALUATED, EXPR} +import com.wavesplatform.lang.v1.compiler.{ExpressionCompiler, Terms} import com.wavesplatform.lang.v1.estimator.ScriptEstimator import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} import com.wavesplatform.lang.v1.evaluator.{ContractEvaluator, EvaluatorV2} import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.lang.v1.traits.domain.Recipient -import com.wavesplatform.lang.v1.{ContractLimits, Serde} +import com.wavesplatform.lang.v1.{ContractLimits, FunctionHeader, Serde} import com.wavesplatform.lang.{Global, ValidationError} import com.wavesplatform.serialization.ScriptValuesJson import com.wavesplatform.settings.RestAPISettings import com.wavesplatform.state.diffs.FeeValidation +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike import com.wavesplatform.state.{Blockchain, Diff} +import com.wavesplatform.transaction.TransactionType.TransactionType import com.wavesplatform.transaction.TxValidationError.{GenericError, ScriptExecutionError} import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{BlockchainContext, DAppEnvironment} +import com.wavesplatform.transaction.smart.{BlockchainContext, DAppEnvironment, InvokeScriptTransaction} +import com.wavesplatform.transaction.{Asset, TransactionType} import com.wavesplatform.utils.Time import monix.eval.Coeval import monix.execution.Scheduler @@ -56,7 +58,7 @@ case class UtilsApiRoute( import UtilsApiRoute._ - private def seed(length: Int) = { + private def seed(length: Int): JsObject = { val seed = new Array[Byte](length) new SecureRandom().nextBytes(seed) //seed mutated here! Json.obj("seed" -> Base58.encode(seed)) @@ -246,8 +248,10 @@ case class UtilsApiRoute( }) def evaluate: Route = - (path("script" / "evaluate" / ScriptedAddress) & jsonPostD[JsObject]) { (address: Address, obj: JsObject) => - val script = blockchain.accountScript(address).get.script + (path("script" / "evaluate" / ScriptedAddress) & jsonPostD[JsObject]) { (address, obj) => + val scriptInfo = blockchain.accountScript(address).get + val pk = scriptInfo.publicKey + val script = scriptInfo.script def parseCall(js: JsReadable) = { val binaryCall = js @@ -266,10 +270,10 @@ case class UtilsApiRoute( val result = for { expr <- parseCall(obj \ "expr") - (result, complexity) <- ScriptCallEvaluator.executeExpression(blockchain, script, address, settings.evaluateScriptComplexityLimit)(expr) + (result, complexity) <- ScriptCallEvaluator.executeExpression(blockchain, script, address, pk, settings.evaluateScriptComplexityLimit)(expr) } yield Json.obj("result" -> ScriptValuesJson.serializeValue(result), "complexity" -> complexity) - val requestData = obj ++ Json.obj("address" -> address.stringRepr) + val requestData = obj ++ Json.obj("address" -> address.toString) val responseJson = result .recover { case e: ScriptExecutionError => Json.obj("error" -> ApiError.ScriptExecutionError.Id, "message" -> e.error) @@ -280,9 +284,10 @@ case class UtilsApiRoute( complete(responseJson) } - private[this] val ScriptedAddress: PathMatcher1[Address] = AddrSegment.map { address => - if (blockchain.hasAccountScript(address)) address - else throw ApiException(CustomValidationError(s"Address $address is not dApp")) + private[this] val ScriptedAddress: PathMatcher1[Address] = AddrSegment.map { + case address: Address if blockchain.hasAccountScript(address) => address + case other => + throw ApiException(CustomValidationError(s"Address $other is not dApp")) } } @@ -310,7 +315,7 @@ object UtilsApiRoute { .map(_._1) } - def executeExpression(blockchain: Blockchain, script: Script, address: Address, limit: Int)( + def executeExpression(blockchain: Blockchain, script: Script, address: Address, pk: PublicKey, limit: Int)( expr: EXPR ): Either[ValidationError, (EVALUATED, Int)] = { for { @@ -325,9 +330,31 @@ object UtilsApiRoute { blockchain, Coproduct[Environment.Tthis](Recipient.Address(ByteStr(address.bytes))), ds, - tx = None, + new InvokeScriptTransactionLike { + override def dApp: AddressOrAlias = address + + override def funcCall: Terms.FUNCTION_CALL = Terms.FUNCTION_CALL(FunctionHeader.User(""), Nil) + + override def payments: Seq[InvokeScriptTransaction.Payment] = Seq.empty + + override def root: InvokeScriptTransactionLike = this + + override val sender: PublicKey = PublicKey(ByteStr(new Array[Byte](32))) + + override def assetFee: (Asset, Long) = Asset.Waves -> 0L + + override def timestamp: Long = System.currentTimeMillis() + + override def chainId: Byte = AddressScheme.current.chainId + + override def id: Coeval[ByteStr] = Coeval.evalOnce(ByteStr.empty) + + override def checkedAssets: Seq[Asset.IssuedAsset] = Seq.empty + + override val tpe: TransactionType = TransactionType.InvokeScript + }, address, - PublicKey(ByteStr.fill(KeyLength)(1)), + pk, Set.empty[Address], limitedExecution = false, limit, diff --git a/node/src/main/scala/com/wavesplatform/api/http/alias/AliasApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/alias/AliasApiRoute.scala index 038ecf4cd11..b8dcbecb78a 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/alias/AliasApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/alias/AliasApiRoute.scala @@ -44,7 +44,7 @@ case class AliasApiRoute( Alias .create(aliasName) .flatMap { a => - blockchain.resolveAlias(a).bimap(_ => TxValidationError.AliasDoesNotExist(a), addr => Json.obj("address" -> addr.stringRepr)) + blockchain.resolveAlias(a).bimap(_ => TxValidationError.AliasDoesNotExist(a), addr => Json.obj("address" -> addr.toString)) } } } @@ -54,7 +54,7 @@ case class AliasApiRoute( def aliasOfAddress: Route = (get & path("by-address" / AddrSegment)) { address => extractScheduler { implicit s => val value: Source[JsValue, NotUsed] = - Source.fromPublisher(commonApi.aliasesOfAddress(address).map { case (_, tx) => JsString(tx.alias.stringRepr) }.toReactivePublisher) + Source.fromPublisher(commonApi.aliasesOfAddress(address).map { case (_, tx) => JsString(tx.alias.toString) }.toReactivePublisher) complete(value) } } diff --git a/node/src/main/scala/com/wavesplatform/api/http/assets/AssetsApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/assets/AssetsApiRoute.scala index 09777343ab1..eb1b397f17a 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/assets/AssetsApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/assets/AssetsApiRoute.scala @@ -201,7 +201,7 @@ case class AssetsApiRoute( def balanceDistribution(assetId: IssuedAsset): Route = balanceDistribution(assetId, blockchain.height, Int.MaxValue, None) { l => - Json.toJson(l.map { case (a, b) => a.stringRepr -> b }.toMap) + Json.toJson(l.map { case (a, b) => a.toString -> b }.toMap) } def balanceDistributionAtHeight(assetId: IssuedAsset, heightParam: Int, limitParam: Int, afterParam: Option[String]): Route = @@ -218,7 +218,7 @@ case class AssetsApiRoute( "lastItem" -> l.lastOption.map(_._1), "items" -> Json.toJson(l.map { case (a, b) => - a.stringRepr -> accept.fold[JsValue](JsNumber(b)) { + a.toString -> accept.fold[JsValue](JsNumber(b)) { case a if a.mediaRanges.exists(CustomJson.acceptsNumbersAsStrings) => JsString(b.toString) case _ => JsNumber(b) } diff --git a/node/src/main/scala/com/wavesplatform/api/http/eth/EthRpcRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/eth/EthRpcRoute.scala new file mode 100644 index 00000000000..1ab44a89023 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/api/http/eth/EthRpcRoute.scala @@ -0,0 +1,220 @@ +package com.wavesplatform.api.http.eth + +import java.math.BigInteger + +import akka.http.scaladsl.server._ +import com.wavesplatform.account.{Address, AddressScheme} +import com.wavesplatform.api.common.CommonTransactionsApi +import com.wavesplatform.api.http._ +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.state.Blockchain +import com.wavesplatform.transaction.Asset.IssuedAsset +import com.wavesplatform.transaction.{ABIConverter, ERC20Address, EthereumTransaction} +import com.wavesplatform.utils.EthEncoding._ +import org.web3j.abi._ +import org.web3j.abi.datatypes.generated.{Uint256, Uint8} +import org.web3j.crypto._ +import play.api.libs.json.Json.JsValueWrapper +import play.api.libs.json._ + +import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.Future +import scala.jdk.CollectionConverters._ +import cats.syntax.traverse._ +import cats.syntax.either._ +import cats.instances.vector._ +import cats.data.Validated +import com.wavesplatform.api.http.ApiError.{CustomValidationError, InvalidIds} +import com.wavesplatform.api.http.assets.AssetsApiRoute +import com.wavesplatform.utils.{EthEncoding, Time} + +class EthRpcRoute(blockchain: Blockchain, transactionsApi: CommonTransactionsApi, time: Time) extends ApiRoute { + val route: Route = pathPrefix("eth") { + (path("assets") & anyParam("id", nonEmpty = true, limit = 100).massValidateEthereumIds) { erc20Ids => + val results = erc20Ids + .map( + id => + id -> (for { + wavesId <- blockchain.resolveERC20Address(ERC20Address(id)) + assetDesc <- blockchain.assetDescription(wavesId) + } yield (wavesId, assetDesc)) + ) + .map { case (id, assetOpt) => Validated.fromOption(assetOpt, EthEncoding.toHexString(id.arr)).toValidatedNel } + .sequence + + results match { + case Validated.Invalid(ids) => + complete(InvalidIds(ids.toList)) // TODO: Something more obvious like "assets does not exist" ? + + case Validated.Valid(assets) => + val jsons = for { + (assetId, desc) <- assets + } yield AssetsApiRoute.jsonDetails(blockchain)(assetId, desc, full = false) + complete(jsons.sequence.leftMap(CustomValidationError(_)).map(JsArray(_))) // TODO: Only first error is displayed + } + } ~ (get & path("abi" / AddrSegment)) { addr => + complete(blockchain.accountScript(addr).map(as => ABIConverter(as.script).jsonABI)) + } ~ (pathEndOrSingleSlash & post & entity(as[JsObject])) { jso => + val id = (jso \ "id").get + val params = (jso \ "params").asOpt[IndexedSeq[JsValue]].getOrElse(Nil) + lazy val param1 = params.head + lazy val param1Str = param1.as[String] + + (jso \ "method").as[String] match { + case "eth_chainId" | "net_version" => + resp(id, quantity(AddressScheme.current.chainId.toInt)) + case "eth_blockNumber" => + resp(id, quantity(blockchain.height)) + case "eth_getTransactionCount" => + resp(id, quantity(time.getTimestamp())) + case "eth_getBlockByNumber" => + resp( + id, + Json.obj( + "number" -> quantity(Integer.parseInt(param1Str.drop(2), 16)) + ) + ) + + case "eth_getBlockByHash" => + val blockId = ByteStr(toBytes(param1Str)) + + resp( + id, + blockchain.heightOf(blockId).flatMap(blockchain.blockHeader).fold[JsValue](JsNull) { header => + Json.obj( + "baseFeePerGas" -> "0x0" + ) + } + ) + case "eth_getBalance" => + val address = Address.fromHexString(param1Str) + resp( + id, + toHexString( + BigInt(blockchain.balance(address)) * EthereumTransaction.AmountMultiplier + ) + ) + case "eth_sendRawTransaction" => + extractTransaction(param1Str) match { + case Left(value) => resp(id, ApiError.fromValidationError(value).json) + case Right(et) => + resp( + id, + transactionsApi.broadcastTransaction(et).map[JsValueWrapper] { result => + result.resultE match { + case Left(error) => ApiError.fromValidationError(error).json + case Right(_) => toHexString(et.id().arr) + } + } + ) + } + + case "eth_getTransactionReceipt" => + val transactionHex = param1Str + val txId = ByteStr(toBytes(transactionHex)) + log.info(s"Get receipt for $transactionHex/$txId") // TODO remove logging + + resp( + id, + transactionsApi.transactionById(txId).fold[JsValue](JsNull) { tm => + tm.transaction match { + case tx: EthereumTransaction => + Json.obj( + "transactionHash" -> toHexString(tm.transaction.id().arr), + "transactionIndex" -> "0x01", + "blockHash" -> toHexString(blockchain.lastBlockId.get.arr), + "blockNumber" -> toHexString(BigInteger.valueOf(tm.height)), + "from" -> toHexString(tx.senderAddress().publicKeyHash), + "to" -> tx.underlying.getTo, + "cumulativeGasUsed" -> toHexString(tx.fee), + "gasUsed" -> toHexString(tx.fee), + "contractAddress" -> JsNull, + "logs" -> Json.arr(), + "logsBloom" -> toHexString(new Array[Byte](32)), + "status" -> (if (tm.succeeded) "0x1" else "0x0") + ) + case _ => JsNull + } + + } + ) + case "eth_call" => + val call = param1.as[JsObject] + val dataString = (call \ "data").as[String] + val contractAddress = (call \ "to").as[String] + + log.info(s"balance: contract address = $contractAddress, assetId = ${assetId(contractAddress)}") // TODO remove logging + + cleanHexPrefix(dataString).take(8) match { + case "95d89b41" => + resp(id, encodeResponse(assetDescription(contractAddress).get.name.toStringUtf8)) + case "313ce567" => + resp(id, encodeResponse(new Uint8(assetDescription(contractAddress).get.decimals))) + case "70a08231" => + resp( + id, + encodeResponse( + new Uint256( + blockchain.balance(Address.fromHexString(dataString.takeRight(40)), assetId(contractAddress).get) + ) + ) + ) + case _ => + log.info(s"Unexpected call $dataString at $contractAddress") + resp(id, "") + } + case "eth_estimateGas" => + val txParams = param1.as[JsObject] + val tx = RawTransaction.createTransaction( + BigInteger.valueOf(System.currentTimeMillis()), + EthereumTransaction.GasPrice, + BigInteger.ONE, + (txParams \ "to").as[String], + (txParams \ "value").asOpt[String].fold(BigInteger.ZERO)(s => new BigInteger(cleanHexPrefix(s), 16)), + (txParams \ "data").asOpt[String].getOrElse("0x") + ) + + val errorOrLong = for { + et <- EthereumTransaction(tx) + (_, txFee, _) <- transactionsApi.calculateFee(et) + } yield txFee + + resp( + id, + errorOrLong + .fold[JsValueWrapper](e => ApiError.fromValidationError(e).json, fee => toHexString(BigInteger.valueOf(fee))) + ) + + case "eth_gasPrice" => + resp(id, toHexString(EthereumTransaction.GasPrice)) + case "eth_getCode" => + val address = Address.fromHexString(param1Str) + resp(id, if (blockchain.hasDApp(address)) "0xff" else "0x") + case _ => + log.trace(s"Unexpected call: ${Json.stringify(jso)}") + complete(Json.obj()) + } + } + } + + @inline + private[this] def quantity(v: Long) = "0x" + java.lang.Long.toString(v, 16) + + private[this] def resp(id: JsValue, resp: JsValueWrapper) = complete(Json.obj("id" -> id, "jsonrpc" -> "2.0", "result" -> resp)) + + private[this] def resp(id: JsValue, resp: Future[JsValueWrapper]) = complete(resp.map(r => Json.obj("id" -> id, "jsonrpc" -> "2.0", "result" -> r))) + + private[this] def assetDescription(contractAddress: String) = + assetId(contractAddress).flatMap(blockchain.assetDescription) + + private[this] def assetId(contractAddress: String): Option[IssuedAsset] = + blockchain.resolveERC20Address(ERC20Address(ByteStr(toBytes(contractAddress)))) + + private[this] def encodeResponse(values: Type*): String = FunctionEncoder.encodeConstructor(values.map(Type.unwrap).asJava) + + private[this] def extractTransaction(transactionHex: String) = TransactionDecoder.decode(transactionHex) match { + case srt: SignedRawTransaction => EthereumTransaction(srt) + case _: RawTransaction => throw new UnsupportedOperationException("Cannot process unsigned transactions") + } +} diff --git a/node/src/main/scala/com/wavesplatform/api/http/eth/Type.scala b/node/src/main/scala/com/wavesplatform/api/http/eth/Type.scala new file mode 100644 index 00000000000..ebc26e665e0 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/api/http/eth/Type.scala @@ -0,0 +1,16 @@ +package com.wavesplatform.api.http.eth + +import org.web3j.abi.datatypes.{Utf8String, Type => EthType} + +sealed trait Type + +private[eth] case class TypeImpl(value: EthType[_]) extends Type + +object Type { + implicit def stringToE(v: String): Type = TypeImpl(new Utf8String(v)) + implicit def rawTypeToE(v: EthType[_]) = TypeImpl(v) + + def unwrap(t: Type): EthType[_] = t match { + case TypeImpl(value) => value + } +} diff --git a/node/src/main/scala/com/wavesplatform/api/http/package.scala b/node/src/main/scala/com/wavesplatform/api/http/package.scala index bd2c5ace80c..d13219a2782 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/package.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/package.scala @@ -3,34 +3,29 @@ package com.wavesplatform.api import java.util.NoSuchElementException import java.util.concurrent.ExecutionException -import scala.concurrent.Future -import scala.util.{Failure, Success, Try} -import scala.util.control.NonFatal - import akka.http.scaladsl.marshalling.ToResponseMarshallable import akka.http.scaladsl.model.StatusCodes -import akka.http.scaladsl.server._ import akka.http.scaladsl.server.Directives._ +import akka.http.scaladsl.server._ import com.wavesplatform.account.{Address, PublicKey} import com.wavesplatform.api.http.ApiError.{InvalidAssetId, InvalidBlockId, InvalidPublicKey, InvalidSignature, InvalidTransactionId, WrongJson} -import com.wavesplatform.api.http.requests._ import com.wavesplatform.api.http.requests.DataRequest._ import com.wavesplatform.api.http.requests.SponsorFeeRequest._ +import com.wavesplatform.api.http.requests._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto -import com.wavesplatform.transaction._ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.TxValidationError.GenericError -import com.wavesplatform.transaction.assets._ -import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction -import com.wavesplatform.transaction.lease._ -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, InvokeExpressionTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction._ import com.wavesplatform.utils.ScorexLogging import monix.execution.Scheduler import play.api.libs.json._ +import scala.concurrent.Future +import scala.util.control.NonFatal +import scala.util.{Failure, Success, Try} + package object http extends ApiMarshallers with ScorexLogging { val versionReads: Reads[Byte] = { val defaultByteReads = implicitly[Reads[Byte]] @@ -58,27 +53,24 @@ package object http extends ApiMarshallers with ScorexLogging { PublicKey .fromBase58String(senderPk) .flatMap { senderPk => - TransactionParsers.by(typeId, version) match { - case None => Left(GenericError(s"Bad transaction type ($typeId) and version ($version)")) - case Some(x) => - (x: @unchecked) match { - case TransferTransaction => txJson.as[TransferRequest].toTxFrom(senderPk) - case CreateAliasTransaction => txJson.as[CreateAliasRequest].toTxFrom(senderPk) - case LeaseTransaction => txJson.as[LeaseRequest].toTxFrom(senderPk) - case LeaseCancelTransaction => txJson.as[LeaseCancelRequest].toTxFrom(senderPk) - case ExchangeTransaction => txJson.as[ExchangeRequest].toTxFrom(senderPk) - case IssueTransaction => txJson.as[IssueRequest].toTxFrom(senderPk) - case ReissueTransaction => txJson.as[ReissueRequest].toTxFrom(senderPk) - case BurnTransaction => txJson.as[BurnRequest].toTxFrom(senderPk) - case MassTransferTransaction => TransactionFactory.massTransferAsset(txJson.as[MassTransferRequest], senderPk) - case DataTransaction => TransactionFactory.data(txJson.as[DataRequest], senderPk) - case InvokeScriptTransaction => TransactionFactory.invokeScript(txJson.as[InvokeScriptRequest], senderPk) - case SetScriptTransaction => TransactionFactory.setScript(txJson.as[SetScriptRequest], senderPk) - case SetAssetScriptTransaction => TransactionFactory.setAssetScript(txJson.as[SetAssetScriptRequest], senderPk) - case SponsorFeeTransaction => TransactionFactory.sponsor(txJson.as[SponsorFeeRequest], senderPk) - case UpdateAssetInfoTransaction => txJson.as[UpdateAssetInfoRequest].toTxFrom(senderPk) - case InvokeExpressionTransaction => TransactionFactory.invokeExpression(txJson.as[InvokeExpressionRequest], senderPk) - } + TransactionType(typeId) match { + case TransactionType.Transfer => txJson.as[TransferRequest].toTxFrom(senderPk) + case TransactionType.CreateAlias => txJson.as[CreateAliasRequest].toTxFrom(senderPk) + case TransactionType.Lease => txJson.as[LeaseRequest].toTxFrom(senderPk) + case TransactionType.LeaseCancel => txJson.as[LeaseCancelRequest].toTxFrom(senderPk) + case TransactionType.Exchange => txJson.as[ExchangeRequest].toTxFrom(senderPk) + case TransactionType.Issue => txJson.as[IssueRequest].toTxFrom(senderPk) + case TransactionType.Reissue => txJson.as[ReissueRequest].toTxFrom(senderPk) + case TransactionType.Burn => txJson.as[BurnRequest].toTxFrom(senderPk) + case TransactionType.MassTransfer => TransactionFactory.massTransferAsset(txJson.as[MassTransferRequest], senderPk) + case TransactionType.Data => TransactionFactory.data(txJson.as[DataRequest], senderPk) + case TransactionType.InvokeScript => TransactionFactory.invokeScript(txJson.as[InvokeScriptRequest], senderPk) + case TransactionType.SetScript => TransactionFactory.setScript(txJson.as[SetScriptRequest], senderPk) + case TransactionType.SetAssetScript => TransactionFactory.setAssetScript(txJson.as[SetAssetScriptRequest], senderPk) + case TransactionType.SponsorFee => TransactionFactory.sponsor(txJson.as[SponsorFeeRequest], senderPk) + case TransactionType.UpdateAssetInfo => txJson.as[UpdateAssetInfoRequest].toTxFrom(senderPk) + case TransactionType.InvokeExpression => TransactionFactory.invokeExpression(txJson.as[InvokeExpressionRequest], senderPk) + case other => throw new IllegalArgumentException(s"Unsupported transaction type: $other") } } .fold(ApiError.fromValidationError, txToResponse) diff --git a/node/src/main/scala/com/wavesplatform/api/http/requests/InvokeScriptRequest.scala b/node/src/main/scala/com/wavesplatform/api/http/requests/InvokeScriptRequest.scala index 9d7b416b90a..7e9a9ea2e5d 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/requests/InvokeScriptRequest.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/requests/InvokeScriptRequest.scala @@ -3,13 +3,13 @@ package com.wavesplatform.api.http.requests import cats.instances.list._ import cats.syntax.either._ import cats.syntax.traverse._ -import com.wavesplatform.account.{AddressOrAlias, PublicKey} +import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.transaction.Proofs -import com.wavesplatform.transaction.smart.InvokeScriptTransaction +import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, InvokeTransaction} import play.api.libs.json._ object InvokeScriptRequest { @@ -75,6 +75,7 @@ object InvokeScriptRequest { } case class InvokeScriptRequest( + chainId: Option[Byte], version: Option[Byte], sender: String, fee: Long, @@ -86,6 +87,7 @@ case class InvokeScriptRequest( ) case class SignedInvokeScriptRequest( + chainId: Option[Byte], version: Option[Byte], senderPublicKey: String, fee: Long, @@ -100,17 +102,18 @@ case class SignedInvokeScriptRequest( for { _sender <- PublicKey.fromBase58String(senderPublicKey) _dappAddress <- AddressOrAlias.fromString(dApp) - _feeAssetId <- parseBase58ToAsset(feeAssetId.filter(_.length > 0), "invalid.feeAssetId") + _feeAssetId <- parseBase58ToAsset(feeAssetId.filter(_.nonEmpty), "invalid.feeAssetId") t <- InvokeScriptTransaction.create( version.getOrElse(2.toByte), _sender, _dappAddress, - call.map(fCallPart => InvokeScriptRequest.buildFunctionCall(fCallPart)), + call.map(InvokeScriptRequest.buildFunctionCall).filterNot(_ == InvokeTransaction.DefaultCall), payment.getOrElse(Seq()), fee, _feeAssetId, timestamp, - proofs + proofs, + chainId.getOrElse(AddressScheme.current.chainId) ) } yield t } diff --git a/node/src/main/scala/com/wavesplatform/api/http/requests/LeaseCancelRequest.scala b/node/src/main/scala/com/wavesplatform/api/http/requests/LeaseCancelRequest.scala index 69996f41dad..ba122934398 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/requests/LeaseCancelRequest.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/requests/LeaseCancelRequest.scala @@ -5,8 +5,8 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.transaction.Proofs import com.wavesplatform.transaction.lease.LeaseCancelTransaction -import play.api.libs.json._ import play.api.libs.functional.syntax._ +import play.api.libs.json._ case class LeaseCancelRequest( version: Option[Byte], diff --git a/node/src/main/scala/com/wavesplatform/api/http/requests/SignedMassTransferRequest.scala b/node/src/main/scala/com/wavesplatform/api/http/requests/SignedMassTransferRequest.scala index 05d3a75d04e..e27ba6aed9d 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/requests/SignedMassTransferRequest.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/requests/SignedMassTransferRequest.scala @@ -38,7 +38,7 @@ case class SignedMassTransferRequest( def toTx: Either[ValidationError, MassTransferTransaction] = for { _sender <- PublicKey.fromBase58String(senderPublicKey) - _assetId <- parseBase58ToAsset(assetId.filter(_.length > 0), "invalid.assetId") + _assetId <- parseBase58ToAsset(assetId.filter(_.nonEmpty), "invalid.assetId") _transfers <- MassTransferTransaction.parseTransfersList(transfers) t <- MassTransferTransaction.create(version.getOrElse(1.toByte), _sender, _assetId, _transfers, fee, timestamp, attachment, proofs) } yield t diff --git a/node/src/main/scala/com/wavesplatform/api/http/requests/TransferRequest.scala b/node/src/main/scala/com/wavesplatform/api/http/requests/TransferRequest.scala index ffc783ab4e8..ce7711f4985 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/requests/TransferRequest.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/requests/TransferRequest.scala @@ -3,8 +3,8 @@ package com.wavesplatform.api.http.requests import com.wavesplatform.account.{AddressOrAlias, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError -import com.wavesplatform.transaction.transfer.TransferTransaction import com.wavesplatform.transaction.{Asset, Proofs} +import com.wavesplatform.transaction.transfer.TransferTransaction import play.api.libs.json._ case class TransferRequest( @@ -17,7 +17,7 @@ case class TransferRequest( feeAssetId: Option[Asset], fee: Long, attachment: Option[ByteStr] = None, - timestamp: Option[Long]= None, + timestamp: Option[Long] = None, signature: Option[ByteStr] = None, proofs: Option[Proofs] = None ) extends TxBroadcastRequest { diff --git a/node/src/main/scala/com/wavesplatform/block/package.scala b/node/src/main/scala/com/wavesplatform/block/package.scala index 60762fe120b..19fe9592a25 100644 --- a/node/src/main/scala/com/wavesplatform/block/package.scala +++ b/node/src/main/scala/com/wavesplatform/block/package.scala @@ -1,17 +1,17 @@ package com.wavesplatform +import scala.util.Try + import cats.syntax.either._ import com.wavesplatform.account.PrivateKey import com.wavesplatform.block.Block.{TransactionProof, TransactionsMerkleTree} -import com.wavesplatform.common.merkle.Merkle._ import com.wavesplatform.block.validation.Validators._ +import com.wavesplatform.common.merkle.Merkle._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.protobuf.transaction.PBTransactions import com.wavesplatform.settings.GenesisSettings import com.wavesplatform.transaction.Transaction -import scala.util.Try - package object block { // Validation @@ -50,9 +50,9 @@ package object block { } } - def mkMerkleTree(txs: Seq[Transaction]): TransactionsMerkleTree = mkLevels(txs.map(PBTransactions.protobuf(_).toByteArray)) + def mkMerkleTree(txs: Seq[Transaction]): TransactionsMerkleTree = mkLevels(txs.map(PBTransactions.toByteArrayMerkle)) def mkTransactionsRoot(version: Byte, transactionData: Seq[Transaction]): ByteStr = if (version < Block.ProtoBlockVersion) ByteStr.empty - else mkLevels(transactionData.map(PBTransactions.protobuf(_).toByteArray)).transactionsRoot + else mkMerkleTree(transactionData).transactionsRoot } diff --git a/node/src/main/scala/com/wavesplatform/block/serialization/BlockSerializer.scala b/node/src/main/scala/com/wavesplatform/block/serialization/BlockSerializer.scala index fb9a43a51e0..7a5b6e6c7b4 100644 --- a/node/src/main/scala/com/wavesplatform/block/serialization/BlockSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/block/serialization/BlockSerializer.scala @@ -61,7 +61,7 @@ object BlockHeaderSerializer { else Json.obj("desiredReward" -> JsNumber(blockHeader.rewardVote)) val generatorJson = - Json.obj("generator" -> blockHeader.generator.toAddress, "generatorPublicKey" -> blockHeader.generator) + Json.obj("generator" -> blockHeader.generator.toAddress.toString, "generatorPublicKey" -> blockHeader.generator) Json.obj( "version" -> blockHeader.version, diff --git a/node/src/main/scala/com/wavesplatform/block/serialization/package.scala b/node/src/main/scala/com/wavesplatform/block/serialization/package.scala index 8e4f7226553..feef7895136 100644 --- a/node/src/main/scala/com/wavesplatform/block/serialization/package.scala +++ b/node/src/main/scala/com/wavesplatform/block/serialization/package.scala @@ -3,17 +3,16 @@ package com.wavesplatform.block import java.nio.ByteBuffer import com.google.common.primitives.{Bytes, Ints, Longs} -import com.wavesplatform.block.Block.{GenesisBlockVersion, NgBlockVersion, PlainBlockVersion, ProtoBlockVersion, RewardBlockVersion} +import com.wavesplatform.block.Block.{PlainBlockVersion, ProtoBlockVersion} import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ -import com.wavesplatform.protobuf.transaction.{PBTransactions, SignedTransaction} +import com.wavesplatform.protobuf.transaction.PBTransactions import com.wavesplatform.protobuf.utils.PBUtils import com.wavesplatform.serialization.ByteBufferOps -import com.wavesplatform.transaction.{Transaction, TransactionParsers} +import com.wavesplatform.transaction.{EthereumTransaction, Transaction, TransactionParsers} package object serialization { private[block] def writeTransactionData(version: Byte, txs: Seq[Transaction]): Array[Byte] = { - val txsBytes = txs.map(tx => if (version == ProtoBlockVersion) PBUtils.encodeDeterministic(PBTransactions.protobuf(tx)) else tx.bytes()) + val txsBytes = txs.map(tx => if (version == ProtoBlockVersion) PBUtils.encodeDeterministic(PBTransactions.protobuf(tx)) else tx.bytes().ensuring(!tx.isInstanceOf[EthereumTransaction])) val txsBytesSize = txsBytes.map(_.length + Ints.BYTES).sum val txsBuf = ByteBuffer.allocate(txsBytesSize) txsBytes.foreach(tx => txsBuf.putInt(tx.length).put(tx)) @@ -21,24 +20,12 @@ package object serialization { Bytes.concat(mkTxsCountBytes(version, txs.size), txsBuf.array()) } - private[block] def readTransactionData(version: Byte, buf: ByteBuffer): Seq[Transaction] = { - val txCount = (version: @unchecked) match { - case GenesisBlockVersion | PlainBlockVersion => buf.getByte - case NgBlockVersion | RewardBlockVersion | ProtoBlockVersion => buf.getInt - } - - val txs = (1 to txCount).foldLeft(List.empty[Transaction]) { - case (txs, _) => - val size = buf.getInt - val txBytes = buf.getByteArray(size) - val tx = version match { - case ProtoBlockVersion => PBTransactions.vanilla(SignedTransaction.parseFrom(txBytes)).explicitGet() - case _ => TransactionParsers.parseBytes(txBytes).get - } - tx :: txs - } - txs.reverse - } + private[block] def readTransactionData(version: Byte, buf: ByteBuffer): Seq[Transaction] = + Seq.fill( + if (version <= PlainBlockVersion) buf.getByte + else if (version <= ProtoBlockVersion) buf.getInt + else throw new IllegalArgumentException(s"Unexpected block version: $version") + )(TransactionParsers.parseBytes(buf.getByteArray(buf.getInt)).get) private[block] def writeConsensusBytes(baseTarget: Long, generationSignature: ByteStr): Array[Byte] = Bytes.concat( @@ -46,8 +33,9 @@ package object serialization { generationSignature.arr ) - def mkTxsCountBytes(version: Byte, txsCount: Int): Array[Byte] = (version: @unchecked) match { - case GenesisBlockVersion | PlainBlockVersion => Array(txsCount.toByte) - case NgBlockVersion | RewardBlockVersion | ProtoBlockVersion => Ints.toByteArray(txsCount) - } + def mkTxsCountBytes(version: Byte, txsCount: Int): Array[Byte] = + if (version <= PlainBlockVersion) Array(txsCount.toByte) + else if (version <= ProtoBlockVersion) Ints.toByteArray(txsCount) + else throw new IllegalArgumentException(s"Unexpected block version: $version") + } diff --git a/node/src/main/scala/com/wavesplatform/consensus/TransactionsOrdering.scala b/node/src/main/scala/com/wavesplatform/consensus/TransactionsOrdering.scala index aeaa323c48b..79ed7d2b5b9 100644 --- a/node/src/main/scala/com/wavesplatform/consensus/TransactionsOrdering.scala +++ b/node/src/main/scala/com/wavesplatform/consensus/TransactionsOrdering.scala @@ -1,8 +1,8 @@ package com.wavesplatform.consensus +import com.wavesplatform.transaction.{Authorized, Transaction} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.InvokeScriptTransaction -import com.wavesplatform.transaction.{Authorized, Transaction} object TransactionsOrdering { trait WavesOrdering extends Ordering[Transaction] { @@ -10,8 +10,8 @@ object TransactionsOrdering { def txTimestampOrder(ts: Long): Long private def orderBy(t: Transaction): (Boolean, Double, Long, Long) = { val byWhiteList = !isWhitelisted(t) // false < true - val size = t.bytes().length - val byFee = if (t.assetFee._1 != Waves) 0 else -t.assetFee._2 + val size = t.bytesSize + val byFee = if (t.feeAssetId != Waves) 0 else -t.fee val byTimestamp = txTimestampOrder(t.timestamp) (byWhiteList, byFee.toDouble / size.toDouble, byFee, byTimestamp) @@ -31,8 +31,8 @@ object TransactionsOrdering { override def isWhitelisted(t: Transaction): Boolean = t match { case _ if whitelistAddresses.isEmpty => false - case a: Authorized if whitelistAddresses.contains(a.sender.toAddress.stringRepr) => true - case i: InvokeScriptTransaction if whitelistAddresses.contains(i.dAppAddressOrAlias.stringRepr) => true + case a: Authorized if whitelistAddresses.contains(a.sender.toAddress.toString) => true + case i: InvokeScriptTransaction if whitelistAddresses.contains(i.dApp.toString) => true case _ => false } override def txTimestampOrder(ts: Long): Long = ts diff --git a/node/src/main/scala/com/wavesplatform/consensus/nxt/api/http/NxtConsensusApiRoute.scala b/node/src/main/scala/com/wavesplatform/consensus/nxt/api/http/NxtConsensusApiRoute.scala new file mode 100644 index 00000000000..e69de29bb2d diff --git a/node/src/main/scala/com/wavesplatform/crypto/package.scala b/node/src/main/scala/com/wavesplatform/crypto/package.scala index b0b28bdf91a..c67c5a5fe5f 100644 --- a/node/src/main/scala/com/wavesplatform/crypto/package.scala +++ b/node/src/main/scala/com/wavesplatform/crypto/package.scala @@ -2,6 +2,8 @@ package com.wavesplatform import java.lang.reflect.Constructor +import scala.util.Try + import com.wavesplatform.account.{PrivateKey, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError @@ -9,13 +11,12 @@ import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.utils._ import org.whispersystems.curve25519.OpportunisticCurve25519Provider -import scala.util.Try - package object crypto extends ScorexLogging { // Constants - val SignatureLength: Int = Curve25519.SignatureLength - val KeyLength: Int = Curve25519.KeyLength - val DigestLength: Int = 32 + val SignatureLength: Int = Curve25519.SignatureLength // 64 + val KeyLength: Int = Curve25519.KeyLength // 32 + val DigestLength: Int = 32 + val EthereumKeyLength: Int = 64 // Additional provider private val provider: OpportunisticCurve25519Provider = { diff --git a/node/src/main/scala/com/wavesplatform/database/Caches.scala b/node/src/main/scala/com/wavesplatform/database/Caches.scala index f49dd8b01de..1940d3f5f10 100644 --- a/node/src/main/scala/com/wavesplatform/database/Caches.scala +++ b/node/src/main/scala/com/wavesplatform/database/Caches.scala @@ -9,6 +9,7 @@ import com.google.common.cache._ import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.block.{Block, SignedBlockHeader} import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.database.protobuf.EthereumTransactionMeta import com.wavesplatform.metrics.LevelDBStats import com.wavesplatform.settings.DBSettings import com.wavesplatform.state._ @@ -170,7 +171,8 @@ abstract class Caches(spendableBalanceChanged: Observer[(Address, Asset)]) exten hitSource: ByteStr, scriptResults: Map[ByteStr, InvokeScriptResult], failedTransactionIds: Set[ByteStr], - stateHash: StateHashBuilder.Result + stateHash: StateHashBuilder.Result, + ethereumTransactionMeta: Map[ByteStr, EthereumTransactionMeta] ): Unit override def append(diff: Diff, carryFee: Long, totalFee: Long, reward: Option[Long], hitSource: ByteStr, block: Block): Unit = { @@ -293,7 +295,8 @@ abstract class Caches(spendableBalanceChanged: Observer[(Address, Asset)]) exten hitSource, diff.scriptResults, failedTransactionIds, - stateHash.result() + stateHash.result(), + diff.ethereumTransactionMeta ) val emptyData = Map.empty[(Address, String), Option[DataEntry[_]]] diff --git a/node/src/main/scala/com/wavesplatform/database/DBResource.scala b/node/src/main/scala/com/wavesplatform/database/DBResource.scala index 334b59ed277..941fdb1410a 100644 --- a/node/src/main/scala/com/wavesplatform/database/DBResource.scala +++ b/node/src/main/scala/com/wavesplatform/database/DBResource.scala @@ -5,7 +5,7 @@ import org.iq80.leveldb.{DB, DBIterator, ReadOptions} trait DBResource extends AutoCloseable { def get[V](key: Key[V]): V def get(key: Array[Byte]): Array[Byte] - def iterator: DBIterator + def iterator: DBIterator // Should have a single instance } object DBResource { @@ -17,7 +17,7 @@ object DBResource { override def get(key: Array[Byte]): Array[Byte] = db.get(key, readOptions) - override val iterator: DBIterator = db.iterator(readOptions) + override lazy val iterator: DBIterator = db.iterator(readOptions) override def close(): Unit = { iterator.close() diff --git a/node/src/main/scala/com/wavesplatform/database/KeyTags.scala b/node/src/main/scala/com/wavesplatform/database/KeyTags.scala index 13afcd455e8..2ffa57abdbf 100644 --- a/node/src/main/scala/com/wavesplatform/database/KeyTags.scala +++ b/node/src/main/scala/com/wavesplatform/database/KeyTags.scala @@ -57,7 +57,8 @@ object KeyTags extends Enumeration { IssuedAssets, UpdatedAssets, SponsoredAssets, - StateHash = Value + StateHash, + EthereumTransactionMeta = Value final implicit class KeyTagExt(val t: KeyTag) extends AnyVal { @inline def prefixBytes: Array[Byte] = Shorts.toByteArray(t.id.toShort) diff --git a/node/src/main/scala/com/wavesplatform/database/Keys.scala b/node/src/main/scala/com/wavesplatform/database/Keys.scala index 7bfc343df67..aee114c8866 100644 --- a/node/src/main/scala/com/wavesplatform/database/Keys.scala +++ b/node/src/main/scala/com/wavesplatform/database/Keys.scala @@ -5,7 +5,7 @@ import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.api.BlockMeta import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.database.protobuf.TransactionMeta +import com.wavesplatform.database.protobuf.{EthereumTransactionMeta, TransactionMeta} import com.wavesplatform.protobuf.transaction.PBRecipients import com.wavesplatform.state._ import com.wavesplatform.state.reader.LeaseDetails @@ -15,7 +15,13 @@ import com.wavesplatform.utils._ object Keys { import KeyHelpers._ - import KeyTags.{AddressId => AddressIdTag, InvokeScriptResult => InvokeScriptResultTag, LeaseDetails => LeaseDetailsTag, _} + import KeyTags.{ + AddressId => AddressIdTag, + EthereumTransactionMeta => EthereumTransactionMetaTag, + InvokeScriptResult => InvokeScriptResultTag, + LeaseDetails => LeaseDetailsTag, + _ + } val version: Key[Int] = intKey(Version, default = 1) val height: Key[Int] = intKey(Height) @@ -49,7 +55,6 @@ object Keys { def sponsorshipAssets(height: Int): Key[Seq[IssuedAsset]] = Key(SponsoredAssets, h(height), d => readAssetIds(d).map(IssuedAsset), ias => writeAssetIds(ias.map(_.id))) - def leaseBalanceHistory(addressId: AddressId): Key[Seq[Int]] = historyKey(LeaseBalanceHistory, addressId.toByteArray) def leaseBalance(addressId: AddressId)(height: Int): Key[LeaseBalance] = Key(LeaseBalance, hAddr(height, addressId), readLeaseBalance, writeLeaseBalance) @@ -180,4 +185,7 @@ object Keys { def stateHash(height: Int): Key[Option[StateHash]] = Key.opt(StateHash, h(height), readStateHash, writeStateHash) + + def ethereumTransactionMeta(height: Height, txNum: TxNum): Key[Option[EthereumTransactionMeta]] = + Key.opt(EthereumTransactionMetaTag, hNum(height, txNum), EthereumTransactionMeta.parseFrom, _.toByteArray) } diff --git a/node/src/main/scala/com/wavesplatform/database/LevelDBWriter.scala b/node/src/main/scala/com/wavesplatform/database/LevelDBWriter.scala index 1d642def20c..e04d690f605 100644 --- a/node/src/main/scala/com/wavesplatform/database/LevelDBWriter.scala +++ b/node/src/main/scala/com/wavesplatform/database/LevelDBWriter.scala @@ -1,13 +1,11 @@ package com.wavesplatform.database -import java.nio.ByteBuffer - import cats.data.Ior import cats.syntax.option._ import cats.syntax.semigroup._ import com.google.common.cache.CacheBuilder import com.google.common.collect.MultimapBuilder -import com.google.common.primitives.{Ints, Shorts} +import com.google.common.primitives.{Bytes, Ints} import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.api.BlockMeta import com.wavesplatform.block.Block.BlockId @@ -16,14 +14,15 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ import com.wavesplatform.database import com.wavesplatform.database.patch.DisableHijackedAliases -import com.wavesplatform.database.protobuf.TransactionMeta +import com.wavesplatform.database.protobuf.{EthereumTransactionMeta, TransactionMeta} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.ValidationError -import com.wavesplatform.protobuf.transaction.PBTransactions +import com.wavesplatform.protobuf.transaction.PBAmounts import com.wavesplatform.settings.{BlockchainSettings, DBSettings, WavesSettings} import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.state.{TxNum, _} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.EthereumTransaction.Transfer import com.wavesplatform.transaction.TxValidationError.{AliasDoesNotExist, AliasIsDisabled} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.assets._ @@ -37,9 +36,8 @@ import org.iq80.leveldb.DB import org.slf4j.LoggerFactory import scala.annotation.tailrec -import scala.collection.mutable.{ArrayBuffer, ListBuffer} +import scala.collection.mutable.ArrayBuffer import scala.jdk.CollectionConverters._ -import scala.util.Try import scala.util.control.NonFatal object LevelDBWriter extends ScorexLogging { @@ -383,7 +381,8 @@ abstract class LevelDBWriter private[database] ( hitSource: ByteStr, scriptResults: Map[ByteStr, InvokeScriptResult], failedTransactionIds: Set[ByteStr], - stateHash: StateHashBuilder.Result + stateHash: StateHashBuilder.Result, + ethereumTransactionMeta: Map[ByteStr, EthereumTransactionMeta] ): Unit = { log.trace(s"Persisting block ${block.id()} at height $height") readWrite { rw => @@ -500,7 +499,7 @@ abstract class LevelDBWriter private[database] ( val nextSeqNr = rw.get(kk) + 1 val txTypeNumSeq = txIds.map { txId => val (tx, num, _) = transactions(txId) - (tx.typeId, num) + (tx.tpe.id.toByte, num) } rw.put(Keys.addressTransactionHN(addressId, nextSeqNr), Some((Height(height), txTypeNumSeq.sortBy(-_._2)))) rw.put(kk, nextSeqNr) @@ -512,7 +511,7 @@ abstract class LevelDBWriter private[database] ( for ((id, (tx, num, succeeded)) <- transactions) { rw.put(Keys.transactionAt(Height(height), num), Some((tx, succeeded))) - rw.put(Keys.transactionMetaById(id), Some(TransactionMeta(height, num, tx.typeId, !succeeded))) + rw.put(Keys.transactionMetaById(id), Some(TransactionMeta(height, num, tx.tpe.id, !succeeded))) } val activationWindowSize = settings.functionalitySettings.activationWindowSize(height) @@ -572,6 +571,10 @@ abstract class LevelDBWriter private[database] ( } } + for ((id, meta) <- ethereumTransactionMeta) { + rw.put(Keys.ethereumTransactionMeta(Height(height), transactions(TransactionId(id))._2), Some(meta)) + } + expiredKeys.foreach(rw.delete(_, "expired-keys")) if (DisableHijackedAliases.height == height) { @@ -606,157 +609,158 @@ abstract class LevelDBWriter private[database] ( log.debug(s"Rolling back to block $targetBlockId at $targetHeight") - val discardedBlocks: Seq[(Block, ByteStr)] = for (currentHeight <- height until targetHeight by -1) yield { - val balancesToInvalidate = Seq.newBuilder[(Address, Asset)] - val ordersToInvalidate = Seq.newBuilder[ByteStr] - val scriptsToDiscard = Seq.newBuilder[Address] - val assetScriptsToDiscard = Seq.newBuilder[IssuedAsset] - val accountDataToInvalidate = Seq.newBuilder[(Address, String)] - - val h = Height(currentHeight) - - val discardedBlock = readWrite { rw => - rw.put(Keys.height, currentHeight - 1) - - val discardedMeta = rw - .get(Keys.blockMetaAt(h)) - .getOrElse(throw new IllegalArgumentException(s"No block at height $currentHeight")) - - log.trace(s"Removing block ${discardedMeta.id} at $currentHeight") - rw.delete(Keys.blockMetaAt(h)) - - val changedAddresses = for { - addressId <- rw.get(Keys.changedAddresses(currentHeight)) - } yield addressId -> rw.get(Keys.idToAddress(addressId)) - - rw.iterateOver(KeyTags.ChangedAssetBalances.prefixBytes ++ Ints.toByteArray(h)) { e => - val assetId = IssuedAsset(ByteStr(e.getKey.takeRight(32))) - for ((addressId, address) <- changedAddresses) { - val kabh = Keys.assetBalanceHistory(addressId, assetId) - val history = rw.get(kabh) - if (history.nonEmpty && history.head == currentHeight) { - log.trace(s"Discarding ${assetId.id} balance for $address at $currentHeight") - balancesToInvalidate += address -> assetId - rw.delete(Keys.assetBalance(addressId, assetId)(history.head)) - rw.put(kabh.keyBytes, writeIntSeq(history.tail)) + val discardedBlocks: Seq[(Block, ByteStr)] = + for (currentHeightInt <- height until targetHeight by -1; currentHeight = Height(currentHeightInt)) yield { + val balancesToInvalidate = Seq.newBuilder[(Address, Asset)] + val ordersToInvalidate = Seq.newBuilder[ByteStr] + val scriptsToDiscard = Seq.newBuilder[Address] + val assetScriptsToDiscard = Seq.newBuilder[IssuedAsset] + val accountDataToInvalidate = Seq.newBuilder[(Address, String)] + + val discardedBlock = readWrite { rw => + rw.put(Keys.height, currentHeight - 1) + + val discardedMeta = rw + .get(Keys.blockMetaAt(currentHeight)) + .getOrElse(throw new IllegalArgumentException(s"No block at height $currentHeight")) + + log.trace(s"Removing block ${discardedMeta.id} at $currentHeight") + + val changedAddresses = for { + addressId <- rw.get(Keys.changedAddresses(currentHeight)) + } yield addressId -> rw.get(Keys.idToAddress(addressId)) + + rw.iterateOver(KeyTags.ChangedAssetBalances.prefixBytes ++ Ints.toByteArray(currentHeight)) { e => + val assetId = IssuedAsset(ByteStr(e.getKey.takeRight(32))) + for ((addressId, address) <- changedAddresses) { + val kabh = Keys.assetBalanceHistory(addressId, assetId) + val history = rw.get(kabh) + if (history.nonEmpty && history.head == currentHeight) { + log.trace(s"Discarding ${assetId.id} balance for $address at $currentHeight") + balancesToInvalidate += address -> assetId + rw.delete(Keys.assetBalance(addressId, assetId)(history.head)) + rw.put(kabh.keyBytes, writeIntSeq(history.tail)) + } } } - } - for ((addressId, address) <- changedAddresses) { - for (k <- rw.get(Keys.changedDataKeys(currentHeight, addressId))) { - log.trace(s"Discarding $k for $address at $currentHeight") - accountDataToInvalidate += (address -> k) - rw.delete(Keys.data(addressId, k)(currentHeight)) - rw.filterHistory(Keys.dataHistory(address, k), currentHeight) - } - rw.delete(Keys.changedDataKeys(currentHeight, addressId)) + for ((addressId, address) <- changedAddresses) { + for (k <- rw.get(Keys.changedDataKeys(currentHeight, addressId))) { + log.trace(s"Discarding $k for $address at $currentHeight") + accountDataToInvalidate += (address -> k) + rw.delete(Keys.data(addressId, k)(currentHeight)) + rw.filterHistory(Keys.dataHistory(address, k), currentHeight) + } + rw.delete(Keys.changedDataKeys(currentHeight, addressId)) - balancesToInvalidate += (address -> Waves) - rw.delete(Keys.wavesBalance(addressId)(currentHeight)) - rw.filterHistory(Keys.wavesBalanceHistory(addressId), currentHeight) + balancesToInvalidate += (address -> Waves) + rw.delete(Keys.wavesBalance(addressId)(currentHeight)) + rw.filterHistory(Keys.wavesBalanceHistory(addressId), currentHeight) - rw.delete(Keys.leaseBalance(addressId)(currentHeight)) - rw.filterHistory(Keys.leaseBalanceHistory(addressId), currentHeight) + rw.delete(Keys.leaseBalance(addressId)(currentHeight)) + rw.filterHistory(Keys.leaseBalanceHistory(addressId), currentHeight) - balanceAtHeightCache.invalidate((currentHeight, addressId)) - leaseBalanceAtHeightCache.invalidate((currentHeight, addressId)) - discardLeaseBalance(address) + balanceAtHeightCache.invalidate((currentHeight, addressId)) + leaseBalanceAtHeightCache.invalidate((currentHeight, addressId)) + discardLeaseBalance(address) - if (dbSettings.storeTransactionsByAddress) { - val kTxSeqNr = Keys.addressTransactionSeqNr(addressId) - val txSeqNr = rw.get(kTxSeqNr) - val kTxHNSeq = Keys.addressTransactionHN(addressId, txSeqNr) + if (dbSettings.storeTransactionsByAddress) { + val kTxSeqNr = Keys.addressTransactionSeqNr(addressId) + val txSeqNr = rw.get(kTxSeqNr) + val kTxHNSeq = Keys.addressTransactionHN(addressId, txSeqNr) - rw.get(kTxHNSeq) - .filter(_._1 == Height(currentHeight)) - .foreach { _ => - rw.delete(kTxHNSeq) - rw.put(kTxSeqNr, (txSeqNr - 1).max(0)) + rw.get(kTxHNSeq).collect { + case (`currentHeight`, _) => + rw.delete(kTxHNSeq) + rw.put(kTxSeqNr, (txSeqNr - 1).max(0)) } + } } - } - - writableDB - .withResource(loadLeaseIds(_, currentHeight, currentHeight, includeCancelled = true)) - .foreach(rollbackLeaseStatus(rw, _, currentHeight)) - - rollbackAssetsInfo(rw, currentHeight) - - val transactions = transactionsAtHeight(h) - - transactions.foreach { - case (num, tx) => - forgetTransaction(tx.id()) - (tx: @unchecked) match { - case _: GenesisTransaction => // genesis transaction can not be rolled back - case _: PaymentTransaction | _: TransferTransaction | _: MassTransferTransaction => - // balances already restored - - case _: IssueTransaction | _: UpdateAssetInfoTransaction | _: ReissueTransaction | _: BurnTransaction | _: SponsorFeeTransaction => - // asset info already restored - - case _: LeaseTransaction | _: LeaseCancelTransaction => - // leases already restored - case tx: SetScriptTransaction => - val address = tx.sender.toAddress - scriptsToDiscard += address - for (addressId <- addressId(address)) { - rw.delete(Keys.addressScript(addressId)(currentHeight)) - rw.filterHistory(Keys.addressScriptHistory(addressId), currentHeight) - } - - case tx: SetAssetScriptTransaction => - val asset = tx.asset - assetScriptsToDiscard += asset - rw.delete(Keys.assetScript(asset)(currentHeight)) - rw.filterHistory(Keys.assetScriptHistory(asset), currentHeight) - - case _: DataTransaction => // see changed data keys removal - - case _: InvokeScriptTransaction | _: InvokeExpressionTransaction => - val k = Keys.invokeScriptResult(h, num) - rw.delete(k) + writableDB + .withResource(loadLeaseIds(_, currentHeight, currentHeight, includeCancelled = true)) + .foreach(rollbackLeaseStatus(rw, _, currentHeight)) + + rollbackAssetsInfo(rw, currentHeight) + + val transactions = transactionsAtHeight(currentHeight) + + transactions.foreach { + case (num, tx) => + forgetTransaction(tx.id()) + (tx: @unchecked) match { + case _: GenesisTransaction => // genesis transaction can not be rolled back + case _: PaymentTransaction | _: TransferTransaction | _: MassTransferTransaction => + // balances already restored + + case _: IssueTransaction | _: UpdateAssetInfoTransaction | _: ReissueTransaction | _: BurnTransaction | _: SponsorFeeTransaction => + // asset info already restored + + case _: LeaseTransaction | _: LeaseCancelTransaction => + // leases already restored + + case tx: SetScriptTransaction => + val address = tx.sender.toAddress + scriptsToDiscard += address + for (addressId <- addressId(address)) { + rw.delete(Keys.addressScript(addressId)(currentHeight)) + rw.filterHistory(Keys.addressScriptHistory(addressId), currentHeight) + } + + case tx: SetAssetScriptTransaction => + val asset = tx.asset + assetScriptsToDiscard += asset + rw.delete(Keys.assetScript(asset)(currentHeight)) + rw.filterHistory(Keys.assetScriptHistory(asset), currentHeight) + + case _: DataTransaction => // see changed data keys removal + + case _: InvokeScriptTransaction | _: InvokeExpressionTransaction => + rw.delete(Keys.invokeScriptResult(currentHeight, num)) + + case tx: CreateAliasTransaction => rw.delete(Keys.addressIdOfAlias(tx.alias)) + case tx: ExchangeTransaction => + ordersToInvalidate += rollbackOrderFill(rw, tx.buyOrder.id(), currentHeight) + ordersToInvalidate += rollbackOrderFill(rw, tx.sellOrder.id(), currentHeight) + case _: EthereumTransaction => + rw.delete(Keys.ethereumTransactionMeta(currentHeight, num)) + } - case tx: CreateAliasTransaction => rw.delete(Keys.addressIdOfAlias(tx.alias)) - case tx: ExchangeTransaction => - ordersToInvalidate += rollbackOrderFill(rw, tx.buyOrder.id(), currentHeight) - ordersToInvalidate += rollbackOrderFill(rw, tx.sellOrder.id(), currentHeight) - } + if (tx.tpe != TransactionType.Genesis) { + rw.delete(Keys.transactionAt(currentHeight, num)) + rw.delete(Keys.transactionMetaById(TransactionId(tx.id()))) + } + } - if (tx.typeId != GenesisTransaction.typeId) { - rw.delete(Keys.transactionAt(h, num)) - rw.delete(Keys.transactionMetaById(TransactionId(tx.id()))) - } - } + rw.delete(Keys.blockMetaAt(currentHeight)) + rw.delete(Keys.score(currentHeight)) + rw.delete(Keys.changedAddresses(currentHeight)) + rw.delete(Keys.heightOf(discardedMeta.id)) + rw.delete(Keys.carryFee(currentHeight)) + rw.delete(Keys.blockTransactionsFee(currentHeight)) + rw.delete(Keys.blockReward(currentHeight)) + rw.delete(Keys.wavesAmount(currentHeight)) + rw.delete(Keys.stateHash(currentHeight)) + rw.delete(Keys.hitSource(currentHeight)) + + if (DisableHijackedAliases.height == currentHeight) { + disabledAliases = DisableHijackedAliases.revert(rw) + } - rw.delete(Keys.blockMetaAt(h)) - rw.delete(Keys.heightOf(discardedMeta.id)) - rw.delete(Keys.carryFee(currentHeight)) - rw.delete(Keys.blockTransactionsFee(currentHeight)) - rw.delete(Keys.blockReward(currentHeight)) - rw.delete(Keys.wavesAmount(currentHeight)) - rw.delete(Keys.stateHash(currentHeight)) + val hitSource = rw.get(Keys.hitSource(currentHeight)).get + val block = createBlock(discardedMeta.header, discardedMeta.signature, transactions.map(_._2)).explicitGet() - if (DisableHijackedAliases.height == currentHeight) { - disabledAliases = DisableHijackedAliases.revert(rw) + (block, hitSource) } - val hitSource = rw.get(Keys.hitSource(currentHeight)).get - val block = createBlock(discardedMeta.header, discardedMeta.signature, transactions.map(_._2)).explicitGet() - - (block, hitSource) + balancesToInvalidate.result().foreach(discardBalance) + ordersToInvalidate.result().foreach(discardVolumeAndFee) + scriptsToDiscard.result().foreach(discardScript) + assetScriptsToDiscard.result().foreach(discardAssetScript) + accountDataToInvalidate.result().foreach(discardAccountData) + discardedBlock } - balancesToInvalidate.result().foreach(discardBalance) - ordersToInvalidate.result().foreach(discardVolumeAndFee) - scriptsToDiscard.result().foreach(discardScript) - assetScriptsToDiscard.result().foreach(discardAssetScript) - accountDataToInvalidate.result().foreach(discardAccountData) - discardedBlock - } - log.debug(s"Rollback to block $targetBlockId at $targetHeight completed") discardedBlocks.reverse } @@ -802,11 +806,21 @@ abstract class LevelDBWriter private[database] ( rw.filterHistory(Keys.leaseDetailsHistory(leaseId), currentHeight) } - override def transferById(id: ByteStr): Option[(Int, TransferTransaction)] = readOnly { db => + override def transferById(id: ByteStr): Option[(Int, TransferTransactionLike)] = readOnly { db => for { tm <- db.get(Keys.transactionMetaById(TransactionId @@ id)) - if tm.`type` == TransferTransaction.typeId - tx <- db.get(Keys.transactionAt(Height(tm.height), TxNum(tm.num.toShort))).collect { case (t: TransferTransaction, true) => t } + if tm.`type` == TransferTransaction.typeId || tm.`type` == TransactionType.Ethereum.id + tx <- db + .get(Keys.transactionAt(Height(tm.height), TxNum(tm.num.toShort))) + .collect { + case (t: TransferTransaction, true) => t + case (e @ EthereumTransaction(_: Transfer, _, _, _), true) => + val meta = db.get(Keys.ethereumTransactionMeta(Height @@ tm.height, TxNum @@ tm.num.toShort)).get + val transfer = meta.payload.transfer.get + val tAmount = transfer.amount.get + val asset = PBAmounts.toVanillaAssetId(tAmount.assetId) + e.toTransferLike(tAmount.amount, Address(transfer.publicKeyHash.toByteArray), asset) + } } yield (height, tx) } @@ -814,21 +828,21 @@ abstract class LevelDBWriter private[database] ( protected def transactionInfo(id: ByteStr, db: ReadOnlyDB): Option[(Int, Transaction, Boolean)] = for { - tm <- db.get(Keys.transactionMetaById(TransactionId(id))) + tm <- transactionMeta(id, db) (tx, _) <- db.get(Keys.transactionAt(Height(tm.height), TxNum(tm.num.toShort))) } yield (tm.height, tx, !tm.failed) - override def transactionMeta(id: ByteStr): Option[(Int, Boolean)] = readOnly { db => - db.get(Keys.transactionMetaById(TransactionId(id))).map { tm => - (tm.height, !tm.failed) - } + private def transactionMeta(id: ByteStr, db: ReadOnlyDB) = db.get(Keys.transactionMetaById(TransactionId(id))) + + override def transactionMeta(id: ByteStr): Option[(Int, Boolean)] = readOnly(transactionMeta(id, _)).map { tm => + (tm.height, !tm.failed) } override def resolveAlias(alias: Alias): Either[ValidationError, Address] = readOnly { db => if (disabledAliases.contains(alias)) Left(AliasIsDisabled(alias)) else db.get(Keys.addressIdOfAlias(alias)) - .map(addressId => db.get(Keys.idToAddress(addressId))) + .map(addressId => Address(db.get(Keys.idToAddress(addressId)).publicKeyHash)) .toRight(AliasDoesNotExist(alias)) } @@ -954,28 +968,18 @@ abstract class LevelDBWriter private[database] ( } private def transactionsAtHeight(h: Height): List[(TxNum, Transaction)] = readOnly { db => - import com.wavesplatform.protobuf.transaction.PBSignedTransaction - - val txs = new ListBuffer[(TxNum, Transaction)]() - - val prefix = ByteBuffer - .allocate(6) - .put(KeyTags.NthTransactionInfoAtHeight.prefixBytes) - .putInt(h) - .array() - - db.iterateOver(prefix) { entry => - val k = entry.getKey - - for { - idx <- Try(Shorts.fromByteArray(k.slice(6, 8))) - tx = readTransactionBytes(entry.getValue) match { - case (_, Left(legacyBytes)) => TransactionParsers.parseBytes(legacyBytes).get - case (_, Right(newBytes)) => PBTransactions.vanilla(PBSignedTransaction.parseFrom(newBytes)).explicitGet() - } - } txs.append((TxNum(idx), tx)) + loadTransactions(h, db).fold[List[(TxNum, Transaction)]](Nil) { transactions => + transactions.zipWithIndex.collect { case ((tx, _), txNum) => TxNum(txNum.toShort) -> tx }.toList } + } - txs.toList + override def resolveERC20Address(address: ERC20Address): Option[IssuedAsset] = writableDB.withResource { r => + import scala.jdk.CollectionConverters._ + r.iterator.seek(Bytes.concat(KeyTags.AssetStaticInfo.prefixBytes, address.arr)) + r.iterator.asScala + .to(LazyList) + .headOption + .map(e => IssuedAsset(ByteStr(e.getKey.drop(2)))) + .filter(asset => asset.id.size == 32 && ERC20Address(asset) == address) } } diff --git a/node/src/main/scala/com/wavesplatform/database/RW.scala b/node/src/main/scala/com/wavesplatform/database/RW.scala index 0f78576b546..c3243259230 100644 --- a/node/src/main/scala/com/wavesplatform/database/RW.scala +++ b/node/src/main/scala/com/wavesplatform/database/RW.scala @@ -28,5 +28,9 @@ class RW(db: DB, readOptions: ReadOptions, batch: WriteBatch) extends ReadOnlyDB def delete[V](key: Key[V]): Unit = batch.delete(key.keyBytes) - def filterHistory(key: Key[Seq[Int]], heightToRemove: Int): Unit = put(key, get(key).filterNot(_ == heightToRemove)) + def filterHistory(key: Key[Seq[Int]], heightToRemove: Int): Unit = { + val newValue = get(key).filterNot(_ == heightToRemove) + if (newValue.nonEmpty) put(key, newValue) + else delete(key) + } } diff --git a/node/src/main/scala/com/wavesplatform/database/jna/LevelDBJNADB.scala b/node/src/main/scala/com/wavesplatform/database/jna/LevelDBJNADB.scala index 18ed7382fd4..8888f3be775 100644 --- a/node/src/main/scala/com/wavesplatform/database/jna/LevelDBJNADB.scala +++ b/node/src/main/scala/com/wavesplatform/database/jna/LevelDBJNADB.scala @@ -117,10 +117,10 @@ private object LevelDBJNADB { false override def prev(): DBEntry = - ??? + throw new NotImplementedError("prev() is not implemented") override def peekPrev(): DBEntry = - ??? + throw new NotImplementedError("peekPrev() is not implemented") override def seekToLast(): Unit = iterator.seekToLast() @@ -136,7 +136,7 @@ private object LevelDBJNADB { new DBEntry { override def getKey: Array[Byte] = pair.getKey override def getValue: Array[Byte] = pair.getValue - override def setValue(value: Array[Byte]): Array[Byte] = ??? + override def setValue(value: Array[Byte]): Array[Byte] = throw new NotImplementedError("setValue(Array[Byte]) is not implemented") } } else { this.endOfData() diff --git a/node/src/main/scala/com/wavesplatform/database/package.scala b/node/src/main/scala/com/wavesplatform/database/package.scala index 688eaa2eaec..a3125f33a34 100644 --- a/node/src/main/scala/com/wavesplatform/database/package.scala +++ b/node/src/main/scala/com/wavesplatform/database/package.scala @@ -4,39 +4,39 @@ import java.io.File import java.nio.ByteBuffer import java.util.{Map => JMap} +import scala.collection.mutable + import com.google.common.base.Charsets.UTF_8 -import com.google.common.io.ByteStreams.{newDataInput, newDataOutput} import com.google.common.io.{ByteArrayDataInput, ByteArrayDataOutput} +import com.google.common.io.ByteStreams.{newDataInput, newDataOutput} import com.google.common.primitives.{Bytes, Ints, Longs} -import com.google.protobuf.{ByteString, CodedInputStream, WireFormat} +import com.google.protobuf.ByteString import com.wavesplatform.account.{AddressScheme, PublicKey} import com.wavesplatform.api.BlockMeta -import com.wavesplatform.block.validation.Validators import com.wavesplatform.block.{Block, BlockHeader} +import com.wavesplatform.block.validation.Validators import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.crypto._ -import com.wavesplatform.database.protobuf.DataEntry.Value -import com.wavesplatform.database.protobuf.TransactionData.Transaction.{LegacyBytes, NewTransaction} import com.wavesplatform.database.{protobuf => pb} +import com.wavesplatform.database.protobuf.DataEntry.Value +import com.wavesplatform.database.protobuf.TransactionData.{Transaction => TD} import com.wavesplatform.lang.script.{Script, ScriptReader} import com.wavesplatform.protobuf.ByteStringExt import com.wavesplatform.protobuf.block.PBBlocks import com.wavesplatform.protobuf.transaction.{PBRecipients, PBTransactions} -import com.wavesplatform.state.StateHash.SectionId import com.wavesplatform.state._ +import com.wavesplatform.state.StateHash.SectionId import com.wavesplatform.state.reader.LeaseDetails +import com.wavesplatform.transaction.{EthereumTransaction, GenesisTransaction, PaymentTransaction, PBSince, Transaction, TransactionParsers, TxValidationError} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.lease.LeaseTransaction -import com.wavesplatform.transaction.{GenesisTransaction, LegacyPBSwitch, PaymentTransaction, Transaction, TransactionParsers, TxValidationError} -import com.wavesplatform.utils.{ScorexLogging, _} +import com.wavesplatform.utils._ import monix.eval.Task import monix.reactive.Observable import org.iq80.leveldb._ import supertagged.TaggedType -import scala.collection.mutable - //noinspection UnstableApiUsage package object database extends ScorexLogging { def openDB(path: String, recreate: Boolean = false): DB = { @@ -201,7 +201,8 @@ package object database extends ScorexLogging { ld.status match { case LeaseDetails.Status.Active => pb.LeaseDetails.Status.Active(com.google.protobuf.empty.Empty()) case LeaseDetails.Status.Cancelled(height, cancelTxId) => - pb.LeaseDetails.Status.Cancelled(pb.LeaseDetails.Cancelled(height, cancelTxId.fold(ByteString.EMPTY)(id => ByteString.copyFrom(id.arr)))) + pb.LeaseDetails.Status + .Cancelled(pb.LeaseDetails.Cancelled(height, cancelTxId.fold(ByteString.EMPTY)(id => ByteString.copyFrom(id.arr)))) case LeaseDetails.Status.Expired(height) => pb.LeaseDetails.Status.Expired(pb.LeaseDetails.Expired(height)) } ) @@ -247,12 +248,6 @@ package object database extends ScorexLogging { def readTransactionHeight(data: Array[Byte]): Int = Ints.fromByteArray(data) - def writeTransactionInfo(txInfo: (Int, Transaction)): Array[Byte] = { - val (h, tx) = txInfo - val txBytes = tx.bytes() - ByteBuffer.allocate(4 + txBytes.length).putInt(h).put(txBytes).array() - } - def readTransactionIds(data: Array[Byte]): Seq[(Int, ByteStr)] = Option(data).fold(Seq.empty[(Int, ByteStr)]) { d => val b = ByteBuffer.wrap(d) val ids = Seq.newBuilder[(Int, ByteStr)] @@ -547,57 +542,25 @@ package object database extends ScorexLogging { val data = pb.TransactionData.parseFrom(b) data.transaction match { - case tx: LegacyBytes => (TransactionParsers.parseBytes(tx.value.toByteArray).get, !data.failed) - case tx: NewTransaction => (PBTransactions.vanilla(tx.value).explicitGet(), !data.failed) - case _ => throw new IllegalArgumentException("Illegal transaction data") + case tx: TD.LegacyBytes => (TransactionParsers.parseBytes(tx.value.toByteArray).get, !data.failed) + case tx: TD.WavesTransaction => (PBTransactions.vanilla(tx.value, unsafe = false).explicitGet(), !data.failed) + case tx: TD.EthereumTransaction => (EthereumTransaction(tx.value.toByteArray).explicitGet(), !data.failed) + case _ => throw new IllegalArgumentException("Illegal transaction data") } } def writeTransaction(v: (Transaction, Boolean)): Array[Byte] = { val (tx, succeeded) = v val ptx = tx match { - case lps: LegacyPBSwitch if !lps.isProtobufVersion => LegacyBytes(ByteString.copyFrom(tx.bytes())) - case _: GenesisTransaction => LegacyBytes(ByteString.copyFrom(tx.bytes())) - case _: PaymentTransaction => LegacyBytes(ByteString.copyFrom(tx.bytes())) - case _ => NewTransaction(PBTransactions.protobuf(tx)) + case lps: PBSince if !lps.isProtobufVersion => TD.LegacyBytes(ByteString.copyFrom(tx.bytes())) + case _: GenesisTransaction => TD.LegacyBytes(ByteString.copyFrom(tx.bytes())) + case _: PaymentTransaction => TD.LegacyBytes(ByteString.copyFrom(tx.bytes())) + case et: EthereumTransaction => TD.EthereumTransaction(ByteString.copyFrom(et.bytes())) + case _ => TD.WavesTransaction(PBTransactions.protobuf(tx)) } pb.TransactionData(ptx, !succeeded).toByteArray } - /** Returns status (succeed - true, failed -false) and bytes (left - legacy format bytes, right - new format bytes) */ - def readTransactionBytes(b: Array[Byte]): (Boolean, Either[Array[Byte], Array[Byte]]) = { - import pb.TransactionData._ - - val coded = CodedInputStream.newInstance(b) - - @inline def validTransactionFieldNum(fieldNum: Int): Boolean = fieldNum == NEW_TRANSACTION_FIELD_NUMBER || fieldNum == LEGACY_BYTES_FIELD_NUMBER - @inline def readBytes(fieldNum: Int): Either[Array[Byte], Array[Byte]] = { - val size = coded.readUInt32() - val bytes = coded.readRawBytes(size) - if (fieldNum == NEW_TRANSACTION_FIELD_NUMBER) Right(bytes) else Left(bytes) - } - - val transactionFieldTag = coded.readTag() - val transactionFieldNum = WireFormat.getTagFieldNumber(transactionFieldTag) - val transactionFieldType = WireFormat.getTagWireType(transactionFieldTag) - require(validTransactionFieldNum(transactionFieldNum), "Unknown `transaction` field in transaction data") - require(transactionFieldType == WireFormat.WIRETYPE_LENGTH_DELIMITED, "Can't parse `transaction` field in transaction data") - val bytes = readBytes(WireFormat.getTagFieldNumber(transactionFieldTag)) - - val succeed = - if (coded.isAtEnd) true - else { - val statusFieldTag = coded.readTag() - val statusFieldNum = WireFormat.getTagFieldNumber(statusFieldTag) - val statusFieldType = WireFormat.getTagWireType(statusFieldTag) - require(statusFieldNum == FAILED_FIELD_NUMBER, "Unknown `failed` field in transaction data") - require(statusFieldType == WireFormat.WIRETYPE_VARINT, "Can't parse `failed` field in transaction data") - !coded.readBool() - } - - (succeed, bytes) - } - def loadTransactions(height: Height, db: ReadOnlyDB): Option[Seq[(Transaction, Boolean)]] = if (height < 1 || db.get(Keys.height) < height) None else { diff --git a/node/src/main/scala/com/wavesplatform/features/BlockchainFeature.scala b/node/src/main/scala/com/wavesplatform/features/BlockchainFeature.scala index f8f41952657..98de9469237 100644 --- a/node/src/main/scala/com/wavesplatform/features/BlockchainFeature.scala +++ b/node/src/main/scala/com/wavesplatform/features/BlockchainFeature.scala @@ -21,6 +21,8 @@ object BlockchainFeatures { val BlockV5 = BlockchainFeature(15, "Ride V4, VRF, Protobuf, Failed transactions") val SynchronousCalls = BlockchainFeature(16, "Ride V5, dApp-to-dApp invocations") val RideV6 = BlockchainFeature(17, "Ride V6") + + // Not exposed val ContinuationTransaction = BlockchainFeature(18, "Continuation Transaction") val LeaseExpiration = BlockchainFeature(19, "Lease Expiration") diff --git a/node/src/main/scala/com/wavesplatform/metrics/BlockStats.scala b/node/src/main/scala/com/wavesplatform/metrics/BlockStats.scala index c767bd2fe17..18d1f56435a 100644 --- a/node/src/main/scala/com/wavesplatform/metrics/BlockStats.scala +++ b/node/src/main/scala/com/wavesplatform/metrics/BlockStats.scala @@ -131,7 +131,7 @@ object BlockStats { "3P5dg6PtSAQmdH1qCGKJWu7bkzRG27mny5i", "3PNDoRLsFoPtW1P3nvVHAt7V6hfpyQ8Az9w" ) - whitelistAddrs(b.sender.toAddress.stringRepr) + whitelistAddrs(b.sender.toAddress.toString) } measurement(Type.Block) diff --git a/node/src/main/scala/com/wavesplatform/metrics/TxProcessingStats.scala b/node/src/main/scala/com/wavesplatform/metrics/TxProcessingStats.scala index 003178167ee..f7d203698ad 100644 --- a/node/src/main/scala/com/wavesplatform/metrics/TxProcessingStats.scala +++ b/node/src/main/scala/com/wavesplatform/metrics/TxProcessingStats.scala @@ -1,19 +1,17 @@ package com.wavesplatform.metrics import com.google.common.base.CaseFormat -import com.wavesplatform.settings.Constants +import com.wavesplatform.transaction.{Transaction, TransactionType} import kamon.Kamon import kamon.metric.Metric import supertagged._ object TxProcessingStats { - val typeToName: Map[Byte, String] = { - def timerName(name: String): String = - CaseFormat.UPPER_CAMEL - .converterTo(CaseFormat.LOWER_HYPHEN) - .convert(name.replace("Transaction", "")) - - Constants.TransactionNames.view.mapValues(timerName).toMap + private val typeToName = { + val converter = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_HYPHEN) + TransactionType.values.map { t => + t -> converter.convert(t.toString) + }.toMap } object TxTimer extends TaggedType[Metric.Timer] @@ -21,12 +19,8 @@ object TxProcessingStats { type TxTimer = TxTimer.Type implicit class TxTimerExt(val t: TxTimer) extends AnyVal { - def measureForType[A](typeId: Byte)(f: => A): A = { - val start = t.withTag("transaction-type", typeToName(typeId)).start() - val result = f - start.stop() - result - } + def measureForType[A](tpe: Transaction.Type)(f: => A): A = + t.withTag("transaction-type", typeToName(tpe)).measure(f) } val invokedScriptExecution: TxTimer = TxTimer(Kamon.timer("tx.processing.script-execution.invoked")) diff --git a/node/src/main/scala/com/wavesplatform/mining/Miner.scala b/node/src/main/scala/com/wavesplatform/mining/Miner.scala index fca2c8b81b2..554528d63f7 100644 --- a/node/src/main/scala/com/wavesplatform/mining/Miner.scala +++ b/node/src/main/scala/com/wavesplatform/mining/Miner.scala @@ -2,6 +2,7 @@ package com.wavesplatform.mining import java.time.LocalTime + import cats.syntax.either._ import com.wavesplatform.account.KeyPair import com.wavesplatform.block.Block._ @@ -26,6 +27,7 @@ import kamon.Kamon import monix.eval.Task import monix.execution.cancelables.{CompositeCancelable, SerialCancelable} import monix.execution.schedulers.SchedulerService +import monix.reactive.Observable import scala.concurrent.duration._ @@ -55,7 +57,8 @@ class MinerImpl( wallet: Wallet, pos: PoSSelector, val minerScheduler: SchedulerService, - val appenderScheduler: SchedulerService + val appenderScheduler: SchedulerService, + transactionAdded: Observable[Unit] ) extends Miner with MinerDebugInfo with ScorexLogging { @@ -78,6 +81,7 @@ class MinerImpl( settings.minerSettings, minerScheduler, appenderScheduler, + transactionAdded, utx.priorityPool.nextMicroBlockSize ) @@ -299,7 +303,7 @@ class MinerImpl( val nonScriptedAccounts = wallet.privateKeyAccounts.filterNot(kp => tempBlockchain.getOrElse(blockchainUpdater).hasAccountScript(kp.toAddress)) scheduledAttempts := CompositeCancelable.fromSet(nonScriptedAccounts.map { account => generateBlockTask(account, tempBlockchain) - .onErrorHandle(err => log.warn(s"Error mining Block: $err")) + .onErrorHandle(err => log.warn(s"Error mining Block", err)) .runAsyncLogErr(appenderScheduler) }.toSet) microBlockAttempt := SerialCancelable() diff --git a/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMiner.scala b/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMiner.scala index 88cdcba8705..b57c2f18ba7 100644 --- a/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMiner.scala +++ b/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMiner.scala @@ -10,6 +10,7 @@ import com.wavesplatform.utx.UtxPool import io.netty.channel.group.ChannelGroup import monix.eval.Task import monix.execution.schedulers.SchedulerService +import monix.reactive.Observable trait MicroBlockMiner { def generateMicroBlockSequence( @@ -29,6 +30,7 @@ object MicroBlockMiner { settings: MinerSettings, minerScheduler: SchedulerService, appenderScheduler: SchedulerService, + transactionAdded: Observable[Unit], nextMicroBlockSize: Int => Int = identity ): MicroBlockMiner = new MicroBlockMinerImpl( @@ -39,6 +41,7 @@ object MicroBlockMiner { settings, minerScheduler, appenderScheduler, + transactionAdded, nextMicroBlockSize ) } diff --git a/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMinerImpl.scala b/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMinerImpl.scala index 8557cbe59e6..78deba1cc76 100644 --- a/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMinerImpl.scala +++ b/node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMinerImpl.scala @@ -21,6 +21,7 @@ import io.netty.channel.group.ChannelGroup import kamon.Kamon import monix.eval.Task import monix.execution.schedulers.SchedulerService +import monix.reactive.Observable import scala.concurrent.duration._ @@ -32,6 +33,7 @@ class MicroBlockMinerImpl( settings: MinerSettings, minerScheduler: SchedulerService, appenderScheduler: SchedulerService, + transactionAdded: Observable[Unit], nextMicroBlockSize: Int => Int ) extends MicroBlockMiner with ScorexLogging { @@ -126,8 +128,8 @@ class MicroBlockMinerImpl( log.trace(s"Stopping forging microBlocks, the block is full: $updatedTotalConstraint") Task.now(Stop) } else { - log.trace("UTX is empty, retrying") - Task.now(Retry) + log.trace("UTX is empty, waiting for new transactions") + transactionAdded.headL.map(_ => Retry) } } } diff --git a/node/src/main/scala/com/wavesplatform/network/BasicMessagesRepo.scala b/node/src/main/scala/com/wavesplatform/network/BasicMessagesRepo.scala index 6eddf79d4b5..21dbaccc39e 100644 --- a/node/src/main/scala/com/wavesplatform/network/BasicMessagesRepo.scala +++ b/node/src/main/scala/com/wavesplatform/network/BasicMessagesRepo.scala @@ -3,21 +3,22 @@ package com.wavesplatform.network import java.net.{InetAddress, InetSocketAddress} import java.util +import scala.util.Try + import com.google.common.primitives.{Bytes, Ints} import com.wavesplatform.account.PublicKey import com.wavesplatform.block.{Block, MicroBlock} +import com.wavesplatform.block.serialization.MicroBlockSerializer import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto import com.wavesplatform.crypto._ import com.wavesplatform.mining.Miner.MaxTransactionsPerMicroblock import com.wavesplatform.mining.MiningConstraints -import com.wavesplatform.network.message.Message._ import com.wavesplatform.network.message._ +import com.wavesplatform.network.message.Message._ import com.wavesplatform.protobuf.block.{PBBlock, PBBlocks, PBMicroBlocks, SignedMicroBlock} import com.wavesplatform.protobuf.transaction.{PBSignedTransaction, PBTransactions} -import com.wavesplatform.transaction.{DataTransaction, Transaction, TransactionParsers} - -import scala.util.Try +import com.wavesplatform.transaction.{DataTransaction, EthereumTransaction, Transaction, TransactionParsers} object GetPeersSpec extends MessageSpec[GetPeers.type] { override val messageCode: Message.MessageCode = 1: Byte @@ -209,7 +210,8 @@ object TransactionSpec extends MessageSpec[Transaction] { override def deserializeData(bytes: Array[Byte]): Try[Transaction] = TransactionParsers.parseBytes(bytes) - override def serializeData(tx: Transaction): Array[Byte] = tx.bytes() + override def serializeData(tx: Transaction): Array[Byte] = + tx.bytes().ensuring(!tx.isInstanceOf[EthereumTransaction]) } object MicroBlockInvSpec extends MessageSpec[MicroBlockInv] { @@ -259,8 +261,10 @@ object LegacyMicroBlockResponseSpec extends MessageSpec[MicroBlockResponse] { override def deserializeData(bytes: Array[Byte]): Try[MicroBlockResponse] = MicroBlock.parseBytes(bytes).map(MicroBlockResponse(_)) - override def serializeData(resp: MicroBlockResponse): Array[Byte] = - resp.microblock.bytes() + override def serializeData(resp: MicroBlockResponse): Array[Byte] = { + require(resp.microblock.version < Block.ProtoBlockVersion) + MicroBlockSerializer.toBytes(resp.microblock) + } override val maxLength: Int = 271 + TransactionSpec.maxLength * MaxTransactionsPerMicroblock } @@ -295,10 +299,10 @@ object PBTransactionSpec extends MessageSpec[Transaction] { override val maxLength: Int = 624 + DataTransaction.MaxProtoBytes + 5 + 100 override def deserializeData(bytes: Array[MessageCode]): Try[Transaction] = - PBTransactions.vanilla(PBSignedTransaction.parseFrom(bytes)).left.map(ve => new IllegalArgumentException(ve.toString)).toTry + PBTransactions.tryToVanilla(PBSignedTransaction.parseFrom(bytes)) override def serializeData(data: Transaction): Array[MessageCode] = - PBTransactions.protobuf(data).toByteArray + PBTransactions.toByteArray(data) } // Virtual, only for logs diff --git a/node/src/main/scala/com/wavesplatform/network/LegacyFrameCodec.scala b/node/src/main/scala/com/wavesplatform/network/LegacyFrameCodec.scala index 394538ff0d6..f0693e04459 100644 --- a/node/src/main/scala/com/wavesplatform/network/LegacyFrameCodec.scala +++ b/node/src/main/scala/com/wavesplatform/network/LegacyFrameCodec.scala @@ -17,7 +17,9 @@ import io.netty.handler.codec.{ByteToMessageCodec, DecoderException} import scala.concurrent.duration.FiniteDuration import scala.util.control.NonFatal -class LegacyFrameCodec(peerDatabase: PeerDatabase, receivedTxsCacheTimeout: FiniteDuration) extends ByteToMessageCodec[Any] with ScorexLogging { +class LegacyFrameCodec(peerDatabase: PeerDatabase, receivedTxsCacheTimeout: FiniteDuration, blockV5Activated: () => Boolean) + extends ByteToMessageCodec[Any] + with ScorexLogging { import BasicMessagesRepo.specsByCodes import LegacyFrameCodec._ @@ -73,7 +75,7 @@ class LegacyFrameCodec(peerDatabase: PeerDatabase, receivedTxsCacheTimeout: Fini override def encode(ctx: ChannelHandlerContext, msg1: Any, out: ByteBuf): Unit = { val msg = (msg1: @unchecked) match { case rb: RawBytes => rb - case tx: Transaction => RawBytes.fromTransaction(tx) + case tx: Transaction => RawBytes.fromTransaction(tx, blockV5Activated()) case block: Block => RawBytes.fromBlock(block) case mb: MicroBlockResponse => RawBytes.fromMicroBlock(mb) } diff --git a/node/src/main/scala/com/wavesplatform/network/NetworkServer.scala b/node/src/main/scala/com/wavesplatform/network/NetworkServer.scala index be5aad88bb4..ee4a58067c6 100644 --- a/node/src/main/scala/com/wavesplatform/network/NetworkServer.scala +++ b/node/src/main/scala/com/wavesplatform/network/NetworkServer.scala @@ -44,7 +44,8 @@ object NetworkServer extends ScorexLogging { utxPool: UtxPool, peerDatabase: PeerDatabase, allChannels: ChannelGroup, - peerInfo: ConcurrentHashMap[Channel, PeerInfo] + peerInfo: ConcurrentHashMap[Channel, PeerInfo], + blockV5Activated: () => Boolean ): NS = { @volatile var shutdownInitiated = false @@ -103,7 +104,7 @@ object NetworkServer extends ScorexLogging { def pipelineTail: Seq[ChannelHandlerAdapter] = Seq( lengthFieldPrepender, new LengthFieldBasedFrameDecoder(MaxFrameLength, 0, LengthFieldSize, 0, LengthFieldSize), - new LegacyFrameCodec(peerDatabase, settings.networkSettings.receivedTxsCacheTimeout), + new LegacyFrameCodec(peerDatabase, settings.networkSettings.receivedTxsCacheTimeout, blockV5Activated), channelClosedHandler, trafficWatcher, discardingHandler, diff --git a/node/src/main/scala/com/wavesplatform/network/client/LegacyChannelInitializer.scala b/node/src/main/scala/com/wavesplatform/network/client/LegacyChannelInitializer.scala index 7790ac16239..a2d18a548d9 100644 --- a/node/src/main/scala/com/wavesplatform/network/client/LegacyChannelInitializer.scala +++ b/node/src/main/scala/com/wavesplatform/network/client/LegacyChannelInitializer.scala @@ -54,7 +54,7 @@ class LegacyChannelInitializer(trafficLoggerSettings: TrafficLogger.Settings, ha new ClientHandshakeHandler(handshake, promise), new LengthFieldPrepender(lengthFieldLength), new LengthFieldBasedFrameDecoder(maxFieldLength, 0, lengthFieldLength, 0, lengthFieldLength), - new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes), + new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes, () => false), new TrafficLogger(trafficLoggerSettings) ) } diff --git a/node/src/main/scala/com/wavesplatform/network/messages.scala b/node/src/main/scala/com/wavesplatform/network/messages.scala index 50e19ca11c6..e0a91fdc73c 100644 --- a/node/src/main/scala/com/wavesplatform/network/messages.scala +++ b/node/src/main/scala/com/wavesplatform/network/messages.scala @@ -8,7 +8,7 @@ import com.wavesplatform.block.Block.BlockId import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto -import com.wavesplatform.transaction.{LegacyPBSwitch, ProtobufOnly, Signed, Transaction} +import com.wavesplatform.transaction.{PBSince, Signed, Transaction} import monix.eval.Coeval sealed trait Message @@ -34,16 +34,17 @@ case class RawBytes(code: Byte, data: Array[Byte]) extends Message { override def equals(obj: Any): Boolean = obj match { case o: RawBytes => o.code == code && util.Arrays.equals(o.data, data) - case _ => false + case _ => false } } object RawBytes { - def fromTransaction(tx: Transaction): RawBytes = tx match { - case p: LegacyPBSwitch if p.isProtobufVersion => RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) - case _: ProtobufOnly => RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) - case tx => RawBytes(TransactionSpec.messageCode, TransactionSpec.serializeData(tx)) - } + def fromTransaction(tx: Transaction, forceProtobuf: Boolean): RawBytes = + tx match { + case p: PBSince if p.isProtobufVersion => RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) + case _ if forceProtobuf => RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) + case tx => RawBytes(TransactionSpec.messageCode, TransactionSpec.serializeData(tx)) + } def fromBlock(b: Block): RawBytes = if (b.header.version < Block.ProtoBlockVersion) RawBytes(BlockSpec.messageCode, BlockSpec.serializeData(b)) diff --git a/node/src/main/scala/com/wavesplatform/network/package.scala b/node/src/main/scala/com/wavesplatform/network/package.scala index 4fe669e6855..77ab4bfee68 100644 --- a/node/src/main/scala/com/wavesplatform/network/package.scala +++ b/node/src/main/scala/com/wavesplatform/network/package.scala @@ -8,7 +8,7 @@ import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.transaction.Transaction import com.wavesplatform.utils.ScorexLogging -import io.netty.channel.group.{ChannelGroup, ChannelGroupFuture, ChannelMatcher} +import io.netty.channel.group.{ChannelGroup, ChannelGroupFuture} import io.netty.channel.local.LocalAddress import io.netty.channel.socket.nio.NioSocketChannel import io.netty.channel.{Channel, ChannelHandlerContext} @@ -83,22 +83,6 @@ package object network extends ScorexLogging { } } - def broadcastMany(messages: Seq[AnyRef], except: Set[Channel] = Set.empty): Unit = { - val channelMatcher: ChannelMatcher = { (channel: Channel) => - !except.contains(channel) - } - messages.foreach { message => - logBroadcast(message, except) - allChannels.write(message, channelMatcher) - } - - allChannels.flush(channelMatcher) - } - - def broadcastTx(tx: Transaction, except: Option[Channel] = None): Unit = allChannels.broadcast(RawBytes.fromTransaction(tx), except) - - def broadcastTx(txs: Seq[Transaction]): Unit = allChannels.broadcastMany(txs.map(RawBytes.fromTransaction)) - private def logBroadcast(message: AnyRef, except: Set[Channel]): Unit = message match { case RawBytes(TransactionSpec.messageCode | PBTransactionSpec.messageCode, _) => case _ => diff --git a/node/src/main/scala/com/wavesplatform/protobuf/block/PBBlocks.scala b/node/src/main/scala/com/wavesplatform/protobuf/block/PBBlocks.scala index 74869bdd9e9..b7f21372cb7 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/block/PBBlocks.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/block/PBBlocks.scala @@ -1,5 +1,7 @@ package com.wavesplatform.protobuf.block +import scala.util.Try + import com.google.protobuf.ByteString import com.wavesplatform.account.AddressScheme import com.wavesplatform.block.BlockHeader @@ -7,8 +9,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.protobuf.ByteStringExt import com.wavesplatform.protobuf.block.Block.{Header => PBHeader} import com.wavesplatform.protobuf.transaction.PBTransactions - -import scala.util.Try +import com.wavesplatform.protobuf.transaction.SignedTransaction.Transaction object PBBlocks { def vanilla(header: PBBlock.Header): BlockHeader = @@ -26,10 +27,7 @@ object PBBlocks { def vanilla(block: PBBlock, unsafe: Boolean = false): Try[VanillaBlock] = Try { require(block.header.isDefined, "block header is missing") - val header = block.getHeader - val transactions = block.transactions.map(PBTransactions.vanilla(_, unsafe).explicitGet()) - - VanillaBlock(vanilla(header), block.signature.toByteStr, transactions) + VanillaBlock(vanilla(block.getHeader), block.signature.toByteStr, block.transactions.map(PBTransactions.vanilla(_, unsafe).explicitGet())) } def protobuf(header: BlockHeader): PBHeader = PBBlock.Header( @@ -55,19 +53,24 @@ object PBBlocks { ) } - def clearChainId(block: PBBlock): PBBlock = { + def clearChainId(block: PBBlock): PBBlock = block.update( _.header.chainId := 0, - _.transactions.foreach(_.transaction.chainId := 0) + _.transactions.foreach(_.transaction.modify { + case Transaction.WavesTransaction(value) => Transaction.WavesTransaction(value.update(_.chainId := 0)) + case other => other + }) ) - } def addChainId(block: PBBlock): PBBlock = { val chainId = AddressScheme.current.chainId block.update( _.header.chainId := chainId, - _.transactions.foreach(_.transaction.chainId := chainId) + _.transactions.foreach(_.transaction.modify { + case Transaction.WavesTransaction(value) => Transaction.WavesTransaction(value.update(_.chainId := chainId)) + case other => other + }) ) } } diff --git a/node/src/main/scala/com/wavesplatform/protobuf/block/PBMicroBlocks.scala b/node/src/main/scala/com/wavesplatform/protobuf/block/PBMicroBlocks.scala index fb38ba6c493..4eea0a57236 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/block/PBMicroBlocks.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/block/PBMicroBlocks.scala @@ -1,5 +1,7 @@ package com.wavesplatform.protobuf.block +import scala.util.Try + import com.wavesplatform.account.PublicKey import com.wavesplatform.block.Block.BlockId import com.wavesplatform.common.utils.EitherExt2 @@ -7,8 +9,6 @@ import com.wavesplatform.network.MicroBlockResponse import com.wavesplatform.protobuf._ import com.wavesplatform.protobuf.transaction.PBTransactions -import scala.util.Try - object PBMicroBlocks { def vanilla(signedMicro: PBSignedMicroBlock, unsafe: Boolean = false): Try[MicroBlockResponse] = Try { diff --git a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBOrders.scala b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBOrders.scala index ffac2f35f3f..46ca203ebe3 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBOrders.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBOrders.scala @@ -1,9 +1,10 @@ package com.wavesplatform.protobuf.transaction +import com.wavesplatform.{transaction => vt} import com.wavesplatform.account.{AddressScheme, PublicKey} +import com.wavesplatform.common.state.ByteStr import com.wavesplatform.protobuf._ import com.wavesplatform.protobuf.order.AssetPair -import com.wavesplatform.{transaction => vt} object PBOrders { import com.wavesplatform.protobuf.utils.PBImplicitConversions._ @@ -26,7 +27,8 @@ object PBOrders { order.expiration, order.getMatcherFee.longAmount, PBAmounts.toVanillaAssetId(order.getMatcherFee.assetId), - order.proofs.map(_.toByteStr) + order.proofs.map(_.toByteStr), + Some(order.eip712Signature.toByteStr).filterNot(_.isEmpty) ) } @@ -46,7 +48,8 @@ object PBOrders { order.expiration, Some((order.matcherFeeAssetId, order.matcherFee)), order.version, - order.proofs.map(_.toByteString) + order.proofs.map(_.toByteString), + order.eip712Signature.getOrElse(ByteStr.empty).toByteString ) } } diff --git a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBRecipients.scala b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBRecipients.scala index 6d810db7826..0b830eac510 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBRecipients.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBRecipients.scala @@ -1,16 +1,17 @@ package com.wavesplatform.protobuf.transaction + import com.google.common.primitives.Bytes import com.google.protobuf.ByteString import com.wavesplatform.account._ import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError +import com.wavesplatform.protobuf.transaction.{Recipient => PBRecipient} import com.wavesplatform.transaction.TxValidationError.GenericError object PBRecipients { - def create(addressOrAlias: AddressOrAlias): Recipient = addressOrAlias match { - case a: Address => Recipient().withPublicKeyHash(ByteString.copyFrom(publicKeyHash(a))) - case a: Alias => Recipient().withAlias(a.name) - case _ => sys.error("Should not happen " + addressOrAlias) + def create(recipient: AddressOrAlias): PBRecipient = recipient match { + case a: Address => PBRecipient().withPublicKeyHash(ByteString.copyFrom(publicKeyHash(a))) + case a: Alias => PBRecipient().withAlias(a.name) } def toAddress(bytes: Array[Byte], chainId: Byte): Either[ValidationError, Address] = bytes.length match { @@ -29,17 +30,17 @@ object PBRecipients { Left(GenericError(s"Invalid address length: ${bytes.length}")) } - def toAddress(r: Recipient, chainId: Byte): Either[ValidationError, Address] = r.recipient match { - case Recipient.Recipient.PublicKeyHash(bytes) => toAddress(bytes.toByteArray, chainId) - case _ => Left(GenericError(s"Not an address: $r")) + def toAddress(r: PBRecipient, chainId: Byte): Either[ValidationError, Address] = r.recipient match { + case PBRecipient.Recipient.PublicKeyHash(bytes) => toAddress(bytes.toByteArray, chainId) + case _ => Left(GenericError(s"Not an address: $r")) } - def toAlias(r: Recipient, chainId: Byte): Either[ValidationError, Alias] = r.recipient match { - case Recipient.Recipient.Alias(alias) => Alias.createWithChainId(alias, chainId) - case _ => Left(GenericError(s"Not an alias: $r")) + def toAlias(r: PBRecipient, chainId: Byte): Either[ValidationError, Alias] = r.recipient match { + case PBRecipient.Recipient.Alias(alias) => Alias.createWithChainId(alias, chainId) + case _ => Left(GenericError(s"Not an alias: $r")) } - def toAddressOrAlias(r: Recipient, chainId: Byte): Either[ValidationError, AddressOrAlias] = { + def toAddressOrAlias(r: PBRecipient, chainId: Byte): Either[ValidationError, AddressOrAlias] = { if (r.recipient.isPublicKeyHash) toAddress(r, chainId) else if (r.recipient.isAlias) toAlias(r, chainId) else Left(GenericError(s"Not an address or alias: $r")) diff --git a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBTransactions.scala b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBTransactions.scala index 23a1cbec79d..7c0d9381b1a 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBTransactions.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/transaction/PBTransactions.scala @@ -1,8 +1,12 @@ package com.wavesplatform.protobuf.transaction +import scala.util.Try + import com.google.protobuf.ByteString +import com.wavesplatform.{transaction => vt} import com.wavesplatform.account.{AddressOrAlias, PublicKey} import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.script.ScriptReader import com.wavesplatform.lang.script.v1.ExprScript @@ -10,28 +14,26 @@ import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms.EXPR import com.wavesplatform.protobuf._ import com.wavesplatform.protobuf.transaction.Transaction.Data +import com.wavesplatform.protobuf.utils.PBImplicitConversions._ import com.wavesplatform.serialization.Deser import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, EmptyDataEntry, IntegerDataEntry, StringDataEntry} +import com.wavesplatform.transaction.{EthereumTransaction, Proofs, TxValidationError} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.assets.UpdateAssetInfoTransaction +import com.wavesplatform.transaction.serialization.impl.PBTransactionSerializer import com.wavesplatform.transaction.smart.InvokeExpressionTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.transfer.MassTransferTransaction import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer -import com.wavesplatform.transaction.{Proofs, TxValidationError} import com.wavesplatform.utils.StringBytes -import com.wavesplatform.{transaction => vt} import scalapb.UnknownFieldSet.empty -import scala.util.Try - object PBTransactions { - import com.wavesplatform.protobuf.utils.PBImplicitConversions._ def createGenesis(chainId: Byte, timestamp: Long, signature: ByteStr, data: GenesisTransactionData): SignedTransaction = new SignedTransaction( - Some(Transaction(chainId, timestamp = timestamp, data = Data.Genesis(data))), + SignedTransaction.Transaction.WavesTransaction(Transaction(chainId, timestamp = timestamp, data = Data.Genesis(data))), Seq(ByteString.copyFrom(signature.arr)) ) @@ -46,7 +48,8 @@ object PBTransactions { data: com.wavesplatform.protobuf.transaction.Transaction.Data = com.wavesplatform.protobuf.transaction.Transaction.Data.Empty ): SignedTransaction = new SignedTransaction( - Some(Transaction(chainId, sender.toByteString, Some((feeAssetId, fee): Amount), timestamp, version, data)), + SignedTransaction.Transaction + .WavesTransaction(Transaction(chainId, sender.toByteString, Some((feeAssetId, fee): Amount), timestamp, version, data)), proofsArray.map(bs => ByteString.copyFrom(bs.arr)) ) @@ -56,47 +59,48 @@ object PBTransactions { } def tryToVanilla(signedTx: PBSignedTransaction): Try[VanillaTransaction] = - vanilla(signedTx).left.map(err => new Exception(err.toString)).toTry - - def vanilla(signedTx: PBSignedTransaction, unsafe: Boolean = false): Either[ValidationError, VanillaTransaction] = { - for { - parsedTx <- signedTx.transaction.toRight(GenericError("Transaction must be specified")) - fee = parsedTx.fee.getOrElse(Amount.defaultInstance) - _ <- Either.cond(parsedTx.data.isDefined, (), GenericError("Transaction data must be specified")) - feeAmount = PBAmounts.toAssetAndAmount(fee) - sender = Option(parsedTx.senderPublicKey) - .filterNot(_.isEmpty) - .map(pk => PublicKey(pk.toByteArray)) - .orNull - tx <- if (unsafe) - Right( - createVanillaUnsafe( - parsedTx.version, - parsedTx.chainId.toByte, - sender, - feeAmount._2, - feeAmount._1, - parsedTx.timestamp, - Proofs(signedTx.proofs.map(_.toByteStr)), - parsedTx.data - ) - ) - else + Try(vanilla(signedTx, unsafe = false).explicitGet()) + + def vanilla(signedTx: PBSignedTransaction, unsafe: Boolean): Either[ValidationError, VanillaTransaction] = + signedTx.transaction match { + case SignedTransaction.Transaction.Empty => Left(GenericError("Transaction must be specified")) + case SignedTransaction.Transaction.EthereumTransaction(value) => EthereumTransaction(value.toByteArray) + case SignedTransaction.Transaction.WavesTransaction(parsedTx) => + val (feeAsset, feeAmount) = PBAmounts.toAssetAndAmount(parsedTx.fee.getOrElse(Amount.defaultInstance)) + val sender = Option(parsedTx.senderPublicKey) + .filterNot(_.isEmpty) + .map(pk => PublicKey(pk.toByteArray)) + .orNull for { - proofs <- Proofs.create(signedTx.proofs.map(_.toByteStr)) - tx <- createVanilla( - parsedTx.version, - parsedTx.chainId.toByte, - sender, - feeAmount._2, - feeAmount._1, - parsedTx.timestamp, - proofs, - parsedTx.data - ) + tx <- if (unsafe) + Right( + createVanillaUnsafe( + parsedTx.version, + parsedTx.chainId.toByte, + sender, + feeAmount, + feeAsset, + parsedTx.timestamp, + Proofs(signedTx.proofs.map(_.toByteStr)), + parsedTx.data + ) + ) + else + for { + proofs <- Proofs.create(signedTx.proofs.map(_.toByteStr)) + tx <- createVanilla( + parsedTx.version, + parsedTx.chainId.toByte, + sender, + feeAmount, + feeAsset, + parsedTx.timestamp, + proofs, + parsedTx.data + ) + } yield tx } yield tx - } yield tx - } + } private[this] def createVanilla( version: Int, @@ -257,13 +261,12 @@ object PBTransactions { import cats.instances.option._ import cats.syntax.traverse._ import com.wavesplatform.lang.v1.Serde - import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL for { dApp <- PBRecipients.toAddressOrAlias(dappAddress, chainId) fcOpt <- Deser - .parseOption(functionCall.asReadOnlyByteBuffer())(Serde.deserialize) + .parseOption(functionCall.asReadOnlyByteBuffer())(Serde.deserializeFunctionCall) .sequence .left .map(e => GenericError(s"Invalid InvokeScript function call: $e")) @@ -277,12 +280,13 @@ object PBTransactions { version.toByte, sender, dApp, - fcOpt.map(_.asInstanceOf[FUNCTION_CALL]), + fcOpt, payments.map(p => vt.smart.InvokeScriptTransaction.Payment(p.longAmount, PBAmounts.toVanillaAssetId(p.assetId))), feeAmount, feeAssetId, timestamp, - proofs + proofs, + chainId ) } yield tx @@ -495,15 +499,14 @@ object PBTransactions { case Data.InvokeScript(InvokeScriptTransactionData(Some(dappAddress), functionCall, payments, `empty`)) => import com.wavesplatform.lang.v1.Serde - import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL vt.smart.InvokeScriptTransaction( version.toByte, sender, PBRecipients.toAddressOrAlias(dappAddress, chainId).explicitGet(), Deser - .parseOption(functionCall.asReadOnlyByteBuffer())(Serde.deserialize) - .map(_.explicitGet().asInstanceOf[FUNCTION_CALL]), + .parseOption(functionCall.asReadOnlyByteBuffer())(Serde.deserializeFunctionCall) + .map(_.explicitGet()), payments.map(p => vt.smart.InvokeScriptTransaction.Payment(p.longAmount, PBAmounts.toVanillaAssetId(p.assetId))), feeAmount, feeAssetId, @@ -559,13 +562,13 @@ object PBTransactions { case tx: vt.transfer.TransferTransaction => import tx._ - val data = TransferTransactionData(Some(recipient), Some((assetId, amount)), attachment.toByteString) + val data = TransferTransactionData(Some(recipient.toPB), Some((assetId, amount)), attachment.toByteString) PBTransactions.create(sender, chainId, fee, feeAssetId, timestamp, version, proofs, Data.Transfer(data)) case tx: vt.CreateAliasTransaction => import tx._ val data = CreateAliasTransactionData(alias.name) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.CreateAlias(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.CreateAlias(data)) case tx: vt.assets.exchange.ExchangeTransaction => import tx._ @@ -576,56 +579,56 @@ object PBTransactions { sellMatcherFee, Seq(PBOrders.protobuf(order1), PBOrders.protobuf(order2)) ) - PBTransactions.create(tx.sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.Exchange(data)) + PBTransactions.create(tx.sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.Exchange(data)) case tx: vt.assets.IssueTransaction => import tx._ val data = IssueTransactionData(name.toStringUtf8, description.toStringUtf8, quantity, decimals, reissuable, toPBScript(script)) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.Issue(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.Issue(data)) case tx: vt.assets.ReissueTransaction => import tx._ val data = ReissueTransactionData(Some(Amount(asset.id.toByteString, quantity)), reissuable) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.Reissue(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.Reissue(data)) case tx: vt.assets.BurnTransaction => import tx._ val data = BurnTransactionData(Some(Amount(asset.id.toByteString, quantity))) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.Burn(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.Burn(data)) case tx @ vt.assets.SetAssetScriptTransaction(_, sender, assetId, script, fee, timestamp, proofs, chainId) => val data = SetAssetScriptTransactionData(assetId.id.toByteString, toPBScript(script)) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, tx.version, proofs, Data.SetAssetScript(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, tx.version, proofs, Data.SetAssetScript(data)) case tx @ vt.smart.SetScriptTransaction(_, sender, script, fee, timestamp, proofs, chainId) => val data = SetScriptTransactionData(toPBScript(script)) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, tx.version, proofs, Data.SetScript(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, tx.version, proofs, Data.SetScript(data)) case tx: vt.lease.LeaseTransaction => import tx._ - val data = LeaseTransactionData(Some(recipient), amount) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.Lease(data)) + val data = LeaseTransactionData(Some(recipient.toPB), amount) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.Lease(data)) case tx: vt.lease.LeaseCancelTransaction => import tx._ val data = LeaseCancelTransactionData(leaseId.toByteString) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.LeaseCancel(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.LeaseCancel(data)) case tx @ MassTransferTransaction(version, sender, assetId, transfers, fee, timestamp, attachment, proofs, chainId) => val data = MassTransferTransactionData( PBAmounts.toPBAssetId(assetId), - transfers.map(pt => MassTransferTransactionData.Transfer(Some(pt.address), pt.amount)), + transfers.map(pt => MassTransferTransactionData.Transfer(Some(pt.address.toPB), pt.amount)), attachment.toByteString ) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.MassTransfer(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.MassTransfer(data)) case tx @ vt.DataTransaction(version, sender, data, fee, timestamp, proofs, chainId) => val txData = DataTransactionData(data.map(toPBDataEntry)) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.DataTransaction(txData)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.DataTransaction(txData)) case tx @ vt.assets.SponsorFeeTransaction(version, sender, assetId, minSponsoredAssetFee, fee, timestamp, proofs, chainId) => val data = SponsorFeeTransactionData(Some(Amount(assetId.id.toByteString, minSponsoredAssetFee.getOrElse(0L)))) - PBTransactions.create(sender, chainId, fee, tx.assetFee._1, timestamp, version, proofs, Data.SponsorFee(data)) + PBTransactions.create(sender, chainId, fee, tx.feeAssetId, timestamp, version, proofs, Data.SponsorFee(data)) case vt.smart.InvokeScriptTransaction(version, sender, dappAddress, fcOpt, payment, fee, feeAssetId, timestamp, proofs, chainId) => val data = Data.InvokeScript(toPBInvokeScriptData(dappAddress, fcOpt, payment)) @@ -645,6 +648,9 @@ object PBTransactions { val data = Data.InvokeExpression(InvokeExpressionTransactionData(tx.expressionBytes.toByteString)) PBTransactions.create(sender, chainId, fee, feeAssetId, timestamp, version, proofs, data) + case et: EthereumTransaction => + PBSignedTransaction(PBSignedTransaction.Transaction.EthereumTransaction(ByteString.copyFrom(et.bytes()))) + case _ => throw new IllegalArgumentException(s"Unsupported transaction: $tx") } @@ -694,4 +700,13 @@ object PBTransactions { case Some(sc) => ByteString.copyFrom(sc.bytes().arr) case None => ByteString.EMPTY } + + // Stores Ethereum txs as-is + def toByteArrayMerkle(tx: VanillaTransaction): Array[Byte] = tx match { + case et: EthereumTransaction => et.bytes() + case vt => toByteArray(vt) + } + + def toByteArray(tx: VanillaTransaction): Array[Byte] = + PBTransactionSerializer.bytes(tx) } diff --git a/node/src/main/scala/com/wavesplatform/protobuf/transaction/transaction.scala b/node/src/main/scala/com/wavesplatform/protobuf/transaction/transaction.scala index 749634d65ee..06ad7145074 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/transaction/transaction.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/transaction/transaction.scala @@ -16,7 +16,5 @@ package object transaction { type VanillaTransaction = com.wavesplatform.transaction.Transaction val VanillaTransaction = com.wavesplatform.transaction.Transaction - type VanillaSignedTransaction = com.wavesplatform.transaction.SignedTransaction - type VanillaAssetId = com.wavesplatform.transaction.Asset } diff --git a/node/src/main/scala/com/wavesplatform/protobuf/utils/PBImplicitConversions.scala b/node/src/main/scala/com/wavesplatform/protobuf/utils/PBImplicitConversions.scala index 119387080ad..7e03564229d 100644 --- a/node/src/main/scala/com/wavesplatform/protobuf/utils/PBImplicitConversions.scala +++ b/node/src/main/scala/com/wavesplatform/protobuf/utils/PBImplicitConversions.scala @@ -8,15 +8,20 @@ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} object PBImplicitConversions { import com.google.protobuf.{ByteString => PBByteString} - import com.wavesplatform.account.{AddressOrAlias, Address => VAddress, Alias => VAlias} + import com.wavesplatform.{account => va} - implicit def fromAddressOrAlias(addressOrAlias: AddressOrAlias): Recipient = PBRecipients.create(addressOrAlias) - implicit def fromAddress(address: VAddress): PBByteString = PBByteString.copyFrom(address.bytes) + implicit class AddressOrAliasToPBExt(val r: va.AddressOrAlias) extends AnyVal { + def toPB: Recipient = r match { + case va.Alias(_, name) => Recipient.of(Recipient.Recipient.Alias(name)) + case w: va.Address => Recipient.of(Recipient.Recipient.PublicKeyHash(PBByteString.copyFrom(w.publicKeyHash))) + + } + } implicit class PBRecipientImplicitConversionOps(val recipient: Recipient) extends AnyVal { - def toAddress(chainId: Byte): Either[ValidationError, VAddress] = PBRecipients.toAddress(recipient, chainId) - def toAlias(chainId: Byte): Either[ValidationError, VAlias] = PBRecipients.toAlias(recipient, chainId) - def toAddressOrAlias(chainId: Byte): Either[ValidationError, AddressOrAlias] = PBRecipients.toAddressOrAlias(recipient, chainId) + def toAddress(chainId: Byte): Either[ValidationError, va.Address] = PBRecipients.toAddress(recipient, chainId) + def toAlias(chainId: Byte): Either[ValidationError, va.Alias] = PBRecipients.toAlias(recipient, chainId) + def toAddressOrAlias(chainId: Byte): Either[ValidationError, va.AddressOrAlias] = PBRecipients.toAddressOrAlias(recipient, chainId) } implicit def fromAssetIdAndAmount(v: (VanillaAssetId, Long)): Amount = v match { diff --git a/node/src/main/scala/com/wavesplatform/serialization/package.scala b/node/src/main/scala/com/wavesplatform/serialization/package.scala index e5acbd0436a..69cee906e5b 100644 --- a/node/src/main/scala/com/wavesplatform/serialization/package.scala +++ b/node/src/main/scala/com/wavesplatform/serialization/package.scala @@ -3,14 +3,14 @@ package com.wavesplatform import java.nio.ByteBuffer import com.google.common.primitives.Shorts -import com.wavesplatform.account.{Address, AddressOrAlias, Alias, PublicKey} +import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ import com.wavesplatform.crypto.{KeyLength, SignatureLength} import com.wavesplatform.lang.script.{Script, ScriptReader} +import com.wavesplatform.transaction.{Asset, Proofs} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.assets.exchange.Order -import com.wavesplatform.transaction.{Asset, Proofs} package object serialization { implicit class ByteBufferOps(private val buf: ByteBuffer) extends AnyVal { diff --git a/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala b/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala index 0b9c198cebf..b278442914b 100644 --- a/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala +++ b/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala @@ -59,12 +59,12 @@ object RewardsSettings { } case class FunctionalitySettings( - featureCheckBlocksPeriod: Int, - blocksForFeatureActivation: Int, + featureCheckBlocksPeriod: Int = 1000, + blocksForFeatureActivation: Int = 800, generationBalanceDepthFrom50To1000AfterHeight: Int = 0, blockVersion3AfterHeight: Int = 0, preActivatedFeatures: Map[Short, Int] = Map.empty, - doubleFeaturesPeriodsAfterHeight: Int, + doubleFeaturesPeriodsAfterHeight: Int = Int.MaxValue, maxTransactionTimeBackOffset: FiniteDuration = 120.minutes, maxTransactionTimeForwardOffset: FiniteDuration = 90.minutes, lastTimeBasedForkParameter: Long = 0L, diff --git a/node/src/main/scala/com/wavesplatform/state/Blockchain.scala b/node/src/main/scala/com/wavesplatform/state/Blockchain.scala index 8d0fba04749..c25f8c9a57b 100644 --- a/node/src/main/scala/com/wavesplatform/state/Blockchain.scala +++ b/node/src/main/scala/com/wavesplatform/state/Blockchain.scala @@ -1,12 +1,13 @@ package com.wavesplatform.state -import com.wavesplatform.account.{Address, AddressOrAlias, Alias} -import com.wavesplatform.block.Block.{BlockId, GenesisBlockVersion, NgBlockVersion, PlainBlockVersion, ProtoBlockVersion, RewardBlockVersion} +import com.wavesplatform.account._ +import com.wavesplatform.block.Block._ import com.wavesplatform.block.{Block, BlockHeader, SignedBlockHeader} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.consensus.GeneratingBalanceProvider import com.wavesplatform.features.{BlockchainFeature, BlockchainFeatureStatus, BlockchainFeatures} import com.wavesplatform.lang.ValidationError +import com.wavesplatform.lang.script.ContractScript import com.wavesplatform.lang.v1.ContractLimits import com.wavesplatform.lang.v1.traits.domain.Issue import com.wavesplatform.settings.BlockchainSettings @@ -14,8 +15,8 @@ import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.AliasDoesNotExist import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, Transaction} +import com.wavesplatform.transaction.transfer.TransferTransactionLike +import com.wavesplatform.transaction.{Asset, ERC20Address, Transaction} trait Blockchain { def settings: BlockchainSettings @@ -41,7 +42,7 @@ trait Blockchain { def wavesAmount(height: Int): BigInt - def transferById(id: ByteStr): Option[(Int, TransferTransaction)] + def transferById(id: ByteStr): Option[(Int, TransferTransactionLike)] def transactionInfo(id: ByteStr): Option[(Int, Transaction, Boolean)] def transactionMeta(id: ByteStr): Option[(Int, Boolean)] @@ -71,6 +72,8 @@ trait Blockchain { def leaseBalance(address: Address): LeaseBalance def balance(address: Address, mayBeAssetId: Asset = Waves): Long + + def resolveERC20Address(address: ERC20Address): Option[IssuedAsset] } object Blockchain { @@ -180,13 +183,20 @@ object Blockchain { if (isFeatureActivated(BlockchainFeatures.BlockV5, height)) ProtoBlockVersion else if (isFeatureActivated(BlockchainFeatures.BlockReward, height)) { if (blockchain.activatedFeatures(BlockchainFeatures.BlockReward.id) == height) NgBlockVersion else RewardBlockVersion - } - else if (blockchain.settings.functionalitySettings.blockVersion3AfterHeight + 1 < height) NgBlockVersion + } else if (blockchain.settings.functionalitySettings.blockVersion3AfterHeight + 1 < height) NgBlockVersion else if (height > 1) PlainBlockVersion else GenesisBlockVersion def binaryData(address: Address, key: String): Option[ByteStr] = blockchain.accountData(address, key).collect { case BinaryDataEntry(_, value) => value } + + def hasDApp(address: Address): Boolean = + blockchain.hasAccountScript(address) && blockchain + .accountScript(address) + .exists(_.script match { + case _: ContractScript.ContractScriptImpl => true + case _ => false + }) } } diff --git a/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala b/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala index b103c8f3a72..df5b5232f52 100644 --- a/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala +++ b/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala @@ -24,7 +24,7 @@ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.{BlockAppendError, GenericError, MicroBlockAppendError} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.lease._ -import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.transfer.TransferTransactionLike import com.wavesplatform.utils.{ScorexLogging, Time, UnsupportedFeature, forceStopApplication} import kamon.Kamon import monix.reactive.subjects.ReplaySubject @@ -642,7 +642,7 @@ class BlockchainUpdaterImpl( } else leveldb.blockHeader(height) } - override def transferById(id: BlockId): Option[(Int, TransferTransaction)] = readLock { + override def transferById(id: BlockId): Option[(Int, TransferTransactionLike)] = readLock { compositeBlockchain.transferById(id) } @@ -720,6 +720,10 @@ class BlockchainUpdaterImpl( } } + override def resolveERC20Address(address: ERC20Address): Option[IssuedAsset] = readLock { + compositeBlockchain.resolveERC20Address(address) + } + private[this] def compositeBlockchain = ngState.fold(leveldb: Blockchain)(CompositeBlockchain(leveldb, _)) diff --git a/node/src/main/scala/com/wavesplatform/state/Diff.scala b/node/src/main/scala/com/wavesplatform/state/Diff.scala index 3a071447681..802577c0fd9 100755 --- a/node/src/main/scala/com/wavesplatform/state/Diff.scala +++ b/node/src/main/scala/com/wavesplatform/state/Diff.scala @@ -7,6 +7,7 @@ import cats.syntax.semigroup._ import com.google.protobuf.ByteString import com.wavesplatform.account.{Address, AddressOrAlias, Alias, PublicKey} import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.database.protobuf.EthereumTransactionMeta import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.script.Script import com.wavesplatform.state.diffs.FeeValidation @@ -157,7 +158,8 @@ case class Diff( sponsorship: Map[IssuedAsset, Sponsorship] = Map.empty, scriptsRun: Int = 0, scriptsComplexity: Long = 0, - scriptResults: Map[ByteStr, InvokeScriptResult] = Map.empty + scriptResults: Map[ByteStr, InvokeScriptResult] = Map.empty, + ethereumTransactionMeta: Map[ByteStr, EthereumTransactionMeta] = Map.empty ) object Diff { @@ -169,19 +171,20 @@ object Diff { override def combine(older: Diff, newer: Diff): Diff = Diff( transactions = older.transactions ++ newer.transactions, - portfolios = older.portfolios.combine(newer.portfolios), + portfolios = older.portfolios |+| newer.portfolios, issuedAssets = older.issuedAssets ++ newer.issuedAssets, updatedAssets = older.updatedAssets |+| newer.updatedAssets, aliases = older.aliases ++ newer.aliases, - orderFills = older.orderFills.combine(newer.orderFills), + orderFills = older.orderFills |+| newer.orderFills, leaseState = older.leaseState ++ newer.leaseState, scripts = older.scripts ++ newer.scripts, assetScripts = older.assetScripts ++ newer.assetScripts, - accountData = older.accountData.combine(newer.accountData), - sponsorship = older.sponsorship.combine(newer.sponsorship), + accountData = older.accountData |+| newer.accountData, + sponsorship = older.sponsorship |+| newer.sponsorship, scriptsRun = older.scriptsRun + newer.scriptsRun, - scriptResults = older.scriptResults.combine(newer.scriptResults), - scriptsComplexity = older.scriptsComplexity + newer.scriptsComplexity + scriptResults = older.scriptResults |+| newer.scriptResults, + scriptsComplexity = older.scriptsComplexity + newer.scriptsComplexity, + ethereumTransactionMeta = older.ethereumTransactionMeta ++ newer.ethereumTransactionMeta ) } diff --git a/node/src/main/scala/com/wavesplatform/state/InvokeScriptResult.scala b/node/src/main/scala/com/wavesplatform/state/InvokeScriptResult.scala index 01cb8f5c720..8da8dcf9125 100644 --- a/node/src/main/scala/com/wavesplatform/state/InvokeScriptResult.scala +++ b/node/src/main/scala/com/wavesplatform/state/InvokeScriptResult.scala @@ -79,7 +79,7 @@ object InvokeScriptResult { object Lease { implicit val recipientWrites = Writes[AddressOrAlias] { case address: Address => implicitly[Writes[Address]].writes(address) - case alias: Alias => JsString(alias.stringRepr) + case alias: Alias => JsString(alias.toString) case _ => JsNull } implicit val jsonWrites = Json.writes[Lease] @@ -110,7 +110,7 @@ object InvokeScriptResult { implicit val errorMessageFormat = Json.writes[ErrorMessage] implicit val invocationFormat: Writes[Invocation] = (i: Invocation) => Json.obj( - "dApp" -> i.dApp, + "dApp" -> i.dApp.toString, "call" -> i.call, "payment" -> i.payments, "stateChanges" -> jsonFormat.writes(i.stateChanges) @@ -184,7 +184,7 @@ object InvokeScriptResult { case ScriptResultV3(ds, ts, _) => InvokeScriptResult(data = ds.map(DataEntry.fromLangDataOp), transfers = ts.map(langTransferToPayment)) - case ScriptResultV4(actions, _, ret) => + case ScriptResultV4(actions, _, _) => // XXX need return value processing val issues = actions.collect { case i: lang.Issue => i } val reissues = actions.collect { case ri: lang.Reissue => ri } @@ -199,13 +199,13 @@ object InvokeScriptResult { Invocation( langAddressToAddress(dApp), Call(fname, args), - (payments.map { + payments.map { case CaseObj(_, fields) => ((fields("assetId"), fields("amount")): @unchecked) match { case (CONST_BYTESTR(b), CONST_LONG(a)) => InvokeScriptResult.AttachedPayment(IssuedAsset(b), a) case (_, CONST_LONG(a)) => InvokeScriptResult.AttachedPayment(Waves, a) } - }), + }, fromLangResult(invokeId, r) ) } diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/AssetTransactionsDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/AssetTransactionsDiff.scala index 2ce4ee73cc0..cfd06e863ad 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/AssetTransactionsDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/AssetTransactionsDiff.scala @@ -10,14 +10,14 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.v1.traits.domain.{Burn, Reissue, SponsorFee} import com.wavesplatform.state._ -import com.wavesplatform.transaction.Asset +import com.wavesplatform.transaction.{Asset, ERC20Address} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.assets._ import com.wavesplatform.utils.ScorexLogging object AssetTransactionsDiff extends ScorexLogging { - def issue(blockchain: Blockchain)(tx: IssueTransaction): Either[ValidationError, Diff] = { + def issue(blockchain: Blockchain)(tx: IssueTransaction): Either[ValidationError, Diff] = { // TODO: unify with InvokeScript action diff? def requireValidUtf(): Boolean = { def isValid(str: ByteString): Boolean = { val convertible = ByteString.copyFromUtf8(str.toStringUtf8) == str @@ -28,6 +28,9 @@ object AssetTransactionsDiff extends ScorexLogging { !activated || (isValid(tx.name) && isValid(tx.description)) } + // First 20 bytes of id should be unique + def requireUnique(): Boolean = blockchain.resolveERC20Address(ERC20Address(tx.asset)).isEmpty + val staticInfo = AssetStaticInfo(TransactionId @@ tx.id(), tx.sender, tx.decimals, blockchain.isNFT(tx)) val volumeInfo = AssetVolumeInfo(tx.reissuable, BigInt(tx.quantity)) val info = AssetInfo(tx.name, tx.description, Height @@ blockchain.height) @@ -36,6 +39,7 @@ object AssetTransactionsDiff extends ScorexLogging { for { _ <- Either.cond(requireValidUtf(), (), GenericError("Valid UTF-8 strings required")) + _ <- Either.cond(requireUnique(), (), GenericError(s"Asset ${tx.asset} is already issued")) result <- DiffsCommon .countVerifierComplexity(tx.script, blockchain, isAsset = true) .map( diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala b/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala index d6c53ba9275..30d2e905972 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala @@ -75,12 +75,12 @@ object BlockDiffer extends ScorexLogging { for { _ <- TracedResult(Either.cond(!verify || block.signatureValid(), (), GenericError(s"Block $block has invalid signature"))) - r <- apply( + r <- generateDiff( CompositeBlockchain(blockchain, Diff.empty, block, hitSource, 0, None), constraint, maybePrevBlock.map(_.header.timestamp), Diff.empty.copy(portfolios = Map(block.sender.toAddress -> (minerReward |+| initialFeeFromThisBlock |+| feeFromPreviousBlock))), - stateHeight >= ngHeight, + hasNg = stateHeight >= ngHeight, block.transactionData, verify ) @@ -113,12 +113,12 @@ object BlockDiffer extends ScorexLogging { ) ) _ <- TracedResult(micro.signaturesValid()) - r <- apply( + r <- generateDiff( blockchain, constraint, prevBlockTimestamp, Diff.empty, - true, + hasNg = true, micro.transactionData, verify ) @@ -132,7 +132,7 @@ object BlockDiffer extends ScorexLogging { case _ => transactionFee } - private[this] def apply( + private[this] def generateDiff( blockchain: Blockchain, initConstraint: MiningConstraint, prevBlockTimestamp: Option[Long], diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/CommonValidation.scala b/node/src/main/scala/com/wavesplatform/state/diffs/CommonValidation.scala index dad89dc0643..fc3fd9f00c7 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/CommonValidation.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/CommonValidation.scala @@ -91,13 +91,13 @@ object CommonValidation { identity for { - address <- blockchain.resolveAlias(citx.dAppAddressOrAlias) + address <- blockchain.resolveAlias(citx.dApp) allowFeeOverdraft = blockchain.accountScript(address) match { case Some(AccountScriptInfo(_, ContractScriptImpl(version, _), _, _)) if version >= V4 && blockchain.useCorrectPaymentCheck => true case _ => false } check <- foldPayments(citx.payments) - .map(p => checkTransfer(citx.sender.toAddress, p.assetId, p.amount, citx.feeAssetId, citx.fee, allowFeeOverdraft)) + .map(p => checkTransfer(citx.senderAddress, p.assetId, p.amount, citx.feeAssetId, citx.fee, allowFeeOverdraft)) .find(_.isLeft) .getOrElse(Right(tx)) } yield check @@ -160,11 +160,11 @@ object CommonValidation { } val versionsBarrier = tx match { - case p: LegacyPBSwitch if p.isProtobufVersion => + case p: PBSince if p.isProtobufVersion => activationBarrier(BlockchainFeatures.BlockV5) - case v: VersionedTransaction if !v.builder.supportedVersions.contains(v.version) => - Left(GenericError(s"Invalid tx version: $v")) + case v: VersionedTransaction if !TransactionParsers.all.contains((v.tpe.id.toByte, v.version)) => + Left(UnsupportedTypeAndVersion(v.tpe.id.toByte, v.version)) case _ => Right(tx) @@ -216,8 +216,12 @@ object CommonValidation { case _: SponsorFeeTransaction => activationBarrier(BlockchainFeatures.FeeSponsorship) case _: InvokeScriptTransaction => activationBarrier(BlockchainFeatures.Ride4DApps) - case _: UpdateAssetInfoTransaction => activationBarrier(BlockchainFeatures.BlockV5) - case _: InvokeExpressionTransaction => activationBarrier(BlockchainFeatures.RideV6) + case _: UpdateAssetInfoTransaction => activationBarrier(BlockchainFeatures.BlockV5) + case iet: InvokeExpressionTransaction => + if (iet.version == 1) activationBarrier(BlockchainFeatures.RideV6) + else Left(TxValidationError.ActivationError(s"Transaction version ${iet.version} has not been activated yet")) + + case _: EthereumTransaction => activationBarrier(BlockchainFeatures.RideV6) case _ => Left(GenericError("Unknown transaction must be explicitly activated")) } diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/DiffsCommon.scala b/node/src/main/scala/com/wavesplatform/state/diffs/DiffsCommon.scala index adfc8c1754a..a7a3b4f55cd 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/DiffsCommon.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/DiffsCommon.scala @@ -20,12 +20,12 @@ import com.wavesplatform.lang.v1.traits.domain._ import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.state.{AssetVolumeInfo, Blockchain, Diff, LeaseBalance, Portfolio, SponsorshipValue} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.ProvenTransaction import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.transaction.{Authorized, Transaction} object DiffsCommon { - def countScriptRuns(blockchain: Blockchain, tx: ProvenTransaction): Int = - tx.checkedAssets.count(blockchain.hasAssetScript) + Some(tx.sender.toAddress).count(blockchain.hasAccountScript) + def countScriptRuns(blockchain: Blockchain, tx: Transaction with Authorized): Int = + tx.smartAssets(blockchain).size + Some(tx.sender.toAddress).count(blockchain.hasAccountScript) def countVerifierComplexity( script: Option[Script], @@ -198,7 +198,7 @@ object DiffsCommon { s"time=$time > allowMultipleLeaseCancelTransactionUntilTimestamp=$allowedTs" ) ) - senderPortfolio = Map(sender.toAddress -> Portfolio(-fee, LeaseBalance(0, -lease.amount))) + senderPortfolio = Map[Address, Portfolio](sender.toAddress -> Portfolio(-fee, LeaseBalance(0, -lease.amount))) recipientPortfolio = Map(recipient -> Portfolio(0, LeaseBalance(-lease.amount, 0))) actionInfo = lease.copy(status = LeaseDetails.Status.Cancelled(blockchain.height, Some(cancelTxId))) } yield Diff( diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/EthereumTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/EthereumTransactionDiff.scala new file mode 100644 index 00000000000..c037594baa9 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/state/diffs/EthereumTransactionDiff.scala @@ -0,0 +1,56 @@ +package com.wavesplatform.state.diffs + +import cats.syntax.semigroup._ +import com.google.protobuf.ByteString +import com.wavesplatform.database.protobuf.EthereumTransactionMeta +import com.wavesplatform.lang.ValidationError +import com.wavesplatform.lang.v1.Serde +import com.wavesplatform.protobuf.transaction.{PBAmounts, PBRecipients} +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionDiff +import com.wavesplatform.state.{Blockchain, Diff} +import com.wavesplatform.transaction.EthereumTransaction +import com.wavesplatform.transaction.smart.script.trace.TracedResult + +object EthereumTransactionDiff { + def apply(blockchain: Blockchain, currentBlockTs: Long)(e: EthereumTransaction): TracedResult[ValidationError, Diff] = + e.payload match { + case et: EthereumTransaction.Transfer => + for { + asset <- TracedResult(et.tryResolveAsset(blockchain)) + transfer <- TracedResult(et.toTransferLike(e, blockchain)) + assetDiff <- TransactionDiffer.assetsVerifierDiff(blockchain, transfer, verify = true, Diff(), Int.MaxValue) + diff <- TransferDiff(blockchain)(e.senderAddress(), et.recipient, et.amount, asset, e.fee, e.feeAssetId) + } yield + assetDiff |+| diff.copy( + ethereumTransactionMeta = Map( + e.id() -> EthereumTransactionMeta( + EthereumTransactionMeta.Payload.Transfer( + EthereumTransactionMeta.Transfer( + ByteString.copyFrom(PBRecipients.publicKeyHash(et.recipient)), + Some(PBAmounts.fromAssetAndAmount(asset, et.amount)) + ) + ) + ) + ) + ) + + case ei: EthereumTransaction.Invocation => + for { + invocation <- TracedResult(ei.toInvokeScriptLike(e, blockchain)) + paymentsDiff <- TransactionDiffer.assetsVerifierDiff(blockchain, invocation, verify = true, Diff(), Int.MaxValue) + diff <- InvokeScriptTransactionDiff(blockchain, currentBlockTs, limitedExecution = true)(invocation) + } yield + paymentsDiff |+| diff.copy( + ethereumTransactionMeta = Map( + e.id() -> EthereumTransactionMeta( + EthereumTransactionMeta.Payload.Invocation( + EthereumTransactionMeta.Invocation( + ByteString.copyFrom(Serde.serialize(invocation.funcCall)), + invocation.payments.map(p => PBAmounts.fromAssetAndAmount(p.assetId, p.amount)) + ) + ) + ) + ) + ) + } +} diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiff.scala index 9f1c85319d6..f54f5033971 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiff.scala @@ -1,5 +1,7 @@ package com.wavesplatform.state.diffs +import scala.util.{Right, Try} + import cats.instances.map._ import cats.kernel.Monoid import cats.syntax.either._ @@ -7,19 +9,17 @@ import com.wavesplatform.account.Address import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.ValidationError import com.wavesplatform.state._ +import com.wavesplatform.transaction.{Asset, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.{GenericError, OrderValidationError} import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order, OrderType} -import com.wavesplatform.transaction.{Asset, TxVersion} - -import scala.util.{Right, Try} object ExchangeTransactionDiff { def apply(blockchain: Blockchain)(tx: ExchangeTransaction): Either[ValidationError, Diff] = { val matcher = tx.buyOrder.matcherPublicKey.toAddress - val buyer = tx.buyOrder.senderPublicKey.toAddress - val seller = tx.sellOrder.senderPublicKey.toAddress + val buyer = tx.buyOrder.senderAddress + val seller = tx.sellOrder.senderAddress val assetIds = List(tx.buyOrder.assetPair.amountAsset, tx.buyOrder.assetPair.priceAsset, tx.sellOrder.assetPair.amountAsset, tx.sellOrder.assetPair.priceAsset).collect { @@ -109,9 +109,9 @@ object ExchangeTransactionDiff { val feeDiff = Monoid.combineAll( Seq( - Map(matcher -> matcherPortfolio), - Map(buyer -> getOrderFeePortfolio(tx.buyOrder, -tx.buyMatcherFee)), - Map(seller -> getOrderFeePortfolio(tx.sellOrder, -tx.sellMatcherFee)) + Map[Address, Portfolio](matcher -> matcherPortfolio), + Map[Address, Portfolio](buyer -> getOrderFeePortfolio(tx.buyOrder, -tx.buyMatcherFee)), + Map[Address, Portfolio](seller -> getOrderFeePortfolio(tx.sellOrder, -tx.sellMatcherFee)) ) ) diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/FeeValidation.scala b/node/src/main/scala/com/wavesplatform/state/diffs/FeeValidation.scala index 07be4f75f2e..3fb08b3faa4 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/FeeValidation.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/FeeValidation.scala @@ -4,14 +4,12 @@ import cats.data.Chain import cats.syntax.foldable._ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.ValidationError -import com.wavesplatform.settings.Constants import com.wavesplatform.state._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError._ import com.wavesplatform.transaction._ import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange._ -import com.wavesplatform.transaction.lease._ import com.wavesplatform.transaction.smart._ import com.wavesplatform.transaction.smart.script.trace.TracedResult.Attribute import com.wavesplatform.transaction.transfer._ @@ -25,25 +23,26 @@ object FeeValidation { val NFTMultiplier = 0.001 val BlockV5Multiplier = 0.001 - val FeeConstants: Map[Byte, Long] = Map( - GenesisTransaction.typeId -> 0, - PaymentTransaction.typeId -> 1, - IssueTransaction.typeId -> 1000, - ReissueTransaction.typeId -> 1000, - BurnTransaction.typeId -> 1, - TransferTransaction.typeId -> 1, - MassTransferTransaction.typeId -> 1, - LeaseTransaction.typeId -> 1, - LeaseCancelTransaction.typeId -> 1, - ExchangeTransaction.typeId -> 3, - CreateAliasTransaction.typeId -> 1, - DataTransaction.typeId -> 1, - SetScriptTransaction.typeId -> 10, - SponsorFeeTransaction.typeId -> 1000, - SetAssetScriptTransaction.typeId -> (1000 - 4), - InvokeScriptTransaction.typeId -> 5, - UpdateAssetInfoTransaction.typeId -> 1, - InvokeExpressionTransaction.typeId -> 10 + val FeeConstants: Map[TransactionType.TransactionType, Long] = Map( + TransactionType.Genesis -> 0, + TransactionType.Payment -> 1, + TransactionType.Issue -> 1000, + TransactionType.Reissue -> 1000, + TransactionType.Burn -> 1, + TransactionType.Transfer -> 1, + TransactionType.MassTransfer -> 1, + TransactionType.Lease -> 1, + TransactionType.LeaseCancel -> 1, + TransactionType.Exchange -> 3, + TransactionType.CreateAlias -> 1, + TransactionType.Data -> 1, + TransactionType.SetScript -> 10, + TransactionType.SponsorFee -> 1000, + TransactionType.SetAssetScript -> (1000 - 4), + TransactionType.InvokeScript -> 5, + TransactionType.UpdateAssetInfo -> 1, + TransactionType.Ethereum -> 1, + TransactionType.InvokeExpression -> 10 ) def apply(blockchain: Blockchain, tx: Transaction): Either[ValidationError, Unit] = { @@ -51,31 +50,30 @@ object FeeValidation { for { feeDetails <- getMinFee(blockchain, tx) _ <- Either.cond( - feeDetails.minFeeInAsset <= tx.assetFee._2, + feeDetails.minFeeInAsset <= tx.fee, (), - notEnoughFeeError(tx.typeId, feeDetails, tx.assetFee._2) + notEnoughFeeError(tx.tpe, feeDetails, tx.fee) ) } yield () } else { - Either.cond(tx.assetFee._2 > 0 || !tx.isInstanceOf[Authorized], (), GenericError(s"Fee must be positive.")) + Either.cond(tx.fee > 0 || !tx.isInstanceOf[Authorized], (), GenericError(s"Fee must be positive.")) } } - private def notEnoughFeeError(txType: Byte, feeDetails: FeeDetails, feeAmount: Long): ValidationError = { - val txName = Constants.TransactionNames(txType) + private def notEnoughFeeError(txType: TransactionType.TransactionType, feeDetails: FeeDetails, feeAmount: Long): ValidationError = { val actualFee = s"$feeAmount in ${feeDetails.asset.fold("WAVES")(_.id.toString)}" val requiredFee = s"${feeDetails.minFeeInWaves} WAVES${feeDetails.asset.fold("")(id => s" or ${feeDetails.minFeeInAsset} ${id.id.toString}")}" - val errorMessage = s"Fee for $txName ($actualFee) does not exceed minimal value of $requiredFee." + val errorMessage = s"Fee for ${txType.transactionName} ($actualFee) does not exceed minimal value of $requiredFee." - GenericError((feeDetails.requirements mkString_ " ") ++ ". " ++ errorMessage) + GenericError((if (feeDetails.requirements.nonEmpty) (feeDetails.requirements mkString_ " ") ++ ". " else "") ++ errorMessage) } private case class FeeInfo(assetInfo: Option[(IssuedAsset, AssetDescription)], requirements: Chain[String], wavesFee: Long) private def feeInUnits(blockchain: Blockchain, tx: Transaction): Either[ValidationError, Long] = { FeeConstants - .get(tx.typeId) + .get(tx.tpe) .map { baseFee => tx match { case tx: MassTransferTransaction => @@ -97,6 +95,11 @@ object FeeValidation { case _: SponsorFeeTransaction => val multiplier = if (blockchain.isFeatureActivated(BlockchainFeatures.BlockV5)) BlockV5Multiplier else 1 (baseFee * multiplier).toLong + case et: EthereumTransaction => + et.payload match { + case _: EthereumTransaction.Transfer => 1 + case _: EthereumTransaction.Invocation => 5 + } case _ => baseFee } } @@ -139,8 +142,9 @@ object FeeValidation { val assetsCount = tx match { case _: InvokeScriptTransaction if blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) => 0 - case tx: ExchangeTransaction => tx.checkedAssets.count(blockchain.hasAssetScript) /* *3 if we decide to check orders and transaction */ - case _ => tx.checkedAssets.count(blockchain.hasAssetScript) + case tx: ExchangeTransaction => + tx.smartAssets(blockchain).size /* *3 if we decide to check orders and transaction */ + case _ => tx.smartAssets(blockchain).size } val finalAssetsCount = @@ -174,7 +178,7 @@ object FeeValidation { } def getMinFee(blockchain: Blockchain, tx: Transaction): Either[ValidationError, FeeDetails] = { - feeAfterSponsorship(tx.assetFee._1, blockchain, tx) + feeAfterSponsorship(tx.feeAssetId, blockchain, tx) .map(feeAfterSmartTokens(blockchain, tx)) .map(feeAfterSmartAccounts(blockchain, tx)) .map { diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiff.scala index dce6fd9c6f1..94819ebfc3e 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiff.scala @@ -19,7 +19,7 @@ object MassTransferTransactionDiff { for { recipientAddr <- blockchain.resolveAlias(xfer.address) portfolio = tx.assetId - .fold(Map(recipientAddr -> Portfolio(xfer.amount, LeaseBalance.empty, Map.empty))) { asset => + .fold(Map[Address, Portfolio](recipientAddr -> Portfolio(xfer.amount, LeaseBalance.empty, Map.empty))) { asset => Map(recipientAddr -> Portfolio(0, LeaseBalance.empty, Map(asset -> xfer.amount))) } } yield (portfolio, xfer.amount) @@ -28,7 +28,7 @@ object MassTransferTransactionDiff { portfoliosEi.flatMap { list: List[(Map[Address, Portfolio], Long)] => val sender = Address.fromPublicKey(tx.sender) - val foldInit = (Map(sender -> Portfolio(-tx.fee, LeaseBalance.empty, Map.empty)), 0L) + val foldInit = (Map[Address, Portfolio](sender -> Portfolio(-tx.fee, LeaseBalance.empty, Map.empty)), 0L) val (recipientPortfolios, totalAmount) = list.fold(foldInit) { (u, v) => (u._1 combine v._1, u._2 + v._2) } @@ -36,8 +36,8 @@ object MassTransferTransactionDiff { recipientPortfolios .combine( tx.assetId - .fold(Map(sender -> Portfolio(-totalAmount, LeaseBalance.empty, Map.empty))) { asset => - Map(sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -totalAmount))) + .fold(Map[Address, Portfolio](sender -> Portfolio(-totalAmount, LeaseBalance.empty, Map.empty))) { asset => + Map[Address, Portfolio](sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -totalAmount))) } ) diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/PaymentTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/PaymentTransactionDiff.scala index cc071abf0ed..5e0818594cd 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/PaymentTransactionDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/PaymentTransactionDiff.scala @@ -19,7 +19,7 @@ object PaymentTransactionDiff { else Right( Diff( - portfolios = Map(tx.recipient -> Portfolio(balance = tx.amount, LeaseBalance.empty, assets = Map.empty)) combine Map( + portfolios = Map[Address, Portfolio](tx.recipient -> Portfolio(balance = tx.amount, LeaseBalance.empty, assets = Map.empty)) combine Map( Address.fromPublicKey(tx.sender) -> Portfolio( balance = -tx.amount - tx.fee, LeaseBalance.empty, diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala b/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala index 92694b1a25a..c082552ee7e 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala @@ -24,7 +24,7 @@ import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.script.trace.{TraceStep, TracedResult} -import com.wavesplatform.transaction.smart._ +import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction, Verifier, _} import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} import play.api.libs.json.Json @@ -74,7 +74,7 @@ object TransactionDiffer { verifierDiff <- if (verify) verifierDiff(blockchain, tx) else Right(Diff.empty).traced transactionDiff <- transactionDiff(blockchain, tx, verifierDiff, currentBlockTimestamp, limitedExecution) remainingComplexity = if (limitedExecution) ContractLimits.FailFreeInvokeComplexity - transactionDiff.scriptsComplexity.toInt else Int.MaxValue - _ <- validateBalance(blockchain, tx.typeId, transactionDiff).traced.leftMap { err => + _ <- validateBalance(blockchain, tx.tpe, transactionDiff).traced.leftMap { err => def acceptFailedByBalance() = acceptFailed(blockchain) && blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) @@ -98,7 +98,7 @@ object TransactionDiffer { ): Either[ValidationError, Unit] = if (verify) stats.commonValidation - .measureForType(tx.typeId) { + .measureForType(tx.tpe) { for { _ <- CommonValidation.disallowFromAnotherNetwork(tx, AddressScheme.current.chainId) _ <- CommonValidation.disallowTxFromFuture(blockchain.settings.functionalitySettings, currentBlockTs, tx) @@ -129,9 +129,9 @@ object TransactionDiffer { private def verifierDiff(blockchain: Blockchain, tx: Transaction) = Verifier(blockchain)(tx).map(complexity => Diff.empty.copy(scriptsComplexity = complexity)) - private def assetsVerifierDiff( + def assetsVerifierDiff( blockchain: Blockchain, - tx: Transaction, + tx: TransactionBase, verify: Boolean, initDiff: Diff, remainingComplexity: Int @@ -152,12 +152,12 @@ object TransactionDiffer { } } - private def validateBalance(blockchain: Blockchain, txType: TxType, diff: Diff): Either[ValidationError, Unit] = + private def validateBalance(blockchain: Blockchain, txType: Transaction.Type, diff: Diff): Either[ValidationError, Unit] = stats.balanceValidation.measureForType(txType)(BalanceDiffValidation(blockchain)(diff).as(())) private def transactionDiff(blockchain: Blockchain, tx: Transaction, initDiff: Diff, currentBlockTs: TxTimestamp, limitedExecution: Boolean) = stats.transactionDiffValidation - .measureForType(tx.typeId) { + .measureForType(tx.tpe) { tx match { case gtx: GenesisTransaction => GenesisTransactionDiff(blockchain.height)(gtx).traced case ptx: PaymentTransaction => PaymentTransactionDiff(blockchain)(ptx).traced @@ -167,7 +167,7 @@ object TransactionDiffer { case rtx: ReissueTransaction => AssetTransactionsDiff.reissue(blockchain, currentBlockTs)(rtx).traced case btx: BurnTransaction => AssetTransactionsDiff.burn(blockchain)(btx).traced case uaitx: UpdateAssetInfoTransaction => AssetTransactionsDiff.updateInfo(blockchain)(uaitx).traced - case ttx: TransferTransaction => TransferTransactionDiff(blockchain, currentBlockTs)(ttx).traced + case ttx: TransferTransaction => TransferTransactionDiff(blockchain)(ttx).traced case mtx: MassTransferTransaction => MassTransferTransactionDiff(blockchain, currentBlockTs)(mtx).traced case ltx: LeaseTransaction => LeaseTransactionsDiff.lease(blockchain)(ltx).traced case ltx: LeaseCancelTransaction => LeaseTransactionsDiff.leaseCancel(blockchain, currentBlockTs)(ltx).traced @@ -176,6 +176,7 @@ object TransactionDiffer { case sstx: SetScriptTransaction => SetScriptTransactionDiff(blockchain)(sstx).traced case sstx: SetAssetScriptTransaction => AssetTransactionsDiff.setAssetScript(blockchain)(sstx).traced case stx: SponsorFeeTransaction => AssetTransactionsDiff.sponsor(blockchain)(stx).traced + case et: EthereumTransaction => EthereumTransactionDiff(blockchain, currentBlockTs)(et) case _ => UnsupportedTransactionType.asLeft.traced } } @@ -196,7 +197,7 @@ object TransactionDiffer { private def validateFee(blockchain: Blockchain, tx: Transaction): Either[ValidationError, Unit] = for { fee <- feePortfolios(blockchain, tx) - _ <- validateBalance(blockchain, tx.typeId, Diff(portfolios = fee)) + _ <- validateBalance(blockchain, tx.tpe, Diff(portfolios = fee)) } yield () private def validateOrder(blockchain: Blockchain, order: Order, matcherFee: Long): Either[ValidationError, Unit] = @@ -209,12 +210,12 @@ object TransactionDiffer { .toRight(GenericError(s"Asset $asset should be issued before it can be traded")) } orderDiff = Diff.empty.copy(portfolios = Map(order.sender.toAddress -> Portfolio.build(order.matcherFeeAssetId, -matcherFee))) - _ <- validateBalance(blockchain, ExchangeTransaction.typeId, orderDiff) + _ <- validateBalance(blockchain, TransactionType.Exchange, orderDiff) } yield () private def validatePayments(blockchain: Blockchain, tx: InvokeScriptTransaction): Either[ValidationError, Unit] = for { - dAppAddress <- blockchain.resolveAlias(tx.dAppAddressOrAlias) + dAppAddress <- blockchain.resolveAlias(tx.dApp) portfolios <- tx.payments .map { case InvokeScriptTransaction.Payment(amt, assetId) => @@ -225,15 +226,15 @@ object TransactionDiffer { .toRight(GenericError(s"Referenced $asset not found")) .as( Monoid.combine( - Map(tx.sender.toAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> -amt))), - Map(dAppAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> amt))) + Map[Address, Portfolio](tx.senderAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> -amt))), + Map[Address, Portfolio](dAppAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> amt))) ) ) case Waves => Monoid .combine( - Map(tx.sender.toAddress -> Portfolio(-amt, LeaseBalance.empty, Map.empty)), - Map(dAppAddress -> Portfolio(amt, LeaseBalance.empty, Map.empty)) + Map[Address, Portfolio](tx.senderAddress -> Portfolio(-amt, LeaseBalance.empty, Map.empty)), + Map[Address, Portfolio](dAppAddress -> Portfolio(amt, LeaseBalance.empty, Map.empty)) ) .asRight } @@ -244,10 +245,10 @@ object TransactionDiffer { } yield () // failed transactions related - private def transactionMayFail(tx: Transaction): Boolean = - tx.typeId == InvokeScriptTransaction.typeId || - tx.typeId == InvokeExpressionTransaction.typeId || - tx.typeId == ExchangeTransaction.typeId + private def transactionMayFail(tx: TransactionBase): Boolean = + tx.tpe == TransactionType.InvokeScript || + tx.tpe == TransactionType.InvokeExpression || + tx.tpe == TransactionType.Exchange private def acceptFailed(blockchain: Blockchain): Boolean = blockchain.isFeatureActivated(BlockV5) @@ -258,7 +259,7 @@ object TransactionDiffer { scriptResult: Option[InvokeScriptResult] ): Either[ValidationError, Diff] = { val extractDAppAddress = tx match { - case it: InvokeTransaction => blockchain.resolveAlias(it.dAppAddressOrAlias).map(Some(_)) + case it: InvokeTransaction => blockchain.resolveAlias(it.dApp).map(Some(_)) case _ => Right(None) } @@ -292,11 +293,13 @@ object TransactionDiffer { // helpers private def feePortfolios(blockchain: Blockchain, tx: Transaction): Either[ValidationError, Map[Address, Portfolio]] = tx match { - case _: GenesisTransaction => Map.empty[Address, Portfolio].asRight - case ptx: PaymentTransaction => Map(ptx.sender.toAddress -> Portfolio(balance = -ptx.fee, LeaseBalance.empty, assets = Map.empty)).asRight + case _: GenesisTransaction => Map.empty[Address, Portfolio].asRight + case ptx: PaymentTransaction => + Map[Address, Portfolio](ptx.sender.toAddress -> Portfolio(balance = -ptx.fee, LeaseBalance.empty, assets = Map.empty)).asRight + case e: EthereumTransaction => Map[Address, Portfolio](e.senderAddress() -> Portfolio(-e.fee)).asRight case ptx: ProvenTransaction => ptx.assetFee match { - case (Waves, fee) => Map(ptx.sender.toAddress -> Portfolio(-fee, LeaseBalance.empty, Map.empty)).asRight + case (Waves, fee) => Map[Address, Portfolio](ptx.sender.toAddress -> Portfolio(-fee, LeaseBalance.empty, Map.empty)).asRight case (asset @ IssuedAsset(_), fee) => for { assetInfo <- blockchain diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/TransferDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/TransferDiff.scala new file mode 100644 index 00000000000..bf36c2cae33 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/state/diffs/TransferDiff.scala @@ -0,0 +1,93 @@ +package com.wavesplatform.state.diffs + +import scala.util.Right +import scala.util.control.NonFatal + +import cats.instances.map._ +import cats.syntax.semigroup._ +import com.wavesplatform.account.{Address, AddressOrAlias} +import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.lang.ValidationError +import com.wavesplatform.state._ +import com.wavesplatform.transaction.{Asset, TxValidationError} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.transaction.transfer.TransferTransaction + +object TransferTransactionDiff { + def apply(blockchain: Blockchain)(tx: TransferTransaction): Either[ValidationError, Diff] = { + TransferDiff(blockchain)(tx.sender.toAddress, tx.recipient, tx.amount, tx.assetId, tx.fee, tx.feeAssetId) + .map(_.copy(scriptsRun = DiffsCommon.countScriptRuns(blockchain, tx))) + } +} + +object TransferDiff { + def apply( + blockchain: Blockchain + )(senderAddress: Address, recipient: AddressOrAlias, amount: Long, assetId: Asset, fee: Long, feeAssetId: Asset): Either[ValidationError, Diff] = { + + val isSmartAsset = feeAssetId match { + case Waves => false + case asset @ IssuedAsset(_) => + blockchain + .assetDescription(asset) + .flatMap(_.script) + .isDefined + } + + for { + recipient <- blockchain.resolveAlias(recipient) + _ <- Either.cond(!isSmartAsset, (), GenericError("Smart assets can't participate in TransferTransactions as a fee")) + + _ <- validateOverflow(blockchain, blockchain.height, amount, fee) + portfolios = (assetId match { + case Waves => + Map(senderAddress -> Portfolio(-amount, LeaseBalance.empty, Map.empty)).combine( + Map(recipient -> Portfolio(amount, LeaseBalance.empty, Map.empty)) + ) + case asset @ IssuedAsset(_) => + Map(senderAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> -amount))).combine( + Map(recipient -> Portfolio(0, LeaseBalance.empty, Map(asset -> amount))) + ) + }).combine( + feeAssetId match { + case Waves => Map(senderAddress -> Portfolio(-fee, LeaseBalance.empty, Map.empty)) + case asset @ IssuedAsset(_) => + val senderPf = Map(senderAddress -> Portfolio(0, LeaseBalance.empty, Map(asset -> -fee))) + if (blockchain.height >= Sponsorship.sponsoredFeesSwitchHeight(blockchain)) { + val sponsorPf = blockchain + .assetDescription(asset) + .collect { + case desc if desc.sponsorship > 0 => + val feeInWaves = Sponsorship.toWaves(fee, desc.sponsorship) + Map[Address, Portfolio](desc.issuer.toAddress -> Portfolio(-feeInWaves, LeaseBalance.empty, Map(asset -> fee))) + } + .getOrElse(Map.empty) + senderPf.combine(sponsorPf) + } else senderPf + } + ) + assetIssued = assetId.fold(true)(blockchain.assetDescription(_).isDefined) + feeAssetIssued = feeAssetId.fold(true)(blockchain.assetDescription(_).isDefined) + _ <- Either.cond( + blockchain.lastBlockTimestamp + .forall(_ <= blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil || (assetIssued && feeAssetIssued)), + (), + GenericError( + s"Unissued assets are not allowed after allowUnissuedAssetsUntil=${blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil}" + ) + ) + } yield Diff(portfolios = portfolios) + } + + private def validateOverflow(blockchain: Blockchain, height: Int, amount: Long, fee: Long) = + if (blockchain.isFeatureActivated(BlockchainFeatures.Ride4DApps, height)) + Right(()) // lets transaction validates itself + else + try { + Math.addExact(fee, amount) + Right(()) + } catch { + case NonFatal(_) => Left(TxValidationError.OverflowError) + } +} diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/TransferTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/TransferTransactionDiff.scala deleted file mode 100644 index 07b791326be..00000000000 --- a/node/src/main/scala/com/wavesplatform/state/diffs/TransferTransactionDiff.scala +++ /dev/null @@ -1,87 +0,0 @@ -package com.wavesplatform.state.diffs - -import cats.instances.map._ -import cats.syntax.semigroup._ -import com.wavesplatform.account.Address -import com.wavesplatform.features.BlockchainFeatures -import com.wavesplatform.lang.ValidationError -import com.wavesplatform.state._ -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.TxValidationError -import com.wavesplatform.transaction.TxValidationError.GenericError -import com.wavesplatform.transaction.transfer._ - -import scala.util.Right -import scala.util.control.NonFatal - -object TransferTransactionDiff { - def apply(blockchain: Blockchain, blockTime: Long)(tx: TransferTransaction): Either[ValidationError, Diff] = { - val sender = Address.fromPublicKey(tx.sender) - - val isSmartAsset = tx.feeAssetId match { - case Waves => false - case asset @ IssuedAsset(_) => - blockchain - .assetDescription(asset) - .flatMap(_.script) - .isDefined - } - - for { - recipient <- blockchain.resolveAlias(tx.recipient) - _ <- Either.cond(!isSmartAsset, (), GenericError("Smart assets can't participate in TransferTransactions as a fee")) - - _ <- validateOverflow(blockchain, blockchain.height, tx) - portfolios = (tx.assetId match { - case Waves => - Map(sender -> Portfolio(-tx.amount, LeaseBalance.empty, Map.empty)).combine( - Map(recipient -> Portfolio(tx.amount, LeaseBalance.empty, Map.empty)) - ) - case asset @ IssuedAsset(_) => - Map(sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -tx.amount))).combine( - Map(recipient -> Portfolio(0, LeaseBalance.empty, Map(asset -> tx.amount))) - ) - }).combine( - tx.feeAssetId match { - case Waves => Map(sender -> Portfolio(-tx.fee, LeaseBalance.empty, Map.empty)) - case asset @ IssuedAsset(_) => - val senderPf = Map(sender -> Portfolio(0, LeaseBalance.empty, Map(asset -> -tx.fee))) - if (blockchain.height >= Sponsorship.sponsoredFeesSwitchHeight(blockchain)) { - val sponsorPf = blockchain - .assetDescription(asset) - .collect { - case desc if desc.sponsorship > 0 => - val feeInWaves = Sponsorship.toWaves(tx.fee, desc.sponsorship) - Map(desc.issuer.toAddress -> Portfolio(-feeInWaves, LeaseBalance.empty, Map(asset -> tx.fee))) - } - .getOrElse(Map.empty) - senderPf.combine(sponsorPf) - } else senderPf - } - ) - assetIssued = tx.assetId.fold(true)(blockchain.assetDescription(_).isDefined) - feeAssetIssued = tx.feeAssetId.fold(true)(blockchain.assetDescription(_).isDefined) - _ <- Either.cond( - blockTime <= blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil || (assetIssued && feeAssetIssued), - (), - GenericError( - s"Unissued assets are not allowed after allowUnissuedAssetsUntil=${blockchain.settings.functionalitySettings.allowUnissuedAssetsUntil}" - ) - ) - } yield Diff( - portfolios = portfolios, - scriptsRun = DiffsCommon.countScriptRuns(blockchain, tx) - ) - } - - private def validateOverflow(blockchain: Blockchain, height: Int, tx: TransferTransaction) = - if (blockchain.isFeatureActivated(BlockchainFeatures.Ride4DApps, height)) - Right(()) // lets transaction validates itself - else - try { - Math.addExact(tx.fee, tx.amount) - Right(()) - } catch { - case NonFatal(_) => Left(TxValidationError.OverflowError) - } -} diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala index 74557cd4e75..b37d8d7361b 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala @@ -20,8 +20,7 @@ import com.wavesplatform.lang.v1.compiler.Terms.{FUNCTION_CALL, _} import com.wavesplatform.lang.v1.evaluator.Log import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.lang.v1.traits.domain.Tx.{BurnPseudoTx, ReissuePseudoTx, ScriptTransfer, SponsorFeePseudoTx} -import com.wavesplatform.lang.v1.traits.domain.{AssetTransfer, _} -import com.wavesplatform.settings.Constants +import com.wavesplatform.lang.v1.traits.domain._ import com.wavesplatform.state._ import com.wavesplatform.state.diffs.DiffsCommon import com.wavesplatform.state.diffs.FeeValidation._ @@ -36,16 +35,15 @@ import com.wavesplatform.transaction.smart.script.trace.AssetVerifierTrace.Asset import com.wavesplatform.transaction.smart.script.trace.TracedResult.Attribute import com.wavesplatform.transaction.smart.script.trace.{AssetVerifierTrace, TracedResult} import com.wavesplatform.transaction.validation.impl.{LeaseCancelTxValidator, LeaseTxValidator, SponsorFeeTxValidator} -import com.wavesplatform.transaction.{Asset, AssetIdLength, LegacyPBSwitch} +import com.wavesplatform.transaction.{Asset, AssetIdLength, ERC20Address, PBSince, TransactionType} import com.wavesplatform.utils._ import shapeless.Coproduct - import scala.util.{Failure, Right, Success, Try} object InvokeDiffsCommon { - def txFeeDiff(blockchain: Blockchain, tx: InvokeTransaction): Either[GenericError, (Long, Map[Address, Portfolio])] = { + def txFeeDiff(blockchain: Blockchain, tx: InvokeScriptTransactionLike): Either[GenericError, (Long, Map[Address, Portfolio])] = { val attachedFee = tx.fee - tx.assetFee._1 match { + tx.feeAssetId match { case Waves => Right((attachedFee, Map(tx.sender.toAddress -> Portfolio(-attachedFee)))) case asset @ IssuedAsset(_) => for { @@ -59,29 +57,29 @@ object InvokeDiffsCommon { ) } yield { val portfolioDiff = - Map(tx.sender.toAddress -> Portfolio(assets = Map(asset -> -attachedFee))) |+| - Map(assetInfo.issuer.toAddress -> Portfolio(-feeInWaves, assets = Map(asset -> attachedFee))) + Map[Address, Portfolio](tx.sender.toAddress -> Portfolio(assets = Map(asset -> -attachedFee))) |+| + Map[Address, Portfolio](assetInfo.issuer.toAddress -> Portfolio(-feeInWaves, assets = Map(asset -> attachedFee))) (feeInWaves, portfolioDiff) } } } private def calculateMinFee( - tx: InvokeTransaction, + tx: InvokeScriptTransactionLike, blockchain: Blockchain, issueList: List[Issue], additionalScriptsInvoked: Int, stepsNumber: Long ): Long = { - val dAppFee = FeeConstants(tx.typeId) * FeeUnit * stepsNumber - val issuesFee = issueList.count(!blockchain.isNFT(_)) * FeeConstants(IssueTransaction.typeId) * FeeUnit + val dAppFee = FeeConstants(tx.tpe) * FeeUnit * stepsNumber + val issuesFee = issueList.count(!blockchain.isNFT(_)) * FeeConstants(TransactionType.Issue) * FeeUnit val actionsFee = additionalScriptsInvoked * ScriptExtraFee dAppFee + issuesFee + actionsFee } private[invoke] def calcAndCheckFee[E <: ValidationError]( makeError: (String, Long) => E, - tx: InvokeTransaction, + tx: InvokeScriptTransactionLike, blockchain: Blockchain, stepLimit: Long, invocationComplexity: Long, @@ -119,7 +117,7 @@ object InvokeDiffsCommon { "" val assetName = tx.assetFee._1.fold("WAVES")(_.id.toString) - val txName = Constants.TransactionNames(tx.typeId) + val txName = tx.tpe.transactionName s"Fee in $assetName for $txName (${tx.assetFee._2} in $assetName)" + s"$stepsInfo$totalScriptsInvokedInfo$issuesInfo " + @@ -207,27 +205,25 @@ object InvokeDiffsCommon { sponsorFeeList.map(sf => IssuedAsset(sf.assetId)) actionComplexities = actionAssets.flatMap(blockchain.assetScript(_).map(_.complexity)) - verifierCount = if (blockchain.hasPaidVerifier(tx.senderAddress)) 1 else 0 - additionalScriptsCount = actionComplexities.size + verifierCount + tx.checkedAssets.count(blockchain.hasAssetScript) + verifierCount = if (blockchain.hasPaidVerifier(tx.sender.toAddress)) 1 else 0 + additionalScriptsCount = actionComplexities.size + verifierCount + tx.paymentAssets.count(blockchain.hasAssetScript) feeDiff <- if (isSyncCall) TracedResult.wrapValue(Map[Address, Portfolio]()) else { val feeActionsCount = if (blockchain.isFeatureActivated(SynchronousCalls)) verifierCount else additionalScriptsCount val stepLimit = ContractLimits.MaxComplexityByVersion(version) - tx.root - .map( - calcAndCheckFee( - FailedTransactionError.feeForActions, - _, - blockchain, - stepLimit, - storingComplexity.min(stepLimit), // complexity increased by sync calls should not require fee for additional steps - issueList ++ otherIssues, - feeActionsCount - ).map(_._2) - ) - .getOrElse(TracedResult(Right(Map[Address, Portfolio]()))) + + calcAndCheckFee( + FailedTransactionError.feeForActions, + tx.root, + blockchain, + stepLimit, + storingComplexity.min(stepLimit), // complexity increased by sync calls should not require fee for additional steps + issueList ++ otherIssues, + feeActionsCount + ).map(_._2) + } _ <- TracedResult( @@ -243,7 +239,7 @@ object InvokeDiffsCommon { } else if (version < V5) { paymentsPart(tx, dAppAddress, feeDiff) } else { - Diff(portfolios = txFeeDiff(blockchain, tx.root.get).explicitGet()._2) + Diff(portfolios = txFeeDiff(blockchain, tx.root).explicitGet()._2) } compositeDiff <- foldActions(blockchain, blockTime, tx, dAppAddress, dAppPublicKey)(actions, paymentsAndFeeDiff, complexityLimit) @@ -284,11 +280,11 @@ object InvokeDiffsCommon { case InvokeScriptTransaction.Payment(amt, assetId) => assetId match { case asset @ IssuedAsset(_) => - Map(tx.senderAddress -> Portfolio(assets = Map(asset -> -amt))) |+| - Map(dAppAddress -> Portfolio(assets = Map(asset -> amt))) + Map(tx.sender.toAddress -> Portfolio(assets = Map(asset -> -amt))) |+| + Map(dAppAddress -> Portfolio(assets = Map(asset -> amt))) case Waves => - Map(tx.senderAddress -> Portfolio(-amt)) |+| - Map(dAppAddress -> Portfolio(amt)) + Map(tx.sender.toAddress -> Portfolio(-amt)) |+| + Map(dAppAddress -> Portfolio(amt)) } } .foldLeft(Map[Address, Portfolio]())(_ |+| _) @@ -311,7 +307,7 @@ object InvokeDiffsCommon { transfers: List[AssetTransfer] ): Either[String, Unit] = if (blockchain.disallowSelfPayment && version >= V4) - if (tx.payments.nonEmpty && tx.senderAddress == dAppAddress) + if (tx.payments.nonEmpty && tx.sender.toAddress == dAppAddress) "DApp self-payment is forbidden since V4".asLeft[Unit] else if (transfers.exists(_.address.bytes == ByteStr(dAppAddress.bytes))) "DApp self-transfer is forbidden since V4".asLeft[Unit] @@ -351,11 +347,11 @@ object InvokeDiffsCommon { s"WriteSet can't contain more than ${ContractLimits.MaxWriteSetSize(stdLibVersion)} entries" ) _ <- Either.cond( - !tx.enableEmptyKeys || dataEntries.forall(_.key.nonEmpty), + tx.enableEmptyKeys || dataEntries.forall(_.key.nonEmpty), (), { - val versionInfo = tx.root.get match { - case s: LegacyPBSwitch => s" in tx version >= ${s.protobufVersion}" - case _ => "" + val versionInfo = tx.root match { + case s: PBSince => s" in tx version >= ${s.protobufVersion}" + case _ => "" } s"Empty keys aren't allowed$versionInfo" } @@ -429,10 +425,14 @@ object InvokeDiffsCommon { def processTransfer(address: Address): TracedResult[FailedTransactionError, Diff] = Asset.fromCompatId(asset) match { case Waves => - TracedResult.wrapValue(Diff(portfolios = Map(address -> Portfolio(amount)) |+| Map(dAppAddress -> Portfolio(-amount)))) + TracedResult.wrapValue( + Diff(portfolios = Map[Address, Portfolio](address -> Portfolio(amount)) |+| Map(dAppAddress -> Portfolio(-amount))) + ) case a @ IssuedAsset(id) => val nextDiff = Diff( - portfolios = Map(address -> Portfolio(assets = Map(a -> amount))) |+| Map(dAppAddress -> Portfolio(assets = Map(a -> -amount))) + portfolios = Map[Address, Portfolio](address -> Portfolio(assets = Map(a -> amount))) |+| Map( + dAppAddress -> Portfolio(assets = Map(a -> -amount)) + ) ) blockchain .assetScript(a) @@ -485,21 +485,20 @@ object InvokeDiffsCommon { TracedResult.wrapValue(Diff(accountData = Map(dAppAddress -> AccountDataInfo(Map(item.key -> dataItemToEntry(item)))))) def applyIssue(itx: InvokeScriptLike, pk: PublicKey, issue: Issue): TracedResult[FailedTransactionError, Diff] = { + val asset = IssuedAsset(issue.id) + if (issue.name .getBytes("UTF-8") .length < IssueTransaction.MinAssetNameLength || issue.name.getBytes("UTF-8").length > IssueTransaction.MaxAssetNameLength) { TracedResult(Left(FailedTransactionError.dAppExecution("Invalid asset name", 0L)), List()) } else if (issue.description.length > IssueTransaction.MaxAssetDescriptionLength) { TracedResult(Left(FailedTransactionError.dAppExecution("Invalid asset description", 0L)), List()) - } else if (blockchain.assetDescription(IssuedAsset(issue.id)).isDefined) { - TracedResult(Left(FailedTransactionError.dAppExecution(s"Asset ${issue.id} is already issued", 0L)), List()) + } else if (blockchain.assetDescription(asset).isDefined || blockchain.resolveERC20Address(ERC20Address(asset)).isDefined) { + TracedResult(Left(FailedTransactionError.dAppExecution(s"Asset $asset is already issued", 0L)), List()) } else { val staticInfo = AssetStaticInfo(TransactionId @@ itx.txId, pk, issue.decimals, blockchain.isNFT(issue)) val volumeInfo = AssetVolumeInfo(issue.isReissuable, BigInt(issue.quantity)) val info = AssetInfo(ByteString.copyFromUtf8(issue.name), ByteString.copyFromUtf8(issue.description), Height @@ blockchain.height) - - val asset = IssuedAsset(issue.id) - DiffsCommon .countVerifierComplexity(None /*issue.compiledScript*/, blockchain, isAsset = true) .map { script => @@ -623,7 +622,7 @@ object InvokeDiffsCommon { isAssetScript = true, scriptContainerAddress = if (blockchain.passCorrectAssetId) Coproduct[Environment.Tthis](Environment.AssetId(assetId.arr)) - else Coproduct[Environment.Tthis](Environment.AssetId(tx.dAppAddressOrAlias.bytes)), + else Coproduct[Environment.Tthis](Environment.AssetId(tx.dApp.bytes)), complexityLimit ) val complexity = if (blockchain.storeEvaluatedComplexity) evaluatedComplexity else estimatedComplexity diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScript.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScript.scala index dc9735d03fb..dbd79b4c2aa 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScript.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScript.scala @@ -4,33 +4,49 @@ import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.transaction.Asset.IssuedAsset -import com.wavesplatform.transaction.TxTimestamp +import com.wavesplatform.transaction.serialization.impl.InvokeScriptTxSerializer +import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.InvokeTransaction +import com.wavesplatform.transaction.{Authorized, TransactionBase, TxTimestamp} +import play.api.libs.json.{JsObject, Json} trait InvokeScriptLike { - def dAppAddressOrAlias: AddressOrAlias + def dApp: AddressOrAlias def funcCall: FUNCTION_CALL def payments: Seq[Payment] - def root: Option[InvokeTransaction] + def root: InvokeScriptTransactionLike def checkedAssets: Seq[IssuedAsset] = payments collect { case Payment(_, assetId: IssuedAsset) => assetId } - def senderAddress: Address - def sender: PublicKey - val enableEmptyKeys: Boolean + val sender: PublicKey +} + +trait InvokeScriptTransactionLike extends TransactionBase with InvokeScriptLike with Authorized + +object InvokeScriptLike { + implicit class ISLExt(val isl: InvokeScriptLike) extends AnyVal { + def enableEmptyKeys: Boolean = isl.root match { + case ist: InvokeScriptTransaction => ist.version == 1 + case _ => true + } + + def paymentAssets: Seq[IssuedAsset] = isl.payments.collect(IssuedAssets) - def txId: ByteStr = root.map(_.id()).getOrElse(ByteStr.empty) - val timestamp: TxTimestamp = root.map(_.timestamp).getOrElse(0L) + def txId: ByteStr = isl.root.id() + def timestamp: TxTimestamp = isl.root.timestamp + + def toJson: JsObject = + Json.obj( + "dApp" -> isl.dApp.toString, + "payment" -> isl.payments + ) ++ Json.obj("call" -> InvokeScriptTxSerializer.functionCallToJson(isl.funcCall)) + } + + val IssuedAssets: PartialFunction[Payment, IssuedAsset] = { case Payment(_, assetId: IssuedAsset) => assetId } } case class InvokeScript( - senderDApp: Address, sender: PublicKey, - dAppAddress: Address, + dApp: Address, funcCall: FUNCTION_CALL, payments: Seq[Payment], - root: Option[InvokeTransaction] -) extends InvokeScriptLike { - def dAppAddressOrAlias: AddressOrAlias = dAppAddress - def senderAddress: Address = senderDApp - val enableEmptyKeys: Boolean = root.forall(_.enableEmptyKeys) -} + root: InvokeScriptTransactionLike +) extends InvokeScriptLike diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala index 9a0cfbedf99..2150b6d6a89 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala @@ -20,12 +20,12 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.evaluator.{ContractEvaluator, IncompleteResult, Log, ScriptResult, ScriptResultV3, ScriptResultV4} import com.wavesplatform.lang.v1.evaluator.ctx.impl.unit import com.wavesplatform.lang.v1.traits.Environment -import com.wavesplatform.lang.v1.traits.domain._ +import com.wavesplatform.lang.v1.traits.domain.{Recipient => RideRecipient, _} import com.wavesplatform.lang.v1.traits.domain.Tx.ScriptTransfer import com.wavesplatform.metrics._ import com.wavesplatform.state._ import com.wavesplatform.state.reader.CompositeBlockchain -import com.wavesplatform.transaction.{Transaction, TxValidationError} +import com.wavesplatform.transaction.{TransactionType, TxValidationError} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.TxValidationError._ import com.wavesplatform.transaction.smart.{DApp => DAppTarget, _} @@ -55,8 +55,8 @@ object InvokeScriptDiff { )( tx: InvokeScript ): CoevalR[(Diff, EVALUATED, Int, Int, Int)] = { - val dAppAddress = tx.dAppAddress - val invoker = tx.senderDApp + val dAppAddress = tx.dApp + val invoker = tx.sender.toAddress val result = blockchain.accountScript(dAppAddress) match { case Some(AccountScriptInfo(pk, ContractScriptImpl(version, contract), _, callableComplexities)) => @@ -108,9 +108,9 @@ object InvokeScriptDiff { val usedComplexity = totalComplexityLimit - nextRemainingComplexity val pseudoTx = ScriptTransfer( Some(assetId), - Recipient.Address(ByteStr(tx.senderDApp.bytes)), + RideRecipient.Address(ByteStr(tx.sender.toAddress.bytes)), tx.sender, - Recipient.Address(ByteStr(tx.dAppAddress.bytes)), + RideRecipient.Address(ByteStr(tx.dApp.bytes)), amount, tx.timestamp, tx.txId @@ -142,29 +142,26 @@ object InvokeScriptDiff { complexityAfterPayments <- CoevalR(Coeval.now(complexityAfterPaymentsTraced)) paymentsComplexity = checkedPayments.map(_._1.complexity).sum.toInt - tthis = Coproduct[Environment.Tthis](Recipient.Address(ByteStr(dAppAddress.bytes))) + tthis = Coproduct[Environment.Tthis](RideRecipient.Address(ByteStr(dAppAddress.bytes))) input <- traced( - tx.root - .map(t => buildThisValue(Coproduct[TxOrd](t: Transaction), blockchain, directives, tthis).leftMap(GenericError.apply)) - .getOrElse(Right(null)) - ) + buildThisValue(Coproduct[TxOrd](tx.root), blockchain, directives, tthis).leftMap(GenericError.apply)) result <- for { (diff, (scriptResult, log), availableActions, availableData, availableDataSize) <- { - stats.invokedScriptExecution.measureForType(InvokeScriptTransaction.typeId)({ + stats.invokedScriptExecution.measureForType(TransactionType.InvokeScript)({ val height = blockchain.height val invocation = ContractEvaluator.Invocation( tx.funcCall, - Recipient.Address(ByteStr(invoker.bytes)), + RideRecipient.Address(ByteStr(invoker.bytes)), ByteStr(tx.sender.arr), - Recipient.Address(ByteStr(tx.root.fold(invoker)(_.senderAddress).bytes)), - ByteStr(tx.root.getOrElse(tx).sender.arr), + RideRecipient.Address(ByteStr(tx.root.sender.toAddress.bytes)), + ByteStr(tx.root.sender.arr), payments, tx.txId, - tx.root.map(_.fee).getOrElse(0L), - tx.root.flatMap(_.feeAssetId.compatId) + tx.root.fee, + tx.root.feeAssetId.compatId ) - val paymentsPart = InvokeDiffsCommon.paymentsPart(tx, tx.dAppAddress, Map()) + val paymentsPart = InvokeDiffsCommon.paymentsPart(tx, tx.dApp, Map()) val (paymentsPartInsideDApp, paymentsPartToResolve) = if (version < V5) (Diff.empty, paymentsPart) else (paymentsPart, Diff.empty) val environment = new DAppEnvironment( AddressScheme.current.chainId, @@ -174,7 +171,7 @@ object InvokeScriptDiff { tthis, directives, tx.root, - tx.dAppAddress, + tx.dApp, pk, calledAddresses, limitedExecution, @@ -281,7 +278,7 @@ object InvokeScriptDiff { } yield (resultDiff, evaluated, remainingActions1, remainingData1, remainingDataSize1) } yield result - case _ => traced(Left(GenericError(s"No contract at address ${tx.dAppAddress}"))) + case _ => traced(Left(GenericError(s"No contract at address ${tx.dApp}"))) } result.leftMap { err => diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala index 747de5b2f8b..e5703e584b6 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala @@ -23,15 +23,14 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.evaluator._ import com.wavesplatform.lang.v1.traits.Environment -import com.wavesplatform.lang.v1.traits.domain._ -import com.wavesplatform.metrics.TxProcessingStats.TxTimerExt +import com.wavesplatform.lang.v1.traits.domain.{Recipient => RideRecipient, _} import com.wavesplatform.metrics.{TxProcessingStats => Stats} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.state._ import com.wavesplatform.state.reader.CompositeBlockchain -import com.wavesplatform.transaction.Transaction +import com.wavesplatform.transaction.TransactionBase import com.wavesplatform.transaction.TxValidationError._ -import com.wavesplatform.transaction.smart.InvokeTransaction.defaultCall +import com.wavesplatform.transaction.smart.InvokeTransaction.DefaultCall import com.wavesplatform.transaction.smart.script.ScriptRunner.TxOrd import com.wavesplatform.transaction.smart.script.trace.{InvokeScriptTrace, TracedResult} import com.wavesplatform.transaction.smart.{DApp => DAppTarget, _} @@ -47,12 +46,12 @@ object InvokeScriptTransactionDiff { } def apply(blockchain: Blockchain, blockTime: Long, limitedExecution: Boolean)( - tx: InvokeTransaction + tx: InvokeScriptTransactionLike ): TracedResult[ValidationError, Diff] = { val accScriptEi = for { - address <- blockchain.resolveAlias(tx.dAppAddressOrAlias) + address <- blockchain.resolveAlias(tx.dApp) scriptOpt = blockchain.accountScript(address) script <- tx match { case ie: InvokeExpressionTransaction => extractFreeCall(ie, blockchain) @@ -81,7 +80,7 @@ object InvokeScriptTransactionDiff { ) def executeMainScript(): TracedResult[ValidationError, MainScriptResult] = { - val scriptResultE = Stats.invokedScriptExecution.measureForType(tx.typeId) { + val scriptResultE = Stats.invokedScriptExecution.measureForType(tx.tpe) { val fullLimit = if (blockchain.estimator == ScriptEstimatorV2) Int.MaxValue //to avoid continuations when evaluating underestimated by EstimatorV2 scripts @@ -96,7 +95,7 @@ object InvokeScriptTransactionDiff { else fullLimit - val paymentsComplexity = tx.checkedAssets.flatMap(blockchain.assetScript).map(_.complexity.toInt).sum + val paymentsComplexity = tx.smartAssets(blockchain).flatMap(blockchain.assetScript).map(_.complexity.toInt).sum for { (result, log) <- evaluateV2( @@ -127,7 +126,7 @@ object InvokeScriptTransactionDiff { List( InvokeScriptTrace( tx.id(), - tx.dAppAddressOrAlias, + tx.dApp, tx.funcCall, scriptResultE.map(_.scriptResult), scriptResultE.fold(_.log, _.log), @@ -231,8 +230,8 @@ object InvokeScriptTransactionDiff { (invocationComplexity, fixedInvocationComplexity) <- calcInvocationComplexity(version, callableComplexities, dAppAddress) (directives, tthis, input) <- TracedResult(for { directives <- DirectiveSet(version, Account, DAppType) - tthis = Coproduct[Environment.Tthis](Recipient.Address(ByteStr(dAppAddress.bytes))) - input <- buildThisValue(Coproduct[TxOrd](tx: Transaction), blockchain, directives, tthis) + tthis = Coproduct[Environment.Tthis](RideRecipient.Address(ByteStr(dAppAddress.bytes))) + input <- buildThisValue(Coproduct[TxOrd](tx: TransactionBase), blockchain, directives, tthis) } yield (directives, tthis, input)).leftMap(GenericError(_)) environment = new DAppEnvironment( @@ -242,10 +241,10 @@ object InvokeScriptTransactionDiff { blockchain, tthis, directives, - Some(tx), + tx, dAppAddress, pk, - Set(tx.senderAddress), + Set(tx.sender.toAddress), limitedExecution, ContractLimits.MaxTotalInvokeComplexity(version), ContractLimits.MaxSyncDAppCalls(version), @@ -255,7 +254,7 @@ object InvokeScriptTransactionDiff { if (version < V5) Diff.empty else InvokeDiffsCommon.paymentsPart(tx, dAppAddress, Map()), invocationTracker ) - invoker = Recipient.Address(ByteStr(tx.sender.toAddress.bytes)) + invoker = RideRecipient.Address(ByteStr(tx.sender.toAddress.bytes)) payments = AttachedPaymentExtractor.extractPayments(tx, version, blockchain, DAppTarget).explicitGet() invocation = ContractEvaluator.Invocation( funcCall, @@ -279,7 +278,7 @@ object InvokeScriptTransactionDiff { } private def extractInvoke( - tx: InvokeTransaction, + tx: InvokeScriptTransactionLike, scriptOpt: Option[AccountScriptInfo] ): Either[GenericError, (PublicKey, StdLibVersion, FUNCTION_CALL, DApp, Map[Int, Map[String, Long]])] = scriptOpt @@ -287,14 +286,14 @@ object InvokeScriptTransactionDiff { case AccountScriptInfo(publicKey, ContractScriptImpl(version, dApp), _, complexities) => (publicKey, version, tx.funcCall, dApp, complexities) } - .toRight(GenericError(s"No contract at address ${tx.dAppAddressOrAlias}")) + .toRight(GenericError(s"No contract at address ${tx.dApp}")) private def extractFreeCall( tx: InvokeExpressionTransaction, blockchain: Blockchain ): Either[GenericError, (PublicKey, StdLibVersion, FUNCTION_CALL, DApp, Map[Int, Map[String, Long]])] = { val annotation = CallableAnnotation(ContractCompiler.FreeCallInvocationArg) - val callable = CallableFunction(annotation, FUNC(defaultCall.function.funcName, Nil, tx.expression.expr)) + val callable = CallableFunction(annotation, FUNC(DefaultCall.function.funcName, Nil, tx.expression.expr)) val dApp = DApp(DAppMeta(), Nil, List(callable), None) val version = tx.expression.stdLibVersion val estimator = blockchain.estimator @@ -303,7 +302,7 @@ object InvokeScriptTransactionDiff { .leftMap(GenericError(_)) .map { case (_, complexities) => - (tx.sender, version, defaultCall, dApp, Map(estimator.version -> complexities)) + (tx.sender, version, DefaultCall, dApp, Map(estimator.version -> complexities)) } } diff --git a/node/src/main/scala/com/wavesplatform/state/package.scala b/node/src/main/scala/com/wavesplatform/state/package.scala index 5616846c43a..c019989f122 100644 --- a/node/src/main/scala/com/wavesplatform/state/package.scala +++ b/node/src/main/scala/com/wavesplatform/state/package.scala @@ -36,7 +36,7 @@ package object state { implicit val dstWrites: Writes[AssetDistribution] = Writes { dst => Json .toJson(dst.map { - case (addr, balance) => addr.stringRepr -> balance + case (addr, balance) => addr.toString -> balance }) } @@ -46,7 +46,7 @@ package object state { implicit val dstPageWrites: Writes[AssetDistributionPage] = Writes { page => Json.obj( "hasNext" -> JsBoolean(page.hasNext), - "lastItem" -> Json.toJson(page.lastItem.map(_.stringRepr)), + "lastItem" -> Json.toJson(page.lastItem.map(_.toString)), "items" -> Json.toJson(page.items) ) } diff --git a/node/src/main/scala/com/wavesplatform/state/patch/CancelLeaseOverflow.scala b/node/src/main/scala/com/wavesplatform/state/patch/CancelLeaseOverflow.scala index 786db6965f5..9b8b0677ab3 100644 --- a/node/src/main/scala/com/wavesplatform/state/patch/CancelLeaseOverflow.scala +++ b/node/src/main/scala/com/wavesplatform/state/patch/CancelLeaseOverflow.scala @@ -8,7 +8,7 @@ import com.wavesplatform.state.{Blockchain, Diff, Portfolio} case object CancelLeaseOverflow extends PatchAtHeight('W' -> 795000) { def apply(blockchain: Blockchain): Diff = { val patch = readPatchData[CancelledLeases]() - val pfs = patch.balances.map { + val pfs = patch.balances.map[Address, Portfolio] { case (address, lb) => Address.fromString(address).explicitGet() -> Portfolio(lease = lb) } diff --git a/node/src/main/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliases.scala b/node/src/main/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliases.scala index d743631697c..da527c150ed 100644 --- a/node/src/main/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliases.scala +++ b/node/src/main/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliases.scala @@ -40,7 +40,7 @@ case object CancelLeasesToDisabledAliases extends PatchDataLoader with DiffPatch id -> ld.copy(status = LeaseDetails.Status.Expired(blockchain.height)) ), portfolios = - Map(ld.sender.toAddress -> Portfolio(lease = LeaseBalance(0, -ld.amount))) |+| + Map[Address, Portfolio](ld.sender.toAddress -> Portfolio(lease = LeaseBalance(0, -ld.amount))) |+| Map(recipientAddress -> Portfolio(lease = LeaseBalance(-ld.amount, 0))) ) } diff --git a/node/src/main/scala/com/wavesplatform/state/reader/CompositeBlockchain.scala b/node/src/main/scala/com/wavesplatform/state/reader/CompositeBlockchain.scala index 02669bb914d..287d68c3b9a 100644 --- a/node/src/main/scala/com/wavesplatform/state/reader/CompositeBlockchain.scala +++ b/node/src/main/scala/com/wavesplatform/state/reader/CompositeBlockchain.scala @@ -14,8 +14,8 @@ import com.wavesplatform.state._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.{AliasDoesNotExist, AliasIsDisabled} import com.wavesplatform.transaction.assets.UpdateAssetInfoTransaction -import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, Transaction} +import com.wavesplatform.transaction.transfer.{TransferTransaction, TransferTransactionLike} +import com.wavesplatform.transaction.{Asset, ERC20Address, Transaction} final class CompositeBlockchain private ( inner: Blockchain, @@ -43,12 +43,13 @@ final class CompositeBlockchain private ( CompositeBlockchain.assetDescription(asset, maybeDiff.orEmpty, inner.assetDescription(asset), inner.assetScript(asset), height) override def leaseDetails(leaseId: ByteStr): Option[LeaseDetails] = { - inner.leaseDetails(leaseId) + inner + .leaseDetails(leaseId) .map(ld => ld.copy(status = diff.leaseState.get(leaseId).map(_.status).getOrElse(ld.status))) .orElse(diff.leaseState.get(leaseId)) } - override def transferById(id: ByteStr): Option[(Int, TransferTransaction)] = + override def transferById(id: ByteStr): Option[(Int, TransferTransactionLike)] = diff.transactions .get(id) .collect { @@ -151,6 +152,11 @@ final class CompositeBlockchain private ( blockMeta .collect { case (_, hitSource) if this.height == height => hitSource } .orElse(inner.hitSource(height)) + + override def resolveERC20Address(address: ERC20Address): Option[IssuedAsset] = + inner + .resolveERC20Address(address) + .orElse(diff.issuedAssets.keys.find(id => ERC20Address(id) == address)) } object CompositeBlockchain { diff --git a/node/src/main/scala/com/wavesplatform/transaction/ABIConverter.scala b/node/src/main/scala/com/wavesplatform/transaction/ABIConverter.scala new file mode 100644 index 00000000000..40ec0d3e519 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/ABIConverter.scala @@ -0,0 +1,230 @@ +package com.wavesplatform.transaction + +import com.esaulpaugh.headlong.abi.{Function, Tuple} +import com.esaulpaugh.headlong.util.FastHex +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.lang.Global +import com.wavesplatform.lang.script.Script +import com.wavesplatform.lang.v1.FunctionHeader +import com.wavesplatform.lang.v1.compiler.Terms.{EVALUATED, FUNCTION_CALL} +import com.wavesplatform.lang.v1.compiler.{Terms, Types} +import com.wavesplatform.transaction.ABIConverter.WavesByteRepr +import com.wavesplatform.transaction.smart.InvokeScriptTransaction +import org.web3j.abi.TypeReference +import org.web3j.abi.datatypes.Type +import play.api.libs.json.{JsArray, JsObject, JsString, Json} + +import scala.jdk.CollectionConverters._ + +object ABIConverter { + val WavesByteRepr: ByteStr = ByteStr(new Array[Byte](32)) + val PaymentListType: Types.LIST = Types.LIST(Types.TUPLE(List(Types.BYTESTR, Types.LONG))) + val PaymentArgSignature: String = "(bytes32,int64)[]" + val PaymentArgJson: JsObject = Json.obj( + "name" -> "payments", + "type" -> "tuple[]", + "components" -> Json.arr( + Json.obj("name" -> "assetId", "type" -> "bytes32"), + Json.obj("name" -> "amount", "type" -> "int64") + ) + ) + + private def buildMethodId(str: String): String = { + val cls = Class.forName("org.web3j.abi.FunctionEncoder") + val method = cls.getDeclaredMethod("buildMethodId", classOf[String]) + method.setAccessible(true) + method.invoke(null, str).asInstanceOf[String] + } + + def ethType(argType: Types.FINAL): String = + (ethTypeObj(argType) \ "type").as[String] + + def ethTypeObj(argType: Types.FINAL): JsObject = { + def t(s: String) = Json.obj("type" -> s) + + argType match { + case Types.BOOLEAN => t("bool") + case Types.LONG => t("int64") + case Types.BYTESTR => t("bytes") + case Types.STRING => t("string") + case Types.LIST(innerType) => + val base = ethTypeObj(innerType) + if (base.value("type").asInstanceOf[JsString].value == "tuple") { + Json.obj( + "type" -> "tuple[]", + "components" -> base.value("components") + ) + } else { + Json.obj("type" -> (base.value("type").as[String] + "[]")) + } + + case Types.UNION(typeList, _) => + t("tuple") ++ Json.obj( + "components" -> { + // Index start from 0 and count from element after typeIndex (from second element of the tuple) + Json.obj("name" -> s"typeIndex", "type" -> "uint8") :: + typeList.map(t => Json.obj("name" -> t.name) ++ ethTypeObj(t)) + } + ) + + // only for payments + case Types.TUPLE(types) => + t("tuple") ++ Json.obj( + "components" -> types.map(t => Json.obj("name" -> t.name) ++ ethTypeObj(t)) + ) + + case other => throw new IllegalArgumentException(s"ethTypeObj: Unexpected type: $other") + } + } + + def ethFuncSignatureTypeName(argType: Types.FINAL): String = argType match { + case Types.BOOLEAN => "bool" + case Types.LONG => "int64" + case Types.BYTESTR => "bytes" + case Types.STRING => "string" + case Types.LIST(innerType) => s"${ethFuncSignatureTypeName(innerType)}[]" + case Types.UNION(typeList, _) => + val unionElementIdxType = "uint8" + val typeNameList = unionElementIdxType :: typeList.map(ethFuncSignatureTypeName) + s"(${typeNameList.mkString(",")})" + case Types.TUPLE(types) => s"(${types.map(ethFuncSignatureTypeName).mkString(",")})" + case other => throw new IllegalArgumentException(s"ethFuncSignatureTypeName: Unexpected type: $other") + } + + def toRideValue(ethArg: Any, rideType: Types.FINAL): EVALUATED = ethArg match { + case bool: Boolean => Terms.CONST_BOOLEAN(bool) + case i: Int => Terms.CONST_LONG(i) + case l: Long => Terms.CONST_LONG(l) + case byteArr: Array[Byte] => Terms.CONST_BYTESTR(ByteStr(byteArr)).explicitGet() //FastHex.encodeToString(byteArr, 0, byteArr.length) + case str: String => Terms.CONST_STRING(str).explicitGet() + + case arr: Array[_] => { + val innerType = rideType match { + case list: Types.LIST => + list.innerType + case _ => + Types.ANY + } + Terms + .ARR( + arr.toVector.map(el => toRideValue(el, innerType)), + limited = true + ) + .explicitGet() + } + + case t: Tuple if rideType.isInstanceOf[Types.UNION] => { + val tupleValList = t.asScala.toVector + if (tupleValList.nonEmpty) { + val unionSubtypeIdx: Int = tupleValList.head.asInstanceOf[Int] + if (unionSubtypeIdx < tupleValList.length) { + toRideValue(tupleValList(unionSubtypeIdx + 1), rideType.asInstanceOf[Types.UNION].typeList(unionSubtypeIdx)) + } else { + throw new UnsupportedOperationException(s"Incorrect tuple size for Union type.") + } + } else { + throw new UnsupportedOperationException(s"Incorrect tuple size for Union type. Empty tuple.") + } + } + + case t: Tuple => + Terms + .ARR( + t.asScala.toVector.map(el => toRideValue(el, Types.ANY)), + limited = true + ) + .explicitGet() + + case _ => throw new UnsupportedOperationException(s"Type not supported: $ethArg") + } +} + +final case class ABIConverter(script: Script) { + case class FunctionArg(name: String, rideType: Types.FINAL) { + lazy val ethType: String = ABIConverter.ethType(rideType) + def ethTypeRef: TypeReference[Type[_]] = TypeReference.makeTypeReference(ethType).asInstanceOf[TypeReference[Type[_]]] + } + + case class FunctionRef(name: String, args: Seq[FunctionArg]) { + + def decodeArgs(data: String): (List[EVALUATED], Seq[InvokeScriptTransaction.Payment]) = { + val ethFunc = new Function(ethSignature) + val ethArgsList = ethFunc.decodeCall(FastHex.decode(data)).asScala.toList + + val result = + ethArgsList.zip(args.map(_.rideType) :+ ABIConverter.PaymentListType).map { case (ethArg, rideT) => ABIConverter.toRideValue(ethArg, rideT) } + + val payment = result.last match { + case Terms.ARR(xs) => + xs.map { + case Terms.ARR(fields) => + fields match { + case Seq(Terms.CONST_BYTESTR(assetId), Terms.CONST_LONG(amount)) => + InvokeScriptTransaction.Payment(amount, assetId match { + case `WavesByteRepr` => Asset.Waves + case assetId => Asset.IssuedAsset(assetId) + }) + + case other => throw new IllegalArgumentException(s"decodeArgs: unexpected term in payment: $other") + } + case other => throw new IllegalArgumentException(s"decodeArgs: unexpected term in payment: $other") + } + + case _ => Nil + } + (result.init, payment) + } + + lazy val ethSignature: String = { + val argTypes = args.map(_.rideType).map(ABIConverter.ethFuncSignatureTypeName) :+ ABIConverter.PaymentArgSignature + s"$name(${argTypes.mkString(",")})" + } + + lazy val ethMethodId: String = ABIConverter.buildMethodId(ethSignature) + } + + private[this] lazy val funcsWithTypes = Global.dAppFuncTypes(script) + + private[this] def functionsWithArgs: Seq[(String, List[(String, Types.FINAL)])] = { + funcsWithTypes match { + case Right(signatures) => signatures.argsWithFuncName + case Left(_) => Nil + } + } + + lazy val funcByMethodId: Map[String, FunctionRef] = + functionsWithArgs + .map { + case (funcName, args) => + FunctionRef(funcName, args.map { case (name, argType) => FunctionArg(name, argType) }) + } + .map(func => func.ethMethodId -> func) + .toMap + + def jsonABI: JsArray = + JsArray(functionsWithArgs.map { + case (funcName, args) => + val inputs = args.map { + case (argName, argType) => + Json.obj("name" -> argName) ++ ABIConverter.ethTypeObj(argType) + } :+ ABIConverter.PaymentArgJson + + Json.obj( + "name" -> funcName, + "type" -> "function", + "constant" -> false, + "payable" -> false, + "stateMutability" -> "nonpayable", + "inputs" -> inputs, + "outputs" -> JsArray.empty + ) + }) + + def decodeFunctionCall(data: String): (FUNCTION_CALL, Seq[InvokeScriptTransaction.Payment]) = { + val methodId = data.substring(0, 8) + val function = funcByMethodId.getOrElse("0x" + methodId, throw new NoSuchElementException(s"Function not defined: $methodId")) + val (args, payment) = function.decodeArgs(data) + (FUNCTION_CALL(FunctionHeader.User(function.name), args), payment) + } +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala index 8114e8d0d9a..914e6cde935 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala @@ -1,10 +1,10 @@ package com.wavesplatform.transaction import com.google.common.primitives.Bytes -import com.wavesplatform.account.{AddressScheme, Alias, KeyPair, PrivateKey, PublicKey} +import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.crypto import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError import com.wavesplatform.transaction.serialization.impl.CreateAliasTxSerializer import com.wavesplatform.transaction.validation.impl.CreateAliasTxValidator @@ -21,24 +21,23 @@ final case class CreateAliasTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends SigProofsSwitch +) extends Transaction(TransactionType.CreateAlias) + with SigProofsSwitch with VersionedTransaction with TxWithFee.InWaves - with LegacyPBSwitch.V3 { + with PBSince.V3 { lazy val alias: Alias = Alias.createWithChainId(aliasName, chainId).explicitGet() - override def builder: TransactionParser = CreateAliasTransaction - override val bodyBytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(CreateAliasTransaction.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(CreateAliasTransaction.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(CreateAliasTransaction.serializer.toJson(this)) + override val bodyBytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(CreateAliasTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(CreateAliasTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(CreateAliasTxSerializer.toJson(this)) override val id: Coeval[ByteStr] = Coeval.evalOnce { - val payload = version match { - case TxVersion.V1 | TxVersion.V2 => Bytes.concat(Array(builder.typeId), alias.bytes) + ByteStr(crypto.fastHash(version match { + case TxVersion.V1 | TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte), alias.bytes) case _ => bodyBytes() - } - ByteStr(crypto.fastHash(payload)) + })) } } @@ -49,13 +48,12 @@ object CreateAliasTransaction extends TransactionParser { val typeId: TxType = 10: Byte implicit val validator = CreateAliasTxValidator - val serializer = CreateAliasTxSerializer implicit def sign(tx: CreateAliasTransaction, privateKey: PrivateKey): CreateAliasTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) override def parseBytes(bytes: Array[TxVersion]): Try[CreateAliasTransaction] = - serializer.parseBytes(bytes) + CreateAliasTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/DataTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/DataTransaction.scala index 95123bed576..a60598d5fa6 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/DataTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/DataTransaction.scala @@ -21,27 +21,25 @@ case class DataTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends ProvenTransaction +) extends Transaction(TransactionType.Data) + with ProvenTransaction with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V2 { + with PBSince.V2 { - //noinspection TypeAnnotation - override val builder = DataTransaction + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(DataTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(DataTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(DataTxSerializer.toJson(this)) - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.eval(builder.serializer.toJson(this)) - - private[wavesplatform] lazy val protoDataPayload = PBTransactions.protobuf(this).getTransaction.getDataTransaction.toByteArray + private[wavesplatform] lazy val protoDataPayload = PBTransactions.protobuf(this).getWavesTransaction.getDataTransaction.toByteArray } object DataTransaction extends TransactionParser { type TransactionT = DataTransaction val MaxBytes: Int = 150 * 1024 // uses for RIDE CONST_STRING and CONST_BYTESTR - val MaxProtoBytes: Int = 165890 // uses for RIDE CONST_BYTESTR + val MaxProtoBytes: Int = 165890 // uses for RIDE CONST_BYTESTR val MaxEntryCount: Int = 100 override val typeId: TxType = 12: Byte @@ -52,10 +50,8 @@ object DataTransaction extends TransactionParser { implicit def sign(tx: DataTransaction, privateKey: PrivateKey): DataTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - val serializer = DataTxSerializer - override def parseBytes(bytes: Array[TxVersion]): Try[DataTransaction] = - serializer.parseBytes(bytes) + DataTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/EthereumTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/EthereumTransaction.scala new file mode 100644 index 00000000000..a3974ce53ca --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/EthereumTransaction.scala @@ -0,0 +1,214 @@ +package com.wavesplatform.transaction + +import java.math.BigInteger + +import scala.reflect.ClassTag +import com.wavesplatform.account._ +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.crypto.EthereumKeyLength +import com.wavesplatform.lang.ValidationError +import com.wavesplatform.lang.v1.compiler.Terms +import com.wavesplatform.state.Blockchain +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike +import com.wavesplatform.transaction.TransactionType.TransactionType +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.transaction.serialization.impl.BaseTxJson +import com.wavesplatform.transaction.smart.InvokeScriptTransaction +import com.wavesplatform.transaction.transfer.TransferTransactionLike +import com.wavesplatform.transaction.validation.{TxConstraints, TxValidator, ValidatedV} +import com.wavesplatform.utils.EthEncoding +import monix.eval.Coeval +import org.web3j.abi.TypeDecoder +import org.web3j.abi.datatypes.{Address => EthAddress} +import org.web3j.abi.datatypes.generated.Uint256 +import org.web3j.crypto._ +import org.web3j.crypto.Sign.SignatureData +import org.web3j.utils.Convert +import play.api.libs.json._ + +final case class EthereumTransaction( + payload: EthereumTransaction.Payload, + underlying: RawTransaction, + signatureData: SignatureData, + override val chainId: Byte +) extends Transaction(TransactionType.Ethereum) + with Authorized + with VersionedTransaction.ConstV1 + with PBSince.V1 { self => + import EthereumTransaction._ + + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(encodeTransaction(underlying, signatureData)) + + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(TransactionEncoder.encode(underlying, chainId.toLong)) + + override val id: Coeval[ByteStr] = Coeval.evalOnce(ByteStr(Hash.sha3(bodyBytes()))) + + override def assetFee: (Asset, Long) = Asset.Waves -> underlying.getGasLimit.longValueExact() + + override val timestamp: TxTimestamp = underlying.getNonce.longValueExact() + + val signerPublicKey: Coeval[PublicKey] = Coeval.evalOnce { + require(signatureData != null, "empty signature data") + val v = BigInt(1, signatureData.getV) + val recoveryId = if (v > 28) v - chainId * 2 - 35 else v - 27 + val sig = new ECDSASignature(new BigInteger(1, signatureData.getR), new BigInteger(1, signatureData.getS)) + + PublicKey( + ByteStr( + Sign + .recoverFromSignature(recoveryId.intValue, sig, id().arr) + .toByteArray + .takeRight(EthereumKeyLength) + ) + ) + } + + val senderAddress: Coeval[Address] = Coeval.evalOnce(signerPublicKey().toAddress(chainId)) + + override val json: Coeval[JsObject] = Coeval.evalOnce( + BaseTxJson.toJson(this) ++ Json.obj( + "bytes" -> EthEncoding.toHexString(bytes()), + "sender" -> senderAddress().toString, + "senderPublicKey" -> signerPublicKey() + ) + ) + + override lazy val sender: PublicKey = signerPublicKey() + + def toTransferLike(a: TxAmount, r: AddressOrAlias, asset: Asset): TransferTransactionLike = new TransferTransactionLike { + override val amount: TxAmount = a + override val recipient: AddressOrAlias = r + override val sender: PublicKey = signerPublicKey() + override val assetId: Asset = asset + override val attachment: ByteStr = ByteStr.empty + override def timestamp: TxTimestamp = self.timestamp + override def chainId: TxType = self.chainId + override def id: Coeval[ByteStr] = self.id + override val tpe: TransactionType = TransactionType.Transfer + override def assetFee: (Asset, TxTimestamp) = self.assetFee + override def checkedAssets: Seq[IssuedAsset] = asset match { + case i: IssuedAsset => Seq(i) + case Asset.Waves => Nil + } + } +} + +object EthereumTransaction { + sealed trait Payload + + case class Transfer(tokenAddress: Option[ERC20Address], amount: Long, recipient: Address) extends Payload { + def tryResolveAsset(blockchain: Blockchain): Either[ValidationError, Asset] = + tokenAddress + .fold[Either[ValidationError, Asset]]( + Right(Waves) + )(a => blockchain.resolveERC20Address(a).toRight(GenericError(s"Can't resolve ERC20 address $a"))) + + def toTransferLike(tx: EthereumTransaction, blockchain: Blockchain): Either[ValidationError, TransferTransactionLike] = + tryResolveAsset(blockchain).map(tx.toTransferLike(amount, recipient, _)) + } + + case class Invocation(dApp: Address, hexCallData: String) extends Payload { + def toInvokeScriptLike(tx: EthereumTransaction, blockchain: Blockchain): Either[ValidationError, InvokeScriptTransactionLike] = + for { + scriptInfo <- blockchain.accountScript(dApp).toRight(GenericError(s"No script at address $dApp")) + (extractedCall, extractedPayments) = ABIConverter(scriptInfo.script).decodeFunctionCall(hexCallData) + } yield + new InvokeScriptTransactionLike { + override def funcCall: Terms.FUNCTION_CALL = extractedCall + override def payments: Seq[InvokeScriptTransaction.Payment] = extractedPayments + override def id: Coeval[ByteStr] = tx.id + override def dApp: AddressOrAlias = Invocation.this.dApp + override val sender: PublicKey = tx.signerPublicKey() + override def root: InvokeScriptTransactionLike = this + override def assetFee: (Asset, TxTimestamp) = tx.assetFee + override def timestamp: TxTimestamp = tx.timestamp + override def chainId: TxVersion = tx.chainId + override def checkedAssets: Seq[Asset.IssuedAsset] = this.paymentAssets + override val tpe: TransactionType = TransactionType.InvokeScript + } + } + + implicit object EthereumTransactionValidator extends TxValidator[EthereumTransaction] { + override def validate(tx: EthereumTransaction): ValidatedV[EthereumTransaction] = TxConstraints.seq(tx)( + TxConstraints.fee(tx.underlying.getGasLimit.longValueExact()), + TxConstraints + .positiveOrZeroAmount((BigInt(tx.underlying.getValue) / AmountMultiplier).bigInteger.longValueExact(), "waves"), + TxConstraints.cond(tx.underlying.getGasPrice == GasPrice, GenericError("Gas price must be 10 Gwei")), + TxConstraints.cond( + tx.underlying.getValue != BigInteger.ZERO || EthEncoding.cleanHexPrefix(tx.underlying.getData).nonEmpty, + GenericError("Transaction cancellation is not supported") + ), + TxConstraints + .cond(tx.underlying.getData.isEmpty || BigInt(tx.underlying.getValue) == 0, GenericError("Transaction should have either data or value")), + tx.payload match { + case Transfer(tokenAddress, amount, _) => + TxConstraints.positiveAmount(amount, tokenAddress.fold("waves")(erc20 => EthEncoding.toHexString(erc20.arr))) + case Invocation(_, _) => TxConstraints.seq(tx)() + } + ) + } + + val GasPrice: BigInteger = Convert.toWei("10", Convert.Unit.GWEI).toBigInteger + + val AmountMultiplier = 10000000000L + + private val decodeMethod = { + val m = classOf[TypeDecoder].getDeclaredMethod("decode", classOf[String], classOf[Int], classOf[Class[_]]) + m.setAccessible(true) + m + } + + private def decode[A](source: String, offset: Int)(implicit ct: ClassTag[A]): A = + decodeMethod.invoke(null, source, offset, ct.runtimeClass.asInstanceOf[Class[A]]).asInstanceOf[A] + + private val encodeMethod = { + val m = classOf[TransactionEncoder].getDeclaredMethod("encode", classOf[RawTransaction], classOf[SignatureData]) + m.setAccessible(true) + m + } + + private def encodeTransaction(tx: RawTransaction, signatureData: SignatureData): Array[Byte] = + encodeMethod.invoke(null, tx, signatureData).asInstanceOf[Array[Byte]] + + def apply(bytes: Array[Byte]): Either[ValidationError, EthereumTransaction] = + apply(TransactionDecoder.decode(EthEncoding.toHexString(bytes)).asInstanceOf[SignedRawTransaction]) + + val ERC20TransferPrefix: String = "a9059cbb" + + def extractPayload(underlying: RawTransaction): Payload = { + val hexData = EthEncoding.cleanHexPrefix(underlying.getData) + val recipientAddress = ByteStr(EthEncoding.toBytes(underlying.getTo)) + if (hexData.isEmpty) { + Transfer( + None, + (BigInt(underlying.getValue) / AmountMultiplier).bigInteger.longValueExact(), + Address(recipientAddress.arr) + ) + } else if (hexData.startsWith(ERC20TransferPrefix)) { + val recipient = decode[EthAddress](hexData, 8) + val amount = decode[Uint256](hexData, 72) + Transfer( + Some(ERC20Address(recipientAddress)), + amount.getValue.longValueExact(), + Address(EthEncoding.toBytes(recipient.toString)) + ) + } else Invocation(Address(recipientAddress.arr), hexData) + } + + def apply(underlying: RawTransaction): Either[ValidationError, EthereumTransaction] = + new EthereumTransaction( + extractPayload(underlying), + underlying, + new SignatureData(Array.emptyByteArray, Array.emptyByteArray, Array.emptyByteArray), + AddressScheme.current.chainId + ).validatedEither + + def apply(underlying: SignedRawTransaction): Either[ValidationError, EthereumTransaction] = + new EthereumTransaction( + extractPayload(underlying), + underlying, + underlying.getSignatureData, + Option(underlying.getChainId).fold(AddressScheme.current.chainId)(_.toByte) + ).validatedEither +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/FastHashId.scala b/node/src/main/scala/com/wavesplatform/transaction/FastHashId.scala index d64c7ac6ec8..a2fccd6188d 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/FastHashId.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/FastHashId.scala @@ -4,12 +4,6 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto import monix.eval.Coeval -trait FastHashId extends ProvenTransaction { - val id: Coeval[ByteStr] = Coeval.evalOnce(FastHashId.create(this.bodyBytes())) -} - -object FastHashId { - def create(bodyBytes: Array[Byte]): ByteStr = { - ByteStr(crypto.fastHash(bodyBytes)) - } +trait FastHashId extends Proven { + val id: Coeval[ByteStr] = Coeval.evalOnce(ByteStr(crypto.fastHash(bodyBytes()))) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/GenesisTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/GenesisTransaction.scala index 5248a1af89b..f96431b7c78 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/GenesisTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/GenesisTransaction.scala @@ -1,5 +1,7 @@ package com.wavesplatform.transaction +import scala.util.Try + import cats.data.Validated import com.google.common.primitives.{Bytes, Ints, Longs} import com.wavesplatform.account.Address @@ -12,17 +14,14 @@ import com.wavesplatform.transaction.validation.{TxConstraints, TxValidator} import monix.eval.Coeval import play.api.libs.json.JsObject -import scala.util.Try - case class GenesisTransaction private (recipient: Address, amount: TxAmount, timestamp: TxTimestamp, signature: ByteStr, chainId: Byte) - extends Transaction { - override val builder = GenesisTransaction + extends Transaction(TransactionType.Genesis) { override val assetFee: (Asset, Long) = (Waves, 0) override val id: Coeval[ByteStr] = Coeval.evalOnce(signature) - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val bytes: Coeval[Array[Byte]] = bodyBytes - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) + val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(GenesisTxSerializer.toBytes(this)) + override val bytes: Coeval[Array[Byte]] = bodyBytes + override val json: Coeval[JsObject] = Coeval.evalOnce(GenesisTxSerializer.toJson(this)) } object GenesisTransaction extends TransactionParser { @@ -31,10 +30,8 @@ object GenesisTransaction extends TransactionParser { override val typeId: TxType = 1: Byte override val supportedVersions: Set[TxVersion] = Set(1) - val serializer = GenesisTxSerializer - override def parseBytes(bytes: Array[TxVersion]): Try[GenesisTransaction] = - serializer.parseBytes(bytes) + GenesisTxSerializer.parseBytes(bytes) implicit val validator: TxValidator[GenesisTransaction] = tx => diff --git a/node/src/main/scala/com/wavesplatform/transaction/LegacyPBSwitch.scala b/node/src/main/scala/com/wavesplatform/transaction/PBSince.scala similarity index 55% rename from node/src/main/scala/com/wavesplatform/transaction/LegacyPBSwitch.scala rename to node/src/main/scala/com/wavesplatform/transaction/PBSince.scala index 05ec831def5..69ebdc017e6 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/LegacyPBSwitch.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/PBSince.scala @@ -2,7 +2,7 @@ package com.wavesplatform.transaction import com.wavesplatform.protobuf.transaction.PBTransactions -trait LegacyPBSwitch { self: Transaction with VersionedTransaction => +trait PBSince { self: Transaction with VersionedTransaction => def protobufVersion: TxVersion final def isProtobufVersion: Boolean = self.version >= protobufVersion @@ -10,12 +10,16 @@ trait LegacyPBSwitch { self: Transaction with VersionedTransaction => if (isProtobufVersion) PBTransactions.protobuf(self).serializedSize else bytes().length } -object LegacyPBSwitch { - trait V2 extends LegacyPBSwitch { self: Transaction with VersionedTransaction => +object PBSince { + trait V1 extends PBSince { self: Transaction with VersionedTransaction => + override def protobufVersion: TxVersion = TxVersion.V1 + } + + trait V2 extends PBSince { self: Transaction with VersionedTransaction => override def protobufVersion: TxVersion = TxVersion.V2 } - trait V3 extends LegacyPBSwitch { self: Transaction with VersionedTransaction => + trait V3 extends PBSince { self: Transaction with VersionedTransaction => override def protobufVersion: TxVersion = TxVersion.V3 } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/PaymentTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/PaymentTransaction.scala index c606170a5f6..934a1efd4e7 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/PaymentTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/PaymentTransaction.scala @@ -1,5 +1,7 @@ package com.wavesplatform.transaction +import scala.util.Try + import com.wavesplatform.account.{Address, KeyPair, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto @@ -10,8 +12,6 @@ import com.wavesplatform.transaction.validation.impl.PaymentTxValidator import monix.eval.Coeval import play.api.libs.json.JsObject -import scala.util.Try - case class PaymentTransaction private ( sender: PublicKey, recipient: Address, @@ -20,15 +20,21 @@ case class PaymentTransaction private ( timestamp: TxTimestamp, signature: ByteStr, chainId: Byte -) extends SignedTransaction +) extends Transaction(TransactionType.Payment) + with Signed + with ProvenTransaction with TxWithFee.InWaves { - override val builder = PaymentTransaction + val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(PaymentTxSerializer.bodyBytes(this)) + + def proofs: Proofs = Proofs(signature) + + val signatureValid: Coeval[Boolean] = Coeval.evalOnce(crypto.verify(signature, bodyBytes(), sender)) + override val id: Coeval[ByteStr] = Coeval.evalOnce(signature) - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(PaymentTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(PaymentTxSerializer.toJson(this)) } object PaymentTransaction extends TransactionParser { @@ -37,18 +43,15 @@ object PaymentTransaction extends TransactionParser { override val typeId: TxType = 2: Byte override val supportedVersions: Set[TxVersion] = Set(1) - val serializer = PaymentTxSerializer - override def parseBytes(bytes: Array[TxVersion]): Try[PaymentTransaction] = - serializer.parseBytes(bytes) + PaymentTxSerializer.parseBytes(bytes) implicit val validator: TxValidator[PaymentTransaction] = PaymentTxValidator - def create(sender: KeyPair, recipient: Address, amount: Long, fee: Long, timestamp: Long): Either[ValidationError, PaymentTransaction] = { + def create(sender: KeyPair, recipient: Address, amount: Long, fee: Long, timestamp: Long): Either[ValidationError, PaymentTransaction] = create(sender.publicKey, recipient, amount, fee, timestamp, ByteStr.empty).map(unsigned => { unsigned.copy(signature = crypto.sign(sender.privateKey, unsigned.bodyBytes())) }) - } def create( sender: PublicKey, diff --git a/node/src/main/scala/com/wavesplatform/transaction/ProtobufOnly.scala b/node/src/main/scala/com/wavesplatform/transaction/ProtobufOnly.scala deleted file mode 100644 index 07da0f60f97..00000000000 --- a/node/src/main/scala/com/wavesplatform/transaction/ProtobufOnly.scala +++ /dev/null @@ -1,3 +0,0 @@ -package com.wavesplatform.transaction - -trait ProtobufOnly // Marker trait diff --git a/node/src/main/scala/com/wavesplatform/transaction/ProvenTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/ProvenTransaction.scala index 174fda1bea9..0357e4e2b39 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/ProvenTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/ProvenTransaction.scala @@ -1,20 +1,5 @@ package com.wavesplatform.transaction -import play.api.libs.json._ +trait ProvenTransaction extends Proven { this: Transaction => -trait ProvenTransaction extends Transaction with Proven { - - // TODO: Delete (use ProvenTXJson) - protected def proofField: Seq[(String, JsValue)] = Seq("proofs" -> JsArray(this.proofs.proofs.map(p => JsString(p.toString)))) - - protected def jsonBase(): JsObject = - Json.obj( - "type" -> typeId, - "id" -> id().toString, - "sender" -> sender.toAddress, - "senderPublicKey" -> sender, - "fee" -> assetFee._2, - "feeAssetId" -> assetFee._1.maybeBase58Repr, - "timestamp" -> timestamp - ) ++ JsObject(proofField) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/SigProofsSwitch.scala b/node/src/main/scala/com/wavesplatform/transaction/SigProofsSwitch.scala index b41dffa4b7f..d4241a18862 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/SigProofsSwitch.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/SigProofsSwitch.scala @@ -1,6 +1,6 @@ package com.wavesplatform.transaction -trait SigProofsSwitch extends ProvenTransaction { self: VersionedTransaction => +trait SigProofsSwitch extends ProvenTransaction { self: Transaction with VersionedTransaction => def usesLegacySignature: Boolean = self.version == Transaction.V1 } diff --git a/node/src/main/scala/com/wavesplatform/transaction/SignedTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/SignedTransaction.scala deleted file mode 100644 index 8f559ec4404..00000000000 --- a/node/src/main/scala/com/wavesplatform/transaction/SignedTransaction.scala +++ /dev/null @@ -1,20 +0,0 @@ -package com.wavesplatform.transaction - -import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.crypto -import monix.eval.Coeval -import play.api.libs.json._ - -trait SignedTransaction extends ProvenTransaction with Signed { - - protected override def proofField: Seq[(String, JsValue)] = { - val sig = JsString(this.signature.toString) - Seq("signature" -> sig, "proofs" -> JsArray(Seq(sig))) - } - - val signature: ByteStr - - def proofs: Proofs = Proofs(signature) - - val signatureValid: Coeval[Boolean] = Coeval.evalOnce(crypto.verify(signature, bodyBytes(), sender)) -} diff --git a/node/src/main/scala/com/wavesplatform/transaction/Transaction.scala b/node/src/main/scala/com/wavesplatform/transaction/Transaction.scala index c8c86c5a03a..a27ae0912d0 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/Transaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/Transaction.scala @@ -2,21 +2,32 @@ package com.wavesplatform.transaction import com.wavesplatform.common.state.ByteStr import com.wavesplatform.protobuf.transaction.PBTransactions +import com.wavesplatform.state.Blockchain import com.wavesplatform.transaction.Asset.IssuedAsset import monix.eval.Coeval import play.api.libs.json.JsObject -trait Transaction { - val id: Coeval[ByteStr] - - def typeId: Byte = builder.typeId - def builder: TransactionParser +trait TransactionBase { def assetFee: (Asset, Long) def timestamp: Long def chainId: Byte + def id: Coeval[ByteStr] + def checkedAssets: Seq[IssuedAsset] + val tpe: TransactionType.TransactionType +} + +object TransactionBase { + implicit class TBExt(val t: TransactionBase) extends AnyVal { + def fee: Long = t.assetFee._2 + def feeAssetId: Asset = t.assetFee._1 + def smartAssets(blockchain: Blockchain): Seq[IssuedAsset] = t.checkedAssets.filter(blockchain.hasAssetScript) + } +} +abstract class Transaction(val tpe: TransactionType.TransactionType, val checkedAssets: Seq[IssuedAsset] = Nil) extends TransactionBase { def bytesSize: Int = bytes().length - val protoSize: Coeval[Int] = Coeval(PBTransactions.protobuf(this).serializedSize) + lazy val protoSize: Coeval[Int] = Coeval(PBTransactions.protobuf(this).serializedSize) + val bodyBytes: Coeval[Array[Byte]] val bytes: Coeval[Array[Byte]] val json: Coeval[JsObject] @@ -28,13 +39,10 @@ trait Transaction { } override def hashCode(): Int = id().hashCode() - - val bodyBytes: Coeval[Array[Byte]] - def checkedAssets: Seq[IssuedAsset] = Nil } object Transaction { - type Type = Byte + type Type = TransactionType.TransactionType val V1: TxVersion = TxVersion.V1 val V2: TxVersion = TxVersion.V2 diff --git a/node/src/main/scala/com/wavesplatform/transaction/TransactionFactory.scala b/node/src/main/scala/com/wavesplatform/transaction/TransactionFactory.scala index b1362a36c5d..130a0344290 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/TransactionFactory.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/TransactionFactory.scala @@ -1,17 +1,17 @@ package com.wavesplatform.transaction import com.wavesplatform.account._ +import com.wavesplatform.api.http.requests._ import com.wavesplatform.api.http.requests.DataRequest._ import com.wavesplatform.api.http.requests.InvokeExpressionRequest._ import com.wavesplatform.api.http.requests.SponsorFeeRequest._ -import com.wavesplatform.api.http.requests._ import com.wavesplatform.api.http.versionReads import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.transaction.Asset.IssuedAsset -import com.wavesplatform.transaction.TxValidationError.{GenericError, UnsupportedTypeAndVersion, WrongChain} +import com.wavesplatform.transaction.TxValidationError.{GenericError, UnsupportedTransactionType, UnsupportedTypeAndVersion, WrongChain} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange._ import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} @@ -287,17 +287,20 @@ object TransactionFactory { signer <- if (request.sender == signerAddress) Right(sender) else wallet.findPrivateKey(signerAddress) contract <- AddressOrAlias.fromString(request.dApp) - tx <- InvokeScriptTransaction.signed( - request.version.getOrElse(1.toByte), - sender.publicKey, - contract, - request.call.map(fCallPart => InvokeScriptRequest.buildFunctionCall(fCallPart)), - request.payment, - request.fee, - Asset.fromCompatId(request.feeAssetId.map(s => ByteStr.decodeBase58(s).get)), - request.timestamp.getOrElse(time.getTimestamp()), - signer.privateKey - ) + tx <- InvokeScriptTransaction + .create( + request.version.getOrElse(1.toByte), + sender.publicKey, + contract, + request.call.map(fCallPart => InvokeScriptRequest.buildFunctionCall(fCallPart)), + request.payment, + request.fee, + Asset.fromCompatId(request.feeAssetId.map(s => ByteStr.decodeBase58(s).get)), + request.timestamp.getOrElse(time.getTimestamp()), + Proofs.empty, + request.chainId.getOrElse(AddressScheme.current.chainId) + ) + .map(_.signWith(signer.privateKey)) } yield tx def invokeScript(request: InvokeScriptRequest, sender: PublicKey): Either[ValidationError, InvokeScriptTransaction] = @@ -313,7 +316,8 @@ object TransactionFactory { request.fee, Asset.fromCompatId(request.feeAssetId.map(s => ByteStr.decodeBase58(s).get)), request.timestamp.getOrElse(0), - Proofs.empty + Proofs.empty, + request.chainId.getOrElse(AddressScheme.current.chainId) ) } yield tx @@ -384,31 +388,33 @@ object TransactionFactory { val typeId = (jsv \ "type").as[Byte] val version = (jsv \ "version").asOpt[Byte](versionReads).getOrElse(1.toByte) - val pf: PartialFunction[TransactionParser, Either[ValidationError, Transaction]] = { - case TransferTransaction => jsv.as[TransferRequest].toTx - case CreateAliasTransaction => jsv.as[CreateAliasRequest].toTx - case LeaseTransaction => jsv.as[LeaseRequest].toTx - case LeaseCancelTransaction => jsv.as[LeaseCancelRequest].toTx - case IssueTransaction => jsv.as[IssueRequest].toTx - case ReissueTransaction => jsv.as[ReissueRequest].toTx - case BurnTransaction => jsv.as[BurnRequest].toTx - case MassTransferTransaction => jsv.as[SignedMassTransferRequest].toTx - case DataTransaction => jsv.as[SignedDataRequest].toTx - case InvokeScriptTransaction => jsv.as[SignedInvokeScriptRequest].toTx - case SetScriptTransaction => jsv.as[SignedSetScriptRequest].toTx - case SetAssetScriptTransaction => jsv.as[SignedSetAssetScriptRequest].toTx - case SponsorFeeTransaction => jsv.as[SignedSponsorFeeRequest].toTx - case ExchangeTransaction => jsv.as[ExchangeRequest].toTx - case UpdateAssetInfoTransaction => jsv.as[SignedUpdateAssetInfoRequest].toTx - case InvokeExpressionTransaction => jsv.as[SignedInvokeExpressionRequest].toTx + val pf: PartialFunction[TransactionType.TransactionType, Either[ValidationError, Transaction]] = { + case TransactionType.Transfer => jsv.as[TransferRequest].toTx + case TransactionType.CreateAlias => jsv.as[CreateAliasRequest].toTx + case TransactionType.Lease => jsv.as[LeaseRequest].toTx + case TransactionType.LeaseCancel => jsv.as[LeaseCancelRequest].toTx + case TransactionType.Issue => jsv.as[IssueRequest].toTx + case TransactionType.Reissue => jsv.as[ReissueRequest].toTx + case TransactionType.Burn => jsv.as[BurnRequest].toTx + case TransactionType.MassTransfer => jsv.as[SignedMassTransferRequest].toTx + case TransactionType.Data => jsv.as[SignedDataRequest].toTx + case TransactionType.InvokeScript => jsv.as[SignedInvokeScriptRequest].toTx + case TransactionType.SetScript => jsv.as[SignedSetScriptRequest].toTx + case TransactionType.SetAssetScript => jsv.as[SignedSetAssetScriptRequest].toTx + case TransactionType.SponsorFee => jsv.as[SignedSponsorFeeRequest].toTx + case TransactionType.Exchange => jsv.as[ExchangeRequest].toTx + case TransactionType.UpdateAssetInfo => jsv.as[SignedUpdateAssetInfoRequest].toTx + case TransactionType.InvokeExpression => jsv.as[SignedInvokeExpressionRequest].toTx } - TransactionParsers.by(typeId, version) match { - case _ if chainId.exists(_ != AddressScheme.current.chainId) => - Left(WrongChain(AddressScheme.current.chainId, chainId.get)) - case Some(txType) if pf.isDefinedAt(txType) => pf(txType) - case _ => Left(UnsupportedTypeAndVersion(typeId, version)) - } + if (chainId.exists(_ != AddressScheme.current.chainId)) { + Left(WrongChain(AddressScheme.current.chainId, chainId.get)) + } else + try pf(TransactionType(typeId)) + catch { + case _: NoSuchElementException => Left(UnsupportedTypeAndVersion(typeId, version)) + case _: MatchError => Left(UnsupportedTransactionType) + } } def parseRequestAndSign(wallet: Wallet, signerAddress: String, time: Time, jsv: JsObject): Either[ValidationError, Transaction] = { @@ -423,25 +429,23 @@ object TransactionFactory { val version = value getOrElse (1: Byte) val txJson = jsv ++ Json.obj("version" -> version) - TransactionParsers.by(typeId, version) match { - case None => Left(UnsupportedTypeAndVersion(typeId, version)) - case Some(x) => - x match { - case TransferTransaction => TransactionFactory.transferAsset(txJson.as[TransferRequest], wallet, signerAddress, time) - case CreateAliasTransaction => TransactionFactory.createAlias(txJson.as[CreateAliasRequest], wallet, signerAddress, time) - case LeaseTransaction => TransactionFactory.lease(txJson.as[LeaseRequest], wallet, signerAddress, time) - case LeaseCancelTransaction => TransactionFactory.leaseCancel(txJson.as[LeaseCancelRequest], wallet, signerAddress, time) - case IssueTransaction => TransactionFactory.issue(txJson.as[IssueRequest], wallet, signerAddress, time) - case ReissueTransaction => TransactionFactory.reissue(txJson.as[ReissueRequest], wallet, signerAddress, time) - case BurnTransaction => TransactionFactory.burn(txJson.as[BurnRequest], wallet, signerAddress, time) - case MassTransferTransaction => TransactionFactory.massTransferAsset(txJson.as[MassTransferRequest], wallet, signerAddress, time) - case DataTransaction => TransactionFactory.data(txJson.as[DataRequest], wallet, signerAddress, time) - case InvokeScriptTransaction => TransactionFactory.invokeScript(txJson.as[InvokeScriptRequest], wallet, signerAddress, time) - case SetScriptTransaction => TransactionFactory.setScript(txJson.as[SetScriptRequest], wallet, signerAddress, time) - case SetAssetScriptTransaction => TransactionFactory.setAssetScript(txJson.as[SetAssetScriptRequest], wallet, signerAddress, time) - case SponsorFeeTransaction => TransactionFactory.sponsor(txJson.as[SponsorFeeRequest], wallet, signerAddress, time) - case _ => Left(TxValidationError.UnsupportedTransactionType) - } + try (TransactionType(typeId): @unchecked) match { + case TransactionType.Transfer => TransactionFactory.transferAsset(txJson.as[TransferRequest], wallet, signerAddress, time) + case TransactionType.CreateAlias => TransactionFactory.createAlias(txJson.as[CreateAliasRequest], wallet, signerAddress, time) + case TransactionType.Lease => TransactionFactory.lease(txJson.as[LeaseRequest], wallet, signerAddress, time) + case TransactionType.LeaseCancel => TransactionFactory.leaseCancel(txJson.as[LeaseCancelRequest], wallet, signerAddress, time) + case TransactionType.Issue => TransactionFactory.issue(txJson.as[IssueRequest], wallet, signerAddress, time) + case TransactionType.Reissue => TransactionFactory.reissue(txJson.as[ReissueRequest], wallet, signerAddress, time) + case TransactionType.Burn => TransactionFactory.burn(txJson.as[BurnRequest], wallet, signerAddress, time) + case TransactionType.MassTransfer => TransactionFactory.massTransferAsset(txJson.as[MassTransferRequest], wallet, signerAddress, time) + case TransactionType.Data => TransactionFactory.data(txJson.as[DataRequest], wallet, signerAddress, time) + case TransactionType.InvokeScript => TransactionFactory.invokeScript(txJson.as[InvokeScriptRequest], wallet, signerAddress, time) + case TransactionType.SetScript => TransactionFactory.setScript(txJson.as[SetScriptRequest], wallet, signerAddress, time) + case TransactionType.SetAssetScript => TransactionFactory.setAssetScript(txJson.as[SetAssetScriptRequest], wallet, signerAddress, time) + case TransactionType.SponsorFee => TransactionFactory.sponsor(txJson.as[SponsorFeeRequest], wallet, signerAddress, time) + } catch { + case _: NoSuchElementException => Left(UnsupportedTypeAndVersion(typeId, version)) + case _: MatchError => Left(UnsupportedTransactionType) } } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/TransactionParsers.scala b/node/src/main/scala/com/wavesplatform/transaction/TransactionParsers.scala index 319f946118e..7cfd0b4c34d 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/TransactionParsers.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/TransactionParsers.scala @@ -39,7 +39,6 @@ object TransactionParsers { SetAssetScriptTransaction, InvokeScriptTransaction, TransferTransaction, - UpdateAssetInfoTransaction, InvokeExpressionTransaction ).flatMap { x => x.supportedVersions.map { version => diff --git a/node/src/main/scala/com/wavesplatform/transaction/TransactionType.scala b/node/src/main/scala/com/wavesplatform/transaction/TransactionType.scala new file mode 100644 index 00000000000..c1ca3e49721 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/TransactionType.scala @@ -0,0 +1,28 @@ +package com.wavesplatform.transaction + +object TransactionType extends Enumeration(1) { + type TransactionType = Value + val Genesis, + Payment, + Issue, + Transfer, + Reissue, + Burn, + Exchange, + Lease, + LeaseCancel, + CreateAlias, + MassTransfer, + Data, + SetScript, + SponsorFee, + SetAssetScript, + InvokeScript, + UpdateAssetInfo, + InvokeExpression, + Ethereum = Value + + implicit class ValueExt(val tpe: TransactionType) extends AnyVal { + def transactionName: String = s"${tpe}Transaction" + } +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/TxValidationError.scala b/node/src/main/scala/com/wavesplatform/transaction/TxValidationError.scala index fcd665d7f50..e140265c4e5 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/TxValidationError.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/TxValidationError.scala @@ -38,7 +38,6 @@ object TxValidationError { case class Mistiming(err: String) extends ValidationError case class BlockAppendError(err: String, b: Block) extends ValidationError case class ActivationError(err: String) extends ValidationError - case class UnsupportedVersion(version: Int) extends ValidationError case class GenericError(err: String) extends ValidationError object GenericError { diff --git a/node/src/main/scala/com/wavesplatform/transaction/VersionedTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/VersionedTransaction.scala index 433e8563ee3..79a93b97a58 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/VersionedTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/VersionedTransaction.scala @@ -3,3 +3,9 @@ package com.wavesplatform.transaction trait VersionedTransaction { def version: TxVersion } + +object VersionedTransaction { + trait ConstV1 extends VersionedTransaction { + def version: TxVersion = TxVersion.V1 + } +} \ No newline at end of file diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/BurnTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/BurnTransaction.scala index 54d5bd1bb02..83a7451e419 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/BurnTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/BurnTransaction.scala @@ -22,20 +22,16 @@ final case class BurnTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends ProvenTransaction +) extends Transaction(TransactionType.Burn, Seq(asset)) with ProvenTransaction with VersionedTransaction with SigProofsSwitch with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V3 { - - override def builder: TransactionParser = BurnTransaction + with PBSince.V3 { override val bodyBytes: Coeval[Array[Byte]] = BurnTxSerializer.bodyBytes(this) override val bytes: Coeval[Array[Byte]] = BurnTxSerializer.toBytes(this) override val json: Coeval[JsObject] = BurnTxSerializer.toJson(this) - - override def checkedAssets: Seq[IssuedAsset] = Seq(asset) } object BurnTransaction extends TransactionParser { diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/IssueTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/IssueTransaction.scala index 00d6bfed204..d63fd49a1a7 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/IssueTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/IssueTransaction.scala @@ -29,19 +29,17 @@ case class IssueTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends VersionedTransaction +) extends Transaction(TransactionType.Issue) + with VersionedTransaction with ProvenTransaction with FastHashId with SigProofsSwitch with TxWithFee.InWaves - with LegacyPBSwitch.V3 { + with PBSince.V3 { - //noinspection TypeAnnotation,ScalaStyle - override def builder = IssueTransaction - - override val bodyBytes: Coeval[Array[TxType]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[TxType]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) + override val bodyBytes: Coeval[Array[TxType]] = Coeval.evalOnce(IssueTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[TxType]] = Coeval.evalOnce(IssueTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(IssueTxSerializer.toJson(this)) } object IssueTransaction extends TransactionParser { @@ -55,8 +53,6 @@ object IssueTransaction extends TransactionParser { override val typeId: TxType = 3: Byte override val supportedVersions: Set[TxVersion] = Set(1, 2, 3) - val serializer = IssueTxSerializer - implicit val validator: TxValidator[IssueTransaction] = IssueTxValidator implicit def sign(tx: IssueTransaction, privateKey: PrivateKey): IssueTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) @@ -150,10 +146,10 @@ object IssueTransaction extends TransactionParser { ): Either[ValidationError, IssueTransaction] = signed(version, sender.publicKey, name, description, quantity, decimals, reissuable, script, fee, timestamp, sender.privateKey) - override def parseBytes(bytes: Array[TxType]): Try[IssueTransaction] = serializer.parseBytes(bytes) + override def parseBytes(bytes: Array[TxType]): Try[IssueTransaction] = IssueTxSerializer.parseBytes(bytes) implicit class IssueTransactionExt(private val tx: IssueTransaction) extends AnyVal { def asset: IssuedAsset = IssuedAsset(assetId) - def assetId: ByteStr = tx.id() + def assetId: ByteStr = tx.id() } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/ReissueTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/ReissueTransaction.scala index 2598d36b367..82e99c88eef 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/ReissueTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/ReissueTransaction.scala @@ -23,21 +23,17 @@ case class ReissueTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends VersionedTransaction +) extends Transaction(TransactionType.Reissue, Seq(asset)) + with VersionedTransaction with ProvenTransaction with SigProofsSwitch with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V3 { + with PBSince.V3 { - //noinspection TypeAnnotation - override val builder = ReissueTransaction - - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) - - override def checkedAssets: Seq[IssuedAsset] = Seq(asset) + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(ReissueTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(ReissueTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(ReissueTxSerializer.toJson(this)) } object ReissueTransaction extends TransactionParser { @@ -50,10 +46,8 @@ object ReissueTransaction extends TransactionParser { implicit def sign(tx: ReissueTransaction, privateKey: PrivateKey): ReissueTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - val serializer = ReissueTxSerializer - override def parseBytes(bytes: Array[TxVersion]): Try[ReissueTransaction] = - serializer.parseBytes(bytes) + ReissueTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/SetAssetScriptTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/SetAssetScriptTransaction.scala index b6b83170874..36eb160876e 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/SetAssetScriptTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/SetAssetScriptTransaction.scala @@ -23,20 +23,16 @@ case class SetAssetScriptTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends VersionedTransaction +) extends Transaction(TransactionType.SetAssetScript, Seq(asset)) + with VersionedTransaction with ProvenTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V2 { + with PBSince.V2 { - //noinspection TypeAnnotation - override val builder = SetAssetScriptTransaction - - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) - - override val checkedAssets: Seq[IssuedAsset] = Seq(asset) + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetAssetScriptTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetAssetScriptTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(SetAssetScriptTxSerializer.toJson(this)) } object SetAssetScriptTransaction extends TransactionParser { diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/SponsorFeeTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/SponsorFeeTransaction.scala index d922c03e3dc..66f74fa4858 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/SponsorFeeTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/SponsorFeeTransaction.scala @@ -22,19 +22,15 @@ case class SponsorFeeTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends ProvenTransaction +) extends Transaction(TransactionType.SponsorFee, Seq(asset)) with ProvenTransaction with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V2 { + with PBSince.V2 { - override val builder: SponsorFeeTransaction.type = SponsorFeeTransaction - - val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) - - override val checkedAssets: Seq[IssuedAsset] = Seq(asset) + val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(SponsorFeeTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(SponsorFeeTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(SponsorFeeTxSerializer.toJson(this)) } object SponsorFeeTransaction extends TransactionParser { @@ -48,10 +44,8 @@ object SponsorFeeTransaction extends TransactionParser { implicit def sign(tx: SponsorFeeTransaction, privateKey: PrivateKey): SponsorFeeTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - val serializer = SponsorFeeTxSerializer - override def parseBytes(bytes: Array[TxVersion]): Try[SponsorFeeTransaction] = - serializer.parseBytes(bytes) + SponsorFeeTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/UpdateAssetInfoTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/UpdateAssetInfoTransaction.scala index c368cd6d791..9ff1bcfdea8 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/UpdateAssetInfoTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/UpdateAssetInfoTransaction.scala @@ -12,8 +12,6 @@ import com.wavesplatform.transaction.validation.impl.UpdateAssetInfoTxValidator import monix.eval.Coeval import play.api.libs.json.{JsObject, Json} -import scala.util.{Failure, Success, Try} - case class UpdateAssetInfoTransaction( version: TxVersion, sender: PublicKey, @@ -25,15 +23,14 @@ case class UpdateAssetInfoTransaction( feeAsset: Asset, proofs: Proofs, chainId: Byte -) extends VersionedTransaction +) extends Transaction(TransactionType.UpdateAssetInfo, Seq(assetId)) + with VersionedTransaction with FastHashId with ProvenTransaction - with ProtobufOnly { self => + with PBSince.V1 { self => override def assetFee: (Asset, TxAmount) = (feeAsset, feeAmount) - override def builder: UpdateAssetInfoTransaction.type = UpdateAssetInfoTransaction - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(PBTransactionSerializer.bodyBytes(self)) override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(PBTransactionSerializer.bytes(self)) @@ -46,29 +43,16 @@ case class UpdateAssetInfoTransaction( "description" -> self.description ) ) - - override def checkedAssets: Seq[IssuedAsset] = Seq(assetId) } -object UpdateAssetInfoTransaction extends TransactionParser { - type TransactionT = UpdateAssetInfoTransaction - - override val typeId: TxType = 17: Byte - override val supportedVersions: Set[TxVersion] = Set(1) +object UpdateAssetInfoTransaction { + val supportedVersions: Set[TxVersion] = Set(1) implicit def sign(tx: UpdateAssetInfoTransaction, privateKey: PrivateKey): UpdateAssetInfoTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) implicit val validator: TxValidator[UpdateAssetInfoTransaction] = UpdateAssetInfoTxValidator - override def parseBytes(bytes: Array[TxType]): Try[UpdateAssetInfoTransaction] = - PBTransactionSerializer - .parseBytes(bytes) - .flatMap { - case tx: UpdateAssetInfoTransaction => Success(tx) - case tx: Transaction => Failure(UnexpectedTransaction(typeId, tx.typeId)) - } - def create( version: Byte, sender: PublicKey, diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/AssetPair.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/AssetPair.scala index ae13afce2e2..f57d3ec17f5 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/AssetPair.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/AssetPair.scala @@ -1,20 +1,19 @@ package com.wavesplatform.transaction.assets.exchange +import scala.util.{Failure, Success, Try} + import com.google.common.primitives.Bytes import com.wavesplatform.common.state.ByteStr import com.wavesplatform.serialization.Deser -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.exchange.Validation.booleanOperators import net.ceedubs.ficus.readers.ValueReader import play.api.libs.json.{JsObject, Json} -import scala.util.{Failure, Success, Try} - - case class AssetPair( - amountAsset: Asset, - priceAsset: Asset + amountAsset: Asset, + priceAsset: Asset ) { import AssetPair._ @@ -28,14 +27,17 @@ case class AssetPair( "amountAsset" -> amountAsset.maybeBase58Repr, "priceAsset" -> priceAsset.maybeBase58Repr ) - def reverse = AssetPair(priceAsset, amountAsset) - + def reverse: AssetPair = AssetPair(priceAsset, amountAsset) def assets: Set[Asset] = Set(amountAsset, priceAsset) } object AssetPair { val WavesName = "WAVES" + implicit class AssetPairExt(val p: AssetPair) extends AnyVal { + def checkedAssets: Seq[IssuedAsset] = Seq(p.priceAsset, p.amountAsset).collect { case ia: Asset.IssuedAsset => ia } + } + def assetIdStr(aid: Asset): String = aid match { case Waves => WavesName case IssuedAsset(id) => id.toString diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/EthOrders.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/EthOrders.scala new file mode 100644 index 00000000000..144d14431a7 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/EthOrders.scala @@ -0,0 +1,162 @@ +package com.wavesplatform.transaction.assets.exchange + +import java.math.BigInteger +import java.nio.ByteBuffer + +import com.wavesplatform.account.{AddressScheme, PublicKey} +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.transaction.Asset +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import org.bouncycastle.util.encoders.Hex +import org.web3j.crypto.{ECDSASignature, Sign, StructuredDataEncoder} +import org.web3j.crypto.Sign.SignatureData +import play.api.libs.json.{JsObject, Json} + +object EthOrders extends App { + def toEip712Json(order: Order): JsObject = { + def encodeAsset(asset: Asset): String = asset match { + case IssuedAsset(id) => id.toString + case Waves => "WAVES" + } + + def encodeOrderType(orderType: OrderType): String = orderType match { + case OrderType.BUY => "BUY" + case OrderType.SELL => "SELL" + } + + val message = Json.obj( + "version" -> order.version.toInt, + "matcherPublicKey" -> order.matcherPublicKey.toString, + "amountAsset" -> encodeAsset(order.assetPair.amountAsset), + "priceAsset" -> encodeAsset(order.assetPair.priceAsset), + "orderType" -> encodeOrderType(order.orderType), + "amount" -> order.amount, + "price" -> order.price, + "timestamp" -> order.timestamp, + "expiration" -> order.expiration, + "matcherFee" -> order.matcherFee, + "matcherFeeAssetId" -> encodeAsset(order.matcherFeeAssetId) + ) + + Json.parse(orderDomainJson).as[JsObject] ++ Json.obj("message" -> message) + } + + def hashOrderStruct(order: Order): Array[Byte] = { + val json = toEip712Json(order) + val encoder = new StructuredDataEncoder(json.toString) + encoder.hashStructuredData() + } + + def recoverEthSignerKey(order: Order, signature: Array[Byte]): PublicKey = { + val bytes = hashOrderStruct(order) + recoverEthSignerKey(bytes, signature) + } + + def recoverEthSignerKey(message: Array[Byte], signature: Array[Byte]): PublicKey = { + val signatureData = EthOrders.decodeSignature(signature) + val signerKey = Sign + .recoverFromSignature( + signatureData.getV.head - 27, + new ECDSASignature(new BigInteger(1, signatureData.getR), new BigInteger(1, signatureData.getS)), + message + ) + .toByteArray + .takeRight(64) + PublicKey(ByteStr(signerKey)) + } + + def decodeSignature(signature: Array[Byte]): SignatureData = { + val buffer = ByteBuffer.wrap(signature) + val paramSize = buffer.remaining() match { + case 129 => 64 + case 65 => 32 + case other => throw new IllegalArgumentException(s"Unexpected signature length: $other") + } + val R = new Array[Byte](paramSize) + val S = new Array[Byte](paramSize) + buffer.get(R) + buffer.get(S) + val V = buffer.get() + new SignatureData(V, R, S) + } + + def orderDomainJson: String = + s""" + |{ + | "types": { + | "EIP712Domain": [ + | { + | "name": "name", + | "type": "string" + | }, + | { + | "name": "version", + | "type": "string" + | }, + | { + | "name": "chainId", + | "type": "uint256" + | }, + | { + | "name": "verifyingContract", + | "type": "address" + | } + | ], + | "Order": [ + | { + | "name": "version", + | "type": "int32" + | }, + | { + | "name": "matcherPublicKey", + | "type": "string" + | }, + | { + | "name": "amountAsset", + | "type": "string" + | }, + | { + | "name": "priceAsset", + | "type": "string" + | }, + | { + | "name": "orderType", + | "type": "string" + | }, + | { + | "name": "amount", + | "type": "int64" + | }, + | { + | "name": "price", + | "type": "int64" + | }, + | { + | "name": "timestamp", + | "type": "int64" + | }, + | { + | "name": "expiration", + | "type": "int64" + | }, + | { + | "name": "matcherFee", + | "type": "int64" + | }, + | { + | "name": "matcherFeeAssetId", + | "type": "string" + | } + | ] + | }, + | "primaryType": "Order", + | "domain": { + | "name": "Waves Exchange", + | "version": "1", + | "chainId": ${AddressScheme.current.chainId}, + | "verifyingContract": "0x${Hex.toHexString(Array.fill[Byte](20)(AddressScheme.current.chainId))}" + | }, + | "message": {} + |} + |""".stripMargin +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala index f8d7cfebda3..357ec839711 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala @@ -3,7 +3,6 @@ package com.wavesplatform.transaction.assets.exchange import com.wavesplatform.account.{AddressScheme, PrivateKey, PublicKey} import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError -import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction._ import com.wavesplatform.transaction.serialization.impl.ExchangeTxSerializer import com.wavesplatform.transaction.validation.impl.ExchangeTxValidator @@ -24,40 +23,33 @@ case class ExchangeTransaction( timestamp: Long, proofs: Proofs, chainId: Byte -) extends VersionedTransaction +) extends Transaction(TransactionType.Exchange, order1.assetPair.checkedAssets) + with VersionedTransaction with ProvenTransaction with TxWithFee.InWaves with FastHashId with SigProofsSwitch - with LegacyPBSwitch.V3 { + with PBSince.V3 { val (buyOrder, sellOrder) = if (order1.orderType == OrderType.BUY) (order1, order2) else (order2, order1) - override def builder: TransactionParser = ExchangeTransaction - override val sender: PublicKey = buyOrder.matcherPublicKey - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(ExchangeTransaction.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(ExchangeTransaction.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(ExchangeTransaction.serializer.toJson(this)) - - override def checkedAssets: Seq[IssuedAsset] = { - val pair = buyOrder.assetPair - Seq(pair.priceAsset, pair.amountAsset) collect { case a: IssuedAsset => a } - } + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(ExchangeTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(ExchangeTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(ExchangeTxSerializer.toJson(this)) } object ExchangeTransaction extends TransactionParser { type TransactionT = ExchangeTransaction implicit val validator = ExchangeTxValidator - val serializer = ExchangeTxSerializer implicit def sign(tx: ExchangeTransaction, privateKey: PrivateKey): ExchangeTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) override def parseBytes(bytes: Array[TxVersion]): Try[ExchangeTransaction] = - serializer.parseBytes(bytes) + ExchangeTxSerializer.parseBytes(bytes) override def supportedVersions: Set[TxVersion] = Set(1, 2, 3) diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/Order.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/Order.scala index bbe9e1b76a3..0a6da4c89f0 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/Order.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/Order.scala @@ -1,37 +1,39 @@ package com.wavesplatform.transaction.assets.exchange -import com.wavesplatform.account.{KeyPair, PrivateKey, PublicKey} +import scala.util.Try + +import com.wavesplatform.account.{Address, KeyPair, PrivateKey, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto -import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.assets.exchange.Validation.booleanOperators import com.wavesplatform.transaction.serialization.impl.OrderSerializer import monix.eval.Coeval import play.api.libs.json.{Format, JsObject} -import scala.util.Try - /** * Order to matcher service for asset exchange */ case class Order( - version: Order.Version, - senderPublicKey: PublicKey, - matcherPublicKey: PublicKey, - assetPair: AssetPair, - orderType: OrderType, - amount: TxAmount, - price: TxAmount, - timestamp: TxTimestamp, - expiration: TxTimestamp, - matcherFee: TxAmount, - matcherFeeAssetId: Asset = Waves, - proofs: Proofs = Proofs.empty + version: Order.Version, + senderPublicKey: PublicKey, + matcherPublicKey: PublicKey, + assetPair: AssetPair, + orderType: OrderType, + amount: TxAmount, + price: TxAmount, + timestamp: TxTimestamp, + expiration: TxTimestamp, + matcherFee: TxAmount, + matcherFeeAssetId: Asset = Waves, + proofs: Proofs = Proofs.empty, + eip712Signature: Option[ByteStr] = None ) extends Proven { import Order._ - val sender: PublicKey = senderPublicKey + val sender: PublicKey = senderPublicKey + def senderAddress: Address = sender.toAddress def isValid(atTime: Long): Validation = { isValidAmount(amount, price) && @@ -41,7 +43,10 @@ case class Order( (timestamp > 0) :| "timestamp should be > 0" && (expiration - atTime <= MaxLiveTime) :| "expiration should be earlier than 30 days" && (expiration >= atTime) :| "expiration should be > currentTime" && - (matcherFeeAssetId == Waves || version >= Order.V3) :| "matcherFeeAssetId should be waves" + (matcherFeeAssetId == Waves || version >= Order.V3) :| "matcherFeeAssetId should be waves" && + (eip712Signature.isEmpty || version >= Order.V4) :| "eip712Signature available only in V4" && + eip712Signature.forall(es => es.size == 65 || es.size == 129) :| "eip712Signature should be of length 65 or 129" && + (eip712Signature.isEmpty || proofs.isEmpty) :| "eip712Signature excludes proofs" } def isValidAmount(matchAmount: Long, matchPrice: Long): Validation = { @@ -51,9 +56,9 @@ case class Order( } val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(OrderSerializer.bodyBytes(this)) - val id: Coeval[ByteStr] = Coeval.evalOnce(ByteStr(crypto.fastHash(bodyBytes()))) - val idStr: Coeval[String] = Coeval.evalOnce(id().toString) - val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(OrderSerializer.toBytes(this)) + val id: Coeval[ByteStr] = Coeval.evalOnce(ByteStr(crypto.fastHash(bodyBytes()))) + val idStr: Coeval[String] = Coeval.evalOnce(id().toString) + val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(OrderSerializer.toBytes(this)) def getReceiveAssetId: Asset = orderType match { case OrderType.BUY => assetPair.amountAsset @@ -105,7 +110,8 @@ object Order { matcherFee: TxAmount, matcherFeeAssetId: Asset = Asset.Waves ): Order = - Order(version, sender.publicKey, matcher, assetPair, orderType, amount, price, timestamp, expiration, matcherFee, matcherFeeAssetId).signWith(sender.privateKey) + Order(version, sender.publicKey, matcher, assetPair, orderType, amount, price, timestamp, expiration, matcherFee, matcherFeeAssetId) + .signWith(sender.privateKey) def buy( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/OrderJson.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/OrderJson.scala index df523635b90..6b113fdc3ef 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/OrderJson.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/OrderJson.scala @@ -1,15 +1,16 @@ package com.wavesplatform.transaction.assets.exchange +import scala.util.{Failure, Success} + import com.wavesplatform.account.PublicKey import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto.SignatureLength -import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.{Asset, Proofs, TxVersion} +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.utils.EthEncoding import play.api.libs.json._ -import scala.util.{Failure, Success} - object OrderJson { import play.api.libs.functional.syntax._ import play.api.libs.json.Reads._ @@ -36,8 +37,8 @@ object OrderJson { implicit lazy val accountPublicKeyReads: Reads[PublicKey] = Reads { case JsString(s) => Base58.tryDecodeWithLimit(s) match { - case Success(bytes) if bytes.length == 32 => JsSuccess(PublicKey(bytes)) - case _ => JsError(Seq(JsPath() -> Seq(JsonValidationError("error.incorrectAccount")))) + case Success(bytes) if PublicKey.isValidSize(bytes.length) => JsSuccess(PublicKey(bytes)) + case _ => JsError(Seq(JsPath() -> Seq(JsonValidationError("error.incorrectAccount")))) } case _ => JsError(Seq(JsPath() -> Seq(JsonValidationError("error.expected.jsstring")))) } @@ -80,7 +81,8 @@ object OrderJson { signature: Option[Array[Byte]], proofs: Option[Array[Array[Byte]]], version: TxVersion, - matcherFeeAssetId: Asset + matcherFeeAssetId: Asset, + eip712Signature: Option[Array[Byte]] ): Order = { val eproofs = @@ -89,7 +91,21 @@ object OrderJson { .orElse(signature.map(s => Proofs(ByteStr(s)))) .getOrElse(Proofs.empty) - Order(version, sender, matcher, assetPair, orderType, amount, price, timestamp, expiration, matcherFee, matcherFeeAssetId, eproofs) + Order( + version, + sender, + matcher, + assetPair, + orderType, + amount, + price, + timestamp, + expiration, + matcherFee, + matcherFeeAssetId, + eproofs, + eip712Signature.map(ByteStr(_)) + ) } private val assetReads: Reads[Asset] = { @@ -142,7 +158,11 @@ object OrderJson { (JsPath \ "version").read[Byte] and (JsPath \ "matcherFeeAssetId") .readNullable[Array[Byte]] - .map(arrOpt => Asset.fromCompatId(arrOpt.map(ByteStr(_)))) + .map(arrOpt => Asset.fromCompatId(arrOpt.map(ByteStr(_)))) and + (JsPath \ "eip712Signature") + .readNullable[String] + .map(_.map(EthEncoding.toBytes)) + r(readOrderV3V4 _) } @@ -150,7 +170,7 @@ object OrderJson { case jsOrder @ JsObject(map) => map.getOrElse("version", JsNumber(1)) match { case JsNumber(x) if x.byteValue >= Order.V3 => orderV3V4Reads.reads(jsOrder) - case _ => orderV1V2Reads.reads(jsOrder) + case _ => orderV1V2Reads.reads(jsOrder) } case invalidOrder => JsError(s"Can't parse invalid order $invalidOrder") } diff --git a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseCancelTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseCancelTransaction.scala index 46c8faa9662..0bbb9595cbf 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseCancelTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseCancelTransaction.scala @@ -21,12 +21,12 @@ final case class LeaseCancelTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends SigProofsSwitch +) extends Transaction(TransactionType.LeaseCancel) + with SigProofsSwitch with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V3 { - override def builder: TransactionParser = LeaseCancelTransaction + with PBSince.V3 { override val bodyBytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseCancelTxSerializer.bodyBytes(this)) override val bytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseCancelTxSerializer.toBytes(this)) override val json: Coeval[JsObject] = Coeval.evalOnce(LeaseCancelTxSerializer.toJson(this)) diff --git a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala index 4af1582ae19..6cb44a9bb87 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala @@ -3,9 +3,9 @@ package com.wavesplatform.transaction.lease import com.wavesplatform.account.{AddressOrAlias, KeyPair, PrivateKey, PublicKey} import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError +import com.wavesplatform.transaction._ import com.wavesplatform.transaction.serialization.impl.LeaseTxSerializer import com.wavesplatform.transaction.validation.impl.LeaseTxValidator -import com.wavesplatform.transaction._ import monix.eval.Coeval import play.api.libs.json.JsObject @@ -20,15 +20,15 @@ final case class LeaseTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends SigProofsSwitch +) extends Transaction(TransactionType.Lease) + with SigProofsSwitch with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V3 { - override def builder: TransactionParser = LeaseTransaction - override val bodyBytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseTransaction.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseTransaction.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(LeaseTransaction.serializer.toJson(this)) + with PBSince.V3 { + override val bodyBytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[TxVersion]] = Coeval.evalOnce(LeaseTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(LeaseTxSerializer.toJson(this)) } object LeaseTransaction extends TransactionParser { @@ -38,13 +38,12 @@ object LeaseTransaction extends TransactionParser { val typeId: TxType = 8: Byte implicit val validator = LeaseTxValidator - val serializer = LeaseTxSerializer implicit def sign(tx: LeaseTransaction, privateKey: PrivateKey): LeaseTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) override def parseBytes(bytes: Array[TxVersion]): Try[LeaseTransaction] = - serializer.parseBytes(bytes) + LeaseTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/package.scala b/node/src/main/scala/com/wavesplatform/transaction/package.scala index d9c1a374552..f7fe818a4a6 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/package.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/package.scala @@ -7,7 +7,11 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError import com.wavesplatform.state.Diff import com.wavesplatform.transaction.validation.TxValidator -import com.wavesplatform.utils.base58Length +import com.wavesplatform.transaction.Asset.IssuedAsset +import com.wavesplatform.utils.{base58Length, EthEncoding} +import play.api.libs.json.{Format, Reads, Writes} +import supertagged._ +import supertagged.postfix._ package object transaction { val AssetIdLength: Int = com.wavesplatform.crypto.DigestLength @@ -37,4 +41,19 @@ package object transaction { implicit class TransactionSignOps[T](val tx: T) extends AnyVal { def signWith(privateKey: PrivateKey)(implicit sign: (T, PrivateKey) => T): T = sign(tx, privateKey) } + + object ERC20Address extends TaggedType[ByteStr] { + def apply(bs: ByteStr): ERC20Address = { + require(bs.arr.length == 20, "ERC20 token address length must be 20 bytes") + bs @@ this + } + + def apply(ia: IssuedAsset): ERC20Address = apply(ia.id.take(20)) + + implicit val jsonFormat: Format[ERC20Address] = Format( + implicitly[Reads[String]].map(str => ERC20Address(ByteStr(EthEncoding.toBytes(str)))), + implicitly[Writes[String]].contramap((addr: ERC20Address) => EthEncoding.toHexString(addr.arr)) + ) + } + type ERC20Address = ERC20Address.Type } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BaseTxJson.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BaseTxJson.scala index 237fe52266e..f3b8fb75dc5 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BaseTxJson.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BaseTxJson.scala @@ -1,30 +1,34 @@ package com.wavesplatform.transaction.serialization.impl -import com.wavesplatform.transaction.{LegacyPBSwitch, ProvenTransaction, SigProofsSwitch, VersionedTransaction} +import com.wavesplatform.transaction.{PBSince, ProvenTransaction, SigProofsSwitch, Transaction, VersionedTransaction} import play.api.libs.json.{JsArray, JsObject, JsString, Json} object BaseTxJson { - def toJson(tx: ProvenTransaction): JsObject = { - import tx._ + def toJson(tx: Transaction): JsObject = { Json.obj( - "type" -> typeId, - "id" -> id().toString, - "sender" -> sender.toAddress, - "senderPublicKey" -> sender, - "fee" -> assetFee._2, - "feeAssetId" -> assetFee._1.maybeBase58Repr, - "timestamp" -> timestamp, - "proofs" -> JsArray(proofs.proofs.map(p => JsString(p.toString))) + "type" -> tx.tpe.id, + "id" -> tx.id().toString, + "fee" -> tx.assetFee._2, + "feeAssetId" -> tx.assetFee._1.maybeBase58Repr, + "timestamp" -> tx.timestamp ) ++ (tx match { - // Compatibility - case s: SigProofsSwitch if s.usesLegacySignature => Json.obj("signature" -> tx.signature.toString) - case _ => Json.obj() - }) ++ (tx match { case v: VersionedTransaction => Json.obj("version" -> v.version) case _ => Json.obj() }) ++ (tx match { - case pbs: LegacyPBSwitch if pbs.isProtobufVersion => Json.obj("chainId" -> tx.chainId) - case _ => Json.obj() + case pbs: PBSince if pbs.isProtobufVersion => Json.obj("chainId" -> tx.chainId) + case _ => Json.obj() + }) ++ (tx match { + case p: ProvenTransaction => + Json.obj( + "sender" -> p.sender.toAddress.toString, + "senderPublicKey" -> p.sender, + "proofs" -> JsArray(p.proofs.proofs.map(p => JsString(p.toString))) + ) ++ (tx match { + // Compatibility + case s: SigProofsSwitch if s.usesLegacySignature => Json.obj("signature" -> s.signature.toString) + case _ => Json.obj() + }) + case _ => JsObject.empty }) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BurnTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BurnTxSerializer.scala index 6fa973452d1..937b19a3672 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BurnTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/BurnTxSerializer.scala @@ -31,8 +31,8 @@ object BurnTxSerializer { ) version match { - case TxVersion.V1 => Bytes.concat(Array(typeId), baseBytes) - case TxVersion.V2 => Bytes.concat(Array(builder.typeId, version, chainId), baseBytes) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), baseBytes) + case TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte, version, chainId), baseBytes) case _ => PBTransactionSerializer.bodyBytes(tx) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/CreateAliasTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/CreateAliasTxSerializer.scala index 3823263d070..77446e5a7a9 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/CreateAliasTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/CreateAliasTxSerializer.scala @@ -26,8 +26,8 @@ object CreateAliasTxSerializer { ) version match { - case TxVersion.V1 => Bytes.concat(Array(builder.typeId), base) - case TxVersion.V2 => Bytes.concat(Array(builder.typeId, version), base) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), base) + case TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte, version), base) case _ => PBTransactionSerializer.bodyBytes(tx) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/DataTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/DataTxSerializer.scala index 24438e803ea..e41447a2f66 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/DataTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/DataTxSerializer.scala @@ -27,7 +27,7 @@ object DataTxSerializer { version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId, version), + Array(tpe.id.toByte, version), sender.arr, Shorts.toByteArray(data.size.toShort), Bytes.concat(data.map(serializeEntry): _*), diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ExchangeTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ExchangeTxSerializer.scala index e9877e67fd2..f7d4925e7f4 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ExchangeTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ExchangeTxSerializer.scala @@ -30,7 +30,7 @@ object ExchangeTxSerializer { version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId), + Array(tpe.id.toByte), Ints.toByteArray(order1.bytes().length), Ints.toByteArray(order2.bytes().length), order1.bytes(), @@ -48,7 +48,7 @@ object ExchangeTxSerializer { if (version == 1) Array(1: Byte) else Array.emptyByteArray Bytes.concat( - Array(0: Byte, builder.typeId, version), + Array(0: Byte, tpe.id.toByte, version), Ints.toByteArray(order1.bytes().length), orderMark(order1.version), order1.bytes(), diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/GenesisTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/GenesisTxSerializer.scala index 74825fb661e..bfa9d5bf934 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/GenesisTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/GenesisTxSerializer.scala @@ -17,19 +17,19 @@ object GenesisTxSerializer { def toJson(tx: GenesisTransaction): JsObject = { import tx._ Json.obj( - "type" -> builder.typeId, + "type" -> tpe.id, "id" -> id().toString, "fee" -> 0, "timestamp" -> timestamp, "signature" -> signature.toString, - "recipient" -> recipient.stringRepr, + "recipient" -> recipient.toString, "amount" -> amount ) } def toBytes(tx: GenesisTransaction): Array[Byte] = { import tx._ - val typeBytes = Array(builder.typeId) + val typeBytes = Array(tpe.id.toByte) val timestampBytes = Longs.toByteArray(timestamp) val rcpBytes = recipient.bytes val amountBytes = Longs.toByteArray(amount) diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/InvokeScriptTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/InvokeScriptTxSerializer.scala index 1979c678959..1265cf36ce3 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/InvokeScriptTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/InvokeScriptTxSerializer.scala @@ -2,26 +2,26 @@ package com.wavesplatform.transaction.serialization.impl import java.nio.ByteBuffer +import scala.util.Try + import com.google.common.primitives.{Bytes, Longs} import com.wavesplatform.account.AddressScheme import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ import com.wavesplatform.lang.v1.Serde import com.wavesplatform.lang.v1.compiler.Terms -import com.wavesplatform.lang.v1.compiler.Terms.{EXPR, FUNCTION_CALL} +import com.wavesplatform.lang.v1.compiler.Terms.EXPR import com.wavesplatform.serialization._ +import com.wavesplatform.transaction.{Asset, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.{Asset, TxVersion} -import play.api.libs.json.{JsArray, JsObject, JsString, Json} - -import scala.util.Try +import play.api.libs.json.{JsArray, JsObject, Json, JsString} object InvokeScriptTxSerializer { def functionCallToJson(fc: Terms.FUNCTION_CALL): JsObject = { Json.obj( - "function" -> JsString(fc.function.asInstanceOf[com.wavesplatform.lang.v1.FunctionHeader.User].internalName), + "function" -> JsString(fc.function.funcName), "args" -> JsArray( fc.args.map { case Terms.ARR(elements) => Json.obj("type" -> "list", "value" -> elements.map(mapSingleArg)) @@ -40,25 +40,16 @@ object InvokeScriptTxSerializer { case arg => throw new NotImplementedError(s"Not supported: $arg") } - def toJson(tx: InvokeScriptTransaction): JsObject = { - import tx._ - BaseTxJson.toJson(tx) ++ Json.obj( - "dApp" -> dAppAddressOrAlias.stringRepr, - "payment" -> payments - ) ++ (funcCallOpt match { - case Some(fc) => Json.obj("call" -> this.functionCallToJson(fc)) - case None => JsObject.empty - }) - } + def toJson(tx: InvokeScriptTransaction): JsObject = BaseTxJson.toJson(tx) ++ tx.toJson def bodyBytes(tx: InvokeScriptTransaction): Array[Byte] = { import tx._ version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId, version, chainId), + Array(tpe.id.toByte, version, chainId), sender.arr, - dAppAddressOrAlias.bytes, + dApp.bytes, Deser.serializeOption(funcCallOpt)(Serde.serialize(_)), Deser.serializeArrays(payments.map(pmt => Longs.toByteArray(pmt.amount) ++ pmt.assetId.byteRepr)), Longs.toByteArray(fee), @@ -90,7 +81,7 @@ object InvokeScriptTxSerializer { val sender = buf.getPublicKey val dApp = buf.getAddressOrAlias - val functionCall = Deser.parseOption(buf)(Serde.deserialize(_).explicitGet().asInstanceOf[FUNCTION_CALL]) + val functionCall = Deser.parseOption(buf)(Serde.deserializeFunctionCall(_).explicitGet()) val payments = Deser.parseArrays(buf).map(parsePayment) val fee = buf.getLong val feeAssetId = buf.getAsset diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/IssueTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/IssueTxSerializer.scala index c6c7cdb451e..8ce076c54db 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/IssueTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/IssueTxSerializer.scala @@ -38,16 +38,16 @@ object IssueTxSerializer { ) version match { - case TxVersion.V1 => Bytes.concat(Array(typeId), baseBytes) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), baseBytes) case TxVersion.V2 => - Bytes.concat(Array(builder.typeId, version, chainId), baseBytes, Deser.serializeOptionOfArrayWithLength(script)(_.bytes().arr)) + Bytes.concat(Array(tpe.id.toByte, version, chainId), baseBytes, Deser.serializeOptionOfArrayWithLength(script)(_.bytes().arr)) case _ => PBTransactionSerializer.bodyBytes(tx) } } def toBytes(tx: IssueTransaction): Array[Byte] = tx.version match { - case TxVersion.V1 => Bytes.concat(Array(tx.typeId), tx.proofs.toSignature.arr, this.bodyBytes(tx)) // Signature before body, typeId appears twice + case TxVersion.V1 => Bytes.concat(Array(tx.tpe.id.toByte), tx.proofs.toSignature.arr, this.bodyBytes(tx)) // Signature before body, typeId appears twice case TxVersion.V2 => Bytes.concat(Array(0: Byte), this.bodyBytes(tx), tx.proofs.bytes()) case _ => PBTransactionSerializer.bytes(tx) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseCancelTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseCancelTxSerializer.scala index e13014ba1e2..eca6961d97e 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseCancelTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseCancelTxSerializer.scala @@ -23,8 +23,8 @@ object LeaseCancelTxSerializer { val baseBytes = Bytes.concat(sender.arr, Longs.toByteArray(fee), Longs.toByteArray(timestamp), leaseId.arr) version match { - case TxVersion.V1 => Bytes.concat(Array(typeId), baseBytes) - case TxVersion.V2 => Bytes.concat(Array(typeId, version, chainId), baseBytes) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), baseBytes) + case TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte, version, chainId), baseBytes) case _ => PBTransactionSerializer.bodyBytes(tx) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseTxSerializer.scala index e71590c5f4a..6abbbeeaee1 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/LeaseTxSerializer.scala @@ -16,7 +16,7 @@ object LeaseTxSerializer { import tx._ BaseTxJson.toJson(tx) ++ Json.obj( "amount" -> amount, - "recipient" -> recipient.stringRepr + "recipient" -> recipient.toString ) } @@ -25,8 +25,8 @@ object LeaseTxSerializer { val baseBytes = Bytes.concat(sender.arr, recipient.bytes, Longs.toByteArray(amount), Longs.toByteArray(fee), Longs.toByteArray(timestamp)) version match { - case TxVersion.V1 => Bytes.concat(Array(typeId), baseBytes) - case TxVersion.V2 => Bytes.concat(Array(typeId, version), Waves.byteRepr, baseBytes) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), baseBytes) + case TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte, version), Waves.byteRepr, baseBytes) case _ => PBTransactionSerializer.bodyBytes(tx) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/MassTransferTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/MassTransferTxSerializer.scala index b28dfc169ff..33a89ad4d19 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/MassTransferTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/MassTransferTxSerializer.scala @@ -3,9 +3,8 @@ package com.wavesplatform.transaction.serialization.impl import java.nio.ByteBuffer import com.google.common.primitives.{Bytes, Longs, Shorts} -import com.wavesplatform.account.{AddressOrAlias, AddressScheme} +import com.wavesplatform.account.AddressScheme import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ import com.wavesplatform.serialization._ import com.wavesplatform.transaction.TxVersion import com.wavesplatform.transaction.transfer.MassTransferTransaction @@ -17,7 +16,7 @@ import scala.util.Try object MassTransferTxSerializer { def transfersJson(transfers: Seq[ParsedTransfer]): JsValue = - Json.toJson(transfers.map { case ParsedTransfer(address, amount) => Transfer(address.stringRepr, amount) }) + Json.toJson(transfers.map { case ParsedTransfer(address, amount) => Transfer(address.toString, amount) }) def toJson(tx: MassTransferTransaction): JsObject = { import tx._ @@ -37,7 +36,7 @@ object MassTransferTxSerializer { val transferBytes = transfers.map { case ParsedTransfer(recipient, amount) => Bytes.concat(recipient.bytes, Longs.toByteArray(amount)) } Bytes.concat( - Array(builder.typeId, version), + Array(tpe.id.toByte, version), sender.arr, assetId.byteRepr, Shorts.toByteArray(transfers.size.toShort), @@ -59,7 +58,7 @@ object MassTransferTxSerializer { def parseBytes(bytes: Array[Byte]): Try[MassTransferTransaction] = Try { def parseTransfers(buf: ByteBuffer): Seq[MassTransferTransaction.ParsedTransfer] = { def readTransfer(buf: ByteBuffer): ParsedTransfer = { - val addressOrAlias = AddressOrAlias.fromBytes(buf).explicitGet() + val addressOrAlias = buf.getAddressOrAlias val amount = buf.getLong ParsedTransfer(addressOrAlias, amount) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/OrderSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/OrderSerializer.scala index 4680677e122..8c3b08f6ee6 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/OrderSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/OrderSerializer.scala @@ -2,23 +2,24 @@ package com.wavesplatform.transaction.serialization.impl import java.nio.ByteBuffer +import scala.util.Try + import com.google.common.primitives.{Bytes, Longs} import com.wavesplatform.protobuf.transaction.PBOrders import com.wavesplatform.protobuf.utils.PBUtils import com.wavesplatform.serialization.ByteBufferOps import com.wavesplatform.transaction.Proofs import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} +import com.wavesplatform.utils.EthEncoding import play.api.libs.json.{JsObject, Json} -import scala.util.Try - object OrderSerializer { def toJson(order: Order): JsObject = { import order._ Json.obj( "version" -> version, "id" -> idStr(), - "sender" -> senderPublicKey.toAddress, + "sender" -> senderPublicKey.toAddress.toString, "senderPublicKey" -> senderPublicKey, "matcherPublicKey" -> matcherPublicKey, "assetPair" -> assetPair.json, @@ -30,7 +31,8 @@ object OrderSerializer { "matcherFee" -> matcherFee, "signature" -> proofs.toSignature.toString, "proofs" -> proofs.proofs.map(_.toString) - ) ++ (if (version >= Order.V3) Json.obj("matcherFeeAssetId" -> matcherFeeAssetId) else JsObject.empty) + ) ++ (if (version >= Order.V3) Json.obj("matcherFeeAssetId" -> matcherFeeAssetId) else JsObject.empty) ++ + (if (version >= Order.V4) Json.obj("eip712Signature" -> eip712Signature.map(bs => EthEncoding.toHexString(bs.arr))) else JsObject.empty) // TODO: Should it be hex or base58? } def bodyBytes(order: Order): Array[Byte] = { diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PBTransactionSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PBTransactionSerializer.scala index edad1afeb39..4cc9a8938ad 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PBTransactionSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PBTransactionSerializer.scala @@ -9,7 +9,7 @@ import scala.util.Try object PBTransactionSerializer { def bodyBytes(tx: Transaction): Array[Byte] = - PBUtils.encodeDeterministic(PBTransactions.protobuf(tx).getTransaction) + PBUtils.encodeDeterministic(PBTransactions.protobuf(tx).getWavesTransaction) def bytes(tx: Transaction): Array[Byte] = PBUtils.encodeDeterministic(PBTransactions.protobuf(tx)) diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PaymentTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PaymentTxSerializer.scala index 3d0bcc8d7de..1030fc65283 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PaymentTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/PaymentTxSerializer.scala @@ -12,13 +12,13 @@ import scala.util.Try object PaymentTxSerializer { def toJson(tx: PaymentTransaction): JsObject = { import tx._ - BaseTxJson.toJson(tx) ++ Json.obj("recipient" -> recipient.stringRepr, "amount" -> amount) + BaseTxJson.toJson(tx) ++ Json.obj("recipient" -> recipient.toString, "amount" -> amount) } def hashBytes(tx: PaymentTransaction): Array[Byte] = { import tx._ Bytes.concat( - Array(builder.typeId), + Array(tpe.id.toByte), Longs.toByteArray(timestamp), sender.arr, recipient.bytes, @@ -30,7 +30,7 @@ object PaymentTxSerializer { def bodyBytes(tx: PaymentTransaction): Array[Byte] = { import tx._ Bytes.concat( - Ints.toByteArray(builder.typeId), // 4 bytes + Ints.toByteArray(tpe.id), // 4 bytes Longs.toByteArray(timestamp), sender.arr, recipient.bytes, diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ReissueTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ReissueTxSerializer.scala index 40fcb698357..31b6971f677 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ReissueTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/ReissueTxSerializer.scala @@ -34,11 +34,11 @@ object ReissueTxSerializer { version match { case TxVersion.V1 => - Bytes.concat(Array(typeId), baseBytes) + Bytes.concat(Array(tpe.id.toByte), baseBytes) case TxVersion.V2 => Bytes.concat( - Array(builder.typeId, version, chainId), + Array(tpe.id.toByte, version, chainId), baseBytes ) @@ -49,7 +49,7 @@ object ReissueTxSerializer { def toBytes(tx: ReissueTransaction): Array[Byte] = { tx.version match { - case TxVersion.V1 => Bytes.concat(Array(tx.typeId), tx.proofs.toSignature.arr, this.bodyBytes(tx)) // Signature before body, typeId appears twice + case TxVersion.V1 => Bytes.concat(Array(tx.tpe.id.toByte), tx.proofs.toSignature.arr, this.bodyBytes(tx)) // Signature before body, typeId appears twice case TxVersion.V2 => Bytes.concat(Array(0: Byte), this.bodyBytes(tx), tx.proofs.bytes()) case _ => PBTransactionSerializer.bytes(tx) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetAssetScriptTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetAssetScriptTxSerializer.scala index 36b9d78f9f5..8a5ae9ed74f 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetAssetScriptTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetAssetScriptTxSerializer.scala @@ -25,7 +25,7 @@ object SetAssetScriptTxSerializer { version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId, version, chainId), + Array(tpe.id.toByte, version, chainId), sender.arr, asset.id.arr, Longs.toByteArray(fee), diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetScriptTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetScriptTxSerializer.scala index f410df05124..a618fbac2eb 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetScriptTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SetScriptTxSerializer.scala @@ -24,7 +24,7 @@ object SetScriptTxSerializer { version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId, version, chainId), + Array(tpe.id.toByte, version, chainId), sender.arr, Deser.serializeOptionOfArrayWithLength(script)(s => s.bytes().arr), Longs.toByteArray(fee), diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SponsorFeeTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SponsorFeeTxSerializer.scala index f8af5bd7987..45249b58bf0 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SponsorFeeTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/SponsorFeeTxSerializer.scala @@ -25,7 +25,7 @@ object SponsorFeeTxSerializer { version match { case TxVersion.V1 => Bytes.concat( - Array(builder.typeId, version), + Array(tpe.id.toByte, version), sender.arr, asset.id.arr, Longs.toByteArray(minSponsoredAssetFee.getOrElse(0)), @@ -40,7 +40,7 @@ object SponsorFeeTxSerializer { def toBytes(tx: SponsorFeeTransaction): Array[Byte] = { if (tx.isProtobufVersion) PBTransactionSerializer.bytes(tx) - else Bytes.concat(Array(0: Byte, tx.typeId, tx.version), this.bodyBytes(tx), tx.proofs.bytes()) // [typeId, version] appears twice + else Bytes.concat(Array(0: Byte, tx.tpe.id.toByte, tx.version), this.bodyBytes(tx), tx.proofs.bytes()) // [typeId, version] appears twice } def parseBytes(bytes: Array[Byte]): Try[SponsorFeeTransaction] = Try { diff --git a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/TransferTxSerializer.scala b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/TransferTxSerializer.scala index 33a25917b6b..449e81bd5b4 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/TransferTxSerializer.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/serialization/impl/TransferTxSerializer.scala @@ -16,7 +16,7 @@ object TransferTxSerializer { def toJson(tx: TransferTransaction): JsObject = { import tx._ BaseTxJson.toJson(tx) ++ Json.obj( - "recipient" -> recipient.stringRepr, + "recipient" -> recipient.toString, "assetId" -> assetId.maybeBase58Repr, "feeAsset" -> feeAssetId.maybeBase58Repr, // legacy v0.11.1 compat "amount" -> amount, @@ -39,14 +39,14 @@ object TransferTxSerializer { ) version match { - case TxVersion.V1 => Bytes.concat(Array(typeId), baseBytes) - case TxVersion.V2 => Bytes.concat(Array(typeId, version), baseBytes) + case TxVersion.V1 => Bytes.concat(Array(tpe.id.toByte), baseBytes) + case TxVersion.V2 => Bytes.concat(Array(tpe.id.toByte, version), baseBytes) case _ => PBTransactionSerializer.bodyBytes(tx) } } def toBytes(tx: TransferTransaction): Array[Byte] = tx.version match { - case TxVersion.V1 => Bytes.concat(Array(tx.typeId), tx.proofs.toSignature.arr, this.bodyBytes(tx)) + case TxVersion.V1 => Bytes.concat(Array(tx.tpe.id.toByte), tx.proofs.toSignature.arr, this.bodyBytes(tx)) case TxVersion.V2 => Bytes.concat(Array(0: Byte), this.bodyBytes(tx), tx.proofs.bytes()) case _ => PBTransactionSerializer.bytes(tx) } @@ -62,7 +62,19 @@ object TransferTxSerializer { val recipient = buf.getAddressOrAlias val attachment = buf.getByteArrayWithLength - TransferTransaction(version, sender, recipient, assetId, amount, feeAssetId, fee, ByteStr(attachment), ts, Proofs.empty, recipient.chainId) + TransferTransaction( + version, + sender, + recipient, + assetId, + amount, + feeAssetId, + fee, + ByteStr(attachment), + ts, + Proofs.empty, + recipient.chainId + ) } require(bytes.length > 2, "buffer underflow while parsing transaction") diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeExpressionTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeExpressionTransaction.scala index 61802573cec..bdaf31826e4 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeExpressionTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeExpressionTransaction.scala @@ -24,20 +24,17 @@ case class InvokeExpressionTransaction( override val timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends InvokeTransaction - with ProtobufOnly { +) extends Transaction(TransactionType.InvokeExpression, Nil) + with InvokeTransaction + with PBSince.V1 { lazy val expressionBytes: ByteStr = expression.bytes.value() - override def root: Option[InvokeTransaction] = Some(this) - override def senderAddress: Address = sender.toAddress - override val dAppAddressOrAlias: AddressOrAlias = sender.toAddress - override val funcCall: Terms.FUNCTION_CALL = InvokeTransaction.defaultCall + override def dApp: AddressOrAlias = sender.toAddress + override def root: InvokeExpressionTransaction = this + override val funcCall: Terms.FUNCTION_CALL = InvokeTransaction.DefaultCall override def payments: Seq[InvokeScriptTransaction.Payment] = Nil - override def checkedAssets: Seq[Asset.IssuedAsset] = Nil - override val enableEmptyKeys: Boolean = false - - override val builder = InvokeExpressionTransaction + override val checkedAssets: Seq[Asset.IssuedAsset] = Nil override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(PBTransactionSerializer.bodyBytes(this)) override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(PBTransactionSerializer.bytes(this)) @@ -66,7 +63,7 @@ object InvokeExpressionTransaction extends TransactionParser { .parseBytes(bytes) .flatMap { case tx: InvokeExpressionTransaction => Success(tx) - case tx: Transaction => Failure(UnexpectedTransaction(typeId, tx.typeId)) + case tx: Transaction => Failure(UnexpectedTransaction(typeId, tx.tpe.id.toByte)) } def create( diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeScriptTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeScriptTransaction.scala index 41ba0409352..193b0917e99 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeScriptTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeScriptTransaction.scala @@ -4,21 +4,21 @@ import com.wavesplatform.account._ import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL +import com.wavesplatform.state.diffs.invoke.{InvokeScriptLike, InvokeScriptTransactionLike} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.serialization.impl.InvokeScriptTxSerializer import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.InvokeTransaction.defaultCall import com.wavesplatform.transaction.validation.TxValidator import com.wavesplatform.transaction.validation.impl.InvokeScriptTxValidator import monix.eval.Coeval -import play.api.libs.json.JsObject +import play.api.libs.json._ import scala.util.Try case class InvokeScriptTransaction( version: TxVersion, sender: PublicKey, - dAppAddressOrAlias: AddressOrAlias, + dApp: AddressOrAlias, funcCallOpt: Option[FUNCTION_CALL], payments: Seq[Payment], fee: TxAmount, @@ -26,20 +26,18 @@ case class InvokeScriptTransaction( override val timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends InvokeTransaction - with LegacyPBSwitch.V2 { +) extends Transaction(TransactionType.InvokeScript, payments.collect(InvokeScriptLike.IssuedAssets)) + with InvokeTransaction + with PBSince.V2 { - override val funcCall: FUNCTION_CALL = funcCallOpt.getOrElse(defaultCall) + override def root: InvokeScriptTransactionLike = this + override val funcCall: FUNCTION_CALL = funcCallOpt.getOrElse(InvokeTransaction.DefaultCall) + def senderAddress: Address = sender.toAddress - override val builder = InvokeScriptTransaction + val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(InvokeScriptTxSerializer.bodyBytes(this)) + val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(InvokeScriptTxSerializer.toBytes(this)) + val json: Coeval[JsObject] = Coeval.evalOnce(InvokeScriptTxSerializer.toJson(this)) - val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) - - override def root: Option[InvokeScriptTransaction] = Some(this) - override def senderAddress: Address = sender.toAddress - override val enableEmptyKeys: Boolean = isProtobufVersion } object InvokeScriptTransaction extends TransactionParser { @@ -53,14 +51,11 @@ object InvokeScriptTransaction extends TransactionParser { implicit def sign(tx: InvokeScriptTransaction, privateKey: PrivateKey): InvokeScriptTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - val serializer = InvokeScriptTxSerializer - override def parseBytes(bytes: Array[Byte]): Try[InvokeScriptTransaction] = - serializer.parseBytes(bytes) + InvokeScriptTxSerializer.parseBytes(bytes) case class Payment(amount: TxAmount, assetId: Asset) object Payment { - import play.api.libs.json.{Json, _} implicit val jsonFormat: Format[Payment] = Json.format } @@ -68,37 +63,13 @@ object InvokeScriptTransaction extends TransactionParser { version: TxVersion, sender: PublicKey, dappAddress: AddressOrAlias, - expr: Option[FUNCTION_CALL], - p: Seq[Payment], - fee: TxAmount, - feeAssetId: Asset, - timestamp: TxTimestamp, - proofs: Proofs - ): Either[ValidationError, InvokeScriptTransaction] = - InvokeScriptTransaction(version, sender, dappAddress, expr, p, fee, feeAssetId, timestamp, proofs, dappAddress.chainId).validatedEither - - def signed( - version: TxVersion, - sender: PublicKey, - dappAddress: AddressOrAlias, - expr: Option[FUNCTION_CALL], + fc: Option[FUNCTION_CALL], p: Seq[Payment], fee: TxAmount, feeAssetId: Asset, timestamp: TxTimestamp, - signer: PrivateKey - ): Either[ValidationError, InvokeScriptTransaction] = - create(version, sender, dappAddress, expr, p, fee, feeAssetId, timestamp, Proofs.empty).map(_.signWith(signer)) - - def selfSigned( - version: TxVersion, - sender: KeyPair, - dappAddress: AddressOrAlias, - expr: Option[FUNCTION_CALL], - p: Seq[Payment], - fee: TxAmount, - feeAssetId: Asset, - timestamp: TxTimestamp + proofs: Proofs, + chainId: Byte ): Either[ValidationError, InvokeScriptTransaction] = - signed(version, sender.publicKey, dappAddress, expr, p, fee, feeAssetId, timestamp, sender.privateKey) + InvokeScriptTransaction(version, sender, dappAddress, fc, p, fee, feeAssetId, timestamp, proofs, chainId).validatedEither } diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeTransaction.scala index 4460b289d7e..b78fb3e34f2 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/InvokeTransaction.scala @@ -2,13 +2,19 @@ package com.wavesplatform.transaction.smart import com.wavesplatform.lang.v1.FunctionHeader.User import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL import com.wavesplatform.lang.v1.evaluator.ContractEvaluator -import com.wavesplatform.state.diffs.invoke.InvokeScriptLike -import com.wavesplatform.transaction.{Asset, FastHashId, ProvenTransaction, TxWithFee, VersionedTransaction} +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike +import com.wavesplatform.transaction.{Asset, FastHashId, ProvenTransaction, Transaction, TxWithFee, VersionedTransaction} -trait InvokeTransaction extends InvokeScriptLike with ProvenTransaction with TxWithFee.InCustomAsset with FastHashId with VersionedTransaction { - override def checkedAssets: Seq[Asset.IssuedAsset] = super[InvokeScriptLike].checkedAssets +trait InvokeTransaction + extends Transaction + with InvokeScriptTransactionLike + with ProvenTransaction + with TxWithFee.InCustomAsset + with FastHashId + with VersionedTransaction { + override val checkedAssets: Seq[Asset.IssuedAsset] = super[InvokeScriptTransactionLike].checkedAssets } object InvokeTransaction { - val defaultCall: FUNCTION_CALL = FUNCTION_CALL(User(ContractEvaluator.DEFAULT_FUNC_NAME), Nil) + val DefaultCall: FUNCTION_CALL = FUNCTION_CALL(User(ContractEvaluator.DEFAULT_FUNC_NAME), Nil) } diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/RealTransactionWrapper.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/RealTransactionWrapper.scala index 4f7d2f8606d..6be303ccdaa 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/RealTransactionWrapper.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/RealTransactionWrapper.scala @@ -7,38 +7,46 @@ import com.wavesplatform.lang.ExecutionError import com.wavesplatform.lang.directives.values.StdLibVersion import com.wavesplatform.lang.v1.compiler.Terms.EVALUATED import com.wavesplatform.lang.v1.traits.domain.Tx.{Header, Proven} -import com.wavesplatform.lang.v1.traits.domain._ +import com.wavesplatform.lang.v1.traits.domain.{Recipient => RideRecipient, _} import com.wavesplatform.protobuf.ByteStringExt import com.wavesplatform.state._ -import com.wavesplatform.transaction._ +import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange.OrderType.{BUY, SELL} import com.wavesplatform.transaction.assets.exchange.{AssetPair, ExchangeTransaction, Order} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.{EthereumTransaction, _} object RealTransactionWrapper { private def header(tx: Transaction, txIdOpt: Option[ByteStr] = None): Header = { val v = tx match { + case _: EthereumTransaction => 0.toByte case vt: VersionedTransaction => vt.version case _ => TxVersion.V1 } - Header(txIdOpt.getOrElse(ByteStr(tx.id().arr)), tx.assetFee._2, tx.timestamp, v) + Header(txIdOpt.getOrElse(ByteStr(tx.id().arr)), tx.fee, tx.timestamp, v) } - private def proven(tx: ProvenTransaction, txIdOpt: Option[ByteStr] = None): Proven = + + private def proven(tx: AuthorizedTransaction, txIdOpt: Option[ByteStr] = None, emptyBodyBytes: Boolean = false): Proven = { + val proofs = tx match { + case p: ProvenTransaction => p.proofs.map(_.arr).map(ByteStr(_)).toIndexedSeq + case _ => Vector() + } Proven( header(tx, txIdOpt), - Recipient.Address(ByteStr(tx.sender.toAddress.bytes)), - ByteStr(tx.bodyBytes()), + RideRecipient.Address(ByteStr(tx.sender.toAddress.bytes)), + if (emptyBodyBytes) ByteStr.empty else ByteStr(tx.bodyBytes()), tx.sender, - tx.proofs.proofs.map(_.arr).map(ByteStr(_)).toIndexedSeq + proofs ) + } implicit def assetPair(a: AssetPair): APair = APair(a.amountAsset.compatId, a.priceAsset.compatId) implicit def ord(o: Order): Ord = Ord( id = o.id(), - sender = Recipient.Address(ByteStr(o.sender.toAddress.bytes)), + sender = RideRecipient.Address(ByteStr(o.sender.toAddress.bytes)), senderPublicKey = o.senderPublicKey, matcherPublicKey = o.matcherPublicKey, assetPair = o.assetPair, @@ -56,20 +64,15 @@ object RealTransactionWrapper { matcherFeeAssetId = o.matcherFeeAssetId.compatId ) - implicit def aoaToRecipient(aoa: AddressOrAlias): Recipient = (aoa: @unchecked) match { - case a: Address => Recipient.Address(ByteStr(a.bytes)) - case a: Alias => Recipient.Alias(a.name) - } - def apply( - tx: Transaction, + tx: TransactionBase, blockchain: Blockchain, stdLibVersion: StdLibVersion, target: AttachedPaymentTarget ): Either[ExecutionError, Tx] = (tx: @unchecked) match { - case g: GenesisTransaction => Tx.Genesis(header(g), g.amount, g.recipient).asRight - case t: TransferTransaction => mapTransferTx(t).asRight + case g: GenesisTransaction => Tx.Genesis(header(g), g.amount, toRide(g.recipient)).asRight + case t: TransferTransactionLike => mapTransferTx(t).asRight case i: IssueTransaction => Tx.Issue( proven(i), @@ -83,7 +86,7 @@ object RealTransactionWrapper { .asRight case r: ReissueTransaction => Tx.ReIssue(proven(r), r.quantity, r.asset.id, r.reissuable).asRight case b: BurnTransaction => Tx.Burn(proven(b), b.quantity, b.asset.id).asRight - case b: LeaseTransaction => Tx.Lease(proven(b), b.amount, b.recipient).asRight + case b: LeaseTransaction => Tx.Lease(proven(b), b.amount, toRide(b.recipient)).asRight case b: LeaseCancelTransaction => Tx.LeaseCancel(proven(b), b.leaseId).asRight case b: CreateAliasTransaction => Tx.CreateAlias(proven(b), b.alias.name).asRight case ms: MassTransferTransaction => @@ -92,13 +95,13 @@ object RealTransactionWrapper { assetId = ms.assetId.compatId, transferCount = ms.transfers.length, totalAmount = ms.transfers.map(_.amount).sum, - transfers = ms.transfers.map(r => com.wavesplatform.lang.v1.traits.domain.Tx.TransferItem(r.address, r.amount)).toIndexedSeq, + transfers = ms.transfers.map(r => com.wavesplatform.lang.v1.traits.domain.Tx.TransferItem(toRide(r.address), r.amount)).toIndexedSeq, attachment = ms.attachment ) .asRight case ss: SetScriptTransaction => Tx.SetScript(proven(ss), ss.script.map(_.bytes())).asRight case ss: SetAssetScriptTransaction => Tx.SetAssetScript(proven(ss), ss.asset.id, ss.script.map(_.bytes())).asRight - case p: PaymentTransaction => Tx.Payment(proven(p), p.amount, p.recipient).asRight + case p: PaymentTransaction => Tx.Payment(proven(p), p.amount, toRide(p.recipient)).asRight case e: ExchangeTransaction => Tx.Exchange(proven(e), e.amount, e.price, e.buyMatcherFee, e.sellMatcherFee, e.buyOrder, e.sellOrder).asRight case s: SponsorFeeTransaction => Tx.Sponsorship(proven(s), s.asset.id, s.minSponsoredAssetFee).asRight case d: DataTransaction => @@ -113,34 +116,69 @@ object RealTransactionWrapper { }.toIndexedSeq ) .asRight - case ci: InvokeScriptTransaction => + + case ie: InvokeExpressionTransaction => + Tx.InvokeExpression(proven(ie), ie.expressionBytes, ie.feeAssetId.compatId).asRight + + case ci: InvokeScriptTransactionLike => + val (version, bodyBytes, proofs) = ci match { + case ist: InvokeScriptTransaction => + (ist.version, ist.bodyBytes(), ist.proofs) + case _ => + (0.toByte, Array.emptyByteArray, Proofs.empty) + } + AttachedPaymentExtractor .extractPayments(ci, stdLibVersion, blockchain, target) .map { payments => Tx.CI( - proven(ci), - ci.dAppAddressOrAlias, + Proven( + Header(ci.id(), ci.fee, ci.timestamp, version), + RideRecipient.Address(ByteStr(ci.sender.toAddress.bytes)), + ByteStr(bodyBytes), + ci.sender, + proofs.toIndexedSeq + ), + toRide(ci.dApp), payments, ci.feeAssetId.compatId, - ci.funcCallOpt.map(_.function.funcName), - ci.funcCallOpt.map(_.args.map(arg => arg.asInstanceOf[EVALUATED])).getOrElse(List.empty) + Some(ci.funcCall.function.funcName), + ci.funcCall.args.map(arg => arg.asInstanceOf[EVALUATED]) ) } - case ie: InvokeExpressionTransaction => - Tx.InvokeExpression(proven(ie), ie.expressionBytes, ie.feeAssetId.compatId).asRight case u: UpdateAssetInfoTransaction => Tx.UpdateAssetInfo(proven(u), u.assetId.id, u.name, u.description).asRight + + case eth: EthereumTransaction => + Left(s"Unexpected $eth") } - def mapTransferTx(t: TransferTransaction): Tx.Transfer = + def mapTransferTx(t: TransferTransactionLike): Tx.Transfer = { + val (version, bodyBytes, proofs) = t match { + case tt: TransferTransaction => + (tt.version, tt.bodyBytes(), tt.proofs) + case _ => + (0.toByte, Array.emptyByteArray, Proofs.empty) + } Tx.Transfer( - proven(t), + Proven( + Header(t.id(), t.fee, t.timestamp, version), + RideRecipient.Address(ByteStr(t.sender.toAddress.bytes)), + ByteStr(bodyBytes), + t.sender, + proofs.toIndexedSeq + ), feeAssetId = t.feeAssetId.compatId, assetId = t.assetId.compatId, amount = t.amount, - recipient = t.recipient, + recipient = toRide(t.recipient), attachment = t.attachment ) + } + def toRide(recipient: AddressOrAlias): RideRecipient = recipient match { + case address: Address => RideRecipient.Address(ByteStr(address.bytes)) + case recipient: Alias => RideRecipient.Alias(recipient.name) + } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/SetScriptTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/SetScriptTransaction.scala index 6d87f22c539..de3d6ea98eb 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/SetScriptTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/SetScriptTransaction.scala @@ -21,18 +21,15 @@ case class SetScriptTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends ProvenTransaction +) extends Transaction(TransactionType.SetScript) with ProvenTransaction with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V2 { + with PBSince.V2 { - //noinspection TypeAnnotation - override val builder = SetScriptTransaction - - val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetScriptTransaction.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetScriptTransaction.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(SetScriptTransaction.serializer.toJson(this)) + val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetScriptTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(SetScriptTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(SetScriptTxSerializer.toJson(this)) } object SetScriptTransaction extends TransactionParser { @@ -42,13 +39,12 @@ object SetScriptTransaction extends TransactionParser { override val supportedVersions: Set[TxVersion] = Set(1, 2) implicit val validator: TxValidator[SetScriptTransaction] = SetScriptTxValidator - val serializer = SetScriptTxSerializer implicit def sign(tx: SetScriptTransaction, privateKey: PrivateKey): SetScriptTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) override def parseBytes(bytes: Array[TxVersion]): Try[SetScriptTransaction] = - serializer.parseBytes(bytes) + SetScriptTxSerializer.parseBytes(bytes) def create( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala index 4315d548cae..1ca240daac4 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala @@ -23,7 +23,7 @@ import com.wavesplatform.state._ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.TxValidationError.{GenericError, ScriptExecutionError, TransactionNotAllowedByScript} import com.wavesplatform.transaction._ -import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order} +import com.wavesplatform.transaction.assets.exchange.{EthOrders, ExchangeTransaction, Order} import com.wavesplatform.transaction.smart.script.ScriptRunner import com.wavesplatform.transaction.smart.script.ScriptRunner.TxOrd import com.wavesplatform.transaction.smart.script.trace.AssetVerifierTrace.AssetContext @@ -45,27 +45,28 @@ object Verifier extends ScorexLogging { def apply(blockchain: Blockchain, limitedExecution: Boolean = false)(tx: Transaction): TracedResult[ValidationError, Int] = (tx: @unchecked) match { case _: GenesisTransaction => Right(0) + case _: EthereumTransaction => Right(0) case pt: ProvenTransaction => (pt, blockchain.accountScript(pt.sender.toAddress)) match { - case (stx: SignedTransaction, None) => + case (stx: PaymentTransaction, None) => stats.signatureVerification - .measureForType(stx.typeId)(stx.signaturesValid()) + .measureForType(stx.tpe)(stx.signaturesValid()) .as(0) case (et: ExchangeTransaction, scriptOpt) => verifyExchange(et, blockchain, scriptOpt, if (limitedExecution) ContractLimits.FailFreeInvokeComplexity else Int.MaxValue) case (tx: SigProofsSwitch, Some(_)) if tx.usesLegacySignature => Left(GenericError("Can't process transaction with signature from scripted account")) - case (_: SignedTransaction, Some(_)) => + case (_: PaymentTransaction, Some(_)) => Left(GenericError("Can't process transaction with signature from scripted account")) case (_: InvokeExpressionTransaction, Some(script)) if forbidInvokeExpressionDueToVerifier(script.script) => Left( GenericError(s"Can't process InvokeExpressionTransaction from RIDE ${script.script.stdLibVersion} verifier, it might be used from $V6")) case (_, Some(script)) => stats.accountScriptExecution - .measureForType(pt.typeId)(verifyTx(blockchain, script.script, script.verifierComplexity.toInt, pt, None)) + .measureForType(pt.tpe)(verifyTx(blockchain, script.script, script.verifierComplexity.toInt, pt, None)) case _ => stats.signatureVerification - .measureForType(tx.typeId)(verifyAsEllipticCurveSignature(pt)) + .measureForType(tx.tpe)(verifyAsEllipticCurveSignature(pt)) .as(0) } } @@ -78,7 +79,7 @@ object Verifier extends ScorexLogging { } /** Verifies asset scripts and returns diff with complexity. In case of error returns spent complexity */ - def assets(blockchain: Blockchain, remainingComplexity: Int)(tx: Transaction): TracedResult[(Long, ValidationError), Diff] = { + def assets(blockchain: Blockchain, remainingComplexity: Int)(tx: TransactionBase): TracedResult[(Long, ValidationError), Diff] = { case class AssetForCheck(asset: IssuedAsset, script: AssetScriptInfo, assetType: AssetContext) @tailrec @@ -96,7 +97,7 @@ object Verifier extends ScorexLogging { def verify = verifyTx(blockchain, script, estimatedComplexity.toInt, tx, Some(asset.id), complexityLimit, context) - stats.assetScriptExecution.measureForType(tx.typeId)(verify) match { + stats.assetScriptExecution.measureForType(tx.tpe)(verify) match { case TracedResult(e @ Left(_), trace, attributes) => (fullComplexity + estimatedComplexity, TracedResult(e, fullTrace ::: trace, fullAttributes ++ attributes)) case TracedResult(Right(complexity), trace, attributes) => @@ -110,10 +111,9 @@ object Verifier extends ScorexLogging { blockchain.assetDescription(asset).flatMap(_.script) val assets = for { - asset <- tx.checkedAssets.toList + asset <- tx.smartAssets(blockchain).toList script <- assetScript(asset) - context = AssetContext.fromTxAndAsset(tx, asset) - } yield AssetForCheck(asset, script, context) + } yield AssetForCheck(asset, script, AssetContext.fromTxAndAsset(tx, asset)) val additionalAssets = tx match { case e: ExchangeTransaction => @@ -150,7 +150,7 @@ object Verifier extends ScorexLogging { blockchain: Blockchain, script: Script, estimatedComplexity: Int, - transaction: Transaction, + transaction: TransactionBase, assetIdOpt: Option[ByteStr], complexityLimit: Int = Int.MaxValue, assetContext: AssetContext.Value = AssetContext.Unknown @@ -228,7 +228,7 @@ object Verifier extends ScorexLogging { complexityLimit: Int ): TracedResult[ValidationError, Int] = { - val typeId = et.typeId + val typeId = et.tpe val sellOrder = et.sellOrder val buyOrder = et.buyOrder @@ -254,7 +254,7 @@ object Verifier extends ScorexLogging { Left(GenericError("Can't process order with signature from scripted account")) } } - .getOrElse(stats.signatureVerification.measureForType(typeId)(verifyAsEllipticCurveSignature(order).as(0))) + .getOrElse(stats.signatureVerification.measureForType(typeId)(verifyOrderSignature(order).as(0))) TracedResult(verificationResult) } @@ -266,6 +266,15 @@ object Verifier extends ScorexLogging { } yield matcherComplexity + sellerComplexity + buyerComplexity } + def verifyOrderSignature(order: Order): Either[GenericError, Order] = + order.eip712Signature match { + case Some(ethSignature) => + val signerKey = EthOrders.recoverEthSignerKey(order, ethSignature.arr) + Either.cond(signerKey == order.senderPublicKey, order, GenericError(s"Ethereum signature invalid for $order")) + + case _ => verifyAsEllipticCurveSignature(order) + } + def verifyAsEllipticCurveSignature[T <: Proven with Authorized](pt: T): Either[GenericError, T] = pt.proofs.proofs match { case p +: Nil => diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala index 926623d8f1c..839d9228d0e 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala @@ -1,9 +1,9 @@ package com.wavesplatform.transaction.smart +import cats.kernel.Monoid import cats.syntax.either._ -import cats.syntax.semigroup._ import com.wavesplatform.account -import com.wavesplatform.account.AddressOrAlias +import com.wavesplatform.account.{AddressOrAlias, PublicKey} import com.wavesplatform.block.BlockHeader import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 @@ -19,7 +19,7 @@ import com.wavesplatform.lang.v1.traits._ import com.wavesplatform.lang.v1.traits.domain.Recipient._ import com.wavesplatform.lang.v1.traits.domain._ import com.wavesplatform.state._ -import com.wavesplatform.state.diffs.invoke.{InvokeScript, InvokeScriptDiff} +import com.wavesplatform.state.diffs.invoke.{InvokeScript, InvokeScriptDiff, InvokeScriptTransactionLike} import com.wavesplatform.state.reader.CompositeBlockchain import com.wavesplatform.transaction.Asset._ import com.wavesplatform.transaction.TxValidationError.{FailedTransactionError, GenericError} @@ -29,12 +29,14 @@ import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.trace.CoevalR.traced import com.wavesplatform.transaction.smart.script.trace.InvokeScriptTrace import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, Transaction} +import com.wavesplatform.transaction.{Asset, TransactionBase} import monix.eval.Coeval import shapeless._ +import scala.util.Try + object WavesEnvironment { - type In = Transaction :+: Order :+: PseudoTx :+: CNil + type In = TransactionBase :+: Order :+: PseudoTx :+: CNil } class WavesEnvironment( @@ -130,7 +132,7 @@ class WavesEnvironment( override def accountBalanceOf(addressOrAlias: Recipient, maybeAssetId: Option[Array[Byte]]): Either[String, Long] = { (for { aoa <- addressOrAlias match { - case Address(bytes) => AddressOrAlias.fromBytes(bytes.arr, position = 0).map(_._1) + case Address(bytes) => AddressOrAlias.fromBytes(bytes.arr) case Alias(name) => com.wavesplatform.account.Alias.create(name) } address <- blockchain.resolveAlias(aoa) @@ -141,7 +143,7 @@ class WavesEnvironment( override def accountWavesBalanceOf(addressOrAlias: Recipient): Either[String, Environment.BalanceDetails] = { (for { aoa <- addressOrAlias match { - case Address(bytes) => AddressOrAlias.fromBytes(bytes.arr, position = 0).map(_._1) + case Address(bytes) => AddressOrAlias.fromBytes(bytes.arr) case Alias(name) => com.wavesplatform.account.Alias.create(name) } address <- blockchain.resolveAlias(aoa) @@ -217,6 +219,14 @@ class WavesEnvironment( address => Address(ByteStr(address.bytes)) ) + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = + Try(PublicKey(publicKey)) + .toEither + .bimap( + _.getMessage, + pk => Address(ByteStr(pk.toAddress.bytes)) + ) + override def accountScript(addressOrAlias: Recipient): Option[Script] = { for { address <- toAddress(addressOrAlias) @@ -285,7 +295,11 @@ object DAppEnvironment { } } - final case class DAppInvocation(dAppAddress: com.wavesplatform.account.Address, call: FUNCTION_CALL, payments: Seq[InvokeScriptTransaction.Payment]) + final case class DAppInvocation( + dAppAddress: com.wavesplatform.account.Address, + call: FUNCTION_CALL, + payments: Seq[InvokeScriptTransaction.Payment] + ) } // Not thread safe @@ -296,7 +310,7 @@ class DAppEnvironment( blockchain: Blockchain, tthis: Environment.Tthis, ds: DirectiveSet, - tx: Option[InvokeTransaction], + tx: InvokeScriptTransactionLike, currentDApp: com.wavesplatform.account.Address, currentDAppPk: com.wavesplatform.account.PublicKey, calledAddresses: Set[com.wavesplatform.account.Address], @@ -308,7 +322,7 @@ class DAppEnvironment( var availableDataSize: Int, var currentDiff: Diff, val invocationRoot: DAppEnvironment.InvocationTreeTracker -) extends WavesEnvironment(nByte, in, h, blockchain, tthis, ds, tx.map(_.id()).getOrElse(ByteStr.empty)) { +) extends WavesEnvironment(nByte, in, h, blockchain, tthis, ds, tx.id()) { private[this] var mutableBlockchain = CompositeBlockchain(blockchain, currentDiff) @@ -343,7 +357,6 @@ class DAppEnvironment( ) .map( InvokeScript( - currentDApp, currentDAppPk, _, FUNCTION_CALL(User(func, func), args), @@ -354,7 +367,7 @@ class DAppEnvironment( ) invocationTracker = { // Log sub-contract invocation - val invocation = DAppEnvironment.DAppInvocation(invoke.dAppAddress, invoke.funcCall, invoke.payments) + val invocation = DAppEnvironment.DAppInvocation(invoke.dApp, invoke.funcCall, invoke.payments) invocationRoot.record(invocation) } (diff, evaluated, remainingActions, remainingData, remainingDataSize) <- InvokeScriptDiff( // This is a recursive call @@ -367,7 +380,7 @@ class DAppEnvironment( availableActions, availableData, availableDataSize, - if (reentrant) calledAddresses else calledAddresses + invoke.senderAddress, + if (reentrant) calledAddresses else calledAddresses + invoke.sender.toAddress, invocationTracker )(invoke) } yield { @@ -375,7 +388,7 @@ class DAppEnvironment( scriptResults = Map(txId -> InvokeScriptResult(invokes = Seq(invocation.copy(stateChanges = diff.scriptResults(txId))))), scriptsRun = diff.scriptsRun + 1 ) - currentDiff = currentDiff |+| fixedDiff + currentDiff = Monoid.combine(currentDiff, fixedDiff) mutableBlockchain = CompositeBlockchain(blockchain, currentDiff) remainingCalls = remainingCalls - 1 availableActions = remainingActions diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/script/trace/TraceStep.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/script/trace/TraceStep.scala index af77ec83b58..edbda481264 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/script/trace/TraceStep.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/script/trace/TraceStep.scala @@ -9,14 +9,14 @@ import com.wavesplatform.lang.v1.evaluator.{Log, ScriptResult} import com.wavesplatform.serialization.ScriptValuesJson import com.wavesplatform.state.InvokeScriptResult import com.wavesplatform.transaction.Asset.IssuedAsset -import com.wavesplatform.transaction.Transaction +import com.wavesplatform.transaction.TransactionBase import com.wavesplatform.transaction.TxValidationError.{FailedTransactionError, ScriptExecutionError, TransactionNotAllowedByScript} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} -import play.api.libs.json._ import play.api.libs.json.Json.JsValueWrapper +import play.api.libs.json._ sealed abstract class TraceStep { def json: JsObject // TODO: Is this format necessary? @@ -31,7 +31,7 @@ case class AccountVerifierTrace( override lazy val json: JsObject = Json .obj( "type" -> "verifier", - "id" -> address.stringRepr + "id" -> address.toString ) ++ TraceStep.maybeErrorJson(errorOpt) } @@ -40,7 +40,7 @@ object AssetVerifierTrace { object AssetContext extends Enumeration { val Unknown, OrderAmount, OrderPrice, MatcherFee, Payment, Reissue, Burn, Sponsor, Transfer, UpdateInfo = Value - def fromTxAndAsset(tx: Transaction, asset: IssuedAsset): AssetContext = tx match { + def fromTxAndAsset(tx: TransactionBase, asset: IssuedAsset): AssetContext = tx match { case i: InvokeScriptTransaction if i.payments.exists(_.assetId == asset) => AssetContext.Payment case e: ExchangeTransaction if e.order1.assetPair.amountAsset == asset => AssetContext.OrderAmount @@ -87,7 +87,7 @@ case class InvokeScriptTrace( def maybeLoggedJson(logged: Boolean)(implicit invokeResultWrites: OWrites[InvokeScriptResult] = InvokeScriptResult.jsonFormat): JsObject = { Json.obj( "type" -> "dApp", - "id" -> dAppAddressOrAlias.stringRepr, + "id" -> dAppAddressOrAlias.toString, "function" -> functionCall.function.funcName, "args" -> functionCall.args.map(_.toString), "invocations" -> invocations.map(_.maybeLoggedJson(logged)(invokeResultWrites)) diff --git a/node/src/main/scala/com/wavesplatform/transaction/transfer/MassTransferTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/transfer/MassTransferTransaction.scala index 4ff5ed6babb..f4560d2d93e 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/transfer/MassTransferTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/transfer/MassTransferTransaction.scala @@ -1,14 +1,16 @@ package com.wavesplatform.transaction.transfer +import scala.util.{Either, Try} + import cats.instances.list._ import cats.syntax.traverse._ import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError +import com.wavesplatform.transaction._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError._ -import com.wavesplatform.transaction._ import com.wavesplatform.transaction.serialization.impl.MassTransferTxSerializer import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer import com.wavesplatform.transaction.validation.TxValidator @@ -16,8 +18,6 @@ import com.wavesplatform.transaction.validation.impl.MassTransferTxValidator import monix.eval.Coeval import play.api.libs.json.{JsObject, Json} -import scala.util.{Either, Try} - case class MassTransferTransaction( version: TxVersion, sender: PublicKey, @@ -28,26 +28,29 @@ case class MassTransferTransaction( attachment: ByteStr, proofs: Proofs, chainId: Byte -) extends ProvenTransaction +) extends Transaction(TransactionType.MassTransfer, assetId match { + case Waves => Seq() + case a: IssuedAsset => Seq(a) + }) + with ProvenTransaction with VersionedTransaction with TxWithFee.InWaves with FastHashId - with LegacyPBSwitch.V2 { - - //noinspection TypeAnnotation - override val builder = MassTransferTransaction - - override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.bodyBytes(this)) - override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(builder.serializer.toBytes(this)) - override val json: Coeval[JsObject] = Coeval.evalOnce(builder.serializer.toJson(this)) - - def compactJson(recipients: Set[AddressOrAlias]): JsObject = - json() ++ Json.obj("transfers" -> MassTransferTxSerializer.transfersJson(transfers.filter(t => recipients.contains(t.address)))) - - override def checkedAssets: Seq[IssuedAsset] = assetId match { - case Waves => Seq() - case a: IssuedAsset => Seq(a) - } + with PBSince.V2 { + + override val bodyBytes: Coeval[Array[Byte]] = Coeval.evalOnce(MassTransferTxSerializer.bodyBytes(this)) + override val bytes: Coeval[Array[Byte]] = Coeval.evalOnce(MassTransferTxSerializer.toBytes(this)) + override val json: Coeval[JsObject] = Coeval.evalOnce(MassTransferTxSerializer.toJson(this)) + + def compactJson(recipient: Address, aliases: Set[Alias]): JsObject = + json() ++ Json.obj( + "transfers" -> MassTransferTxSerializer.transfersJson(transfers.filter { t => + t.address match { + case a: Address => a == recipient + case a: Alias => aliases(a) + } + }) + ) } object MassTransferTransaction extends TransactionParser { @@ -63,11 +66,8 @@ object MassTransferTransaction extends TransactionParser { implicit def sign(tx: MassTransferTransaction, privateKey: PrivateKey): MassTransferTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - //noinspection TypeAnnotation - val serializer = MassTransferTxSerializer - override def parseBytes(bytes: Array[Byte]): Try[MassTransferTransaction] = - serializer.parseBytes(bytes) + MassTransferTxSerializer.parseBytes(bytes) case class Transfer( recipient: String, diff --git a/node/src/main/scala/com/wavesplatform/transaction/transfer/TransferTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/transfer/TransferTransaction.scala index 2bc5a4bbfc6..bb54a300a2a 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/transfer/TransferTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/transfer/TransferTransaction.scala @@ -27,24 +27,28 @@ case class TransferTransaction( timestamp: TxTimestamp, proofs: Proofs, chainId: Byte -) extends VersionedTransaction - with SigProofsSwitch +) extends Transaction(TransactionType.Transfer, assetId match { + case Waves => Seq() + case a: IssuedAsset => Seq(a) + }) + with TransferTransactionLike + with VersionedTransaction with FastHashId + with SigProofsSwitch with TxWithFee.InCustomAsset - with LegacyPBSwitch.V3 { - - override val typeId: TxType = TransferTransaction.typeId + with PBSince.V3 { - val bodyBytes: Coeval[TxByteArray] = Coeval.evalOnce(TransferTransaction.serializer.bodyBytes(this)) - val bytes: Coeval[TxByteArray] = Coeval.evalOnce(TransferTransaction.serializer.toBytes(this)) - final val json: Coeval[JsObject] = Coeval.evalOnce(TransferTransaction.serializer.toJson(this)) - - override def checkedAssets: Seq[IssuedAsset] = assetId match { - case a: IssuedAsset => Seq(a) - case Waves => Nil - } + val bodyBytes: Coeval[TxByteArray] = Coeval.evalOnce(TransferTxSerializer.bodyBytes(this)) + val bytes: Coeval[TxByteArray] = Coeval.evalOnce(TransferTxSerializer.toBytes(this)) + final val json: Coeval[JsObject] = Coeval.evalOnce(TransferTxSerializer.toJson(this)) +} - override def builder: TransactionParser = TransferTransaction +trait TransferTransactionLike extends TransactionBase with Authorized { + val sender: PublicKey + val recipient: AddressOrAlias + val assetId: Asset + val amount: TxAmount + val attachment: ByteStr } object TransferTransaction extends TransactionParser { @@ -61,9 +65,7 @@ object TransferTransaction extends TransactionParser { implicit def sign(tx: TransferTransaction, privateKey: PrivateKey): TransferTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) - val serializer = TransferTxSerializer - - override def parseBytes(bytes: TxByteArray): Try[TransferTransaction] = serializer.parseBytes(bytes) + override def parseBytes(bytes: TxByteArray): Try[TransferTransaction] = TransferTxSerializer.parseBytes(bytes) def create( version: TxVersion, @@ -77,7 +79,7 @@ object TransferTransaction extends TransactionParser { timestamp: TxTimestamp, proofs: Proofs ): Either[ValidationError, TransferTransaction] = - TransferTransaction(version, sender, recipient, asset, amount, feeAsset, fee, attachment, timestamp, proofs, recipient.chainId).validatedEither + TransferTransaction(version, sender, recipient, asset, amount, feeAsset, fee, attachment, timestamp, proofs, AddressScheme.current.chainId).validatedEither def signed( version: TxVersion, diff --git a/node/src/main/scala/com/wavesplatform/transaction/utils/EthConverters.scala b/node/src/main/scala/com/wavesplatform/transaction/utils/EthConverters.scala new file mode 100644 index 00000000000..0eaff6764be --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/utils/EthConverters.scala @@ -0,0 +1,27 @@ +package com.wavesplatform.transaction.utils + +import com.wavesplatform.account.{Address, KeyPair} +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.utils.EthEncoding +import org.web3j.crypto.{Bip32ECKeyPair, ECKeyPair, Keys} + +object EthConverters { + implicit class EthereumKeyPairExt(private val kp: KeyPair) extends AnyVal { + def toEthKeyPair: Bip32ECKeyPair = Bip32ECKeyPair.generateKeyPair(kp.seed) + def toEthAddress: String = toEthKeyPair.toEthAddress + def toEthWavesAddress: Address = toEthKeyPair.toWavesAddress + } + + implicit class EthereumAddressExt(private val address: Address) extends AnyVal { + def toEthAddress: String = EthEncoding.toHexString(address.publicKeyHash) + } + + implicit class EthereumECKeyPairExt(private val kp: ECKeyPair) extends AnyVal { + def toWavesAddress: Address = Address(EthEncoding.toBytes(toEthAddress)) + def toEthAddress: String = Keys.getAddress(kp) + } + + implicit class EthereumByteStrExt(private val bs: ByteStr) extends AnyVal { + def toHexString: String = EthEncoding.toHexString(bs.arr) + } +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/utils/EthTxGenerator.scala b/node/src/main/scala/com/wavesplatform/transaction/utils/EthTxGenerator.scala new file mode 100644 index 00000000000..37734d263ae --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/utils/EthTxGenerator.scala @@ -0,0 +1,200 @@ +package com.wavesplatform.transaction.utils + +import com.wavesplatform.account.Address +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils._ +import com.wavesplatform.transaction.{ABIConverter, Asset, EthereumTransaction} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.utils.EthEncoding +import org.web3j.abi.FunctionEncoder +import org.web3j.abi.datatypes.{AbiTypes, StructType} +import org.web3j.crypto._ + +// TODO: Move to separate package available to node-generator and node:test +object EthTxGenerator { + sealed trait Arg + object Arg { + case class Integer(v: Long, typeStr: String = "int64") extends Arg + case class Bytes(v: ByteStr, typeStr: String = "bytes") extends Arg + case class Str(v: String) extends Arg + case class BigInteger(bi: BigInt, typeStr: String = "int256") extends Arg + case class Bool(b: Boolean) extends Arg + case class List(listType: Arg, elements: Seq[Arg]) extends Arg + case class Union(index: Int, fields: Seq[Arg]) extends Arg + case class Struct(values: Arg*) extends Arg + } + + import org.web3j.abi.{datatypes => ethTypes} + // import com.esaulpaugh.headlong.{abi => hl} + // import scala.jdk.CollectionConverters._ + + //noinspection ScalaDeprecation + /* def toEthType(value: Terms.EVALUATED): ethTypes.Type[_] = value match { // TODO remove + case Terms.CONST_LONG(t) => new ethTypes.generated.Int64(t) + case Terms.CONST_BIGINT(t) => new ethTypes.generated.Int256(t.bigInteger) + case bs: Terms.CONST_BYTESTR => new ethTypes.DynamicBytes(bs.bs.arr) + case s: Terms.CONST_STRING => new ethTypes.Utf8String(s.s) + case Terms.CONST_BOOLEAN(b) => new ethTypes.Bool(b) + case ARR(xs) => + val ethTypedXs = xs.map(toEthType) + val arrayClass = (ethTypedXs.headOption match { + case Some(value) => + if (classOf[StructType].isAssignableFrom(value.getClass)) value.getClass + else ethTypes.AbiTypes.getType(value.getTypeAsString) + + case None => classOf[ethTypes.BytesType] + }).asInstanceOf[Class[ethTypes.Type[_]]] + + new ethTypes.DynamicArray(arrayClass, ethTypedXs: _*) { + override def getTypeAsString: String = { + val head = ethTypedXs.headOption.getOrElse(ethTypes.generated.Bytes32.DEFAULT) + (if (classOf[StructType].isAssignableFrom(head.getClass)) head.getTypeAsString else AbiTypes.getTypeAString(getComponentType)) + "[]" + } + } + + case CaseObj(_, fields) => new ethTypes.DynamicStruct(fields.values.toSeq.map(toEthType): _*) + case _ => ??? + } */ + + def toEthType(value: Arg): ethTypes.Type[_] = value match { + case Arg.Integer(v, typeStr) => + val typeClass = ethTypes.AbiTypes.getType(typeStr) + typeClass.getConstructor(classOf[Long]).newInstance(v) + case Arg.BigInteger(bi, typeStr) => + val typeClass = ethTypes.AbiTypes.getType(typeStr) + typeClass.getConstructor(classOf[java.math.BigInteger]).newInstance(bi.bigInteger) + case Arg.Str(v) => + new ethTypes.Utf8String(v) + case Arg.Bytes(v, typeStr) => + val typeClass = ethTypes.AbiTypes.getType(typeStr) + typeClass.getConstructor(classOf[Array[Byte]]).newInstance(v.arr) + case Arg.Bool(b) => + new ethTypes.Bool(b) + case Arg.List(listType, elements) => + val ethTypedXs = elements.map(toEthType) + val arrayClass = toEthType(listType) + new ethTypes.DynamicArray(arrayClass.getClass.asInstanceOf[Class[ethTypes.Type[_]]], ethTypedXs: _*) { + override def getTypeAsString: String = + (if (classOf[StructType].isAssignableFrom(arrayClass.getClass)) arrayClass.getTypeAsString else AbiTypes.getTypeAString(getComponentType)) + "[]" + } + case Arg.Union(index, fields) => + new ethTypes.DynamicStruct(toEthType(Arg.Integer(index, "uint8")) +: fields.map(toEthType): _*) + + case Arg.Struct(values @ _*) => new ethTypes.StaticStruct(values.map(toEthType): _*) + } + + /* def toHLEthType(value: Terms.EVALUATED): hl.ABIType[_] = value match { + case Terms.CONST_LONG(_) => hl.TypeFactory.create[hl.LongType]("int64") + case Terms.CONST_BIGINT(_) => hl.TypeFactory.create[hl.BigIntegerType]("int256") + case Terms.CONST_BOOLEAN(_) => hl.TypeFactory.create[hl.BooleanType]("bool") + case _: Terms.CONST_BYTESTR => hl.TypeFactory.create[hl.ArrayType[hl.ByteType, Array[Byte]]]("bytes") + case _: Terms.CONST_STRING => hl.TypeFactory.create[hl.ArrayType[hl.ByteType, String]]("string") + case ARR(xs) => hl.TypeFactory.create[hl.ArrayType[_, _]](s"${toHLEthType(xs.head)}[]") + case CaseObj(_, fields) => hl.TypeFactory.create[hl.TupleType](fields.values.map(toHLEthType).mkString("(", ",", ")")) + } + + def toHLEthValue(value: Terms.EVALUATED): Any = value match { + case Terms.CONST_LONG(t) => java.lang.Long.valueOf(t) + case Terms.CONST_BIGINT(t) => t.bigInteger + case bs: Terms.CONST_BYTESTR => bs.bs.arr + case s: Terms.CONST_STRING => s.s + case Terms.CONST_BOOLEAN(b) => java.lang.Boolean.valueOf(b) + case ARR(xs) => + val values = xs.map(toHLEthValue) + values.toArray(ClassTag(values.head.getClass)) + case CaseObj(_, fields) => hl.Tuple.of(fields.values.toSeq.map(toHLEthValue): _*) + case _ => ??? + } */ + + def signRawTransaction(keyPair: ECKeyPair, chainId: Byte)(raw: RawTransaction): EthereumTransaction = { + val signedTx = + new SignedRawTransaction(raw.getTransaction, Sign.signMessage(TransactionEncoder.encode(raw, chainId.toLong), keyPair, true)) + EthereumTransaction(signedTx).explicitGet() + } + + def generateEthTransfer(keyPair: ECKeyPair, recipient: Address, amount: Long, asset: Asset): EthereumTransaction = asset match { + case Asset.Waves => + signRawTransaction(keyPair, recipient.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis()).bigInteger, + EthereumTransaction.GasPrice, + BigInt(100000).bigInteger, // fee + EthEncoding.toHexString(recipient.publicKeyHash), + (BigInt(amount) * EthereumTransaction.AmountMultiplier).bigInteger, + "" + ) + ) + + case Asset.IssuedAsset(assetId) => + import scala.jdk.CollectionConverters._ + val function = new org.web3j.abi.datatypes.Function( + "transfer", + Seq[ethTypes.Type[_]]( + new ethTypes.Address(EthEncoding.toHexString(recipient.publicKeyHash)), + new ethTypes.generated.Uint256(amount) + ).asJava, + Nil.asJava + ) + + signRawTransaction(keyPair, recipient.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis()).bigInteger, + EthereumTransaction.GasPrice, + BigInt(100000).bigInteger, // fee + EthEncoding.toHexString(assetId.arr.take(20)), // asset erc20 "contract" address + FunctionEncoder.encode(function) + ) + ) + } + + def generateEthInvoke( + keyPair: ECKeyPair, + address: Address, + funcName: String, + args: Seq[Arg], + payments: Seq[Payment], + fee: Long = 500000 + ): EthereumTransaction = { + import scala.jdk.CollectionConverters._ + val paymentsArg = { + val tuples = payments.toVector.map { p => + val assetId = p.assetId match { + case Asset.IssuedAsset(id) => id + case Asset.Waves => ABIConverter.WavesByteRepr + } + Arg.Struct(Arg.Bytes(assetId, "bytes32"), Arg.Integer(p.amount)) + } + Arg.List(Arg.Struct(Arg.Bytes(ABIConverter.WavesByteRepr, "bytes32"), Arg.Integer(0)), tuples) + } + + val fullArgs = (args :+ paymentsArg) + + /* val ethFunc = new hl.Function( + hl.TypeEnum.FUNCTION, + funcName, + hl.TupleType.of(fullArgs.map(a => toHLEthType(a).getCanonicalType): _*), + hl.TupleType.EMPTY, + null, + hl.Function.newDefaultDigest() + ) + val values = fullArgs.map(toHLEthValue) + val ethCallData = EthEncoding.toHexString(ethFunc.encodeCallWithArgs(values:_*).array()) */ + + val argsAsEth = fullArgs.map(toEthType) + val function = new org.web3j.abi.datatypes.Function( + funcName, + argsAsEth.asJava, + Nil.asJava + ) + + signRawTransaction(keyPair, address.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis()).bigInteger, + EthereumTransaction.GasPrice, + BigInt(fee).bigInteger, + EthEncoding.toHexString(address.publicKeyHash), + FunctionEncoder.encode(function) + ) + ) + } +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/utils/Signed.scala b/node/src/main/scala/com/wavesplatform/transaction/utils/Signed.scala new file mode 100644 index 00000000000..ea3ba8cbb24 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/transaction/utils/Signed.scala @@ -0,0 +1,24 @@ +package com.wavesplatform.transaction.utils + +import com.wavesplatform.account.{AddressOrAlias, KeyPair} +import com.wavesplatform.common.utils._ +import com.wavesplatform.lang.v1.compiler.Terms +import com.wavesplatform.transaction.{Asset, Proofs, TxAmount, TxTimestamp} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction + +object Signed { + def invokeScript( + version: Byte, + sender: KeyPair, + dApp: AddressOrAlias, + functionCall: Option[Terms.FUNCTION_CALL], + payments: Seq[InvokeScriptTransaction.Payment], + fee: TxAmount, + feeAssetId: Asset, + timestamp: TxTimestamp + ): InvokeScriptTransaction = + InvokeScriptTransaction + .create(version, sender.publicKey, dApp, functionCall, payments, fee, feeAssetId, timestamp, Proofs.empty, dApp.chainId) + .map(_.signWith(sender.privateKey)) + .explicitGet() +} diff --git a/node/src/main/scala/com/wavesplatform/transaction/validation/TxConstraints.scala b/node/src/main/scala/com/wavesplatform/transaction/validation/TxConstraints.scala index 2a4771b0a47..9f277408615 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/validation/TxConstraints.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/validation/TxConstraints.scala @@ -1,5 +1,7 @@ package com.wavesplatform.transaction.validation +import scala.util.Try + import cats.data.{NonEmptyList, Validated} import cats.data.Validated.{Invalid, Valid} import cats.implicits._ @@ -7,12 +9,10 @@ import com.google.protobuf.ByteString import com.wavesplatform.account.AddressOrAlias import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.ValidationError +import com.wavesplatform.transaction.{Asset, TxValidationError, TxVersion, VersionedTransaction} import com.wavesplatform.transaction.TxValidationError.{GenericError, TooBigArray} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, TxValidationError, TxVersion, VersionedTransaction} - -import scala.util.Try object TxConstraints { // Generic diff --git a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/InvokeScriptTxValidator.scala b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/InvokeScriptTxValidator.scala index 1229d2ae9b5..75255365b3c 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/InvokeScriptTxValidator.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/InvokeScriptTxValidator.scala @@ -25,7 +25,7 @@ object InvokeScriptTxValidator extends TxValidator[InvokeScriptTransaction] { def checkLength = if (tx.isProtobufVersion) PBTransactions - .toPBInvokeScriptData(tx.dAppAddressOrAlias, tx.funcCallOpt, tx.payments) + .toPBInvokeScriptData(tx.dApp, tx.funcCallOpt, tx.payments) .toByteArray .length <= ContractLimits.MaxInvokeScriptSizeInBytes else tx.bytes().length <= ContractLimits.MaxInvokeScriptSizeInBytes @@ -37,7 +37,7 @@ object InvokeScriptTxValidator extends TxValidator[InvokeScriptTransaction] { } V.seq(tx)( - V.addressChainId(dAppAddressOrAlias, chainId), + V.addressChainId(dApp, chainId), V.cond( funcCallOpt.isEmpty || funcCallOpt.get.args.size <= ContractLimits.MaxInvokeScriptArgs, GenericError(s"InvokeScript can't have more than ${ContractLimits.MaxInvokeScriptArgs} arguments") diff --git a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/MassTransferTxValidator.scala b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/MassTransferTxValidator.scala index ea2bc47c52a..6bcb69ad304 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/MassTransferTxValidator.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/MassTransferTxValidator.scala @@ -1,5 +1,6 @@ package com.wavesplatform.transaction.validation.impl +import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.transfer.MassTransferTransaction import com.wavesplatform.transaction.transfer.MassTransferTransaction.MaxTransferCount @@ -14,7 +15,10 @@ object MassTransferTxValidator extends TxValidator[MassTransferTransaction] { V.transferAttachment(attachment), V.cond(transfers.forall(_.amount >= 0), GenericError("One of the transfers has negative amount")), V.fee(fee), - V.chainIds(chainId, transfers.map(_.address.chainId): _*) + V.chainIds(chainId, transfers.view.map(_.address).collect { + case wa: Address => wa.chainId + case wl: Alias => wl.chainId + }.toSeq: _*) ) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/UpdateAssetInfoTxValidator.scala b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/UpdateAssetInfoTxValidator.scala index a2a2563b1ff..4333c4cc79d 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/validation/impl/UpdateAssetInfoTxValidator.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/validation/impl/UpdateAssetInfoTxValidator.scala @@ -3,13 +3,12 @@ package com.wavesplatform.transaction.validation.impl import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.assets.UpdateAssetInfoTransaction import com.wavesplatform.transaction.validation.{TxValidator, ValidatedV} -import com.wavesplatform.transaction.{Asset, TxValidationError} +import com.wavesplatform.transaction.Asset import com.wavesplatform.utils.StringBytes object UpdateAssetInfoTxValidator extends TxValidator[UpdateAssetInfoTransaction] { override def validate(tx: UpdateAssetInfoTransaction): ValidatedV[UpdateAssetInfoTransaction] = V.seq(tx)( - V.cond(UpdateAssetInfoTransaction.supportedVersions(tx.version), TxValidationError.UnsupportedVersion(tx.version)), V.fee(tx.feeAmount), V.asset[IssuedAsset](tx.assetId), V.asset[Asset](tx.feeAsset), diff --git a/node/src/main/scala/com/wavesplatform/utils/EthEncoding.scala b/node/src/main/scala/com/wavesplatform/utils/EthEncoding.scala new file mode 100644 index 00000000000..7c43ef3b7c4 --- /dev/null +++ b/node/src/main/scala/com/wavesplatform/utils/EthEncoding.scala @@ -0,0 +1,10 @@ +package com.wavesplatform.utils + +import org.web3j.utils.Numeric + +object EthEncoding { + def toHexString(bs: Array[Byte]): String = Numeric.toHexString(bs) + def toHexString(bs: BigInt): String = Numeric.toHexStringWithPrefixSafe(bs.bigInteger) + def toBytes(hexString: String): Array[Byte] = Numeric.hexStringToByteArray(hexString) + def cleanHexPrefix(hexString: String): String = Numeric.cleanHexPrefix(hexString) +} diff --git a/node/src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala b/node/src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala index e0ba5b2c1de..b0c47869b6e 100644 --- a/node/src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala +++ b/node/src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala @@ -122,7 +122,7 @@ class UtxPoolImpl( } val allowed = recipients.nonEmpty && - recipients.forall(r => utxSettings.allowBlacklistedTransferTo.contains(r.stringRepr)) + recipients.forall(r => utxSettings.allowBlacklistedTransferTo.contains(r.toString)) Either.cond(allowed, (), SenderIsBlacklisted(addr)) case _ => Right(()) } @@ -255,10 +255,10 @@ class UtxPoolImpl( private def scriptedAddresses(tx: Transaction): Set[Address] = tx match { case t if inUTXPoolOrdering.isWhitelisted(t) => Set.empty case i: InvokeScriptTransaction => - Set(i.sender.toAddress) - .filter(blockchain.hasAccountScript) ++ blockchain.resolveAlias(i.dAppAddressOrAlias).fold[Set[Address]](_ => Set.empty, Set(_)) + Set[Address](i.senderAddress) + .filter(blockchain.hasAccountScript) ++ blockchain.resolveAlias(i.dApp).fold[Set[Address]](_ => Set.empty, Set(_)) case e: ExchangeTransaction => - Set(e.sender.toAddress, e.buyOrder.sender.toAddress, e.sellOrder.sender.toAddress).filter(blockchain.hasAccountScript) + Set[Address](e.sender.toAddress, e.buyOrder.sender.toAddress, e.sellOrder.sender.toAddress).filter(blockchain.hasAccountScript) case a: Authorized if blockchain.hasAccountScript(a.sender.toAddress) => Set(a.sender.toAddress) case _ => Set.empty } diff --git a/node/src/main/scala/com/wavesplatform/wallet/Wallet.scala b/node/src/main/scala/com/wavesplatform/wallet/Wallet.scala index 8df243f5b3d..35f6ea9dd15 100644 --- a/node/src/main/scala/com/wavesplatform/wallet/Wallet.scala +++ b/node/src/main/scala/com/wavesplatform/wallet/Wallet.scala @@ -144,7 +144,7 @@ object Wallet extends ScorexLogging { } override def privateKeyAccount(account: Address): Either[ValidationError, KeyPair] = - accountsCache.get(account.stringRepr).toRight[ValidationError](MissingSenderPrivateKey) + accountsCache.get(account.toString).toRight[ValidationError](MissingSenderPrivateKey) override def nonce: Int = walletData.nonce diff --git a/node/src/test/scala/com/wavesplatform/BlockGen.scala b/node/src/test/scala/com/wavesplatform/BlockGen.scala index 87669c92a72..f4249c1e1de 100644 --- a/node/src/test/scala/com/wavesplatform/BlockGen.scala +++ b/node/src/test/scala/com/wavesplatform/BlockGen.scala @@ -5,7 +5,7 @@ import com.wavesplatform.block.Block import com.wavesplatform.block.Block.{GenerationSignatureLength, GenerationVRFSignatureLength, ProtoBlockVersion} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.transaction.{ProvenTransaction, Transaction} +import com.wavesplatform.transaction.Transaction import org.scalacheck.Gen import org.scalatest.Suite @@ -13,7 +13,7 @@ trait BlockGen extends TransactionGen { _: Suite => import BlockGen._ - val blockParamGen: Gen[(Seq[ProvenTransaction], KeyPair)] = for { + val blockParamGen: Gen[(Seq[Transaction], KeyPair)] = for { count <- Gen.choose(minTransactionsInBlockCount, maxTransactionsInBlockCount) transactions <- randomTransactionsGen(count) signer <- accountGen diff --git a/node/src/test/scala/com/wavesplatform/BlockchainStubHelpers.scala b/node/src/test/scala/com/wavesplatform/BlockchainStubHelpers.scala index 7f92076bdb1..2e32af6d052 100644 --- a/node/src/test/scala/com/wavesplatform/BlockchainStubHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/BlockchainStubHelpers.scala @@ -1,17 +1,28 @@ package com.wavesplatform +import scala.concurrent.Future + +import com.google.protobuf.ByteString +import com.wavesplatform.account.{Address, PublicKey} import com.wavesplatform.block.SignedBlockHeader -import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.features.{BlockchainFeature, BlockchainFeatures} import com.wavesplatform.lagonaki.mocks.TestBlock +import com.wavesplatform.lang.script.Script +import com.wavesplatform.lang.ValidationError import com.wavesplatform.network.TransactionPublisher import com.wavesplatform.settings.WavesSettings +import com.wavesplatform.state.{AccountScriptInfo, AssetDescription, AssetScriptInfo, Blockchain, Diff, Height, LeaseBalance, NG, VolumeAndFee} import com.wavesplatform.state.diffs.TransactionDiffer -import com.wavesplatform.state.{Blockchain, LeaseBalance, NG, VolumeAndFee} -import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.TxHelpers +import com.wavesplatform.transaction.{Asset, ERC20Address, Transaction, TxHelpers} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.smart.script.trace.TracedResult +import com.wavesplatform.utils.{SystemTime, Time} +import io.netty.channel.Channel +import com.wavesplatform.common.utils._ import org.scalamock.MockFactoryBase - -import scala.concurrent.Future +import org.scalamock.matchers.MockParameter trait BlockchainStubHelpers { self: MockFactoryBase => def createBlockchainStub(f: Blockchain => Unit = _ => ()): Blockchain with NG = { @@ -35,7 +46,7 @@ trait BlockchainStubHelpers { self: MockFactoryBase => (blockchain.leaseBalance _).when(*).returns(LeaseBalance.empty) (() => blockchain.height).when().returns(1) (blockchain.blockHeader _).when(*).returns { - val block = TestBlock.create(Nil) + val block = TestBlock.create(System.currentTimeMillis(), Nil) Some(SignedBlockHeader(block.header, block.signature)) } (blockchain.filledVolumeAndFee _).when(*).returns(VolumeAndFee.empty) @@ -47,4 +58,97 @@ trait BlockchainStubHelpers { self: MockFactoryBase => def createTxPublisherStub(blockchain: Blockchain): TransactionPublisher = { (transaction, _) => Future.successful(TransactionDiffer(blockchain.lastBlockTimestamp, System.currentTimeMillis())(blockchain, transaction).map(_ => true)) } + + implicit class BlockchainStubOps(blockchain: Blockchain) { + def stub: StubHelpers = StubHelpers(blockchain) + } + + case class StubHelpers(blockchain: Blockchain) { + def activateFeatures(features: BlockchainFeature*): Unit = { + (() => blockchain.activatedFeatures).when().returns(features.map(_.id -> 0).toMap) + } + + def activateAllFeatures(): Unit = { + this.activateFeatures(BlockchainFeatures.implemented.flatMap(BlockchainFeatures.feature).toSeq: _*) + } + + def creditBalance(address: MockParameter[Address], asset: MockParameter[Asset], amount: Long = Long.MaxValue / 3): Unit = { + (blockchain.balance _).when(address, asset).returns(amount) + } + + def issueAsset(id: ByteStr, script: Option[Script] = None): Unit = { + (blockchain.assetDescription _) + .when(IssuedAsset(id)) + .returns( + Some( + AssetDescription( + id, + TestValues.keyPair.publicKey, + ByteString.copyFromUtf8("test"), + ByteString.copyFromUtf8("test"), + 8, + reissuable = false, + 10000, + Height(1), + script.map(script => AssetScriptInfo(script, 1L)), + 0L, + nft = false + ) + ) + ) + (blockchain.assetScript _).when(IssuedAsset(id)).returns(script.map(script => AssetScriptInfo(script, 1L))) + (blockchain.resolveERC20Address _).when(ERC20Address(id.take(20))).returns(Some(IssuedAsset(id))) + (blockchain.transactionInfo _) + .when(id) + .returns( + Some( + ( + 1, // height + IssueTransaction + .selfSigned(2.toByte, TestValues.keyPair, "test", "test", 10000, 8, reissuable = true, script, 500000L, 123L) + .explicitGet(), + true // applied + ) + ) + ) + } + + def setScript(address: Address, script: Script): Unit = { + (blockchain.hasAccountScript _).when(address).returns(true) + + (blockchain.accountScript _) + .when(address) + .returns( + Some( + AccountScriptInfo( + PublicKey(new Array[Byte](32)), + script, + 1L, + new Map[Int, Map[String, Long]] { + def removed(key: Int): Map[Int, Map[String, Long]] = ??? + def updated[V1 >: Map[String, Long]](key: Int, value: V1): Map[Int, V1] = ??? + def get(key: Int): Option[Map[String, Long]] = + Some(new Map[String, Long] { + def removed(key: String): Map[String, Long] = ??? + def updated[V1 >: Long](key: String, value: V1): Map[String, V1] = ??? + def get(key: String): Option[Long] = Some(1L) + def iterator: Iterator[(String, Long)] = ??? + }) + def iterator: Iterator[(Int, Map[String, Long])] = ??? + } + ) + ) + ) + } + + def transactionDiffer(time: Time = SystemTime, withFailed: Boolean = false): Transaction => TracedResult[ValidationError, Diff] = { + if (withFailed) TransactionDiffer(Some(time.correctedTime()), time.correctedTime())(blockchain, _) + else TransactionDiffer.forceValidate(Some(time.correctedTime()), time.correctedTime())(blockchain, _) + } + + def transactionPublisher(time: Time = SystemTime): TransactionPublisher = (tx: Transaction, _: Option[Channel]) => { + val differ = transactionDiffer(time) + Future.successful(differ(tx).map(_ => true)) + } + } } diff --git a/node/src/test/scala/com/wavesplatform/BlocksTransactionsHelpers.scala b/node/src/test/scala/com/wavesplatform/BlocksTransactionsHelpers.scala index 7ebbb571e03..ed5da9a573d 100644 --- a/node/src/test/scala/com/wavesplatform/BlocksTransactionsHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/BlocksTransactionsHelpers.scala @@ -1,6 +1,6 @@ package com.wavesplatform -import com.wavesplatform.account.{Address, AddressOrAlias, KeyPair} +import com.wavesplatform.account.{AddressOrAlias, KeyPair} import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils._ @@ -9,12 +9,13 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL import com.wavesplatform.protobuf.block.PBBlocks import com.wavesplatform.state.StringDataEntry +import com.wavesplatform.transaction.{DataTransaction, Transaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{DataTransaction, Transaction, TxVersion} +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils._ import org.scalacheck.Gen @@ -96,14 +97,14 @@ trait BlocksTransactionsHelpers { self: TransactionGen => def invokeScript( from: KeyPair, - dapp: Address, + dapp: AddressOrAlias, call: FUNCTION_CALL, payments: Seq[InvokeScriptTransaction.Payment] = Nil, timestamp: Gen[Long] = timestampGen ): Gen[InvokeScriptTransaction] = for { timestamp <- timestamp - } yield InvokeScriptTransaction.selfSigned(1.toByte, from, dapp, Some(call), payments, FeeAmount * 2, Waves, timestamp).explicitGet() + } yield Signed.invokeScript(1.toByte, from, dapp, Some(call), payments, FeeAmount * 2, Waves, timestamp) } object UnsafeBlocks { @@ -135,10 +136,7 @@ trait BlocksTransactionsHelpers { self: TransactionGen => ts: Long ): (Block, MicroBlock) = { val newTotalBlock = unsafeBlock(totalRefTo, prevTotal.transactionData ++ txs, signer, version, ts) - val unsigned = new MicroBlock(version, signer.publicKey, txs, prevTotal.id(), newTotalBlock.signature, ByteStr.empty) - val signature = crypto.sign(signer.privateKey, unsigned.bytes()) - val signed = unsigned.copy(signature = signature) - (newTotalBlock, signed) + (newTotalBlock, MicroBlock.buildAndSign(version, signer, txs, prevTotal.id(), newTotalBlock.signature).explicitGet()) } def unsafeBlock( diff --git a/node/src/test/scala/com/wavesplatform/RequestGen.scala b/node/src/test/scala/com/wavesplatform/RequestGen.scala index c9fc04c1001..641730b1bfc 100644 --- a/node/src/test/scala/com/wavesplatform/RequestGen.scala +++ b/node/src/test/scala/com/wavesplatform/RequestGen.scala @@ -1,7 +1,7 @@ package com.wavesplatform import com.wavesplatform.account.Alias -import com.wavesplatform.api.http.requests.{BurnV1Request, IssueV1Request, ReissueV1Request, SignedBurnV1Request, SignedCreateAliasV1Request, SignedIssueV1Request, SignedLeaseCancelV1Request, SignedLeaseV1Request, SignedReissueV1Request, SignedTransferV1Request, TransferV1Request} +import com.wavesplatform.api.http.requests._ import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto._ import com.wavesplatform.transaction.assets._ @@ -96,7 +96,7 @@ trait RequestGen extends TransactionGen { _: Suite => val transferReq: G[TransferV1Request] = for { (account, fee) <- commonFields - recipient <- accountOrAliasGen.map(_.stringRepr) + recipient <- accountOrAliasGen.map(_.toString) amount <- positiveLongGen assetId <- assetIdStringGen feeAssetId <- assetIdStringGen diff --git a/node/src/test/scala/com/wavesplatform/TestHelpers.scala b/node/src/test/scala/com/wavesplatform/TestHelpers.scala index 2823bf728d3..b6b12f47df8 100644 --- a/node/src/test/scala/com/wavesplatform/TestHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/TestHelpers.scala @@ -15,7 +15,7 @@ object TestHelpers { val totalAmount = balances.values.sum val transactions = balances.map { case (account, amount) => - GenesisTransactionSettings(account.stringRepr, amount) + GenesisTransactionSettings(account.toString, amount) }.toSeq GenesisSettings(blockTimestamp, blockTimestamp, totalAmount, None, transactions, 1000, 60.seconds) diff --git a/node/src/test/scala/com/wavesplatform/TransactionGen.scala b/node/src/test/scala/com/wavesplatform/TransactionGen.scala index cfd17a14e41..d0c3faaabd9 100644 --- a/node/src/test/scala/com/wavesplatform/TransactionGen.scala +++ b/node/src/test/scala/com/wavesplatform/TransactionGen.scala @@ -1,34 +1,35 @@ package com.wavesplatform +import scala.concurrent.duration._ +import scala.util.Random + import com.wavesplatform.account._ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.directives.values.V3 -import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.script.{ContractScript, Script} +import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.v1.{ContractLimits, FunctionHeader} import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.testing.{ScriptGen, TypedScriptGen} -import com.wavesplatform.lang.v1.{ContractLimits, FunctionHeader} import com.wavesplatform.settings.{Constants, FunctionalitySettings} import com.wavesplatform.state._ import com.wavesplatform.state.diffs.ENOUGH_AMT -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange._ import com.wavesplatform.transaction.lease._ -import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.transfer.MassTransferTransaction.{MaxTransferCount, ParsedTransfer} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.transfer._ -import org.scalacheck.Gen.{alphaLowerChar, alphaUpperChar, frequency, numChar} +import com.wavesplatform.transaction.transfer.MassTransferTransaction.{MaxTransferCount, ParsedTransfer} +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.{Arbitrary, Gen} +import org.scalacheck.Gen.{alphaLowerChar, alphaUpperChar, frequency, numChar} import org.scalatest.Suite -import scala.concurrent.duration._ -import scala.util.Random - trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: Suite => val ScriptExtraFee = 400000L @@ -94,7 +95,7 @@ trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: val positiveLongGen: Gen[Long] = Gen.choose(1, 100000000L * 100000000L / 100) val positiveIntGen: Gen[Int] = Gen.choose(1, Int.MaxValue / 100) - val smallFeeGen: Gen[Long] = Gen.choose(400000, 100000000) + val smallFeeGen: Gen[Long] = Gen.choose(400000L, 100000000L) val maxOrderTimeGen: Gen[Long] = Gen.choose(10000L, Order.MaxLiveTime).map(_ + ntpTime.correctedTime()) val timestampGen: Gen[Long] = Gen.choose(1L, Long.MaxValue - 100) @@ -338,7 +339,7 @@ trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: } yield TransferTransaction(2.toByte, sender.publicKey, recipient, assetId, amount, feeAssetId, feeAmount, attachment, timestamp, proofs, recipient.chainId)) .label("VersionedTransferTransaction") - def versionedTransferGenP(sender: PublicKey, recipient: Address, proofs: Proofs): Gen[TransferTransaction] = + def versionedTransferGenP(sender: PublicKey, recipient: AddressOrAlias, proofs: Proofs): Gen[TransferTransaction] = (for { amt <- positiveLongGen fee <- smallFeeGen @@ -582,9 +583,7 @@ trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: fc <- funcCallGen fee <- smallFeeGen timestamp <- timestampGen - } yield InvokeScriptTransaction - .selfSigned(1.toByte, sender, dappAddress.toAddress, Some(fc), payments, fee, Waves, timestamp) - .explicitGet() + } yield Signed.invokeScript(1.toByte, sender, dappAddress.toAddress, Some(fc), payments, fee, Waves, timestamp) val paymentListGen: Gen[Seq[Payment]] = for { @@ -826,7 +825,7 @@ trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: .explicitGet() } - val randomTransactionGen: Gen[ProvenTransaction] = (for { + val randomTransactionGen: Gen[Transaction with ProvenTransaction] = (for { tr <- transferV1Gen (is, ri, bu) <- issueReissueBurnGen.retryUntil { case (i, r, b) => i.version == 1 && r.version == 1 && b.version == 1 @@ -836,7 +835,7 @@ trait TransactionGenBase extends ScriptGen with TypedScriptGen with NTPTime { _: tx <- Gen.oneOf(tr, is, ri, ca, bu, xt) } yield tx).label("random transaction") - def randomTransactionsGen(count: Int): Gen[Seq[ProvenTransaction]] = + def randomTransactionsGen(count: Int): Gen[Seq[Transaction]] = for { transactions <- Gen.listOfN(count, randomTransactionGen) } yield transactions diff --git a/node/src/test/scala/com/wavesplatform/account/AccountOrAliasSpecification.scala b/node/src/test/scala/com/wavesplatform/account/AccountOrAliasSpecification.scala index 850b95460c4..53274cd8dab 100644 --- a/node/src/test/scala/com/wavesplatform/account/AccountOrAliasSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/account/AccountOrAliasSpecification.scala @@ -17,15 +17,15 @@ class AccountOrAliasSpecification extends PropSpec { forAll(aliasGen) { alias: Alias => val bytes = alias.bytes val representation = Alias.fromBytes(bytes).explicitGet() - representation.stringRepr shouldBe representation.stringRepr + representation.toString shouldBe representation.toString } } property("AccountOrAlias serialization round trip") { forAll(accountOrAliasGen) { aoa: AddressOrAlias => val bytes = aoa.bytes - val addressOrAlias = AddressOrAlias.fromBytes(bytes, 0).explicitGet() - addressOrAlias._1.stringRepr shouldBe aoa.stringRepr + val addressOrAlias = AddressOrAlias.fromBytes(bytes).explicitGet() + addressOrAlias.toString shouldBe aoa.toString } } } diff --git a/node/src/test/scala/com/wavesplatform/api/eth/EthRpcRouteSpec.scala b/node/src/test/scala/com/wavesplatform/api/eth/EthRpcRouteSpec.scala new file mode 100644 index 00000000000..59f22d51534 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/api/eth/EthRpcRouteSpec.scala @@ -0,0 +1,193 @@ +package com.wavesplatform.api.eth + +import com.wavesplatform.BlockchainStubHelpers +import com.wavesplatform.account.Address +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} +import com.wavesplatform.api.http.ApiMarshallers._ +import com.wavesplatform.api.http.eth.EthRpcRoute +import com.wavesplatform.block.SignedBlockHeader +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.http.RouteSpec +import com.wavesplatform.lagonaki.mocks.TestBlock +import com.wavesplatform.state.{Blockchain, Height} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.TxHelpers +import com.wavesplatform.transaction.smart.script.trace.TracedResult +import com.wavesplatform.transaction.utils.EthConverters._ +import com.wavesplatform.transaction.utils.EthTxGenerator +import com.wavesplatform.utils.{EthEncoding, EthHelpers, EthSetChainId} +import org.scalamock.scalatest.PathMockFactory +import org.scalatest.BeforeAndAfterEach +import org.scalatest.matchers.should.Matchers +import play.api.libs.json.Json.JsValueWrapper +import play.api.libs.json.{JsArray, JsObject, Json} + +import scala.concurrent.Future + +class EthRpcRouteSpec + extends RouteSpec("/eth") + with Matchers + with PathMockFactory + with BlockchainStubHelpers + with EthHelpers + with EthSetChainId + with BeforeAndAfterEach { + var blockchain = stub[Blockchain] + var transactionsApi = stub[CommonTransactionsApi] + var route = new EthRpcRoute(blockchain, transactionsApi, ntpTime) + + "eth_chainId" in testRpc("eth_chainId")(resultInt shouldBe 'E'.toLong) + + "eth_gasPrice" in testRpc("eth_gasPrice")(resultInt shouldBe 10000000000L) + + "eth_blockNumber" in { + (() => blockchain.height).when().returning(123) + testRpc("eth_blockNumber")(resultInt shouldBe 123) + } + + "eth_getBalance" in { + (blockchain.balance _).when(*, *).returning(123) + testRpc("eth_getBalance", EthEncoding.toHexString(EthStubBytes32.take(20)))(resultInt shouldBe 1230000000000L) + } + + "eth_getCode" - { + "no contract" in { + testRpc("eth_getCode", EthEncoding.toHexString(EthStubBytes32.take(20)))(result shouldBe "0x") + } + + "has contract" in { + val testAddress = Address(EthStubBytes32.take(20)) + blockchain.stub.setScript(testAddress, TxHelpers.scriptV5("")) + testRpc("eth_getCode", EthEncoding.toHexString(testAddress.publicKeyHash))(result shouldBe "0xff") + } + } + + "eth_estimateGas" in { + (transactionsApi.calculateFee _).when(*).returns(Right((Waves, 500000L, 500000L))) + testRpc("eth_estimateGas", Json.obj("to" -> TxHelpers.secondAddress.toEthAddress, "value" -> 0, "data" -> "0x00")) { + resultInt shouldBe 500000 + } + } + + "eth_call" - { + "asset calls" in { + val assetId = ByteStr(EthStubBytes32) + val fakeAddress = Address(assetId.take(20).arr) + val assetContract = EthEncoding.toHexString(fakeAddress.publicKeyHash) + blockchain.stub.issueAsset(assetId) + blockchain.stub.creditBalance(fakeAddress, IssuedAsset(assetId), 255) + + withClue("asset name")( + testRpc("eth_call", Json.obj("to" -> assetContract, "data" -> "0x95d89b41"))( + result shouldBe "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000047465737400000000000000000000000000000000000000000000000000000000" + ) + ) + + withClue("asset decimals")( + testRpc("eth_call", Json.obj("to" -> assetContract, "data" -> "0x313ce567"))( + result shouldBe "0000000000000000000000000000000000000000000000000000000000000008" + ) + ) + + withClue("asset balance")( + testRpc("eth_call", Json.obj("to" -> assetContract, "data" -> ("70a08231" + assetContract.drop(2))))( + result shouldBe "00000000000000000000000000000000000000000000000000000000000000ff" + ) + ) + } + } + + "eth_getTransactionReceipt" in { + val block = TestBlock.create(Nil) + val transaction = EthTxGenerator.generateEthInvoke(TxHelpers.defaultSigner.toEthKeyPair, TxHelpers.secondAddress, "test", Nil, Nil) + (() => blockchain.height).when().returns(1) + (blockchain.blockHeader _).when(1).returns { + Some(SignedBlockHeader(block.header, block.signature)) + } + (transactionsApi.transactionById _) + .when(transaction.id()) + .returns(Some(TransactionMeta.Ethereum(Height(1), transaction, succeeded = true, None, None))) + + testRpc("eth_getTransactionReceipt", transaction.id().toHexString)(resultJson should matchJson(s"""{ + | "transactionHash" : "${transaction + .id() + .toHexString}", + | "transactionIndex" : "0x01", + | "blockHash" : "${block.id().toHexString}", + | "blockNumber" : "0x01", + | "from" : "0xf1f6bdabc1b48e7d75957b361881be9c40e4b424", + | "to" : "0x3d3ad884fa042927b9d6c37df70af5c0bd9516c5", + | "cumulativeGasUsed" : "0x7a120", + | "gasUsed" : "0x7a120", + | "contractAddress" : null, + | "logs" : [ ], + | "logsBloom" : "0x0000000000000000000000000000000000000000000000000000000000000000", + | "status" : "0x1" + |}""".stripMargin)) + } + + "eth_sendRawTransaction" in { + val transaction = EthTxGenerator.generateEthInvoke(TxHelpers.defaultSigner.toEthKeyPair, TxHelpers.secondAddress, "test", Nil, Nil) + (transactionsApi.broadcastTransaction _).when(*).returns(Future.successful(TracedResult(Right(true)))) + testRpc("eth_sendRawTransaction", EthEncoding.toHexString(transaction.bytes()))( + result shouldBe transaction.id().toHexString + ) + } + + "eth/assets" in { + val testAsset1 = ByteStr(Array.fill(32)(1.toByte)) + val testAsset2 = ByteStr(Array.fill(32)(2.toByte)) + blockchain.stub.issueAsset(testAsset1) + blockchain.stub.issueAsset(testAsset2) + + route.route + .anyParamTest(routePath("/assets"), "id")(EthEncoding.toHexString(testAsset1.take(20).arr), EthEncoding.toHexString(testAsset2.take(20).arr)) { + responseAs[JsArray] should matchJson("""[ { + | "assetId" : "4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi", + | "issueHeight" : 1, + | "issueTimestamp" : 123, + | "issuer" : "3FrCwv8uFRxQazhX6Lno45aZ68Bof6ScaeF", + | "issuerPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "name" : "test", + | "description" : "test", + | "decimals" : 8, + | "reissuable" : false, + | "quantity" : 10000, + | "scripted" : false, + | "minSponsoredAssetFee" : null, + | "originTransactionId" : "4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi" + |}, { + | "assetId" : "8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR", + | "issueHeight" : 1, + | "issueTimestamp" : 123, + | "issuer" : "3FrCwv8uFRxQazhX6Lno45aZ68Bof6ScaeF", + | "issuerPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "name" : "test", + | "description" : "test", + | "decimals" : 8, + | "reissuable" : false, + | "quantity" : 10000, + | "scripted" : false, + | "minSponsoredAssetFee" : null, + | "originTransactionId" : "8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR" + |} ]""".stripMargin) + } + } + + // Helpers + def testRpc(method: String, params: JsValueWrapper*)(doCheck: => Unit): Unit = { + val entity = Json.obj("method" -> method, "params" -> Json.arr(params: _*), "id" -> "test") + Post(routePath("/"), entity) ~> route.route ~> check(doCheck) + } + + def resultJson: JsObject = (responseAs[JsObject] \ "result").as[JsObject] + def result: String = (responseAs[JsObject] \ "result").as[String] + def resultInt: Long = java.lang.Long.valueOf((responseAs[JsObject] \ "result").as[String].drop(2), 16) + + override protected def beforeEach(): Unit = { // Just resets stubs + super.beforeEach() + blockchain = stub[Blockchain] + transactionsApi = stub[CommonTransactionsApi] + route = new EthRpcRoute(blockchain, transactionsApi, ntpTime) + } +} diff --git a/node/src/test/scala/com/wavesplatform/api/http/CustomJsonMarshallerSpec.scala b/node/src/test/scala/com/wavesplatform/api/http/CustomJsonMarshallerSpec.scala index db524051d5c..39c6b0d608f 100644 --- a/node/src/test/scala/com/wavesplatform/api/http/CustomJsonMarshallerSpec.scala +++ b/node/src/test/scala/com/wavesplatform/api/http/CustomJsonMarshallerSpec.scala @@ -1,31 +1,30 @@ package com.wavesplatform.api.http +import scala.reflect.ClassTag + import akka.http.scaladsl.model.HttpRequest import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.model.headers.Accept import akka.http.scaladsl.server.Route import akka.http.scaladsl.testkit.ScalatestRouteTest -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta -import com.wavesplatform.api.common.{CommonAccountsApi, CommonAssetsApi, CommonTransactionsApi} +import com.wavesplatform.{NTPTime, TestWallet} +import com.wavesplatform.api.common.{CommonAccountsApi, CommonAssetsApi, CommonTransactionsApi, TransactionMeta} import com.wavesplatform.api.http.assets.AssetsApiRoute import com.wavesplatform.common.state.ByteStr import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.DefaultBlockchainSettings import com.wavesplatform.http.{ApiErrorMatchers, RestAPISettingsHelper} import com.wavesplatform.network.TransactionPublisher -import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.state.{Blockchain, Height} +import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.test.PropSpec import com.wavesplatform.transaction.Asset import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.utx.UtxPool -import com.wavesplatform.{NTPTime, TestWallet} import org.scalactic.source.Position import org.scalamock.scalatest.PathMockFactory import play.api.libs.json._ -import scala.reflect.ClassTag - class CustomJsonMarshallerSpec extends PropSpec with RestAPISettingsHelper diff --git a/node/src/test/scala/com/wavesplatform/api/http/TraceResultJsonTest.scala b/node/src/test/scala/com/wavesplatform/api/http/TraceResultJsonTest.scala index 82ac20e53ac..5ebe30a3092 100644 --- a/node/src/test/scala/com/wavesplatform/api/http/TraceResultJsonTest.scala +++ b/node/src/test/scala/com/wavesplatform/api/http/TraceResultJsonTest.scala @@ -7,13 +7,13 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.v1.FunctionHeader.User import com.wavesplatform.lang.v1.compiler.Terms.{CONST_LONG, CONST_STRING, FUNCTION_CALL} import com.wavesplatform.lang.v1.evaluator.ScriptResultV3 -import com.wavesplatform.lang.v1.traits.domain.{AssetTransfer, Recipient} import com.wavesplatform.lang.v1.traits.domain.DataItem.Lng +import com.wavesplatform.lang.v1.traits.domain.{AssetTransfer, Recipient} import com.wavesplatform.test.PropSpec -import com.wavesplatform.transaction.{Proofs, TxValidationError} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.script.trace.{InvokeScriptTrace, TracedResult} +import com.wavesplatform.transaction.{Proofs, TxValidationError} import com.wavesplatform.utils.JsonMatchers class TraceResultJsonTest extends PropSpec with JsonMatchers { @@ -26,12 +26,13 @@ class TraceResultJsonTest extends PropSpec with JsonMatchers { 1.toByte, sender = publicKey, dappAddress = address, - expr = Some(FUNCTION_CALL(User("func"), List(CONST_STRING("param").explicitGet(), CONST_LONG(1)))), + fc = Some(FUNCTION_CALL(User("func"), List(CONST_STRING("param").explicitGet(), CONST_LONG(1)))), p = List(InvokeScriptTransaction.Payment(1L, Waves)), fee = 10000000L, feeAssetId = Waves, timestamp = 1111L, - proofs = Proofs(List(proof)) + proofs = Proofs(List(proof)), + address.chainId ) } yield tx ).explicitGet() @@ -41,11 +42,11 @@ class TraceResultJsonTest extends PropSpec with JsonMatchers { "amount" -> Right(CONST_LONG(12345)), "invocation" -> CONST_STRING("str") ) - val recipient = Recipient.Address(ByteStr(tx.dAppAddressOrAlias.bytes)) + val recipient = Recipient.Address(ByteStr(tx.dApp.bytes)) val trace = List( InvokeScriptTrace( tx.id(), - tx.dAppAddressOrAlias, + tx.dApp, tx.funcCall, Right( ScriptResultV3( @@ -225,7 +226,7 @@ class TraceResultJsonTest extends PropSpec with JsonMatchers { val trace = List( InvokeScriptTrace( tx.id(), - tx.dAppAddressOrAlias, + tx.dApp, tx.funcCall, Left(TxValidationError.ScriptExecutionError(reason, vars, None)), vars, diff --git a/node/src/test/scala/com/wavesplatform/api/http/requests/RequestsSpec.scala b/node/src/test/scala/com/wavesplatform/api/http/requests/RequestsSpec.scala index 481dabafe1b..b1d3fbb1ff9 100644 --- a/node/src/test/scala/com/wavesplatform/api/http/requests/RequestsSpec.scala +++ b/node/src/test/scala/com/wavesplatform/api/http/requests/RequestsSpec.scala @@ -26,7 +26,7 @@ class RequestsSpec extends FreeSpec with OptionValues { "timestamp" -> System.currentTimeMillis(), "fee" -> 100000, "amount" -> 10000, - "recipient" -> recipient.publicKey.toAddress.stringRepr, + "recipient" -> recipient.publicKey.toAddress.toString, "proofs" -> JsArray(proofs.proofs.map(p => JsString(p.toString))) ) )).label(s"Transfer Request v$version") diff --git a/node/src/test/scala/com/wavesplatform/consensus/nxt/TransactionsOrderingSpecification.scala b/node/src/test/scala/com/wavesplatform/consensus/nxt/TransactionsOrderingSpecification.scala index a044e4aa3a3..bbbe2e650cf 100644 --- a/node/src/test/scala/com/wavesplatform/consensus/nxt/TransactionsOrderingSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/consensus/nxt/TransactionsOrderingSpecification.scala @@ -225,6 +225,6 @@ class TransactionsOrderingSpecification extends PropSpec { ) .explicitGet() ) - Random.shuffle(correctSeq).sorted(TransactionsOrdering.InUTXPool(Set(whitelisted.toAddress.stringRepr))) shouldBe correctSeq + Random.shuffle(correctSeq).sorted(TransactionsOrdering.InUTXPool(Set(whitelisted.toAddress.toString))) shouldBe correctSeq } } diff --git a/node/src/test/scala/com/wavesplatform/database/LevelDBWriterSpec.scala b/node/src/test/scala/com/wavesplatform/database/LevelDBWriterSpec.scala index 63ebe9f5933..87c87e09894 100644 --- a/node/src/test/scala/com/wavesplatform/database/LevelDBWriterSpec.scala +++ b/node/src/test/scala/com/wavesplatform/database/LevelDBWriterSpec.scala @@ -296,7 +296,7 @@ class LevelDBWriterSpec forAll(randomTransactionGen) { tx => val transactionId = tx.id() - db.put(Keys.transactionMetaById(TransactionId @@ transactionId).keyBytes, TransactionMeta(1, 0, tx.typeId, true).toByteArray) + db.put(Keys.transactionMetaById(TransactionId @@ transactionId).keyBytes, TransactionMeta(1, 0, tx.tpe.id, true).toByteArray) db.put(Keys.transactionAt(Height @@ 1, TxNum @@ 0.toShort).keyBytes, Array[Byte](1, 2, 3, 4, 5, 6)) writer.transferById(transactionId) shouldBe None @@ -326,7 +326,7 @@ class LevelDBWriterSpec forAll(scenario) { case (tx, s) => val transactionId = tx.id() - db.put(Keys.transactionMetaById(TransactionId(transactionId)).keyBytes, TransactionMeta(1, 0, tx.typeId, !s).toByteArray) + db.put(Keys.transactionMetaById(TransactionId(transactionId)).keyBytes, TransactionMeta(1, 0, tx.tpe.id, !s).toByteArray) db.put(Keys.transactionAt(Height(1), TxNum(0.toShort)).keyBytes, database.writeTransaction((tx, s))) writer.transactionInfo(transactionId) shouldBe Some((1, tx, s)) diff --git a/node/src/test/scala/com/wavesplatform/db/WithState.scala b/node/src/test/scala/com/wavesplatform/db/WithState.scala index f59f56c1483..ddee77d63d8 100644 --- a/node/src/test/scala/com/wavesplatform/db/WithState.scala +++ b/node/src/test/scala/com/wavesplatform/db/WithState.scala @@ -13,10 +13,11 @@ import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.directives.values._ import com.wavesplatform.mining.MiningConstraint import com.wavesplatform.settings.{BlockchainSettings, FunctionalitySettings, TestSettings, WavesSettings, loadConfig, TestFunctionalitySettings => TFS} -import com.wavesplatform.state.diffs.{BlockDiffer, produce} +import com.wavesplatform.state.diffs.BlockDiffer import com.wavesplatform.state.reader.CompositeBlockchain import com.wavesplatform.state.utils.TestLevelDB import com.wavesplatform.state.{Blockchain, BlockchainUpdaterImpl, Diff} +import com.wavesplatform.test._ import com.wavesplatform.transaction.smart.script.trace.TracedResult import com.wavesplatform.transaction.{Asset, Transaction} import com.wavesplatform.{NTPTime, TestHelpers} diff --git a/node/src/test/scala/com/wavesplatform/features/FeatureProviderTest.scala b/node/src/test/scala/com/wavesplatform/features/FeatureProviderTest.scala index 8db6996911f..d0130757ccc 100644 --- a/node/src/test/scala/com/wavesplatform/features/FeatureProviderTest.scala +++ b/node/src/test/scala/com/wavesplatform/features/FeatureProviderTest.scala @@ -25,6 +25,7 @@ class FeatureProviderTest extends FlatSpec with MockFactory { ) val blockchain = mock[Blockchain] + (() => blockchain.height).expects().anyNumberOfTimes().returning(1) (() => blockchain.activatedFeatures).expects().anyNumberOfTimes().returning(features) (() => blockchain.settings).expects().anyNumberOfTimes().returning(BlockchainSettings('W', fs, GenesisSettings.MAINNET, RewardsSettings.MAINNET)) diff --git a/node/src/test/scala/com/wavesplatform/features/RideV5LimitsChangeTest.scala b/node/src/test/scala/com/wavesplatform/features/RideV5LimitsChangeTest.scala index 464b3b63eff..c0fe97fd76f 100644 --- a/node/src/test/scala/com/wavesplatform/features/RideV5LimitsChangeTest.scala +++ b/node/src/test/scala/com/wavesplatform/features/RideV5LimitsChangeTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.features -import com.wavesplatform.TestTime import com.wavesplatform.block.Block import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBadReferencesTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBadReferencesTest.scala index 25aea249ca7..b618c0c9f1e 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBadReferencesTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBadReferencesTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockMicroblockSequencesSameTransactionsTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockMicroblockSequencesSameTransactionsTest.scala index 5d8219d67cd..c50f60b701c 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockMicroblockSequencesSameTransactionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockMicroblockSequencesSameTransactionsTest.scala @@ -6,7 +6,7 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockOnlyTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockOnlyTest.scala index 1d07118555c..92ef31c9f73 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockOnlyTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBlockOnlyTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala index 94c061427ef..8bae5d5df82 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala @@ -5,8 +5,8 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.settings.{BlockchainSettings, WavesSettings} -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ import com.wavesplatform.transaction.assets.{BurnTransaction, IssueTransaction, ReissueTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeNextBlockOrMicroBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeNextBlockOrMicroBlockTest.scala index caa1b540005..386c18ddf26 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeNextBlockOrMicroBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeNextBlockOrMicroBlockTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeSameBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeSameBlockTest.scala index cac16c28c46..30607890ae2 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeSameBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterGeneratorFeeSameBlockTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterInMemoryDiffTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterInMemoryDiffTest.scala index 27fd1b99a92..d7d94c1f36a 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterInMemoryDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterInMemoryDiffTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterKeyAndMicroBlockConflictTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterKeyAndMicroBlockConflictTest.scala index f7f7b022b8c..bfa4dd83759 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterKeyAndMicroBlockConflictTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterKeyAndMicroBlockConflictTest.scala @@ -137,14 +137,14 @@ class BlockchainUpdaterKeyAndMicroBlockConflictTest val (keyBlock, microBlocks) = unsafeChainBaseAndMicro( totalRefTo = genesisBlock.signature, base = Seq(transfer1), - micros = Seq(Seq(), Seq(transfer2)), + micros = Seq(Seq(transfer2)), signer = richAccount, version = 3, timestamp = blockTime ) val (keyBlock1, _) = unsafeChainBaseAndMicro( - totalRefTo = microBlocks.head.totalResBlockSig, + totalRefTo = keyBlock.id(), base = Seq(transfer3), micros = Nil, signer = secondAccount, diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterLiquidBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterLiquidBlockTest.scala index 8f9f720973e..44fae96b6ec 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterLiquidBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterLiquidBlockTest.scala @@ -36,7 +36,7 @@ class BlockchainUpdaterLiquidBlockTest extends PropSpec with DomainScenarioDrive val (keyBlock, microBlocks) = unsafeChainBaseAndMicro( totalRefTo = prevBlock.signature, base = keyBlockTxs, - micros = microTxs.grouped(math.max(1, txNumberInMicros / 5)).toSeq, + micros = microTxs.grouped((txNumberInMicros / 5) min 500 max 1).toSeq, signer = TestBlock.defaultSigner, version = 3, timestamp = ntpNow diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockBadSignaturesTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockBadSignaturesTest.scala index 6c4e9f0ea5c..1bc8836ccd6 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockBadSignaturesTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockBadSignaturesTest.scala @@ -7,7 +7,7 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockSunnyDayTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockSunnyDayTest.scala index 081807db207..24a49536557 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockSunnyDayTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterMicroblockSunnyDayTest.scala @@ -7,7 +7,7 @@ import com.wavesplatform.crypto._ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala index 1b2d54910c8..f2309eaee4d 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala @@ -9,7 +9,7 @@ import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.settings.{BlockchainSettings, WavesSettings} import com.wavesplatform.state._ import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.transfer._ @@ -130,8 +130,8 @@ class BlockchainUpdaterSponsoredFeeBlockTest extends PropSpec with DomainScenari val (block0, microBlocks) = chainBaseAndMicro(randomSig, genesis, Seq(Seq(masterToAlice, feeAsset, sponsor), Seq(aliceToBob, bobToMaster))) val block0TotalFee = block0.transactionData - .filter(_.assetFee._1 == Waves) - .map(_.assetFee._2) + .filter(_.feeAssetId == Waves) + .map(_.fee) .sum { diff --git a/node/src/test/scala/com/wavesplatform/history/Domain.scala b/node/src/test/scala/com/wavesplatform/history/Domain.scala index 703326f4cd1..78a03b66460 100644 --- a/node/src/test/scala/com/wavesplatform/history/Domain.scala +++ b/node/src/test/scala/com/wavesplatform/history/Domain.scala @@ -1,14 +1,14 @@ package com.wavesplatform.history +import scala.collection.immutable.SortedMap import scala.concurrent.Future import scala.concurrent.duration._ import cats.syntax.option._ import com.wavesplatform.{database, Application} -import com.wavesplatform.account.Address +import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.api.BlockMeta -import com.wavesplatform.api.common.{AddressPortfolio, AddressTransactions, CommonBlocksApi, CommonTransactionsApi} -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.api.common._ import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.block.Block.BlockId import com.wavesplatform.common.state.ByteStr @@ -19,13 +19,14 @@ import com.wavesplatform.database.{DBExt, Keys, LevelDBWriter} import com.wavesplatform.events.BlockchainUpdateTriggers import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.ValidationError +import com.wavesplatform.lang.script.Script import com.wavesplatform.settings.WavesSettings import com.wavesplatform.state._ import com.wavesplatform.state.diffs.TransactionDiffer import com.wavesplatform.transaction.{BlockchainUpdater, _} import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.smart.script.trace.TracedResult -import com.wavesplatform.utils.SystemTime +import com.wavesplatform.utils.{EthEncoding, SystemTime} import com.wavesplatform.utx.UtxPoolImpl import com.wavesplatform.wallet.Wallet import monix.execution.Scheduler.Implicits.global @@ -44,8 +45,8 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite val transactionDiffer: Transaction => TracedResult[ValidationError, Diff] = TransactionDiffer(blockchain.lastBlockTimestamp, System.currentTimeMillis())(blockchain, _) - lazy val utxPool = new UtxPoolImpl(SystemTime, blockchain, settings.utxSettings) - lazy val wallet = Wallet(settings.walletSettings.copy(file = None)) + lazy val utxPool: UtxPoolImpl = new UtxPoolImpl(SystemTime, blockchain, settings.utxSettings) + lazy val wallet: Wallet = Wallet(settings.walletSettings.copy(file = None)) object commonApi { def invokeScriptResult(transactionId: ByteStr): InvokeScriptResult = @@ -54,7 +55,7 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite def addressTransactions(address: Address): Seq[Transaction] = transactions.transactionsByAddress(address, None, Set.empty, None).map(_.transaction).toListL.runSyncUnsafe() - lazy val transactions = CommonTransactionsApi( + lazy val transactions: CommonTransactionsApi = CommonTransactionsApi( blockchainUpdater.bestLiquidDiff.map(diff => Height(blockchainUpdater.height) -> diff), db, blockchain, @@ -65,6 +66,28 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite ) } + def liquidState: Option[NgState] = { + val cls = classOf[BlockchainUpdaterImpl] + val field = cls.getDeclaredField("ngState") + field.setAccessible(true) + field.get(blockchain).asInstanceOf[Option[NgState]] + } + + def makeStateHard(): (Int, SortedMap[String, String]) = { + if (liquidState.isDefined) appendBlock() // Just append empty block + (hardStateHeight, hardStateSnapshot()) + } + + def hardStateHeight: Int = { + db.get(Keys.height) + } + + def hardStateSnapshot(): SortedMap[String, String] = { + val builder = SortedMap.newBuilder[String, String] + db.iterateOver(Array.emptyByteArray)(e => builder.addOne(EthEncoding.toHexString(e.getKey).drop(2) -> EthEncoding.toHexString(e.getValue).drop(2))) + builder.result() + } + def lastBlock: Block = { blockchainUpdater.lastBlockId .flatMap(blockchainUpdater.liquidBlock) @@ -75,6 +98,8 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite def liquidDiff: Diff = blockchainUpdater.bestLiquidDiff.getOrElse(Diff.empty) + def microBlocks: Vector[MicroBlock] = blockchain.microblockIds.reverseIterator.flatMap(blockchain.microBlock).to(Vector) + def effBalance(a: Address): Long = blockchainUpdater.effectiveBalance(a, 1000) def appendBlock(b: Block): Seq[Diff] = blockchainUpdater.processBlock(b).explicitGet() @@ -223,6 +248,28 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite CommonBlocksApi(blockchainUpdater, loadBlockMetaAt(db, blockchainUpdater), loadBlockInfoAt(db, blockchainUpdater)) } + + //noinspection ScalaStyle + object helpers { + def creditWavesToDefaultSigner(amount: Long = 10_0000_0000): Unit = { + import com.wavesplatform.transaction.utils.EthConverters._ + appendBlock(TxHelpers.genesis(TxHelpers.defaultAddress, amount), TxHelpers.genesis(TxHelpers.defaultSigner.toEthWavesAddress, amount)) + } + + def creditWavesFromDefaultSigner(to: Address, amount: Long = 1_0000_0000): Unit = { + appendBlock(TxHelpers.transfer(to = to, amount = amount)) + } + + def issueAsset(script: Script = null): IssuedAsset = { + val transaction = TxHelpers.issue(script = script) + appendBlock(transaction) + IssuedAsset(transaction.id()) + } + + def setScript(account: KeyPair, script: Script): Unit = { + appendBlock(TxHelpers.setScript(account, script)) + } + } } object Domain { diff --git a/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala b/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala index c976e56a153..f5498ea0870 100644 --- a/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala +++ b/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala @@ -9,9 +9,8 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.{Constants, FunctionalitySettings} -import com.wavesplatform.state.diffs.produce import com.wavesplatform.state.{Blockchain, LeaseBalance} -import com.wavesplatform.test.FreeSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.lease.LeaseTransaction import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/http/AddressRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/AddressRouteSpec.scala index db187bb5556..feb7f08c03c 100644 --- a/node/src/test/scala/com/wavesplatform/http/AddressRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/AddressRouteSpec.scala @@ -2,8 +2,8 @@ package com.wavesplatform.http import akka.http.scaladsl.testkit.RouteTestTimeout import com.google.protobuf.ByteString -import com.wavesplatform.{crypto, TestTime, TestWallet} -import com.wavesplatform.account.{Address, AddressOrAlias} +import com.wavesplatform.{crypto, TestWallet} +import com.wavesplatform.account.Address import com.wavesplatform.api.common.CommonAccountsApi import com.wavesplatform.api.http.AddressApiRoute import com.wavesplatform.api.http.ApiError.ApiKeyNotValid @@ -22,6 +22,7 @@ import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.protobuf.dapp.DAppMeta.CallableFuncSignature import com.wavesplatform.state.diffs.FeeValidation import com.wavesplatform.state.{AccountScriptInfo, Blockchain} +import com.wavesplatform.test._ import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.utils.Schedulers import io.netty.util.HashedWheelTimer @@ -297,7 +298,7 @@ class AddressRouteSpec val contractWithoutMeta = contractWithMeta.copy(meta = DAppMeta()) (blockchain.accountScript _) .when(allAccounts(4).toAddress) - .onCall((_: AddressOrAlias) => Some(AccountScriptInfo(allAccounts(4).publicKey, ContractScript(V3, contractWithoutMeta).explicitGet(), 11L))) + .onCall((_: Address) => Some(AccountScriptInfo(allAccounts(4).publicKey, ContractScript(V3, contractWithoutMeta).explicitGet(), 11L))) Get(routePath(s"/scriptInfo/${allAddresses(4)}/meta")) ~> route ~> check { val response = responseAs[JsObject] @@ -321,7 +322,7 @@ class AddressRouteSpec (blockchain.accountScript _) .when(allAccounts(6).toAddress) .onCall( - (_: AddressOrAlias) => + (_: Address) => Some( AccountScriptInfo( allAccounts(6).publicKey, diff --git a/node/src/test/scala/com/wavesplatform/http/AssetsBroadcastRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/AssetsBroadcastRouteSpec.scala index a768eb64f13..d1c167d39b7 100644 --- a/node/src/test/scala/com/wavesplatform/http/AssetsBroadcastRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/AssetsBroadcastRouteSpec.scala @@ -240,7 +240,7 @@ class AssetsBroadcastRouteSpec SignedTransferV1Request( Base58.encode(tx.sender.arr), assetId.maybeBase58Repr, - recipient.stringRepr, + recipient.toString, amount, fee, feeAssetId.maybeBase58Repr, @@ -255,7 +255,7 @@ class AssetsBroadcastRouteSpec SignedTransferV2Request( Base58.encode(tx.sender.arr), assetId.maybeBase58Repr, - recipient.stringRepr, + recipient.toString, amount, feeAssetId.maybeBase58Repr, fee, diff --git a/node/src/test/scala/com/wavesplatform/http/AssetsRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/AssetsRouteSpec.scala index f679a09eebc..fa843e8fb8a 100644 --- a/node/src/test/scala/com/wavesplatform/http/AssetsRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/AssetsRouteSpec.scala @@ -3,10 +3,9 @@ package com.wavesplatform.http import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.server.Route import com.google.protobuf.ByteString -import com.wavesplatform.{RequestGen, TestTime, TestValues} import com.wavesplatform.account.Address -import com.wavesplatform.api.common.{CommonAccountsApi, CommonAssetsApi} import com.wavesplatform.api.common.CommonAssetsApi.AssetInfo +import com.wavesplatform.api.common.{CommonAccountsApi, CommonAssetsApi} import com.wavesplatform.api.http.ApiMarshallers._ import com.wavesplatform.api.http.assets.AssetsApiRoute import com.wavesplatform.api.http.requests.{TransferV1Request, TransferV2Request} @@ -17,16 +16,17 @@ import com.wavesplatform.lang.v1.estimator.ScriptEstimatorV1 import com.wavesplatform.state.{AssetDescription, AssetScriptInfo, Blockchain, Height} import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.IssuedAsset +import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.transfer._ -import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.wallet.Wallet +import com.wavesplatform.{RequestGen, TestValues} import monix.reactive.Observable import org.scalacheck.Gen import org.scalamock.scalatest.PathMockFactory import org.scalatest.concurrent.Eventually import org.scalatestplus.scalacheck.{ScalaCheckPropertyChecks => PropertyChecks} -import play.api.libs.json.{JsObject, Json, JsValue, Writes} +import play.api.libs.json.{JsObject, JsValue, Json, Writes} class AssetsRouteSpec extends RouteSpec("/assets") @@ -229,9 +229,9 @@ class AssetsRouteSpec val response = responseAs[JsObject] response shouldBe Json.obj( "hasNext" -> false, - "lastItem" -> TestValues.address.stringRepr, + "lastItem" -> TestValues.address.toString, "items" -> Json.obj( - TestValues.address.stringRepr -> 10L + TestValues.address.toString -> 10L ) ) } diff --git a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala index ecfb155a5b0..c44a1dfe742 100644 --- a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala @@ -1,9 +1,11 @@ package com.wavesplatform.http +import scala.util.Random + import akka.http.scaladsl.model.{ContentTypes, HttpEntity, StatusCodes} +import com.wavesplatform.{BlockchainStubHelpers, NTPTime, TestValues, TestWallet} import com.wavesplatform.account.Alias -import com.wavesplatform.api.common.CommonTransactionsApi -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} import com.wavesplatform.api.http.ApiError.ApiKeyNotValid import com.wavesplatform.api.http.DebugApiRoute import com.wavesplatform.block.SignedBlockHeader @@ -21,24 +23,21 @@ import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext import com.wavesplatform.lang.v1.traits.domain.{Issue, Lease, LeaseCancel, Recipient} import com.wavesplatform.network.PeerDatabase import com.wavesplatform.settings.{TestFunctionalitySettings, WavesSettings} +import com.wavesplatform.state.{AccountScriptInfo, AssetDescription, AssetScriptInfo, Blockchain, Height, InvokeScriptResult, NG, StateHash} import com.wavesplatform.state.StateHash.SectionId import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.reader.LeaseDetails -import com.wavesplatform.state.{AccountScriptInfo, AssetDescription, AssetScriptInfo, Blockchain, Height, InvokeScriptResult, NG, StateHash} import com.wavesplatform.test._ +import com.wavesplatform.transaction.{ERC20Address, TxHelpers, TxVersion} import com.wavesplatform.transaction.assets.exchange.OrderType import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{TxHelpers, TxVersion} -import com.wavesplatform.{BlockchainStubHelpers, NTPTime, TestValues, TestWallet} import monix.eval.Task import org.scalamock.scalatest.PathMockFactory import org.scalatest.Assertion -import play.api.libs.json.{JsArray, JsObject, JsValue, Json} - -import scala.util.Random +import play.api.libs.json.{JsArray, JsObject, Json, JsValue} //noinspection ScalaStyle class DebugApiRouteSpec @@ -233,6 +232,9 @@ class DebugApiRouteSpec ) ) + (blockchain.resolveERC20Address _).when(ERC20Address(TestValues.asset)).returns(Some(TestValues.asset)) + (blockchain.resolveERC20Address _).when(*).returns(None) + val (dAppScript, _) = ScriptCompiler .compile( s""" diff --git a/node/src/test/scala/com/wavesplatform/http/LeaseRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/LeaseRouteSpec.scala index 6d321ecbc20..670796d942b 100644 --- a/node/src/test/scala/com/wavesplatform/http/LeaseRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/LeaseRouteSpec.scala @@ -1,7 +1,10 @@ package com.wavesplatform.http +import scala.concurrent.Future + import akka.http.scaladsl.model.{ContentTypes, FormData, HttpEntity} import akka.http.scaladsl.server.Route +import com.wavesplatform.{NTPTime, TestWallet, TransactionGen} import com.wavesplatform.account.{Address, AddressOrAlias, KeyPair} import com.wavesplatform.api.common.{CommonAccountsApi, LeaseInfo} import com.wavesplatform.api.http.ApiMarshallers._ @@ -16,22 +19,20 @@ import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BYTESTR, CONST_LONG, FUNCTION_CALL} import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.network.TransactionPublisher -import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.state.{BinaryDataEntry, Blockchain, Diff} +import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, TxHelpers, TxVersion} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.trace.TracedResult -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{Asset, TxHelpers, TxVersion} +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils.SystemTime import com.wavesplatform.wallet.Wallet -import com.wavesplatform.{NTPTime, TestWallet, TransactionGen} import org.scalacheck.Gen import org.scalamock.scalatest.PathMockFactory import play.api.libs.json.{JsArray, JsObject, Json} -import scala.concurrent.Future - class LeaseRouteSpec extends RouteSpec("/leasing") with TransactionGen @@ -87,23 +88,21 @@ class LeaseRouteSpec .explicitGet() private def invokeLeaseCancel(sender: KeyPair, leaseId: ByteStr) = - InvokeScriptTransaction - .selfSigned( - TxVersion.V2, - sender, - sender.toAddress, - Some( - FUNCTION_CALL( - FunctionHeader.User("cancelLease"), - List(CONST_BYTESTR(leaseId).explicitGet()) - ) - ), - Seq.empty, - 0.005.waves, - Asset.Waves, - ntpTime.getTimestamp() - ) - .explicitGet() + Signed.invokeScript( + TxVersion.V2, + sender, + sender.toAddress, + Some( + FUNCTION_CALL( + FunctionHeader.User("cancelLease"), + List(CONST_BYTESTR(leaseId).explicitGet()) + ) + ), + Seq.empty, + 0.005.waves, + Asset.Waves, + ntpTime.getTimestamp() + ) private def leaseCancelTransaction(sender: KeyPair, leaseId: ByteStr) = LeaseCancelTransaction.selfSigned(TxVersion.V3, sender, leaseId, 0.001.waves, ntpTime.getTimestamp()).explicitGet() @@ -202,23 +201,21 @@ class LeaseRouteSpec sender, genesis, setScriptTransaction(sender), - InvokeScriptTransaction - .selfSigned( - TxVersion.V2, - sender, - sender.toAddress, - Some( - FUNCTION_CALL( - FunctionHeader.User("leaseTo"), - List(CONST_BYTESTR(ByteStr(recipient.toAddress.bytes)).explicitGet(), CONST_LONG(10_000.waves)) - ) - ), - Seq.empty, - 0.005.waves, - Asset.Waves, - ntpTime.getTimestamp() - ) - .explicitGet(), + Signed.invokeScript( + TxVersion.V2, + sender, + sender.toAddress, + Some( + FUNCTION_CALL( + FunctionHeader.User("leaseTo"), + List(CONST_BYTESTR(ByteStr(recipient.toAddress.bytes)).explicitGet(), CONST_LONG(10_000.waves)) + ) + ), + Seq.empty, + 0.005.waves, + Asset.Waves, + ntpTime.getTimestamp() + ), recipient.toAddress ) @@ -325,27 +322,25 @@ class LeaseRouteSpec case ((proxy, target, recipient), genesisTransactions) => withRoute { (d, r) => d.appendBlock(genesisTransactions: _*) - val ist = InvokeScriptTransaction - .selfSigned( - TxVersion.V2, - proxy, - proxy.toAddress, - Some( - FUNCTION_CALL( - FunctionHeader.User("callProxy"), - List( - CONST_BYTESTR(ByteStr(target.toAddress.bytes)).explicitGet(), - CONST_BYTESTR(ByteStr(recipient.bytes)).explicitGet(), - CONST_LONG(10_000.waves) - ) + val ist = Signed.invokeScript( + TxVersion.V2, + proxy, + proxy.toAddress, + Some( + FUNCTION_CALL( + FunctionHeader.User("callProxy"), + List( + CONST_BYTESTR(ByteStr(target.toAddress.bytes)).explicitGet(), + CONST_BYTESTR(ByteStr(recipient.bytes)).explicitGet(), + CONST_LONG(10_000.waves) ) - ), - Seq.empty, - 0.005.waves, - Asset.Waves, - ntpTime.getTimestamp() - ) - .explicitGet() + ) + ), + Seq.empty, + 0.005.waves, + Asset.Waves, + ntpTime.getTimestamp() + ) d.appendBlock(ist) val leaseId = d.blockchain diff --git a/node/src/test/scala/com/wavesplatform/http/ProtoVersionTransactionsSpec.scala b/node/src/test/scala/com/wavesplatform/http/ProtoVersionTransactionsSpec.scala index 5be5bf15ac0..32a9f25e5f6 100644 --- a/node/src/test/scala/com/wavesplatform/http/ProtoVersionTransactionsSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/ProtoVersionTransactionsSpec.scala @@ -206,7 +206,8 @@ class ProtoVersionTransactionsSpec extends RouteSpec("/transactions") with RestA InvokeScriptTxFee, IssuedAsset(feeAssetId), Now, - Proofs.empty + Proofs.empty, + dapp.chainId ) .explicitGet() @@ -434,7 +435,7 @@ class ProtoVersionTransactionsSpec extends RouteSpec("/transactions") with RestA } def decode(base64Str: String): Transaction = { - PBTransactions.vanilla(PBSignedTransaction.parseFrom(Base64.decode(base64Str))).explicitGet() + PBTransactions.vanilla(PBSignedTransaction.parseFrom(Base64.decode(base64Str)), unsafe = true).explicitGet() } } } diff --git a/node/src/test/scala/com/wavesplatform/http/TransactionBroadcastSpec.scala b/node/src/test/scala/com/wavesplatform/http/TransactionBroadcastSpec.scala new file mode 100644 index 00000000000..fa459266c5b --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/http/TransactionBroadcastSpec.scala @@ -0,0 +1,347 @@ +package com.wavesplatform.http + +import scala.concurrent.Future +import scala.util.Random + +import com.wavesplatform.BlockchainStubHelpers +import com.wavesplatform.account.{AddressScheme, KeyPair} +import com.wavesplatform.api.common.CommonTransactionsApi +import com.wavesplatform.api.http.ApiMarshallers._ +import com.wavesplatform.api.http.TransactionsApiRoute +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils._ +import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 +import com.wavesplatform.lang.v1.traits.domain.{Lease, Recipient} +import com.wavesplatform.network.TransactionPublisher +import com.wavesplatform.state.{AccountScriptInfo, Blockchain} +import com.wavesplatform.test.TestTime +import com.wavesplatform.transaction.{Asset, Proofs, TxHelpers, TxVersion} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction +import com.wavesplatform.transaction.smart.script.ScriptCompiler +import com.wavesplatform.transaction.smart.script.trace.{AccountVerifierTrace, TracedResult} +import com.wavesplatform.utils.EthHelpers +import com.wavesplatform.wallet.Wallet +import org.scalamock.scalatest.PathMockFactory +import play.api.libs.json.{JsObject, Json, JsValue} + +class TransactionBroadcastSpec + extends RouteSpec("/transactions") + with RestAPISettingsHelper + with PathMockFactory + with BlockchainStubHelpers + with EthHelpers { + private val blockchain = stub[Blockchain] + private val transactionPublisher = stub[TransactionPublisher] + private val testTime = new TestTime + + private val transactionsApiRoute = new TransactionsApiRoute( + restAPISettings, + stub[CommonTransactionsApi], + stub[Wallet], + blockchain, + mockFunction[Int], + transactionPublisher, + testTime + ) + + private val route = seal(transactionsApiRoute.route) + + "exchange" - { + "accepted with ETH signed orders" in EthChainId.withEChainId { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + } + + val transactionPublisher = blockchain.stub.transactionPublisher(testTime) + + val route = transactionsApiRoute.copy(blockchain = blockchain, transactionPublisher = transactionPublisher).route + + val ethBuyOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xe5ff562bfb0296e95b631365599c87f1c5002597bf56a131f289765275d2580f5344c62999404c37cd858ea037328ac91eca16ad1ce69c345ebb52fde70b66251c" + ) + ) + + val ethSellOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.SELL, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xc8ba2bdafd27742546b3be34883efc51d6cdffbb235798d7b51876c6854791f019b0522d7a39b6f2087cba46ae86919b71a2d9d7920dfc8e00246d8f02a258f21b" + ) + ) + + val transaction = TxHelpers.exchange(ethBuyOrder, ethSellOrder, TxVersion.V3, 100) + testTime.setTime(100) + Post(routePath("/broadcast"), transaction.json()) ~> route ~> check { + responseAs[JsObject] should matchJson(s"""{ + | "type" : 7, + | "id" : "${transaction.id()}", + | "sender" : "3FrCwv8uFRxQazhX6Lno45aZ68Bof6ScaeF", + | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "fee" : 1000000, + | "feeAssetId" : null, + | "timestamp" : 100, + | "proofs" : [ "${transaction.signature}" ], + | "version" : 3, + | "chainId" : 69, + | "order1" : { + | "version" : 4, + | "id" : "${ethBuyOrder.id()}", + | "sender" : "3FzoJXUesFqzf4nmMYejpUDYmFJvkwEiQG6", + | "senderPublicKey" : "5BQPcwDXaZexgonPb8ipDrLRXY3RHn1kFLP9fqp1s6M6xiRhC4LvsAq2HueXCMzkpuXsrLnuBA3SdkJyuhNZXMCd", + | "matcherPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "assetPair" : { + | "amountAsset" : "5fQPsn8hoaVddFG26cWQ5QFdqxWtUPNaZ9zH2E6LYzFn", + | "priceAsset" : null + | }, + | "orderType" : "buy", + | "amount" : 1, + | "price" : 100, + | "timestamp" : 1, + | "expiration" : 123, + | "matcherFee" : 100000, + | "signature" : "", + | "proofs" : [ ], + | "matcherFeeAssetId" : null, + | "eip712Signature" : "0xe5ff562bfb0296e95b631365599c87f1c5002597bf56a131f289765275d2580f5344c62999404c37cd858ea037328ac91eca16ad1ce69c345ebb52fde70b66251c" + | }, + | "order2" : { + | "version" : 4, + | "id" : "${ethSellOrder.id()}", + | "sender" : "3FzoJXUesFqzf4nmMYejpUDYmFJvkwEiQG6", + | "senderPublicKey" : "5BQPcwDXaZexgonPb8ipDrLRXY3RHn1kFLP9fqp1s6M6xiRhC4LvsAq2HueXCMzkpuXsrLnuBA3SdkJyuhNZXMCd", + | "matcherPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "assetPair" : { + | "amountAsset" : "5fQPsn8hoaVddFG26cWQ5QFdqxWtUPNaZ9zH2E6LYzFn", + | "priceAsset" : null + | }, + | "orderType" : "sell", + | "amount" : 1, + | "price" : 100, + | "timestamp" : 1, + | "expiration" : 123, + | "matcherFee" : 100000, + | "signature" : "", + | "proofs" : [ ], + | "matcherFeeAssetId" : null, + | "eip712Signature" : "0xc8ba2bdafd27742546b3be34883efc51d6cdffbb235798d7b51876c6854791f019b0522d7a39b6f2087cba46ae86919b71a2d9d7920dfc8e00246d8f02a258f21b" + | }, + | "amount" : 1, + | "price" : 100, + | "buyMatcherFee" : 100000, + | "sellMatcherFee" : 100000 + |} + |""".stripMargin) + } + } + } + + "invoke script" - { + def withInvokeScriptTransaction(f: (KeyPair, InvokeScriptTransaction) => Unit): Unit = { + val seed = new Array[Byte](32) + Random.nextBytes(seed) + val sender: KeyPair = KeyPair(seed) + val ist = InvokeScriptTransaction( + TxVersion.V1, + sender.publicKey, + sender.toAddress, + None, + Seq.empty, + 500000L, + Asset.Waves, + testTime.getTimestamp(), + Proofs.empty, + AddressScheme.current.chainId + ).signWith(sender.privateKey) + f(sender, ist) + } + + "shows trace when trace is enabled" in withInvokeScriptTransaction { (sender, ist) => + val accountTrace = AccountVerifierTrace(sender.toAddress, Some(GenericError("Error in account script"))) + (transactionPublisher.validateAndBroadcast _) + .when(*, None) + .returning( + Future.successful(TracedResult(Right(true), List(accountTrace))) + ) + Post(routePath("/broadcast?trace=true"), ist.json()) ~> route ~> check { + val result = responseAs[JsObject] + (result \ "trace").as[JsValue] shouldBe Json.arr(accountTrace.json) + } + } + + "does not show trace when trace is disabled" in withInvokeScriptTransaction { (sender, ist) => + val accountTrace = AccountVerifierTrace(sender.toAddress, Some(GenericError("Error in account script"))) + (transactionPublisher.validateAndBroadcast _) + .when(*, None) + .returning( + Future.successful(TracedResult(Right(true), List(accountTrace))) + ) + Post(routePath("/broadcast"), ist.json()) ~> route ~> check { + (responseAs[JsObject] \ "trace") shouldBe empty + } + Post(routePath("/broadcast?trace=false"), ist.json()) ~> route ~> check { + (responseAs[JsObject] \ "trace") shouldBe empty + } + } + + "generates valid trace with vars" in { + val invoke = TxHelpers.invoke(TxHelpers.defaultAddress, "test") + val leaseCancelId = ByteStr(bytes32gen.sample.get) + + val amount1 = 100 + val nonce1 = 0 + val recipient1 = Recipient.Address(ByteStr.decodeBase58("3NAgxLPGnw3RGv9JT6NTDaG5D1iLUehg2xd").get) + val leaseId1 = Lease.calculateId(Lease(recipient1, amount1, nonce1), invoke.id()) + + val amount2 = 20 + val nonce2 = 2 + val recipient2 = Recipient.Alias("some_alias") + val leaseId2 = Lease.calculateId(Lease(recipient2, amount2, nonce2), invoke.id()) + + val blockchain = createBlockchainStub { blockchain => + val (dAppScript, _) = ScriptCompiler + .compile( + s""" + |{-# STDLIB_VERSION 5 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable(i) + |func test() = { + | let test = 1 + | if (test == 1) + | then + | [ + | Lease(Address(base58'${recipient1.bytes}'), $amount1, $nonce1), + | Lease(Alias("${recipient2.name}"), $amount2, $nonce2), + | LeaseCancel(base58'$leaseCancelId') + | ] + | else [] + |} + |""".stripMargin, + ScriptEstimatorV3 + ) + .explicitGet() + + (blockchain.leaseDetails _) + .when(*) + .returns(None) + .anyNumberOfTimes() + (blockchain.resolveAlias _) + .when(*) + .returns(Right(accountGen.sample.get.toAddress)) + .anyNumberOfTimes() + (blockchain.accountScript _) + .when(*) + .returns( + Some( + AccountScriptInfo( + TxHelpers.defaultSigner.publicKey, + dAppScript, + 0L, + Map(3 -> Seq("test").map(_ -> 0L).toMap) + ) + ) + ) + + (blockchain.hasAccountScript _).when(*).returns(true) + } + val publisher = createTxPublisherStub(blockchain) + val route = transactionsApiRoute.copy(blockchain = blockchain, transactionPublisher = publisher).route + + Post(routePath("/broadcast?trace=true"), invoke.json()) ~> route ~> check { + responseAs[JsObject] should matchJson( + s"""{ + | "type" : 16, + | "id" : "${invoke.id()}", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "fee" : 1000000, + | "feeAssetId" : null, + | "timestamp" : ${invoke.timestamp}, + | "proofs" : [ "${invoke.signature}" ], + | "version" : 1, + | "dApp" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "payment" : [ ], + | "call" : { + | "function" : "test", + | "args" : [ ] + | }, + | "trace" : [ { + | "type" : "verifier", + | "id" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "result" : "success", + | "error" : null + | }, { + | "type" : "dApp", + | "id" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "function" : "test", + | "args" : [ ], + | "invocations": [], + | "result" : { + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ + | { + | "recipient" : "${recipient1.bytes}", + | "amount" : $amount1, + | "nonce" : $nonce1, + | "id" : "$leaseId1" + | }, + | { + | "recipient" : "alias:T:${recipient2.name}", + | "amount" : $amount2, + | "nonce" : $nonce2, + | "id" : "$leaseId2" + | } + | ], + | "leaseCancels" : [ + | { + | "id":"$leaseCancelId" + | } + | ], + | "invokes" : [ ] + | }, + | "error" : null, + | "vars" : [ { + | "name" : "test", + | "type" : "Int", + | "value" : 1 + | } ] + | } ] + |}""".stripMargin + ) + } + } + } +} diff --git a/node/src/test/scala/com/wavesplatform/http/TransactionsRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/TransactionsRouteSpec.scala index 48c7811765f..a564d77b249 100644 --- a/node/src/test/scala/com/wavesplatform/http/TransactionsRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/TransactionsRouteSpec.scala @@ -1,9 +1,11 @@ package com.wavesplatform.http +import scala.util.Random + import akka.http.scaladsl.model._ -import com.wavesplatform.account.{AddressScheme, KeyPair, PublicKey} -import com.wavesplatform.api.common.CommonTransactionsApi -import com.wavesplatform.api.common.CommonTransactionsApi.TransactionMeta +import com.wavesplatform.{BlockchainStubHelpers, BlockGen, TestValues, TestWallet} +import com.wavesplatform.account.PublicKey +import com.wavesplatform.api.common.{CommonTransactionsApi, TransactionMeta} import com.wavesplatform.api.http.ApiError._ import com.wavesplatform.api.http.ApiMarshallers._ import com.wavesplatform.api.http.TransactionsApiRoute @@ -17,33 +19,29 @@ import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BOOLEAN, CONST_LONG, FUNCTION_CALL, TRUE} import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 -import com.wavesplatform.lang.v1.traits.domain.{Lease, LeaseCancel, Recipient} +import com.wavesplatform.lang.v1.traits.domain.LeaseCancel import com.wavesplatform.network.TransactionPublisher import com.wavesplatform.settings.{TestFunctionalitySettings, WavesSettings} -import com.wavesplatform.state.diffs.FeeValidation.FeeDetails +import com.wavesplatform.state.{AccountScriptInfo, Blockchain, Height, InvokeScriptResult} import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation} +import com.wavesplatform.state.diffs.FeeValidation.FeeDetails import com.wavesplatform.state.reader.LeaseDetails -import com.wavesplatform.state.{AccountScriptInfo, Blockchain, Height, InvokeScriptResult} -import com.wavesplatform.transaction.Asset.IssuedAsset -import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.test.TestTime +import com.wavesplatform.transaction.{Asset, Transaction, TxHelpers} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.serialization.impl.InvokeScriptTxSerializer import com.wavesplatform.transaction.smart.InvokeScriptTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.script.trace.{AccountVerifierTrace, TracedResult} import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} -import com.wavesplatform.transaction.{Asset, Proofs, Transaction, TxHelpers, TxVersion} -import com.wavesplatform.{BlockGen, BlockchainStubHelpers, TestTime, TestValues, TestWallet} +import com.wavesplatform.transaction.utils.EthTxGenerator +import com.wavesplatform.utils.{EthEncoding, EthHelpers} import monix.reactive.Observable -import org.scalacheck.Gen._ import org.scalacheck.{Arbitrary, Gen} +import org.scalacheck.Gen._ import org.scalamock.scalatest.MockFactory import org.scalatest.OptionValues -import play.api.libs.json.Json.JsValueWrapper import play.api.libs.json._ - -import scala.concurrent.Future -import scala.util.Random +import play.api.libs.json.Json.JsValueWrapper class TransactionsRouteSpec extends RouteSpec("/transactions") @@ -52,7 +50,8 @@ class TransactionsRouteSpec with BlockGen with OptionValues with TestWallet - with BlockchainStubHelpers { + with BlockchainStubHelpers + with EthHelpers { private val blockchain = mock[Blockchain] private val utxPoolSynchronizer = mock[TransactionPublisher] @@ -241,7 +240,7 @@ class TransactionsRouteSpec .map { case FeeDetails(asset, _, feeInAsset, feeInWaves) => (asset, feeInAsset, feeInWaves) - } + } ) .anyNumberOfTimes() @@ -289,18 +288,18 @@ class TransactionsRouteSpec val setScript = TxHelpers.setScript( dAppSigner, TxHelpers.script(""" - |{-# STDLIB_VERSION 5 #-} - |{-# SCRIPT_TYPE ACCOUNT #-} - |{-# CONTENT_TYPE DAPP #-} - | - |@Callable(i) - |func issue() = { - | [ - | Issue("name", "description", 1000, 4, true, unit, 0), - | Issue("name", "description", 1000, 4, true, unit, 1) - | ] - |} - |""".stripMargin) + |{-# STDLIB_VERSION 5 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable(i) + |func issue() = { + | [ + | Issue("name", "description", 1000, 4, true, unit, 0), + | Issue("name", "description", 1000, 4, true, unit, 1) + | ] + |} + |""".stripMargin) ) val invokeScript = TxHelpers.invoke(dAppAddress, "issue") @@ -386,31 +385,31 @@ class TransactionsRouteSpec Get(routePath(s"/address/${TxHelpers.secondAddress}/limit/10")) ~> route ~> check { val json = (responseAs[JsArray] \ 0 \ 0).as[JsObject] json shouldBe Json.parse(s"""{ - | "type" : 9, - | "id" : "${leaseCancel.id()}", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", - | "fee" : 1000000, - | "feeAssetId" : null, - | "timestamp" : ${leaseCancel.timestamp}, - | "proofs" : [ "${leaseCancel.signature}" ], - | "version" : 2, - | "leaseId" : "${lease.id()}", - | "chainId" : 84, - | "height" : 1, - | "applicationStatus" : "succeeded", - | "lease" : { - | "id" : "${lease.id()}", - | "originTransactionId" : "${lease.id()}", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", - | "amount" : 1000000000, - | "height" : 1, - | "status" : "canceled", - | "cancelHeight" : 2, - | "cancelTransactionId" : "${leaseCancel.id()}" - | } - |}""".stripMargin) + | "type" : 9, + | "id" : "${leaseCancel.id()}", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "fee" : 1000000, + | "feeAssetId" : null, + | "timestamp" : ${leaseCancel.timestamp}, + | "proofs" : [ "${leaseCancel.signature}" ], + | "version" : 2, + | "leaseId" : "${lease.id()}", + | "chainId" : 84, + | "height" : 1, + | "applicationStatus" : "succeeded", + | "lease" : { + | "id" : "${lease.id()}", + | "originTransactionId" : "${lease.id()}", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", + | "amount" : 1000000000, + | "height" : 1, + | "status" : "canceled", + | "cancelHeight" : 2, + | "cancelTransactionId" : "${leaseCancel.id()}" + | } + |}""".stripMargin) } } @@ -532,56 +531,171 @@ class TransactionsRouteSpec status shouldEqual StatusCodes.OK val json = (responseAs[JsArray] \ 0 \ 0 \ "stateChanges").as[JsObject] json should matchJson(s"""{ - | "data": [], - | "transfers": [], - | "issues": [], - | "reissues": [], - | "burns": [], - | "sponsorFees": [], - | "leases": [ - | { - | "id": "$leaseId1", - | "originTransactionId": "$leaseId1", - | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount": 123, - | "height": 1, - | "status":"active", - | "cancelHeight" : null, - | "cancelTransactionId" : null - | }, - | { - | "id": "$leaseId2", - | "originTransactionId": "$leaseId2", - | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount": 123, - | "height": 1, - | "status":"active", - | "cancelHeight" : null, - | "cancelTransactionId" : null - | } - | ], - | "leaseCancels": [ - | { - | "id": "$leaseCancelId", - | "originTransactionId": "$leaseCancelId", - | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount": 123, - | "height": 1, - | "status":"canceled", - | "cancelHeight" : 2, - | "cancelTransactionId" : "$leaseCancelId" - | } - | ], - | "invokes": [] - |}""".stripMargin) + | "data": [], + | "transfers": [], + | "issues": [], + | "reissues": [], + | "burns": [], + | "sponsorFees": [], + | "leases": [ + | { + | "id": "$leaseId1", + | "originTransactionId": "$leaseId1", + | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount": 123, + | "height": 1, + | "status":"active", + | "cancelHeight" : null, + | "cancelTransactionId" : null + | }, + | { + | "id": "$leaseId2", + | "originTransactionId": "$leaseId2", + | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount": 123, + | "height": 1, + | "status":"active", + | "cancelHeight" : null, + | "cancelTransactionId" : null + | } + | ], + | "leaseCancels": [ + | { + | "id": "$leaseCancelId", + | "originTransactionId": "$leaseCancelId", + | "sender": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient": "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount": 123, + | "height": 1, + | "status":"canceled", + | "cancelHeight" : 2, + | "cancelTransactionId" : "$leaseCancelId" + | } + | ], + | "invokes": [] + |}""".stripMargin) } } } routePath("/info/{id}") - { + "returns meta for eth transfer" in { + val blockchain = createBlockchainStub { blockchain => + blockchain.stub.creditBalance(TxHelpers.defaultEthAddress, Waves) + blockchain.stub.activateAllFeatures() + } + + val differ = blockchain.stub.transactionDiffer().andThen(_.resultE.explicitGet()) + val transaction = EthTxGenerator.generateEthTransfer(TxHelpers.defaultEthSigner, TxHelpers.secondAddress, 10, Waves) + val diff = differ(transaction) + val transactionsApi = stub[CommonTransactionsApi] + (transactionsApi.transactionById _) + .when(transaction.id()) + .returning( + Some( + TransactionMeta.Ethereum( + Height(1), + transaction, + succeeded = true, + diff.ethereumTransactionMeta.values.headOption, + diff.scriptResults.values.headOption + ) + ) + ) + + val route = seal(transactionsApiRoute.copy(blockchain = blockchain, commonApi = transactionsApi).route) + Get(routePath(s"/info/${transaction.id()}")) ~> route ~> check { + responseAs[JsObject] should matchJson(s"""{ + | "type" : 19, + | "id" : "${transaction.id()}", + | "fee" : 100000, + | "feeAssetId" : null, + | "timestamp" : ${transaction.timestamp}, + | "version" : 1, + | "chainId" : 84, + | "bytes" : "${EthEncoding.toHexString(transaction.bytes())}", + | "sender" : "3NByUD1YE9SQPzmf2KqVqrjGMutNSfc4oBC", + | "senderPublicKey" : "5vwTDMooR7Hp57MekN7qHz7fHNVrkn2Nx4CiWdq4cyBR4LNnZWYAr7UfBbzhmSvtNkv6e45aJ4Q4aKCSinyHVw33", + | "height" : 1, + | "applicationStatus" : "succeeded", + | "payload" : { + | "type" : "transfer", + | "recipient" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", + | "asset" : null, + | "amount" : 10 + | } + |}""".stripMargin) + } + } + + "returns meta and state changes for eth invoke" in { + val blockchain = createBlockchainStub { blockchain => + blockchain.stub.creditBalance(TxHelpers.defaultEthAddress, Waves) + blockchain.stub.setScript(TxHelpers.secondAddress, TxHelpers.scriptV5("""@Callable(i) + |func test() = [] + |""".stripMargin)) + blockchain.stub.activateAllFeatures() + } + + val differ = blockchain.stub.transactionDiffer().andThen(_.resultE.explicitGet()) + val transaction = EthTxGenerator.generateEthInvoke(TxHelpers.defaultEthSigner, TxHelpers.secondAddress, "test", Nil, Nil) + val diff = differ(transaction) + val transactionsApi = stub[CommonTransactionsApi] + (transactionsApi.transactionById _) + .when(transaction.id()) + .returning( + Some( + TransactionMeta.Ethereum( + Height(1), + transaction, + succeeded = true, + diff.ethereumTransactionMeta.values.headOption, + diff.scriptResults.values.headOption + ) + ) + ) + + val route = seal(transactionsApiRoute.copy(blockchain = blockchain, commonApi = transactionsApi).route) + Get(routePath(s"/info/${transaction.id()}")) ~> route ~> check { + responseAs[JsObject] should matchJson(s"""{ + | "type" : 19, + | "id" : "${transaction.id()}", + | "fee" : 500000, + | "feeAssetId" : null, + | "timestamp" : ${transaction.timestamp}, + | "version" : 1, + | "chainId" : 84, + | "bytes" : "${EthEncoding.toHexString(transaction.bytes())}", + | "sender" : "3NByUD1YE9SQPzmf2KqVqrjGMutNSfc4oBC", + | "senderPublicKey" : "5vwTDMooR7Hp57MekN7qHz7fHNVrkn2Nx4CiWdq4cyBR4LNnZWYAr7UfBbzhmSvtNkv6e45aJ4Q4aKCSinyHVw33", + | "height" : 1, + | "applicationStatus" : "succeeded", + | "payload" : { + | "type" : "invocation", + | "dApp" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", + | "call" : { + | "function" : "test", + | "args" : [ ] + | }, + | "payment" : [ ], + | "stateChanges" : { + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + | } + | } + |}""".stripMargin) + } + } + "returns lease tx for lease cancel tx" in { val lease = TxHelpers.lease() val leaseCancel = TxHelpers.leaseCancel(lease.id()) @@ -605,31 +719,31 @@ class TransactionsRouteSpec Get(routePath(s"/info/${leaseCancel.id()}")) ~> route ~> check { val json = responseAs[JsObject] json shouldBe Json.parse(s"""{ - | "type" : 9, - | "id" : "${leaseCancel.id()}", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", - | "fee" : 1000000, - | "feeAssetId" : null, - | "timestamp" : ${leaseCancel.timestamp}, - | "proofs" : [ "${leaseCancel.signature}" ], - | "version" : 2, - | "leaseId" : "${lease.id()}", - | "chainId" : 84, - | "height" : 1, - | "applicationStatus" : "succeeded", - | "lease" : { - | "id" : "${lease.id()}", - | "originTransactionId" : "${lease.id()}", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", - | "amount" : 1000000000, - | "height" : 1, - | "status" : "canceled", - | "cancelHeight" : 2, - | "cancelTransactionId" : "${leaseCancel.id()}" - | } - |}""".stripMargin) + | "type" : 9, + | "id" : "${leaseCancel.id()}", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", + | "fee" : 1000000, + | "feeAssetId" : null, + | "timestamp" : ${leaseCancel.timestamp}, + | "proofs" : [ "${leaseCancel.signature}" ], + | "version" : 2, + | "leaseId" : "${lease.id()}", + | "chainId" : 84, + | "height" : 1, + | "applicationStatus" : "succeeded", + | "lease" : { + | "id" : "${lease.id()}", + | "originTransactionId" : "${lease.id()}", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", + | "amount" : 1000000000, + | "height" : 1, + | "status" : "canceled", + | "cancelHeight" : 2, + | "cancelTransactionId" : "${leaseCancel.id()}" + | } + |}""".stripMargin) } } @@ -776,85 +890,85 @@ class TransactionsRouteSpec status shouldEqual StatusCodes.OK val json = (responseAs[JsObject] \ "stateChanges").as[JsObject] json should matchJson(s"""{ - | "data" : [ ], - | "transfers" : [ ], - | "issues" : [ ], - | "reissues" : [ ], - | "burns" : [ ], - | "sponsorFees" : [ ], - | "leases" : [ { - | "id" : "$leaseId1", - | "originTransactionId" : "$leaseId1", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount" : 123, - | "height" : 1, - | "status":"active", - | "cancelHeight" : null, - | "cancelTransactionId" : null - | }, { - | "id" : "$leaseId2", - | "originTransactionId" : "$leaseId2", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount" : 123, - | "height" : 1, - | "status":"active", - | "cancelHeight" : null, - | "cancelTransactionId" : null - | } ], - | "leaseCancels" : [ { - | "id" : "$leaseCancelId", - | "originTransactionId" : "$leaseCancelId", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount" : 123, - | "height" : 1, - | "status" : "canceled", - | "cancelHeight" : 2, - | "cancelTransactionId" : "$leaseCancelId" - | } ], - | "invokes" : [ { - | "dApp" : "$nestedInvokeAddress", - | "call" : { - | "function" : "nested", - | "args" : [ ] - | }, - | "payment" : [ ], - | "stateChanges" : { - | "data" : [ ], - | "transfers" : [ ], - | "issues" : [ ], - | "reissues" : [ ], - | "burns" : [ ], - | "sponsorFees" : [ ], - | "leases" : [ { - | "id" : "$nestedLeaseId", - | "originTransactionId" : "$nestedLeaseId", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount" : 123, - | "height" : 1, - | "status":"active", - | "cancelHeight" : null, - | "cancelTransactionId" : null - | } ], - | "leaseCancels" : [ { - | "id" : "$nestedLeaseCancelId", - | "originTransactionId" : "$nestedLeaseCancelId", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "amount" : 123, - | "height" : 1, - | "status" : "canceled", - | "cancelHeight" : 2, - | "cancelTransactionId" : "$nestedLeaseCancelId" - | } ], - | "invokes" : [ ] - | } - | } ] - |} - |""".stripMargin) + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ { + | "id" : "$leaseId1", + | "originTransactionId" : "$leaseId1", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount" : 123, + | "height" : 1, + | "status":"active", + | "cancelHeight" : null, + | "cancelTransactionId" : null + | }, { + | "id" : "$leaseId2", + | "originTransactionId" : "$leaseId2", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount" : 123, + | "height" : 1, + | "status":"active", + | "cancelHeight" : null, + | "cancelTransactionId" : null + | } ], + | "leaseCancels" : [ { + | "id" : "$leaseCancelId", + | "originTransactionId" : "$leaseCancelId", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount" : 123, + | "height" : 1, + | "status" : "canceled", + | "cancelHeight" : 2, + | "cancelTransactionId" : "$leaseCancelId" + | } ], + | "invokes" : [ { + | "dApp" : "$nestedInvokeAddress", + | "call" : { + | "function" : "nested", + | "args" : [ ] + | }, + | "payment" : [ ], + | "stateChanges" : { + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ { + | "id" : "$nestedLeaseId", + | "originTransactionId" : "$nestedLeaseId", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount" : 123, + | "height" : 1, + | "status":"active", + | "cancelHeight" : null, + | "cancelTransactionId" : null + | } ], + | "leaseCancels" : [ { + | "id" : "$nestedLeaseCancelId", + | "originTransactionId" : "$nestedLeaseCancelId", + | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "recipient" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", + | "amount" : 123, + | "height" : 1, + | "status" : "canceled", + | "cancelHeight" : 2, + | "cancelTransactionId" : "$nestedLeaseCancelId" + | } ], + | "invokes" : [ ] + | } + | } ] + |} + |""".stripMargin) } } @@ -1054,7 +1168,7 @@ class TransactionsRouteSpec val funcName = "func" val funcWithoutArgs = Json.obj("function" -> funcName) val funcWithEmptyArgs = Json.obj("function" -> funcName, "args" -> JsArray.empty) - val funcWithArgs = InvokeScriptTransaction.serializer.functionCallToJson( + val funcWithArgs = InvokeScriptTxSerializer.functionCallToJson( FUNCTION_CALL( FunctionHeader.User(funcName), List(CONST_LONG(1), CONST_BOOLEAN(true)) @@ -1087,191 +1201,6 @@ class TransactionsRouteSpec } } - routePath("/broadcast") - { - def withInvokeScriptTransaction(f: (KeyPair, InvokeScriptTransaction) => Unit): Unit = { - val seed = new Array[Byte](32) - Random.nextBytes(seed) - val sender: KeyPair = KeyPair(seed) - val ist = InvokeScriptTransaction( - TxVersion.V1, - sender.publicKey, - sender.toAddress, - None, - Seq.empty, - 500000L, - Asset.Waves, - testTime.getTimestamp(), - Proofs.empty, - AddressScheme.current.chainId - ).signWith(sender.privateKey) - f(sender, ist) - } - - "shows trace when trace is enabled" in withInvokeScriptTransaction { (sender, ist) => - val accountTrace = AccountVerifierTrace(sender.toAddress, Some(GenericError("Error in account script"))) - (utxPoolSynchronizer.validateAndBroadcast _) - .expects(*, None) - .returning( - Future.successful(TracedResult(Right(true), List(accountTrace))) - ) - .once() - Post(routePath("/broadcast?trace=true"), ist.json()) ~> route ~> check { - val result = responseAs[JsObject] - (result \ "trace").as[JsValue] shouldBe Json.arr(accountTrace.json) - } - } - - "does not show trace when trace is disabled" in withInvokeScriptTransaction { (sender, ist) => - val accountTrace = AccountVerifierTrace(sender.toAddress, Some(GenericError("Error in account script"))) - (utxPoolSynchronizer.validateAndBroadcast _) - .expects(*, None) - .returning( - Future.successful(TracedResult(Right(true), List(accountTrace))) - ) - .twice() - Post(routePath("/broadcast"), ist.json()) ~> route ~> check { - (responseAs[JsObject] \ "trace") shouldBe empty - } - Post(routePath("/broadcast?trace=false"), ist.json()) ~> route ~> check { - (responseAs[JsObject] \ "trace") shouldBe empty - } - } - - "generates valid trace with vars" in { - val invoke = TxHelpers.invoke(TxHelpers.defaultAddress, "test") - val leaseCancelId = ByteStr(bytes32gen.sample.get) - - val amount1 = 100 - val nonce1 = 0 - val recipient1 = Recipient.Address(ByteStr.decodeBase58("3NAgxLPGnw3RGv9JT6NTDaG5D1iLUehg2xd").get) - val leaseId1 = Lease.calculateId(Lease(recipient1, amount1, nonce1), invoke.id()) - - val amount2 = 20 - val nonce2 = 2 - val recipient2 = Recipient.Alias("some_alias") - val leaseId2 = Lease.calculateId(Lease(recipient2, amount2, nonce2), invoke.id()) - - val blockchain = createBlockchainStub { blockchain => - val (dAppScript, _) = ScriptCompiler - .compile( - s""" - |{-# STDLIB_VERSION 5 #-} - |{-# SCRIPT_TYPE ACCOUNT #-} - |{-# CONTENT_TYPE DAPP #-} - | - |@Callable(i) - |func test() = { - | let test = 1 - | if (test == 1) - | then - | [ - | Lease(Address(base58'${recipient1.bytes}'), $amount1, $nonce1), - | Lease(Alias("${recipient2.name}"), $amount2, $nonce2), - | LeaseCancel(base58'$leaseCancelId') - | ] - | else [] - |} - |""".stripMargin, - ScriptEstimatorV3 - ) - .explicitGet() - - (blockchain.leaseDetails _) - .when(*) - .returns(None) - .anyNumberOfTimes() - (blockchain.resolveAlias _) - .when(*) - .returns(Right(accountGen.sample.get.toAddress)) - .anyNumberOfTimes() - (blockchain.accountScript _) - .when(*) - .returns( - Some( - AccountScriptInfo( - TxHelpers.defaultSigner.publicKey, - dAppScript, - 0L, - Map(3 -> Seq("test").map(_ -> 0L).toMap) - ) - ) - ) - - (blockchain.hasAccountScript _).when(*).returns(true) - } - val publisher = createTxPublisherStub(blockchain) - val route = transactionsApiRoute.copy(blockchain = blockchain, transactionPublisher = publisher).route - - Post(routePath("/broadcast?trace=true"), invoke.json()) ~> route ~> check { - responseAs[JsObject] should matchJson( - s"""{ - | "type" : 16, - | "id" : "${invoke.id()}", - | "sender" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "senderPublicKey" : "9BUoYQYq7K38mkk61q8aMH9kD9fKSVL1Fib7FbH6nUkQ", - | "fee" : 1000000, - | "feeAssetId" : null, - | "timestamp" : ${invoke.timestamp}, - | "proofs" : [ "${invoke.signature}" ], - | "version" : 1, - | "dApp" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "payment" : [ ], - | "call" : { - | "function" : "test", - | "args" : [ ] - | }, - | "trace" : [ { - | "type" : "verifier", - | "id" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "result" : "success", - | "error" : null - | }, { - | "type" : "dApp", - | "id" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9", - | "function" : "test", - | "args" : [ ], - | "invocations": [], - | "result" : { - | "data" : [ ], - | "transfers" : [ ], - | "issues" : [ ], - | "reissues" : [ ], - | "burns" : [ ], - | "sponsorFees" : [ ], - | "leases" : [ - | { - | "recipient" : "${recipient1.bytes}", - | "amount" : $amount1, - | "nonce" : $nonce1, - | "id" : "$leaseId1" - | }, - | { - | "recipient" : "alias:T:${recipient2.name}", - | "amount" : $amount2, - | "nonce" : $nonce2, - | "id" : "$leaseId2" - | } - | ], - | "leaseCancels" : [ - | { - | "id":"$leaseCancelId" - | } - | ], - | "invokes" : [ ] - | }, - | "error" : null, - | "vars" : [ { - | "name" : "test", - | "type" : "Int", - | "value" : 1 - | } ] - | } ] - |}""".stripMargin - ) - } - } - } - routePath("/merkleProof") - { val transactionsGen = for { txsSize <- Gen.choose(1, 10) diff --git a/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala index 59c5121df54..4f8a62f1941 100644 --- a/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala @@ -2,7 +2,7 @@ package com.wavesplatform.http import akka.http.scaladsl.testkit.RouteTestTimeout import com.google.protobuf.ByteString -import com.wavesplatform.account.{Address, PublicKey} +import com.wavesplatform.account.Address import com.wavesplatform.api.http.ApiError.TooBigArrayAllocation import com.wavesplatform.api.http.ApiMarshallers._ import com.wavesplatform.api.http.UtilsApiRoute @@ -811,7 +811,7 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with """.stripMargin val (script, _) = ScriptCompiler.compile(str, ScriptEstimatorV2).explicitGet() - AccountScriptInfo(PublicKey(new Array[Byte](32)), script, 0, Map(1 -> Map("testCallable" -> 200, "testSyncCallComplexityExcess" -> 100))) + AccountScriptInfo(TxHelpers.defaultSigner.publicKey, script, 0, Map(1 -> Map("testCallable" -> 200, "testSyncCallComplexityExcess" -> 100))) } val dAppAddress = TxHelpers.defaultSigner.toAddress @@ -826,7 +826,7 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with def responseJson: JsObject = { val fullJson = responseAs[JsObject] - (fullJson \ "address").as[String] shouldBe dAppAddress.stringRepr + (fullJson \ "address").as[String] shouldBe dAppAddress.toString (fullJson \ "expr").as[String] should not be empty (fullJson \ "result").asOpt[JsObject].getOrElse(fullJson - "address" - "expr") } @@ -920,6 +920,11 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with .returning(DefaultBlockchainSettings) .anyNumberOfTimes() + (utilsApi.blockchain.balance _) + .when(*, *) + .returning(1000) + .anyNumberOfTimes() + evalScript(""" testSyncinvoke() """) ~> route ~> check { responseAs[String] shouldBe """{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"testSyncInvoke"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":94,"expr":" testSyncinvoke() ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" } @@ -953,7 +958,7 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with | } """.stripMargin ) - AccountScriptInfo(PublicKey(new Array[Byte](32)), script, 0, Map(1 -> Map("callable" -> 999))) + AccountScriptInfo(TxHelpers.secondSigner.publicKey, script, 0, Map(1 -> Map("callable" -> 999))) } (blockchain.hasAccountScript _).when(dAppAddress2).returning(true).anyNumberOfTimes() (blockchain.accountScript _).when(dAppAddress2).returning(Some(testScript2)).anyNumberOfTimes() diff --git a/node/src/test/scala/com/wavesplatform/http/package.scala b/node/src/test/scala/com/wavesplatform/http/package.scala index 5dab2a045c8..222fbaee309 100644 --- a/node/src/test/scala/com/wavesplatform/http/package.scala +++ b/node/src/test/scala/com/wavesplatform/http/package.scala @@ -64,8 +64,8 @@ package object http { Base58 .tryDecodeWithLimit(str) .toEither - .flatMap(AddressOrAlias.fromBytes(_, 0)) - .map { case (x, _) => JsSuccess(x) } + .flatMap(AddressOrAlias.fromBytes) + .map(JsSuccess(_)) .getOrElse(JsError("Can't read PublicKey")) case _ => JsError("Can't read PublicKey") diff --git a/node/src/test/scala/com/wavesplatform/lagonaki/unit/BlockSpecification.scala b/node/src/test/scala/com/wavesplatform/lagonaki/unit/BlockSpecification.scala index 4ebba33505c..aa9100c9892 100644 --- a/node/src/test/scala/com/wavesplatform/lagonaki/unit/BlockSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/lagonaki/unit/BlockSpecification.scala @@ -5,12 +5,11 @@ import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.metrics.Instrumented -import com.wavesplatform.state.diffs.produce import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ import com.wavesplatform.crypto -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import org.scalacheck.Arbitrary.arbitrary import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/lagonaki/unit/MicroBlockSpecification.scala b/node/src/test/scala/com/wavesplatform/lagonaki/unit/MicroBlockSpecification.scala index abede5c1a53..d283422b8cf 100644 --- a/node/src/test/scala/com/wavesplatform/lagonaki/unit/MicroBlockSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/lagonaki/unit/MicroBlockSpecification.scala @@ -1,12 +1,12 @@ package com.wavesplatform.lagonaki.unit import com.wavesplatform.account.KeyPair +import com.wavesplatform.block.serialization.MicroBlockSerializer import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.mining.Miner -import com.wavesplatform.state.diffs.produce -import com.wavesplatform.test.FunSuite +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.transfer._ @@ -34,7 +34,7 @@ class MicroBlockSpecification extends FunSuite with MockFactory { val transactions = Seq(tr, tr2) val microBlock = MicroBlock.buildAndSign(3.toByte, sender, transactions, prevResBlockSig, totalResBlockSig).explicitGet() - val parsedBlock = MicroBlock.parseBytes(microBlock.bytes()).get + val parsedBlock = MicroBlock.parseBytes(MicroBlockSerializer.toBytes(microBlock)).get assert(microBlock.signaturesValid().isRight) assert(parsedBlock.signaturesValid().isRight) diff --git a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala index b2e700b2c5e..bed073610e6 100644 --- a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala +++ b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala @@ -2,15 +2,11 @@ package com.wavesplatform.mining import java.util.concurrent.atomic.AtomicReference -import scala.concurrent.Await -import scala.concurrent.duration._ - import com.typesafe.config.ConfigFactory -import com.wavesplatform.{crypto, protobuf, BlocksTransactionsHelpers, TestTime} import com.wavesplatform.account.{AddressOrAlias, KeyPair} -import com.wavesplatform.block.{Block, BlockHeader, SignedBlockHeader} import com.wavesplatform.block.serialization.{BlockHeaderSerializer, BlockSerializer} import com.wavesplatform.block.validation.Validators +import com.wavesplatform.block.{Block, BlockHeader, SignedBlockHeader} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.consensus.PoSSelector @@ -21,24 +17,27 @@ import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.ValidationError import com.wavesplatform.protobuf.block.PBBlocks import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings, WalletSettings, WavesSettings} -import com.wavesplatform.state.{diffs, Blockchain, BlockchainUpdaterImpl, NG} import com.wavesplatform.state.appender.BlockAppender -import com.wavesplatform.test.FlatSpec -import com.wavesplatform.transaction.{BlockchainUpdater, GenesisTransaction, Transaction, TxVersion} +import com.wavesplatform.state.{Blockchain, BlockchainUpdaterImpl, NG, diffs} +import com.wavesplatform.test.{FlatSpec, _} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.{BlockchainUpdater, GenesisTransaction, Transaction, TxHelpers, TxVersion} import com.wavesplatform.utils.Time import com.wavesplatform.utx.UtxPoolImpl import com.wavesplatform.wallet.Wallet +import com.wavesplatform.{BlocksTransactionsHelpers, crypto, protobuf} import io.netty.channel.group.DefaultChannelGroup import io.netty.util.concurrent.GlobalEventExecutor import monix.eval.Task import monix.execution.Scheduler -import monix.reactive.Observer +import monix.reactive.{Observable, Observer} import org.scalacheck.Gen import org.scalatest._ import org.scalatest.enablers.Length +import scala.concurrent.Await +import scala.concurrent.duration._ class BlockV5Test extends FlatSpec with WithDomain @@ -407,7 +406,7 @@ class BlockV5Test def lastBlock: SignedBlockHeader = d.blockchainUpdater.lastBlockHeader.get - val block1 = applyBlock(genesis) // h=1 + val block1 = applyBlock(genesis, TxHelpers.genesis(TxHelpers.defaultAddress)) // h=1 block1.id() shouldBe block1.signature block1.id() should have length crypto.SignatureLength @@ -420,11 +419,11 @@ class BlockV5Test block3.id() should have length crypto.DigestLength val (keyBlock, microBlocks) = - UnsafeBlocks.unsafeChainBaseAndMicro(block3.id(), Nil, Seq(Nil, Nil), acc, Block.ProtoBlockVersion, System.currentTimeMillis()) + UnsafeBlocks.unsafeChainBaseAndMicro(block3.id(), Nil, Seq(Seq(TxHelpers.transfer()), Seq(TxHelpers.transfer())), acc, Block.ProtoBlockVersion, System.currentTimeMillis()) d.appendBlock(keyBlock) microBlocks.foreach(d.appendMicroBlock) - val mb1 = d.blockchainUpdater.microBlock(d.blockchainUpdater.microblockIds.head).get + val mb1 = d.microBlocks.head mb1.totalResBlockSig should have length crypto.SignatureLength mb1.reference should not be keyBlock.signature mb1.reference shouldBe keyBlock.id() @@ -472,7 +471,7 @@ class BlockV5Test val utxPool = new UtxPoolImpl(time, blockchain, settings.utxSettings) val minerScheduler = Scheduler.singleThread("miner") val appenderScheduler = Scheduler.singleThread("appender") - val miner = new MinerImpl(allChannels, blockchain, settings, time, utxPool, wallet, pos, minerScheduler, appenderScheduler) + val miner = new MinerImpl(allChannels, blockchain, settings, time, utxPool, wallet, pos, minerScheduler, appenderScheduler, Observable.empty) val blockAppender = BlockAppender(blockchain, time, utxPool, pos, appenderScheduler) _ f(miner, blockAppender, appenderScheduler) } diff --git a/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala b/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala index 6f45aa4b30f..f4238f466b1 100644 --- a/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala @@ -31,6 +31,7 @@ import io.netty.util.concurrent.GlobalEventExecutor import monix.eval.Task import monix.execution.Scheduler import monix.execution.schedulers.SchedulerService +import monix.reactive.Observable import org.scalacheck.{Arbitrary, Gen} class BlockWithMaxBaseTargetTest extends FreeSpec with WithDB with DBCacheSettings { @@ -44,7 +45,7 @@ class BlockWithMaxBaseTargetTest extends FreeSpec with WithDB with DBCacheSettin val allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE) val wallet = Wallet(WalletSettings(None, Some("123"), None)) val miner = - new MinerImpl(allChannels, bcu, settings, ntpTime, utxPoolStub, wallet, pos, scheduler, scheduler) + new MinerImpl(allChannels, bcu, settings, ntpTime, utxPoolStub, wallet, pos, scheduler, scheduler, Observable.empty) val signal = new Semaphore(1) signal.acquire() diff --git a/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala b/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala index 0fb8dfc6a7e..f29077addae 100644 --- a/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala +++ b/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala @@ -17,6 +17,7 @@ import com.wavesplatform.transaction.{CreateAliasTransaction, GenesisTransaction import com.wavesplatform.utils.Schedulers import com.wavesplatform.utx.UtxPoolImpl import monix.execution.Scheduler +import monix.reactive.Observable import org.scalamock.scalatest.PathMockFactory class MicroBlockMinerSpec extends FlatSpec with PathMockFactory with WithDomain { @@ -36,6 +37,7 @@ class MicroBlockMinerSpec extends FlatSpec with PathMockFactory with WithDomain settings.minerSettings, scheduler, scheduler, + Observable.empty, identity ) diff --git a/node/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala b/node/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala index d34aa67797b..b1d3daf8e16 100644 --- a/node/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala +++ b/node/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala @@ -20,6 +20,7 @@ import io.netty.util.concurrent.GlobalEventExecutor import monix.eval.Task import monix.execution.Scheduler import monix.execution.Scheduler.Implicits.global +import monix.reactive.Observable import org.scalamock.scalatest.PathMockFactory class MiningFailuresSuite extends FlatSpec with PathMockFactory with WithDB { @@ -64,7 +65,8 @@ class MiningFailuresSuite extends FlatSpec with PathMockFactory with WithDB { wallet, pos, scheduler, - scheduler + scheduler, + Observable.empty ) } diff --git a/node/src/test/scala/com/wavesplatform/mining/MiningWithRewardSuite.scala b/node/src/test/scala/com/wavesplatform/mining/MiningWithRewardSuite.scala index 74d7f238ac6..40d5ee778e7 100644 --- a/node/src/test/scala/com/wavesplatform/mining/MiningWithRewardSuite.scala +++ b/node/src/test/scala/com/wavesplatform/mining/MiningWithRewardSuite.scala @@ -27,6 +27,7 @@ import io.netty.channel.group.DefaultChannelGroup import io.netty.util.concurrent.GlobalEventExecutor import monix.eval.Task import monix.execution.Scheduler +import monix.reactive.Observable import org.iq80.leveldb.DB import org.scalacheck.{Arbitrary, Gen} import org.scalatest.compatible.Assertion @@ -126,7 +127,7 @@ class MiningWithRewardSuite extends AsyncFlatSpec with Matchers with WithDB with scheduler = Scheduler.singleThread("appender") allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE) wallet = Wallet(WalletSettings(None, Some("123"), None)) - miner = new MinerImpl(allChannels, blockchainUpdater, settings, ntpTime, utxPool, wallet, pos, scheduler, scheduler) + miner = new MinerImpl(allChannels, blockchainUpdater, settings, ntpTime, utxPool, wallet, pos, scheduler, scheduler, Observable.empty) account = createAccount ts = ntpTime.correctedTime() - 60000 genesisBlock = TestBlock.create(ts + 2, List(GenesisTransaction.create(account.toAddress, ENOUGH_AMT, ts + 1).explicitGet())) diff --git a/node/src/test/scala/com/wavesplatform/network/BasicMessagesRepoSpec.scala b/node/src/test/scala/com/wavesplatform/network/BasicMessagesRepoSpec.scala index 5d6764f9d89..084a5d291de 100644 --- a/node/src/test/scala/com/wavesplatform/network/BasicMessagesRepoSpec.scala +++ b/node/src/test/scala/com/wavesplatform/network/BasicMessagesRepoSpec.scala @@ -75,7 +75,7 @@ class BasicMessagesRepoSpec extends FreeSpec { "PBTransactionSpec max length" in { val maxSizeTransaction = PBSignedTransaction( - Some( + PBSignedTransaction.Transaction.WavesTransaction( PBTransaction( Byte.MaxValue, ByteString.copyFrom(bytes32gen.sample.get), diff --git a/node/src/test/scala/com/wavesplatform/network/LegacyFrameCodecSpec.scala b/node/src/test/scala/com/wavesplatform/network/LegacyFrameCodecSpec.scala index 9750dd7182b..5a494b70b8f 100644 --- a/node/src/test/scala/com/wavesplatform/network/LegacyFrameCodecSpec.scala +++ b/node/src/test/scala/com/wavesplatform/network/LegacyFrameCodecSpec.scala @@ -19,7 +19,7 @@ import scala.concurrent.duration.DurationInt class LegacyFrameCodecSpec extends FreeSpec with MockFactory { "should handle one message" in forAll(issueGen) { origTx => - val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes) + val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes, () => false) val buff = Unpooled.buffer write(buff, origTx, TransactionSpec) @@ -34,7 +34,7 @@ class LegacyFrameCodecSpec extends FreeSpec with MockFactory { } "should handle multiple messages" in forAll(Gen.nonEmptyListOf(issueGen)) { origTxs => - val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes) + val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes, () => false) val buff = Unpooled.buffer origTxs.foreach(write(buff, _, TransactionSpec)) @@ -55,7 +55,7 @@ class LegacyFrameCodecSpec extends FreeSpec with MockFactory { "should reject an already received transaction" in { val tx = issueGen.sample.getOrElse(throw new RuntimeException("Can't generate a sample transaction")) - val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes) + val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes, () => false) val ch = new EmbeddedChannel(codec) val buff1 = Unpooled.buffer @@ -71,7 +71,7 @@ class LegacyFrameCodecSpec extends FreeSpec with MockFactory { "should not reject an already received GetPeers" in { val msg = KnownPeers(Seq(InetSocketAddress.createUnresolved("127.0.0.1", 80))) - val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes) + val codec = new LegacyFrameCodec(PeerDatabase.NoOp, 3.minutes, () => false) val ch = new EmbeddedChannel(codec) val buff1 = Unpooled.buffer @@ -89,7 +89,7 @@ class LegacyFrameCodecSpec extends FreeSpec with MockFactory { val tx = UpdateAssetInfoTransaction .selfSigned(1, TestValues.keyPair, TestValues.asset.id, "bomz", "", System.currentTimeMillis(), TestValues.fee, Waves) .explicitGet() - RawBytes.fromTransaction(tx) shouldBe RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) + RawBytes.fromTransaction(tx, false) shouldBe RawBytes(PBTransactionSpec.messageCode, PBTransactionSpec.serializeData(tx)) } private def write[T <: AnyRef](buff: ByteBuf, msg: T, spec: MessageSpec[T]): Unit = { diff --git a/node/src/test/scala/com/wavesplatform/network/MessageCodecSpec.scala b/node/src/test/scala/com/wavesplatform/network/MessageCodecSpec.scala index d0f6cb01280..97608810afd 100644 --- a/node/src/test/scala/com/wavesplatform/network/MessageCodecSpec.scala +++ b/node/src/test/scala/com/wavesplatform/network/MessageCodecSpec.scala @@ -11,7 +11,7 @@ import io.netty.channel.embedded.EmbeddedChannel class MessageCodecSpec extends FreeSpec { "should block a sender of invalid messages" in { - val codec = new SpiedMessageCodec + val codec = new SpyingMessageCodec val ch = new EmbeddedChannel(codec) ch.writeInbound(RawBytes(TransactionSpec.messageCode, "foo".getBytes(StandardCharsets.UTF_8))) @@ -20,18 +20,18 @@ class MessageCodecSpec extends FreeSpec { codec.blockCalls shouldBe 1 } - "should not block a sender of valid messages" in forAll(randomTransactionGen) { origTx: ProvenTransaction => - val codec = new SpiedMessageCodec + "should not block a sender of valid messages" in forAll(randomTransactionGen) { origTx: Transaction with ProvenTransaction => + val codec = new SpyingMessageCodec val ch = new EmbeddedChannel(codec) - ch.writeInbound(RawBytes.fromTransaction(origTx)) + ch.writeInbound(RawBytes.fromTransaction(origTx, forceProtobuf = false)) val decodedTx = ch.readInbound[Transaction]() decodedTx shouldBe origTx codec.blockCalls shouldBe 0 } - private class SpiedMessageCodec extends MessageCodec(PeerDatabase.NoOp) { + private class SpyingMessageCodec extends MessageCodec(PeerDatabase.NoOp) { var blockCalls = 0 override def block(ctx: ChannelHandlerContext, e: Throwable): Unit = { diff --git a/node/src/test/scala/com/wavesplatform/network/MicroBlockResponseSpec.scala b/node/src/test/scala/com/wavesplatform/network/MicroBlockResponseSpec.scala new file mode 100644 index 00000000000..5259bf77e0c --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/network/MicroBlockResponseSpec.scala @@ -0,0 +1,15 @@ +package com.wavesplatform.network + +import com.wavesplatform.common.utils.Base64 +import com.wavesplatform.test._ + +class MicroBlockResponseSpec extends FreeSpec { + private val microBlockBytes = Base64.decode( + "CqMCCAUSINDAl9MzGkepj6WsZ+1NZv0grSgzJogVswMTP7+ug6LoGkDJBEdWcsDc/bat2ljrW74o9l7Y+Pcp07ra2VRe/HLU/Oq6cT7xJqyqZ7xoXP5tLKcnq4hF/5FtS/NYx5zX3RMPIiDk9FCvGrDyyqy8jzX1qe6cEdv5NRXv+hSH+BMnnFtqBSqYAQpUCFQSIBjkoQIwpcrsWlpsgLJVOBo27loBDODD+h473uYYaxMSGgQQoI0GIOvZ5ffzLigDwgYeChYKFCCTgv+auCSYevJXZ7mkKyv2/dkoEgQQoI0GEkD5K5E+HKr3IXYhnwLZaWVsIF+tJdbvV4LFjksWIeLoopDf46TTE2XXXb64R2ZsbWV0QJpQ3cNqTnKXGcB2DesIEkA+/2wKSB07Tg2uBH9OGuIXLBH7FzKPLllyjn7TlvYTLZrohyNSBAIQ3sM9UwPQkUDSC1NGYBFwRHRdF+gPfQcDGiAzlpLCohmCR1KXVnxw5AVO7Xq60gorXfInMXSiS3Qf9Q==" + ) + + "Signature is valid" in { + val parsedMicroBlock = PBMicroBlockSpec.deserializeData(microBlockBytes).get.microblock + parsedMicroBlock.signatureValid() shouldBe true + } +} diff --git a/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala b/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala index c06cb7077a7..972b0685052 100644 --- a/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/BlockchainUpdaterImplSpec.scala @@ -1,7 +1,10 @@ package com.wavesplatform.state +import scala.util.Random + import com.google.common.primitives.Longs import com.typesafe.config.ConfigFactory +import com.wavesplatform.{EitherMatchers, NTPTime, RequestGen} import com.wavesplatform.TestHelpers.enableNG import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.block.Block @@ -10,25 +13,23 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain} import com.wavesplatform.events.BlockchainUpdateTriggers import com.wavesplatform.features.BlockchainFeatures -import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.history.{chainBaseAndMicro, randomSig} +import com.wavesplatform.history.Domain.BlockchainUpdaterExt import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 -import com.wavesplatform.settings.{WavesSettings, loadConfig} +import com.wavesplatform.settings.{loadConfig, WavesSettings} import com.wavesplatform.state.diffs.ENOUGH_AMT -import com.wavesplatform.test.FreeSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{GenesisTransaction, Transaction} +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils.Time -import com.wavesplatform.{EitherMatchers, NTPTime, RequestGen} import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory -import scala.util.Random - class BlockchainUpdaterImplSpec extends FreeSpec with EitherMatchers @@ -296,7 +297,7 @@ class BlockchainUpdaterImplSpec ) val invoke = - InvokeScriptTransaction.selfSigned(3.toByte, sender, dapp.toAddress, None, Seq.empty, 50_0000L, Waves, ntpTime.getTimestamp()).explicitGet() + Signed.invokeScript(3.toByte, sender, dapp.toAddress, None, Seq.empty, 50_0000L, Waves, ntpTime.getTimestamp()) d.appendBlock(d.createBlock(5.toByte, Seq(invoke))) } diff --git a/node/src/test/scala/com/wavesplatform/state/CommonSpec.scala b/node/src/test/scala/com/wavesplatform/state/CommonSpec.scala index 848841c59e1..572890ab5bc 100644 --- a/node/src/test/scala/com/wavesplatform/state/CommonSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/CommonSpec.scala @@ -6,10 +6,9 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.crypto.SignatureLength import com.wavesplatform.db.WithDomain import com.wavesplatform.lagonaki.mocks.TestBlock +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.GenesisTransaction -import com.wavesplatform.TestTime -import com.wavesplatform.test.FreeSpec class CommonSpec extends FreeSpec with WithDomain { private val time = new TestTime diff --git a/node/src/test/scala/com/wavesplatform/state/NgStateTest.scala b/node/src/test/scala/com/wavesplatform/state/NgStateTest.scala index d13004b9b91..881037d25ca 100644 --- a/node/src/test/scala/com/wavesplatform/state/NgStateTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/NgStateTest.scala @@ -3,7 +3,7 @@ package com.wavesplatform.state import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.history._ import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala index 1fdcabd0f7a..6d911a69c8d 100644 --- a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala @@ -8,6 +8,7 @@ import com.wavesplatform.crypto.SignatureLength import com.wavesplatform.db.WithDomain import com.wavesplatform.features.BlockchainFeatures._ import com.wavesplatform.features._ +import com.wavesplatform.history import com.wavesplatform.history.Domain import com.wavesplatform.it.util.AddressOrAliasExt import com.wavesplatform.lagonaki.mocks.TestBlock @@ -19,16 +20,16 @@ import com.wavesplatform.lang.v1.compiler.{Terms, TestCompiler} import com.wavesplatform.lang.v1.traits.domain.Lease import com.wavesplatform.settings.{TestFunctionalitySettings, WavesSettings} import com.wavesplatform.state.reader.LeaseDetails -import com.wavesplatform.test.FreeSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.AliasDoesNotExist import com.wavesplatform.transaction.assets.{IssueTransaction, ReissueTransaction} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, InvokeTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.{InvokeTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.transaction.{CreateAliasTransaction, DataTransaction, GenesisTransaction, Transaction, TxVersion} import com.wavesplatform.utils.StringBytes -import com.wavesplatform.{TestTime, history} import org.scalacheck.Gen.alphaLowerChar import org.scalacheck.{Arbitrary, Gen} import org.scalatest.{Assertion, Assertions} @@ -546,9 +547,7 @@ class RollbackSpec extends FreeSpec with WithDomain { val fee = 150000000L val invoke = ss.fold[InvokeTransaction]( - InvokeScriptTransaction - .selfSigned(2.toByte, invoker, dApp.toAddress, Some(fc), Seq.empty, fee, Waves, nextTs) - .explicitGet() + Signed.invokeScript(2.toByte, invoker, dApp.toAddress, Some(fc), Seq.empty, fee, Waves, nextTs) )( setScript => diffs.ci.toInvokeExpression(setScript, invoker, Some(fee), Some(fc)) ) diff --git a/node/src/test/scala/com/wavesplatform/state/TransactionsByAddressSpec.scala b/node/src/test/scala/com/wavesplatform/state/TransactionsByAddressSpec.scala index 20dfcd99039..3cadafbc485 100644 --- a/node/src/test/scala/com/wavesplatform/state/TransactionsByAddressSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/TransactionsByAddressSpec.scala @@ -42,7 +42,7 @@ class TransactionsByAddressSpec extends FreeSpec with BlockGen with WithDomain { genesisTimestamp, Constants.TotalWaves, None, - Seq(GenesisTransactionSettings(sender.toAddress.stringRepr, Constants.TotalWaves)), + Seq(GenesisTransactionSettings(sender.toAddress.toString, Constants.TotalWaves)), 1000, 1.minute ) diff --git a/node/src/test/scala/com/wavesplatform/state/appender/ExtensionAppenderSpec.scala b/node/src/test/scala/com/wavesplatform/state/appender/ExtensionAppenderSpec.scala index 05ac534fcd7..ff706a9613e 100644 --- a/node/src/test/scala/com/wavesplatform/state/appender/ExtensionAppenderSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/appender/ExtensionAppenderSpec.scala @@ -1,11 +1,10 @@ package com.wavesplatform.state.appender -import com.wavesplatform.TestTime import com.wavesplatform.block.Block import com.wavesplatform.common.utils._ import com.wavesplatform.db.WithDomain import com.wavesplatform.network.{ExtensionBlocks, InvalidBlockStorage, PeerDatabase} -import com.wavesplatform.test.FlatSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.utils.SystemTime import com.wavesplatform.utx.UtxPoolImpl diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala index 1e255f2fad2..07aea25e900 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala @@ -1,6 +1,7 @@ package com.wavesplatform.state.diffs import cats._ +import com.wavesplatform.BlocksTransactionsHelpers import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 @@ -16,12 +17,11 @@ import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.settings.{FunctionalitySettings, TestFunctionalitySettings} import com.wavesplatform.state._ import com.wavesplatform.state.diffs.smart.smartEnabledFS +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.transfer._ import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import com.wavesplatform.BlocksTransactionsHelpers -import com.wavesplatform.test.PropSpec import fastparse.Parsed import org.scalacheck.{Arbitrary, Gen} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/BalanceDiffValidationTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/BalanceDiffValidationTest.scala index 71cafd268cf..b921f0e8a3f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/BalanceDiffValidationTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/BalanceDiffValidationTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.lease.LeaseTransaction import com.wavesplatform.transaction.transfer._ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferDetailedDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferDetailedDiffTest.scala index b6e0b2b0a01..f51bb4aeb43 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferDetailedDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferDetailedDiffTest.scala @@ -12,7 +12,7 @@ import com.wavesplatform.state.diffs.BlockDiffer.DetailedDiff import com.wavesplatform.state.{Blockchain, Diff} import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.BlockGen -import com.wavesplatform.test.FreeSpec +import com.wavesplatform.test._ import org.scalacheck.Gen class BlockDifferDetailedDiffTest extends FreeSpec with BlockGen with WithState { @@ -107,7 +107,7 @@ class BlockDifferDetailedDiffTest extends FreeSpec with BlockGen with WithState "with NG" - { val ngFs = TFS.Enabled.copy(preActivatedFeatures = TFS.Enabled.preActivatedFeatures + (BlockchainFeatures.NG.id -> 0)) - "no history — only 40% from current block" in + "no history - only 40% from current block" in forAll(genesisTransfersBlockGen) { case (addr1, _, _, _, b) => assertDetailedDiff(Seq.empty, b, ngFs) { @@ -116,7 +116,7 @@ class BlockDifferDetailedDiffTest extends FreeSpec with BlockGen with WithState } } - "with history — 60% from last + 40% from current block" in { + "with history - 60% from last + 40% from current block" in { val blocksNgMinerGen: Gen[(Seq[Block], Block, Address)] = for { a1 <- accountGen a2 <- accountGen suchThat (_ != a1) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala index c9188662889..2e926a3247f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala @@ -2,6 +2,7 @@ package com.wavesplatform.state.diffs import java.util.concurrent.ThreadLocalRandom +import com.wavesplatform.BlockGen import com.wavesplatform.account.KeyPair import com.wavesplatform.block.Block import com.wavesplatform.common.utils.EitherExt2 @@ -10,9 +11,8 @@ import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.FunctionalitySettings import com.wavesplatform.state.{Blockchain, Diff} +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction -import com.wavesplatform.BlockGen -import com.wavesplatform.test.FreeSpec class BlockDifferTest extends FreeSpec with BlockGen with WithState { private val TransactionFee = 10 diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala index 68dd2fe2dfd..728248e3a13 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala @@ -12,7 +12,7 @@ import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.mining.MiningConstraint import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTimeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTimeTest.scala index 586b37e203d..0e84884ee71 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTimeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTimeTest.scala @@ -4,7 +4,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithState import com.wavesplatform.settings.TestFunctionalitySettings.Enabled import com.wavesplatform.state._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import org.scalacheck.Gen class CommonValidationTimeTest extends PropSpec with WithState { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala index 65cbdd6b761..f2b69433986 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala @@ -9,10 +9,10 @@ import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state._ import com.wavesplatform.state.utils.addressTransactions -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.{Asset, CreateAliasTransaction, GenesisTransaction, Transaction} +import com.wavesplatform.transaction.{Asset, CreateAliasTransaction, GenesisTransaction, Transaction, TransactionType} import org.scalacheck.Gen class CreateAliasTransactionDiffTest extends PropSpec with WithState { @@ -49,7 +49,7 @@ class CreateAliasTransactionDiffTest extends PropSpec with WithState { val senderAcc = anotherAliasTx.sender.toAddress blockDiff.aliases shouldBe Map(anotherAliasTx.alias -> senderAcc) - addressTransactions(db, Some(Height(newState.height + 1) -> blockDiff), senderAcc, Set(CreateAliasTransaction.typeId), None).collect { + addressTransactions(db, Some(Height(newState.height + 1) -> blockDiff), senderAcc, Set(TransactionType.CreateAlias), None).collect { case (_, cat: CreateAliasTransaction) => cat.alias }.toSet shouldBe Set( anotherAliasTx.alias, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/DataTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/DataTransactionDiffTest.scala index e4a800f8251..7d2e220fbc2 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/DataTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/DataTransactionDiffTest.scala @@ -8,7 +8,7 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, DataEntry, IntegerDataEntry} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction} import org.scalacheck.{Arbitrary, Gen} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala index f66e5f90e0a..e3e6e2d2511 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala @@ -19,7 +19,7 @@ import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctio import com.wavesplatform.state._ import com.wavesplatform.state.diffs.ExchangeTransactionDiff.getOrderFeePortfolio import com.wavesplatform.state.diffs.TransactionDiffer.TransactionValidationError -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.AccountBalanceError import com.wavesplatform.transaction._ @@ -175,7 +175,7 @@ class ExchangeTransactionDiffTest totalPortfolioDiff.assets.values.toSet shouldBe Set(0L) val matcherPortfolio = - Monoid.combineAll(blockDiff.portfolios.view.filterKeys(_.stringRepr == exchange.sender.toAddress.stringRepr).values) + Monoid.combineAll(blockDiff.portfolios.view.filterKeys(_ == exchange.sender.toAddress).values) val restoredMatcherPortfolio = Monoid.combineAll( @@ -270,7 +270,7 @@ class ExchangeTransactionDiffTest totalPortfolioDiff.assets.values.toSet shouldBe Set(0L) val matcherPortfolio = - Monoid.combineAll(blockDiff.portfolios.view.filterKeys(_.stringRepr == exchange.sender.toAddress.stringRepr).values) + Monoid.combineAll(blockDiff.portfolios.view.filterKeys(_ == exchange.sender.toAddress).values) val restoredMatcherPortfolio = Monoid.combineAll( @@ -675,7 +675,7 @@ class ExchangeTransactionDiffTest forAll(allValidP) { case (genesis, transfers, issueAndScripts, etx) => - val enoughFee = FeeValidation.ScriptExtraFee + FeeValidation.FeeConstants(ExchangeTransaction.typeId) * FeeValidation.FeeUnit + val enoughFee = FeeValidation.ScriptExtraFee + FeeValidation.FeeConstants(TransactionType.Exchange) * FeeValidation.FeeUnit val smallFee = enoughFee - 1 val exchangeWithSmallFee = ExchangeTransaction .signed(2.toByte, MATCHER.privateKey, etx.buyOrder, etx.sellOrder, 1000000, 1000000, 0, 0, smallFee, etx.timestamp) @@ -1187,7 +1187,6 @@ class ExchangeTransactionDiffTest val order2FeeAssetIssue = TxHelpers.issue(script = TestValues.assetScript) test(priceAssetIssue, amountAssetIssue, order1FeeAssetIssue, order2FeeAssetIssue, TestValues.rejectAssetScriptComplexity) - } withClue("amount asset fails") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/GenesisTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/GenesisTransactionDiffTest.scala index d2f27beab3c..3982a033115 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/GenesisTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/GenesisTransactionDiffTest.scala @@ -4,7 +4,7 @@ import cats._ import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.state._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import org.scalacheck.Gen class GenesisTransactionDiffTest extends PropSpec with WithState { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiffTest.scala index f3a34e50acf..cb6e08bbbb4 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/MassTransferTransactionDiffTest.scala @@ -6,7 +6,7 @@ import com.wavesplatform.db.WithState import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/PaymentTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/PaymentTransactionDiffTest.scala index 3490c30a710..ac6e274cc96 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/PaymentTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/PaymentTransactionDiffTest.scala @@ -6,7 +6,7 @@ import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.{GenesisTransaction, PaymentTransaction} import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala index 2e3bf90bfb0..e6d0f582431 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala @@ -9,7 +9,7 @@ import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.ValidationError import com.wavesplatform.mining.MiningConstraint import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.assets.{IssueTransaction, ReissueTransaction} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala index 4fa18e68f0d..0b94895858d 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala @@ -13,7 +13,7 @@ import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state._ import com.wavesplatform.state.reader.CompositeBlockchain -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction._ import com.wavesplatform.transaction.assets._ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala index bc4dd3f83cf..75728ca0691 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala @@ -1,6 +1,6 @@ package com.wavesplatform.state.diffs -import com.wavesplatform.TestTime +import com.wavesplatform.test.TestTime import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain import com.wavesplatform.features.BlockchainFeatures @@ -15,7 +15,7 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.compiler.{Terms, TestCompiler} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.{FunctionalitySettings, TestFunctionalitySettings} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.smart.SetScriptTransaction diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala index a171c74da62..c9b3e5b6bef 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala @@ -8,7 +8,7 @@ import com.wavesplatform.features.BlockchainFeatures.BlockV5 import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings} import com.wavesplatform.state._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.lease.LeaseTransaction @@ -133,7 +133,7 @@ class SponsorshipDiffTest extends PropSpec with WithState { assertDiffEi(setupBlocks, block(Seq(insufficientFee)), s) { blockDiffEi => val minFee = Sponsorship .fromWaves( - FeeValidation.FeeConstants(insufficientFee.typeId) * FeeValidation.FeeUnit, + FeeValidation.FeeConstants(insufficientFee.tpe) * FeeValidation.FeeUnit, sponsor.minSponsoredAssetFee.get ) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/TransactionValidationErrorPrintTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/TransactionValidationErrorPrintTest.scala index 067f952002d..39ea8510b77 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/TransactionValidationErrorPrintTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/TransactionValidationErrorPrintTest.scala @@ -11,7 +11,7 @@ import com.wavesplatform.lang.utils.compilerContext import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.state.diffs.TransactionDiffer.TransactionValidationError -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.ScriptExecutionError import com.wavesplatform.transaction.assets.{IssueTransaction, SetAssetScriptTransaction} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/TransferTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala similarity index 95% rename from node/src/test/scala/com/wavesplatform/state/diffs/TransferTransactionDiffTest.scala rename to node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala index 28ca6fc1492..63f954746e2 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/TransferTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala @@ -8,7 +8,7 @@ import com.wavesplatform.db.WithState import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.assets._ @@ -16,7 +16,7 @@ import com.wavesplatform.transaction.transfer._ import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxValidationError} import org.scalacheck.Gen -class TransferTransactionDiffTest extends PropSpec with WithState { +class TransferDiffTest extends PropSpec with WithState { val preconditionsAndTransfer: Gen[(GenesisTransaction, IssueTransaction, IssueTransaction, TransferTransaction)] = for { master <- accountGen @@ -110,7 +110,7 @@ class TransferTransactionDiffTest extends PropSpec with WithState { case (genesis, issue, fee, transfer) => assertDiffAndState(Seq(TestBlock.create(Seq(genesis))), TestBlock.create(Seq(issue, fee)), smartEnabledFS) { case (_, state) => - val diffOrError = TransferTransactionDiff(state, System.currentTimeMillis())(transfer) + val diffOrError = TransferDiff(state)(transfer.sender.toAddress, transfer.recipient, transfer.amount, transfer.assetId, transfer.fee, transfer.feeAssetId) diffOrError shouldBe Left(GenericError("Smart assets can't participate in TransferTransactions as a fee")) } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala index 7bd1ffe0e42..a7b6f662c5c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala @@ -6,7 +6,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain, WithState} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock -import com.wavesplatform.lang.contract.DApp +import com.wavesplatform.lang.contract import com.wavesplatform.lang.contract.DApp.{CallableAnnotation, CallableFunction} import com.wavesplatform.lang.directives.values.V5 import com.wavesplatform.lang.script.ContractScript.ContractScriptImpl @@ -20,11 +20,11 @@ import com.wavesplatform.lang.v1.evaluator.FunctionIds.TO_BIGINT import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, Transaction} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -61,7 +61,7 @@ class BigIntInvokeTest def dApp(action: EXPR => FUNCTION_CALL): Script = { ContractScriptImpl( V5, - DApp( + contract.DApp( DAppMeta(), Nil, List( @@ -92,8 +92,7 @@ class BigIntInvokeTest genesis <- GenesisTransaction.create(dAppAcc.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, dAppAcc, Some(dApp(action)), fee, ts) - invoke <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts) - } yield (List(genesis, genesis2, setDApp), invoke) + } yield (List(genesis, genesis2, setDApp), Signed.invokeScript(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts)) }.explicitGet() def assert(action: EXPR => FUNCTION_CALL, message: String) = { @@ -188,9 +187,7 @@ class BigIntInvokeTest genesis2 = GenesisTransaction.create(dApp2Acc.toAddress, ENOUGH_AMT, ts).explicitGet() setDApp1 = SetScriptTransaction.selfSigned(1.toByte, dApp1Acc, Some(dApp1(dApp2Acc.toAddress)), fee, ts).explicitGet() setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2Acc, Some(dApp2), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1Acc, dApp1Acc.toAddress, Some(FUNCTION_CALL(User("default"), Nil)), Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1Acc, dApp1Acc.toAddress, Some(FUNCTION_CALL(User("default"), Nil)), Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, setDApp1, setDApp2), invoke) val (preparingTxs, invoke) = preconditions.sample.get diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala index 48f067a624d..fbb1d35605a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala @@ -10,16 +10,17 @@ import com.wavesplatform.lang.directives.values.V4 import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.settings.TestFunctionalitySettings +import com.wavesplatform.state.{EmptyDataEntry, SponsorshipValue} +import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} import com.wavesplatform.state.diffs.TransactionDiffer.TransactionValidationError -import com.wavesplatform.state.diffs.{ENOUGH_AMT, _} -import com.wavesplatform.state.{EmptyDataEntry, SponsorshipValue} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TransactionType, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.script.trace.{AssetVerifierTrace, InvokeScriptTrace} import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} +import com.wavesplatform.transaction.smart.script.trace.{AssetVerifierTrace, InvokeScriptTrace} +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalatest.EitherValues @@ -59,7 +60,7 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { Seq(TestBlock.create(genesis :+ setScript :+ issue)), TestBlock.create(Seq(invoke)), features - )(_ should produce("Transaction is not allowed by script of the asset", requireFailed = true)) + )(_ should produceRejectOrFailedDiff("Transaction is not allowed by script of the asset", requireFailed = true)) } } @@ -80,7 +81,7 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { Seq(TestBlock.create(genesis :+ setScript :+ issue)), TestBlock.create(Seq(invoke)), features - )(_ should produce("Transaction is not allowed by script of the asset", requireFailed = true)) + )(_ should produceRejectOrFailedDiff("Transaction is not allowed by script of the asset", requireFailed = true)) } } @@ -127,14 +128,14 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { } property("check fee") { - val minimalFee = 6 * ScriptExtraFee + FeeConstants(InvokeScriptTransaction.typeId) * FeeValidation.FeeUnit + val minimalFee = 6 * ScriptExtraFee + FeeConstants(TransactionType.InvokeScript) * FeeValidation.FeeUnit forAll(multiActionPreconditions(feeMultiplier = 5, withScriptError = false)) { case (genesis, setScript, invoke, issue, _, _, _, _, _) => assertDiffEi( Seq(TestBlock.create(genesis :+ setScript :+ issue)), TestBlock.create(Seq(invoke)), features - )(_ should produce(s" with 6 total scripts invoked does not exceed minimal value of $minimalFee WAVES")) + )(_ should produceRejectOrFailedDiff(s" with 6 total scripts invoked does not exceed minimal value of $minimalFee WAVES")) } } @@ -179,8 +180,7 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, dApp, fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) - } yield (List(genesis, genesis2), setDApp, ci, master) + } yield (List(genesis, genesis2), setDApp, Signed.invokeScript(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3), master) }.explicitGet() forAll(deleteEntryPreconditions) { @@ -218,8 +218,15 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, dApp, fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) - } yield (List(genesis, genesis2), setDApp, ci, issue, master, reissueAmount, burnAmount) + } yield ( + List(genesis, genesis2), + setDApp, + Signed.invokeScript(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3), + issue, + master, + reissueAmount, + burnAmount + ) }.explicitGet() private def sponsorFeePreconditions: Gen[(List[GenesisTransaction], SetScriptTransaction, InvokeScriptTransaction, Option[Long])] = @@ -227,7 +234,7 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { master <- accountGen invoker <- accountGen ts <- timestampGen - fee <- ciFee(1).map(_ + FeeUnit * FeeConstants(IssueTransaction.typeId)) + fee <- ciFee(1).map(_ + FeeUnit * FeeConstants(TransactionType.Issue)) minSponsoredAssetFee <- Gen.oneOf(None, Some(1000L)) } yield { val dApp = Some(sponsorFeeDApp(minSponsoredAssetFee)) @@ -235,8 +242,12 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, dApp, fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) - } yield (List(genesis, genesis2), setDApp, ci, minSponsoredAssetFee) + } yield ( + List(genesis, genesis2), + setDApp, + Signed.invokeScript(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3), + minSponsoredAssetFee + ) }.explicitGet() private def multiActionDApp( @@ -341,7 +352,7 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(TxVersion.V1, master, dApp, fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(TxVersion.V1, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) + ci = Signed.invokeScript(TxVersion.V1, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) } yield (List(genesis, genesis2), setDApp, ci, issue, master, invoker, reissueAmount, burnAmount, transferAmount) }.explicitGet() @@ -416,8 +427,13 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, dApp, fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3) - } yield (List(genesis, genesis2, setDApp), ci, master, invoker, amount) + } yield ( + List(genesis, genesis2, setDApp), + Signed.invokeScript(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts + 3), + master, + invoker, + amount + ) }.explicitGet() private def issueDApp( diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV5LimitTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV5LimitTest.scala index 893d1ef8e85..5986d7b8d5b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV5LimitTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV5LimitTest.scala @@ -1,5 +1,6 @@ package com.wavesplatform.state.diffs.ci +import com.wavesplatform.TransactionGen import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -7,10 +8,10 @@ import com.wavesplatform.lang.directives.values.{StdLibVersion, V4, V5} import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test._ -import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import com.wavesplatform.{TestTime, TransactionGen} +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalatest.EitherValues import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -71,8 +72,8 @@ class CallableV5LimitTest setProhibitedScript = SetScriptTransaction.selfSigned(1.toByte, dApp, Some(contract(6, V5)), fee, ts).explicitGet() setProhibitedV4Script = SetScriptTransaction.selfSigned(1.toByte, dApp, Some(contract(5, V4)), fee, ts).explicitGet() setSyncDApp = SetScriptTransaction.selfSigned(1.toByte, syncDApp, Some(syncDAppScript(dApp.toAddress)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp.toAddress, None, Nil, fee, Waves, ts).explicitGet() - syncInvoke = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, syncDApp.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invoke = Signed.invokeScript(TxVersion.V3, invoker, dApp.toAddress, None, Nil, fee, Waves, ts) + syncInvoke = Signed.invokeScript(TxVersion.V3, invoker, syncDApp.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3), setAcceptableScript, setProhibitedScript, setProhibitedV4Script, setSyncDApp, invoke, syncInvoke) property("callable limit is 10000 from V5") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala index 3bcb1d840c3..bbc49c556a4 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala @@ -3,22 +3,22 @@ package com.wavesplatform.state.diffs.ci import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain, WithState} import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.lang.contract import com.wavesplatform.lang.contract.DApp.{CallableAnnotation, CallableFunction} import com.wavesplatform.lang.directives.values.V4 import com.wavesplatform.lang.script.ContractScript.ContractScriptImpl import com.wavesplatform.lang.script.Script -import com.wavesplatform.lang.contract.DApp import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BOOLEAN, CONST_LONG, CONST_STRING, FUNC, FUNCTION_CALL, REF} import com.wavesplatform.lang.v1.evaluator.FunctionIds import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, Transaction} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -54,7 +54,7 @@ class DAppDataEntryTypeTest val value = if (constructor == "BooleanEntry") CONST_LONG(1) else CONST_BOOLEAN(true) ContractScriptImpl( V4, - DApp( + contract.DApp( DAppMeta(), Nil, List( @@ -91,8 +91,7 @@ class DAppDataEntryTypeTest genesis <- GenesisTransaction.create(dAppAcc.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, dAppAcc, Some(dApp(constructor)), fee, ts) - invoke <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts) - } yield (List(genesis, genesis2, setDApp), invoke) + } yield (List(genesis, genesis2, setDApp), Signed.invokeScript(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts)) }.explicitGet() private def assert(constructor: String) = { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala index 38bca0ad932..251392e8d30 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala @@ -1,22 +1,19 @@ package com.wavesplatform.state.diffs.ci -import com.wavesplatform.TestTime import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain import com.wavesplatform.lang.directives.values.V5 import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.{GenesisTransaction, TxHelpers, TxVersion} import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed class IllegalAddressChainIdTest extends PropSpec with WithDomain { import DomainPresets._ - private val time = new TestTime - private def ts = time.getTimestamp() - private val contract = TestCompiler(V5).compileContract( s""" | @Callable(i) @@ -32,10 +29,10 @@ class IllegalAddressChainIdTest extends PropSpec with WithDomain { master <- accountGen invoker <- accountGen fee <- ciFee() - gTx1 = GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts).explicitGet() - gTx2 = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts).explicitGet() - ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(contract), fee, ts).explicitGet() - invokeTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, ts).explicitGet() + gTx1 = GenesisTransaction.create(master.toAddress, ENOUGH_AMT, TxHelpers.timestamp).explicitGet() + gTx2 = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, TxHelpers.timestamp).explicitGet() + ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(contract), fee, TxHelpers.timestamp).explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, TxHelpers.timestamp) } yield (Seq(gTx1, gTx2, ssTx), invokeTx) private val error = "Address belongs to another network: expected: 84(T), actual: 87(W)" diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsAvailabilityTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsAvailabilityTest.scala index b290ef532b6..0d5ecdc8b45 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsAvailabilityTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsAvailabilityTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 @@ -10,11 +9,12 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -122,7 +122,7 @@ class InvokeActionsAvailabilityTest ssTx2 = SetScriptTransaction.selfSigned(1.toByte, proxyDApp, Some(proxyDAppScript(callingDApp.toAddress)), fee, ts).explicitGet() asset = IssuedAsset(issue.id.value()) payments = Seq(Payment(paymentAmount, asset)) - invoke = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, proxyDApp.toAddress, None, payments, fee, Waves, ts).explicitGet() + invoke = Signed.invokeScript(TxVersion.V3, invoker, proxyDApp.toAddress, None, payments, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx, ssTx2, issue), invoke, proxyDApp.toAddress, callingDApp.toAddress) property("actions availability in sync call") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala index ad99a0584d4..e948c0dbadd 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala @@ -11,27 +11,20 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TransactionType} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{GenesisTransaction, Transaction} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} -class InvokeActionsFeeTest - extends PropSpec - with Inside - with WithState - with DBCacheSettings - with MockFactory - with WithDomain - with EitherValues { +class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCacheSettings with MockFactory with WithDomain with EitherValues { private val time = new TestTime private def ts = time.getTimestamp() @@ -109,11 +102,9 @@ class InvokeActionsFeeTest ) setVerifier <- SetScriptTransaction.selfSigned(1.toByte, scriptedInvoker, Some(verifier), fee, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, dAppAcc, Some(dApp(asset)), fee, ts) - payments = Seq(Payment(1, asset), Payment(1, asset)) - invokeFromScripted = () => - InvokeScriptTransaction.selfSigned(1.toByte, scriptedInvoker, dAppAcc.toAddress, None, payments, fee, Waves, ts).explicitGet() - invokeFromNonScripted = () => - InvokeScriptTransaction.selfSigned(1.toByte, nonScriptedInvoker, dAppAcc.toAddress, None, payments, fee, Waves, ts).explicitGet() + payments = Seq(Payment(1, asset), Payment(1, asset)) + invokeFromScripted = () => Signed.invokeScript(1.toByte, scriptedInvoker, dAppAcc.toAddress, None, payments, fee, Waves, ts) + invokeFromNonScripted = () => Signed.invokeScript(1.toByte, nonScriptedInvoker, dAppAcc.toAddress, None, payments, fee, Waves, ts) } yield (List(genesis, genesis2, genesis3, issue, transfer1, transfer2, setVerifier, setDApp), invokeFromScripted, invokeFromNonScripted) }.explicitGet() @@ -128,12 +119,12 @@ class InvokeActionsFeeTest d.blockchain.bestLiquidDiff.get.errorMessage(invokeFromScripted1.id()).get.text should include( s"Fee in WAVES for InvokeScriptTransaction (${invokeFromScripted1.fee} in WAVES) " + s"with 6 total scripts invoked " + - s"does not exceed minimal value of ${FeeConstants(InvokeScriptTransaction.typeId) * FeeUnit + 6 * ScriptExtraFee} WAVES" + s"does not exceed minimal value of ${FeeConstants(TransactionType.InvokeScript) * FeeUnit + 6 * ScriptExtraFee} WAVES" ) d.blockchain.bestLiquidDiff.get.errorMessage(invokeFromNonScripted1.id()).get.text should include( s"Fee in WAVES for InvokeScriptTransaction (${invokeFromNonScripted1.fee} in WAVES) " + s"with 5 total scripts invoked " + - s"does not exceed minimal value of ${FeeConstants(InvokeScriptTransaction.typeId) * FeeUnit + 5 * ScriptExtraFee} WAVES" + s"does not exceed minimal value of ${FeeConstants(TransactionType.InvokeScript) * FeeUnit + 5 * ScriptExtraFee} WAVES" ) d.appendBlock() @@ -145,7 +136,7 @@ class InvokeActionsFeeTest d.blockchain.bestLiquidDiff.get.errorMessage(invokeFromScripted2.id()).get.text should include( s"Fee in WAVES for InvokeScriptTransaction (${invokeFromScripted2.fee} in WAVES) " + s"with 1 total scripts invoked " + - s"does not exceed minimal value of ${FeeConstants(InvokeScriptTransaction.typeId) * FeeUnit + ScriptExtraFee} WAVES" + s"does not exceed minimal value of ${FeeConstants(TransactionType.InvokeScript) * FeeUnit + ScriptExtraFee} WAVES" ) d.blockchain.bestLiquidDiff.get.errorMessage(invokeFromNonScripted2.id()) shouldBe None } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala index 02e6678766d..a46966a9e2c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala @@ -10,14 +10,14 @@ import com.wavesplatform.lang.v1.FunctionHeader.User import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.settings.TestFunctionalitySettings +import com.wavesplatform.state.{Diff, InvokeScriptResult, NewTransactionInfo, Portfolio} import com.wavesplatform.state.InvokeScriptResult.ErrorMessage import com.wavesplatform.state.diffs.ENOUGH_AMT -import com.wavesplatform.state.{Diff, InvokeScriptResult, NewTransactionInfo, Portfolio} -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.test._ import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -64,15 +64,13 @@ class InvokeAssetChecksTest extends PropSpec with Inside with WithState with DBC genesis2Tx = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts).explicitGet() setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(dApp), fee, ts + 2).explicitGet() call = Some(FUNCTION_CALL(User(func), Nil)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, call, Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, call, Seq(), fee, Waves, ts + 3) } yield (activated, func, invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) val (activated, func, invoke, genesisTxs) = transferBase58WavesDAppScenario.sample.get tempDb { _ => val miner = TestBlock.defaultSigner.toAddress - val dAppAddress = invoke.dAppAddressOrAlias.asInstanceOf[Address] + val dAppAddress = invoke.dApp.asInstanceOf[Address] def invokeInfo(succeeded: Boolean) = Map(invoke.id() -> NewTransactionInfo(invoke, Set(invoke.senderAddress, dAppAddress), succeeded)) @@ -190,12 +188,24 @@ class InvokeAssetChecksTest extends PropSpec with Inside with WithState with DBC genesis2 = GenesisTransaction.create(emptyDAppAcc.toAddress, ENOUGH_AMT, ts).explicitGet() setDApp = SetScriptTransaction.selfSigned(1.toByte, dAppAcc, Some(dApp(emptyDAppAcc.toAddress)), fee, ts).explicitGet() setDApp2 = SetScriptTransaction.selfSigned(1.toByte, emptyDAppAcc, Some(emptyDApp), fee, ts).explicitGet() - invokeInvalidLength = InvokeScriptTransaction - .selfSigned(1.toByte, dAppAcc, dAppAcc.toAddress, Some(FUNCTION_CALL(User("invalidLength"), Nil)), Nil, fee, Waves, ts) - .explicitGet() - invokeUnexisting = InvokeScriptTransaction - .selfSigned(1.toByte, dAppAcc, dAppAcc.toAddress, Some(FUNCTION_CALL(User("unexisting"), Nil)), Nil, fee, Waves, ts) - .explicitGet() + invokeInvalidLength = Signed.invokeScript( + 1.toByte, + dAppAcc, + dAppAcc.toAddress, + Some(FUNCTION_CALL(User("invalidLength"), Nil)), + Nil, + fee, + Waves, + ts) + invokeUnexisting = Signed.invokeScript( + 1.toByte, + dAppAcc, + dAppAcc.toAddress, + Some(FUNCTION_CALL(User("unexisting"), Nil)), + Nil, + fee, + Waves, + ts) } yield (List(genesis, genesis2, setDApp, setDApp2), invokeInvalidLength, invokeUnexisting) val (preparingTxs, invokeInvalidLength, invokeUnexisting) = preconditions.sample.get diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala index ecf28815849..b524c25e189 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala @@ -1,5 +1,6 @@ package com.wavesplatform.state.diffs.ci +import com.wavesplatform.TransactionGenBase import com.wavesplatform.account.Address import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 @@ -13,9 +14,9 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import com.wavesplatform.{TestTime, TransactionGenBase} class InvokeDataEntriesBytesTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -87,7 +88,7 @@ class InvokeDataEntriesBytesTest extends PropSpec with WithDomain with Transacti ssTx2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp2Script(dApp3.toAddress, size)), fee, ts).explicitGet() ssTx3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp3Script(dApp4.toAddress, size)), fee, ts).explicitGet() ssTx4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp4Script(size, !reach15kb)), fee, ts).explicitGet() - invokeTx = () => InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invokeTx = () => Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, gTx4, gTx5, ssTx1, ssTx2, ssTx3, ssTx4), invokeTx) private val settings = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala index af86d8b1c18..e0e6784601b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala @@ -1,4 +1,7 @@ package com.wavesplatform.state.diffs.ci + +import scala.util.Try + import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain, WithState} import com.wavesplatform.features.BlockchainFeatures @@ -6,21 +9,19 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{CONST_LONG, CONST_STRING, FUNCTION_CALL} import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} import com.wavesplatform.state.{IntegerDataEntry, StringDataEntry} +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, Transaction} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.EitherValues -import scala.util.Try - class InvokeFeeMultiplierTest extends PropSpec with WithState with DBCacheSettings with MockFactory with WithDomain with EitherValues { private val time = new TestTime @@ -92,9 +93,9 @@ class InvokeFeeMultiplierTest extends PropSpec with WithState with DBCacheSettin ) call = Some(FUNCTION_CALL(FunctionHeader.User("buyBack"), Nil)) payment = Seq(Payment(1, IssuedAsset(issue.id()))) - initInvoke <- InvokeScriptTransaction.selfSigned(1.toByte, master, master.toAddress, initCall, Nil, initFee, Waves, ts) - invoke1 <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, call, payment, fee, Waves, ts) - invoke2 <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, call, payment, fee, Waves, ts) + initInvoke = Signed.invokeScript(1.toByte, master, master.toAddress, initCall, Nil, initFee, Waves, ts) + invoke1 = Signed.invokeScript(1.toByte, invoker, master.toAddress, call, payment, fee, Waves, ts) + invoke2 = Signed.invokeScript(1.toByte, invoker, master.toAddress, call, payment, fee, Waves, ts) } yield (List(genesis, genesis2, setDApp, issue, data1, initInvoke), invoke1, data2, invoke2) }.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsAvailabilityTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsAvailabilityTest.scala index 93c717a571b..5966983591a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsAvailabilityTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsAvailabilityTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain} @@ -9,11 +8,12 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -79,7 +79,7 @@ class InvokePaymentsAvailabilityTest extends PropSpec with Inside with DBCacheSe asset = IssuedAsset(issue.id.value()) payments = Seq(Payment(paymentAmount, asset)) dApp = if (syncCall) proxyDApp.toAddress else callingDApp.toAddress - invokeTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp, None, payments, fee, Waves, ts).explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, dApp, None, payments, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx, ssTx2, issue), invokeTx, callingDApp.toAddress, proxyDApp.toAddress, asset) property("payments availability in usual call") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsLimitTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsLimitTest.scala index 8634438e4fd..2684b6267b7 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsLimitTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokePaymentsLimitTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain, WithState} @@ -9,12 +8,13 @@ import com.wavesplatform.lang.directives.values.{StdLibVersion, V4, V5} import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -70,7 +70,7 @@ class InvokePaymentsLimitTest extends PropSpec } ssTx = SetScriptTransaction.selfSigned(1.toByte, dApp1, Some(dApp(version, nestedInvoke)), fee, ts).explicitGet() ssTx2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(version, None)), fee, ts).explicitGet() - invokeTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp1.toAddress, None, txPayments, fee, Waves, ts).explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, txPayments, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx, ssTx2) ++ issues, invokeTx) private def assertLimit(version: StdLibVersion, count: Int, nested: Boolean) = { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala index d03c65c2531..15e458150ac 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala @@ -1,5 +1,7 @@ package com.wavesplatform.state.diffs.ci +import scala.collection.immutable + import cats.kernel.Monoid import com.google.protobuf.ByteString import com.wavesplatform.account._ @@ -9,47 +11,46 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock +import com.wavesplatform.lang.{utils, Global} import com.wavesplatform.lang.contract.DApp import com.wavesplatform.lang.contract.DApp.{CallableAnnotation, CallableFunction} -import com.wavesplatform.lang.directives.values.{DApp => DAppType, _} import com.wavesplatform.lang.directives.{DirectiveDictionary, DirectiveSet} -import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.directives.values.{DApp => DAppType, _} import com.wavesplatform.lang.script.{ContractScript, Script} +import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.v1.{compiler, ContractLimits, FunctionHeader} import com.wavesplatform.lang.v1.FunctionHeader.{Native, User} import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 +import com.wavesplatform.lang.v1.evaluator.{FunctionIds, ScriptResultV3} import com.wavesplatform.lang.v1.evaluator.FunctionIds.{CREATE_LIST, THROW} -import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{FieldNames, WavesContext} import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} -import com.wavesplatform.lang.v1.evaluator.{FunctionIds, ScriptResultV3} +import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{FieldNames, WavesContext} import com.wavesplatform.lang.v1.parser.{Expressions, Parser} import com.wavesplatform.lang.v1.traits.Environment -import com.wavesplatform.lang.v1.{ContractLimits, FunctionHeader, compiler} -import com.wavesplatform.lang.{Global, utils} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.TestSettings import com.wavesplatform.state._ +import com.wavesplatform.state.diffs.{produceRejectOrFailedDiff, ENOUGH_AMT, FeeValidation} import com.wavesplatform.state.diffs.FeeValidation.FeeConstants import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionDiff -import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, utils => _, _} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError._ import com.wavesplatform.transaction.assets._ +import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.smart.script.trace.{AssetVerifierTrace, InvokeScriptTrace} -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, _} +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils._ import org.scalacheck.{Arbitrary, Gen} import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} -import scala.collection.immutable - class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCacheSettings with EitherValues with Inside with MockFactory { import DomainPresets._ @@ -316,8 +317,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa FunctionHeader.User(funcBinding), List.fill(invocationParamsCount)(FALSE) ) - ci = InvokeScriptTransaction - .selfSigned( + ci = Signed.invokeScript( 1.toByte, invoker, master.toAddress, @@ -333,9 +333,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } else { Waves }, - ts - ) - .explicitGet() + ts) } yield (List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) } @@ -387,8 +385,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ci = InvokeScriptTransaction - .selfSigned( + ci = Signed.invokeScript( txVersion, invoker, master.toAddress, @@ -396,9 +393,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa payment.toSeq, if (sponsored) sponsoredFee else fee, if (sponsored) sponsorTx.asset else Waves, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (if (selfSend) List(genesis) else List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithVerifier( @@ -431,8 +426,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ci = InvokeScriptTransaction - .selfSigned( + ci = Signed.invokeScript( 1.toByte, invoker, master.toAddress, @@ -448,9 +442,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } else { Waves }, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (List(genesis, genesis2), setVerifier, setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithAlias( @@ -482,8 +474,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ciWithAlias = InvokeScriptTransaction - .selfSigned( + ciWithAlias = Signed.invokeScript( 1.toByte, invoker, masterAlias, @@ -499,11 +490,8 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } else { Waves }, - ts + 3 - ) - .explicitGet() - ciWithFakeAlias = InvokeScriptTransaction - .selfSigned( + ts + 3) + ciWithFakeAlias = Signed.invokeScript( 1.toByte, invoker, fakeAlias, @@ -519,9 +507,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } else { Waves }, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (List(genesis, genesis2), master, setContract, ciWithAlias, ciWithFakeAlias, aliasTx) property("invoking contract results contract's state") { @@ -543,22 +529,33 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } } - property("can't use empty keys in v2") { + property("can't more than 5kb of data") { forAll(for { + r <- preconditionsAndSetContract(s => dataContractGen(s, bigData = true)) + } yield (r._1, r._2, r._3)) { + case (genesis, setScript, ci) => + assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fsWithV5) { + _ should produceRejectOrFailedDiff("WriteSet size can't exceed") + } + } + } + + property("can't use empty keys in v2") { + /*forAll(for { r <- preconditionsAndSetContract(s => dataContractGen(s, emptyData = true), txVersion = TxVersion.V1) } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fsWithV5) { _.explicitGet() } - } + }*/ forAll(for { r <- preconditionsAndSetContract(s => dataContractGen(s, emptyData = true), txVersion = TxVersion.V2) } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fsWithV5) { - _ should produce("Empty keys aren't allowed") + _ should produceRejectOrFailedDiff("Empty keys aren't allowed") } } } @@ -672,7 +669,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa TestBlock.create(Seq(ci.copy(1.toByte, proofs = proofs))), fs ) { - _ should produce("Transactions from non-scripted accounts must have exactly 1 proof") + _ should produceRejectOrFailedDiff("Transactions from non-scripted accounts must have exactly 1 proof") } } } @@ -692,7 +689,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa TestBlock.create(Seq(ci.copy(1.toByte, proofs = proofs))), fs ) { - _ should produce("Proof doesn't validate as signature") + _ should produceRejectOrFailedDiff("Proof doesn't validate as signature") } } } @@ -722,7 +719,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._3, r._6, r._5)) { case (_, _, genesis, setScript, aliasTx, ciWithFakeAlias) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(aliasTx, setScript))), TestBlock.create(Seq(ciWithFakeAlias)), fs) { - _ should produce("does not exist") + _ should produceRejectOrFailedDiff("does not exist") } } } @@ -736,13 +733,13 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3)) { case (_, _, genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Actions count limit is exceeded") + _ should produceRejectOrFailedDiff("Actions count limit is exceeded") } } } val chainId: Byte = AddressScheme.current.chainId - val enoughFee: TxAmount = FeeValidation.ScriptExtraFee + FeeValidation.FeeConstants(IssueTransaction.typeId) * FeeValidation.FeeUnit + val enoughFee: TxAmount = FeeValidation.ScriptExtraFee + FeeValidation.FeeConstants(TransactionType.Issue) * FeeValidation.FeeUnit property("invoking contract receive payment") { forAll(for { @@ -884,7 +881,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3, asset, invoker)) { case (_, _, genesis, setScript, ci, asset, invoker) => assertDiffEiTraced(Seq(TestBlock.create(genesis ++ Seq(asset, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi.resultE should produce("TransactionNotAllowedByScript") + blockDiffEi.resultE should produceRejectOrFailedDiff("TransactionNotAllowedByScript") inside(blockDiffEi.trace) { case List(_, AssetVerifierTrace(assetId, Some(tne: TransactionNotAllowedByScript), _)) => assetId shouldBe asset.id() @@ -950,7 +947,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3, asset, master)) { case (_, _, genesis, setScript, ci, asset, _) => assertDiffEiTraced(Seq(TestBlock.create(genesis ++ Seq(asset, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi.resultE should produce("Transaction is not allowed by script") + blockDiffEi.resultE should produceRejectOrFailedDiff("Transaction is not allowed by script") } } } @@ -991,14 +988,14 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3, asset1, asset2, master)) { case (_, _, genesis, setScript, ci, asset1, asset2, _) => assertDiffEiTraced(Seq(TestBlock.create(genesis ++ Seq(asset1, asset2, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi.resultE should produce("Transaction is not allowed by script") + blockDiffEi.resultE should produceRejectOrFailedDiff("Transaction is not allowed by script") inside(blockDiffEi.trace) { case List( InvokeScriptTrace(_, dAppAddress, functionCall, Right(ScriptResultV3(_, transfers, _)), _, _), AssetVerifierTrace(allowedAssetId, None, _), AssetVerifierTrace(bannedAssetId, Some(_: FailedTransactionError), _) ) => - dAppAddress shouldBe ci.dAppAddressOrAlias + dAppAddress shouldBe ci.dApp functionCall shouldBe ci.funcCall allowedAssetId shouldBe asset1.id() @@ -1056,7 +1053,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa TestBlock.create(Seq(ci)), fs ) { blockDiffEi => - blockDiffEi.resultE should produce("TransactionValidationError") + blockDiffEi.resultE should produceRejectOrFailedDiff("TransactionValidationError") inside(blockDiffEi.trace) { case List( InvokeScriptTrace(_, _, _, Right(ScriptResultV3(_, transfers, _)), _, _), @@ -1097,7 +1094,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa .selfSigned(2.toByte, master, acc.toAddress, IssuedAsset(asset.id()), asset.quantity / 10, Waves, enoughFee, ByteStr.empty, ts) .explicitGet() assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(asset, t, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi should produce("Negative amount") + blockDiffEi should produceRejectOrFailedDiff("Negative amount") } } } @@ -1111,8 +1108,8 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa funcBinding <- validAliasStringGen fee <- ciFee(1) fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet())) - ci = InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, Some(fc), Seq(Payment(-1, Waves)), fee, Waves, ts) - } yield ci) { _ should produce("NonPositiveAmount") } + ci = InvokeScriptTransaction.create(1.toByte, invoker.publicKey, master.toAddress, Some(fc), Seq(Payment(-1, Waves)), fee, Waves, ts, Proofs.empty, AddressScheme.current.chainId) + } yield ci) { _ should produceRejectOrFailedDiff("NonPositiveAmount") } } property("smart asset payment require extra fee") { @@ -1139,7 +1136,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3, asset, master)) { case (acc, amount, genesis, setScript, ci, asset, master) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(asset, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi should produce("does not exceed minimal value") + blockDiffEi should produceRejectOrFailedDiff("does not exceed minimal value") } } } @@ -1172,7 +1169,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3, asset, invoker)) { case (_, _, genesis, setScript, ci, asset, _) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(asset, setScript))), TestBlock.create(Seq(ci)), fs) { blockDiffEi => - blockDiffEi should produce("does not exceed minimal value") + blockDiffEi should produceRejectOrFailedDiff("does not exceed minimal value") } } } @@ -1192,7 +1189,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Attempt to transfer unavailable funds") + _ should produceRejectOrFailedDiff("Attempt to transfer unavailable funds") } } } @@ -1208,7 +1205,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Attempt to transfer unavailable funds") + _ should produceRejectOrFailedDiff("Attempt to transfer unavailable funds") } } } @@ -1256,7 +1253,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Can't apply (CONST_BOOLEAN) to 'parseInt(str: String)'") + _ should produceRejectOrFailedDiff("Can't apply (CONST_BOOLEAN) to 'parseInt(str: String)'") } } } @@ -1267,7 +1264,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (r._1, r._2, r._3)) { case (genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Stored data count limit is exceeded") + _ should produceRejectOrFailedDiff("Stored data count limit is exceeded") } } } @@ -1297,7 +1294,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa else fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), settings) { - _ should produce( + _ should produceRejectOrFailedDiff( s"Data entry key size = ${ContractLimits.MaxKeySizeInBytesByVersion(version) + 1} bytes " + s"must be less than ${ContractLimits.MaxKeySizeInBytesByVersion(version)}" ) @@ -1335,7 +1332,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa if (version == V3) _ shouldBe Symbol("right") else - _ should produce("Data entry key should not be empty") + _ should produceRejectOrFailedDiff("Data entry key should not be empty") } } } @@ -1347,7 +1344,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (r._1, r._2, r._3, invocationArgsCount)) { case (genesis, setScript, ci, count) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce(s"takes 2 args but $count were(was) given") + _ should produceRejectOrFailedDiff(s"takes 2 args but $count were(was) given") } } } @@ -1404,7 +1401,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3)) { case (_, _, genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce(s"takes 1 args but 0 were(was) given") + _ should produceRejectOrFailedDiff(s"takes 1 args but 0 were(was) given") } } } @@ -1420,7 +1417,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa } yield (a, am, r._1, r._2, r._3)) { case (_, _, genesis, setScript, ci) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(ci)), fs) { - _ should produce("Cannot find callable function `default`, address = ") + _ should produceRejectOrFailedDiff("Cannot find callable function `default`, address = ") } } } @@ -1463,7 +1460,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa case (genesis, setScript, ci) => val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(Seq(genesis.head, setScript))), TestBlock.create(Seq(ci)), features) { - _ should produce("DApp self-payment is forbidden since V4") + _ should produceRejectOrFailedDiff("DApp self-payment is forbidden since V4") } } } @@ -1485,7 +1482,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa case (genesis, setScript, ci) => val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(Seq(genesis.head, setScript))), TestBlock.create(Seq(ci)), features) { - _ should produce("DApp self-transfer is forbidden since V4") + _ should produceRejectOrFailedDiff("DApp self-transfer is forbidden since V4") } } } @@ -1577,9 +1574,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (assetTx, invokeTx, master, script, funcBinding) val blockchain: Blockchain = mock[Blockchain] @@ -1633,7 +1628,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ) InvokeScriptTransactionDiff .apply(blockchain, invoke.timestamp, limitedExecution = false)(invoke) - .resultE should produce("is already issued") + .resultE should produceRejectOrFailedDiff("is already issued") } } @@ -1667,9 +1662,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, assetTx, setScriptTx)) property("Reissuing unreissued asset should produce error") { @@ -1681,7 +1674,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => - ei should produce("Asset is not reissuable") + ei should produceRejectOrFailedDiff("Asset is not reissuable") } } } @@ -1720,9 +1713,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("issued asset can be transfered") { @@ -1773,9 +1764,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("nonissued asset cann't be transfered") { @@ -1787,7 +1776,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => - ei should produce("negative asset balance") + ei should produceRejectOrFailedDiff("negative asset balance") } } } @@ -1826,9 +1815,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("duplicate issuing asset should produce diff error") { @@ -1854,7 +1841,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa case (genesis, setScript, issue, sponsorFee, invoke) => assertDiffEi(Seq(TestBlock.create(genesis ++ Seq(issue, sponsorFee, setScript))), TestBlock.create(Seq(invoke)), fsWithV5) { diff => invoke.feeAssetId shouldBe sponsorFee.asset - invoke.dAppAddressOrAlias shouldBe invoke.sender.toAddress + invoke.dApp shouldBe invoke.sender.toAddress val dv = diff.explicitGet() val senderChange = dv.portfolios(invoke.sender.toAddress).balanceOf(sponsorFee.asset) @@ -1865,8 +1852,8 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa property(s"accepts failed transactions after ${BlockchainFeatures.BlockV5} activation") { def failInvariant(funcBinding: String, sponsorTx: SponsorFeeTransaction, issueTx: IssueTransaction): Gen[(TxAmount, Asset, DApp, List[EXPR])] = { - val feeInWaves = FeeConstants(InvokeScriptTransaction.typeId) * FeeValidation.FeeUnit - val feeInAsset = Sponsorship.fromWaves(FeeConstants(InvokeScriptTransaction.typeId) * FeeValidation.FeeUnit, sponsorTx.minSponsoredAssetFee.get) + val feeInWaves = FeeConstants(TransactionType.InvokeScript) * FeeValidation.FeeUnit + val feeInAsset = Sponsorship.fromWaves(FeeConstants(TransactionType.InvokeScript) * FeeValidation.FeeUnit, sponsorTx.minSponsoredAssetFee.get) Gen.oneOf( Gen.const((feeInWaves, Waves, issueContract(funcBinding), List.empty[EXPR])), // insufficient fee Gen.const((feeInAsset, sponsorTx.asset, issueContract(funcBinding), List.empty[EXPR])), // insufficient fee @@ -1903,9 +1890,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), args) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) } yield (invokeTx, (ENOUGH_AMT - enoughFee, i1Tx.quantity), Seq(g1Tx, g2Tx, g3Tx, i1Tx, i2Tx, sTx, tTx, ssTx)) forAll(failedTxScenario) { @@ -1945,15 +1930,13 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet())) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) } yield (invokeTx, Seq(g1Tx, g2Tx, iTx, sTx, tTx, ssTx)) forAll(scenario) { case (invoke, genesisTxs) => assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce("AccountBalanceError") + ei should produceRejectOrFailedDiff("AccountBalanceError") } } } @@ -2017,9 +2000,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa txs = Seq("throw", "insufficient fee", "negative amount", "overflow amount", "self payment", "max actions", "invalid data entries", "ok") .map { arg => val fc = Terms.FUNCTION_CALL(FunctionHeader.User("sameComplexity"), List(CONST_STRING(arg).explicitGet())) - val tx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 4) - .explicitGet() + val tx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 4) (arg, tx) } } yield (Seq(gTx1, gTx2, ssTx, iTx), master.toAddress, txs) @@ -2112,9 +2093,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = iTxs.takeRight(2).map(tx => Payment(10, IssuedAsset(tx.assetId))) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2) ++ invokerScriptTx ++ iTxs ++ tTxs ++ saTxs :+ ssTx, invokeTx, master.toAddress, complexity) forAll(scenario) { @@ -2167,9 +2146,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(script), fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, alias, ssTx), invokeTx, master.toAddress, script) forAll(scenario) { @@ -2233,9 +2210,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, ssTx), invokeTx, master.toAddress) forAll(scenario) { @@ -2298,9 +2273,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, ssTx), invokeTx, master.toAddress) forAll(scenario) { @@ -2405,9 +2378,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -2520,9 +2491,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -2631,9 +2600,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -2735,9 +2702,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -2841,9 +2806,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -2940,9 +2903,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -3039,9 +3000,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { @@ -3093,14 +3052,12 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, ssTx), invokeTx) val (genesisTxs, invokeTx) = recursiveScenario.sample.get assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invokeTx), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce(s"DApp calls limit = 100 is exceeded") + ei should produceRejectOrFailedDiff(s"DApp calls limit = 100 is exceeded") } } @@ -3201,9 +3158,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx, iTx), invokeTx, master.toAddress, service.toAddress, iTx.id()) forAll(scenario) { @@ -3313,15 +3268,13 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx, iTx), invokeTx, master.toAddress, service.toAddress, iTx.id()) forAll(scenario) { case (genesisTxs, invokeTx, dApp, service, asset) => assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invokeTx), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce(s"Transaction is not allowed by script of the asset $asset") + ei should produceRejectOrFailedDiff(s"Transaction is not allowed by script of the asset $asset") } } } @@ -3428,15 +3381,13 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx, iTx), invokeTx, master.toAddress, service.toAddress, iTx.id()) forAll(scenario) { case (genesisTxs, invokeTx, dApp, service, asset) => assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invokeTx), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce(s"Transaction is not allowed by script of the asset $asset") + ei should produceRejectOrFailedDiff(s"Transaction is not allowed by script of the asset $asset") } } } @@ -3535,15 +3486,13 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(20, IssuedAsset(iTx.id()))) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx, iTx), invokeTx, master.toAddress, service.toAddress, iTx.id()) forAll(scenario) { case (genesisTxs, invokeTx, dApp, service, asset) => assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invokeTx), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce( + ei should produceRejectOrFailedDiff( s"Attempt to transfer unavailable funds: " + s"Transaction application leads to negative asset '$asset' balance to (at least) temporary negative state, current balance is 0" ) @@ -3579,7 +3528,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa | let paymentAsset = this.issuer.getBinaryValue("paymentAsset") | let startWavesBalance = this.issuer.getIntegerValue("startWavesBalance") | let startInvokerBalance = this.issuer.getIntegerValue("startInvokerBalance") - | let resultInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress.stringRepr}')).regular + | let resultInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress}')).regular | let issuerBalance = wavesBalance(this.issuer) | | assetBalance(this.issuer, this.id) == $ENOUGH_AMT && @@ -3600,7 +3549,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa | | @Callable(i) | func bar(startInvokerBalance: Int, startWavesBalance: Int, startPaymentAssetBalance: Int, paymentAsset: ByteVector) = { - | let resultInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress.stringRepr}')).regular + | let resultInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress}')).regular | let paymentAssetBalance = assetBalance(i.caller, paymentAsset) | | if ( @@ -3629,7 +3578,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa | | @Callable(i) | func foo() = { - | strict startInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress.stringRepr}')).regular + | strict startInvokerBalance = wavesBalance(Address(base58'${invoker.toAddress}')).regular | strict startWavesBalance = wavesBalance(this).regular | strict startPaymentAssetBalance = assetBalance(this, base58'$paymentAsset') | @@ -3686,9 +3635,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa setServiceDApp = SetScriptTransaction.selfSigned(1.toByte, serviceDAppAcc, serviceDAppScript.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(paymentFromInvokerAmount, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, clientDAppAcc.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, clientDAppAcc.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield ( Seq(gTx1, gTx2, gTx3, setServiceDApp, setClientDApp, paymentIssue, transferIssue), invokeTx, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala index 0287777f717..b6a84c9dd96 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala @@ -1,5 +1,7 @@ package com.wavesplatform.state.diffs.ci +import scala.collection.immutable + import cats.kernel.Monoid import com.wavesplatform.account._ import com.wavesplatform.block.Block @@ -8,39 +10,38 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithState} import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock +import com.wavesplatform.lang.{utils, Global} import com.wavesplatform.lang.contract.DApp import com.wavesplatform.lang.contract.DApp.{CallableAnnotation, CallableFunction} import com.wavesplatform.lang.directives.DirectiveSet import com.wavesplatform.lang.directives.values.{DApp => DAppType, _} -import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.script.{ContractScript, Script} +import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.v1.{compiler, FunctionHeader} import com.wavesplatform.lang.v1.FunctionHeader.{Native, User} import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.evaluator.FunctionIds import com.wavesplatform.lang.v1.evaluator.FunctionIds.{CREATE_LIST, THROW} -import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{FieldNames, WavesContext} import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} +import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{FieldNames, WavesContext} import com.wavesplatform.lang.v1.parser.{Expressions, Parser} import com.wavesplatform.lang.v1.traits.Environment -import com.wavesplatform.lang.v1.{FunctionHeader, compiler} -import com.wavesplatform.lang.{Global, utils} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state._ -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.state.diffs.{produceRejectOrFailedDiff, ENOUGH_AMT} +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, utils => _, _} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets._ -import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{Asset, _} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalamock.scalatest.MockFactory import org.scalatest.EitherValues -import scala.collection.immutable - class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSettings with MockFactory with EitherValues { private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( @@ -315,26 +316,24 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti FunctionHeader.User(funcBinding), List.fill(invocationParamsCount)(FALSE) ) - ci = InvokeScriptTransaction - .selfSigned( - 1.toByte, - invoker, - master.toAddress, - Some(fc), - payment.toSeq, - if (sponsored) { - sponsorTx.minSponsoredAssetFee.get * 5 - } else { - fee - }, - if (sponsored) { - IssuedAsset(issueTx.id()) - } else { - Waves - }, - ts - ) - .explicitGet() + ci = Signed.invokeScript( + 1.toByte, + invoker, + master.toAddress, + Some(fc), + payment.toSeq, + if (sponsored) { + sponsorTx.minSponsoredAssetFee.get * 5 + } else { + fee + }, + if (sponsored) { + IssuedAsset(issueTx.id()) + } else { + Waves + }, + ts + ) } yield (List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) } @@ -386,8 +385,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ci = InvokeScriptTransaction - .selfSigned( + ci = Signed.invokeScript( txVersion, invoker, master.toAddress, @@ -395,9 +393,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti payment.toSeq, if (sponsored) sponsoredFee else fee, if (sponsored) sponsorTx.asset else Waves, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (if (selfSend) List(genesis) else List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithVerifier( @@ -430,8 +426,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ci = InvokeScriptTransaction - .selfSigned( + ci = Signed.invokeScript( 1.toByte, invoker, master.toAddress, @@ -447,9 +442,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti } else { Waves }, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (List(genesis, genesis2), setVerifier, setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithAlias( @@ -481,8 +474,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti Some(Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet()))) else None - ciWithAlias = InvokeScriptTransaction - .selfSigned( + ciWithAlias = Signed.invokeScript( 1.toByte, invoker, masterAlias, @@ -498,11 +490,8 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti } else { Waves }, - ts + 3 - ) - .explicitGet() - ciWithFakeAlias = InvokeScriptTransaction - .selfSigned( + ts + 3) + ciWithFakeAlias = Signed.invokeScript( 1.toByte, invoker, fakeAlias, @@ -518,9 +507,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti } else { Waves }, - ts + 3 - ) - .explicitGet() + ts + 3) } yield (List(genesis, genesis2), master, setContract, ciWithAlias, ciWithFakeAlias, aliasTx) property("Allow not more 30 non-data actions") { @@ -615,15 +602,13 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { case (genesisTxs, invokeTx, dApp, service) => assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invokeTx), Block.ProtoBlockVersion), fsWithV5) { ei => - ei should produce("Actions count limit is exceeded") + ei should produceRejectOrFailedDiff("Actions count limit is exceeded") } } } @@ -716,9 +701,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti ssTx1 = SetScriptTransaction.selfSigned(1.toByte, service, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) - .explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2, gTx3, aliasTx, ssTx1, ssTx), invokeTx, master.toAddress, service.toAddress) forAll(scenario) { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala index d6c90539866..a3316bb9ed7 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala @@ -1,8 +1,9 @@ package com.wavesplatform.state.diffs.ci +import scala.util.Random + import cats.instances.list._ import cats.syntax.traverse._ -import com.wavesplatform.TestTime import com.wavesplatform.account.{Address, Alias} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 @@ -15,18 +16,17 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.lang.v1.traits.domain.{Lease, Recipient} import com.wavesplatform.settings.{FunctionalitySettings, TestFunctionalitySettings} -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} import com.wavesplatform.state.{LeaseBalance, Portfolio} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Authorized, GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{Authorized, GenesisTransaction, Transaction} +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalatest.exceptions.TestFailedException -import scala.util.Random - class LeaseActionDiffTest extends PropSpec with WithDomain { private val time = new TestTime private def ts = time.getTimestamp() @@ -201,7 +201,7 @@ class LeaseActionDiffTest extends PropSpec with WithDomain { for { genesis <- GenesisTransaction.create(dAppAcc.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) - invoke <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts) + invoke = Signed.invokeScript(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts) leasesFromDApp <- (1 to leaseCancelCount).toList.traverse( i => LeaseTransaction.selfSigned(2.toByte, dAppAcc, invoker.toAddress, leaseTxAmount1, fee, ts + i) ) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ListParamInvokeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ListParamInvokeTest.scala index 1ddec8b90a3..8c89918bd1a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ListParamInvokeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ListParamInvokeTest.scala @@ -15,11 +15,12 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.lang.v1.evaluator.FunctionIds import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalatest.Inside @@ -33,16 +34,26 @@ class ListParamInvokeTest extends PropSpec with WithState with Inside { List( CallableFunction( CallableAnnotation("i"), - FUNC("f", List("args"), + FUNC( + "f", + List("args"), FUNCTION_CALL( Native(FunctionIds.CREATE_LIST), List( - FUNCTION_CALL(User("DataEntry"), List(CONST_STRING("entry1").explicitGet(), FUNCTION_CALL(Native(FunctionIds.GET_LIST), List(REF("args"), CONST_LONG(0))))), + FUNCTION_CALL( + User("DataEntry"), + List(CONST_STRING("entry1").explicitGet(), FUNCTION_CALL(Native(FunctionIds.GET_LIST), List(REF("args"), CONST_LONG(0)))) + ), FUNCTION_CALL( Native(FunctionIds.CREATE_LIST), List( - FUNCTION_CALL(User("DataEntry"), List(CONST_STRING("entry2").explicitGet(), FUNCTION_CALL(Native(FunctionIds.GET_LIST), List(REF("args"), CONST_LONG(1))))), - REF("nil"))) + FUNCTION_CALL( + User("DataEntry"), + List(CONST_STRING("entry2").explicitGet(), FUNCTION_CALL(Native(FunctionIds.GET_LIST), List(REF("args"), CONST_LONG(1)))) + ), + REF("nil") + ) + ) ) ) ) @@ -80,17 +91,22 @@ class ListParamInvokeTest extends PropSpec with WithState with Inside { Some( FUNCTION_CALL( User("f"), - List(ARR(IndexedSeq( - CONST_STRING("value1").explicitGet(), - CONST_STRING("value2").explicitGet() - ), false).explicitGet()) + List( + ARR( + IndexedSeq( + CONST_STRING("value1").explicitGet(), + CONST_STRING("value2").explicitGet() + ), + false + ).explicitGet() + ) ) ) for { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, Some(dApp), fee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, functionCall, Nil, fee, Waves, ts + 3) + ci = Signed.invokeScript(1.toByte, invoker, master.toAddress, functionCall, Nil, fee, Waves, ts + 3) } yield (List(genesis, genesis2), setDApp, ci, master.toAddress) }.explicitGet() @@ -130,7 +146,7 @@ class ListParamInvokeTest extends PropSpec with WithState with Inside { val parameters = Seq( BlockchainFeatures.SmartAccounts, BlockchainFeatures.SmartAssets, - BlockchainFeatures.Ride4DApps, + BlockchainFeatures.Ride4DApps ) ++ v4ForkO TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = parameters.map(_.id -> 0).toMap) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala index 8c406e95739..28ab3117811 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala @@ -14,11 +14,12 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.settings.{Constants, TestFunctionalitySettings} import com.wavesplatform.state.Diff import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen class MultiPaymentInvokeDiffTest extends PropSpec with WithState { @@ -138,7 +139,7 @@ class MultiPaymentInvokeDiffTest extends PropSpec with WithState { features ) { val expectedFee = (0.005 + 0.004 + 0.004 * (ContractLimits.MaxAttachedPaymentAmount - 1)) * Constants.UnitsInWave - _ should produce( + _ should produceRejectOrFailedDiff( s"Fee in WAVES for InvokeScriptTransaction (${ci.fee} in WAVES) " + s"with ${ContractLimits.MaxAttachedPaymentAmount} total scripts invoked " + s"does not exceed minimal value of ${expectedFee.toLong} WAVES" @@ -233,7 +234,7 @@ class MultiPaymentInvokeDiffTest extends PropSpec with WithState { val payments = issues.map(i => Payment(1, IssuedAsset(i.id()))) (issues, payments) } - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, payments, fee, Waves, ts + 3) + ci = Signed.invokeScript(1.toByte, invoker, master.toAddress, None, payments, fee, Waves, ts + 3) } yield (List(genesis, genesis2), setVerifier, setDApp, ci, issues, master, invoker, fee) }.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/OverdraftTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/OverdraftTest.scala index 3a8bac4952d..39ea7e30ad9 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/OverdraftTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/OverdraftTest.scala @@ -11,22 +11,23 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.ContractLimits import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.settings.FunctionalitySettings +import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation} import com.wavesplatform.state.diffs.FeeValidation.FeeConstants -import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TransactionType} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen class OverdraftTest extends PropSpec with WithDomain { import DomainPresets._ - private val InvokeFee = FeeConstants(InvokeScriptTransaction.typeId) * FeeValidation.FeeUnit - private val SetScriptFee = FeeConstants(SetScriptTransaction.typeId) * FeeValidation.FeeUnit - private val IssueFee = FeeConstants(IssueTransaction.typeId) * FeeValidation.FeeUnit + private val InvokeFee = FeeConstants(TransactionType.InvokeScript) * FeeValidation.FeeUnit + private val SetScriptFee = FeeConstants(TransactionType.SetScript) * FeeValidation.FeeUnit + private val IssueFee = FeeConstants(TransactionType.Issue) * FeeValidation.FeeUnit private val dAppVersions: List[StdLibVersion] = DirectiveDictionary[StdLibVersion].all @@ -140,7 +141,7 @@ class OverdraftTest extends PropSpec with WithDomain { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, invokerBalance, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, Some(dApp), SetScriptFee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, payment, fee, Waves, ts + 3) + ci = Signed.invokeScript(1.toByte, invoker, master.toAddress, None, payment, fee, Waves, ts + 3) } yield (List(genesis, genesis2), setDApp, ci, issue) }.explicitGet() @@ -159,7 +160,7 @@ class OverdraftTest extends PropSpec with WithDomain { genesis <- GenesisTransaction.create(master.toAddress, ENOUGH_AMT, ts) genesis2 <- GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts) setDApp <- SetScriptTransaction.selfSigned(1.toByte, master, Some(payingAssetDApp(version, issue.assetId)), SetScriptFee, ts + 2) - ci <- InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, payments, InvokeFee, Waves, ts + 3) + ci = Signed.invokeScript(1.toByte, invoker, master.toAddress, None, payments, InvokeFee, Waves, ts + 3) } yield (List(genesis, genesis2), setDApp, ci, issue) }.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala index 9aa2884dd9a..fec55bd37ed 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala @@ -9,12 +9,12 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{CreateAliasTransaction, GenesisTransaction, Transaction} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{CreateAliasTransaction, GenesisTransaction, Transaction} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen class ScriptTransferByAliasTest extends PropSpec with WithDomain { @@ -89,7 +89,7 @@ class ScriptTransferByAliasTest extends PropSpec with WithDomain { issue <- IssueTransaction.selfSigned(2.toByte, dAppAcc, "Asset", "Description", ENOUGH_AMT, 8, true, Some(verifier), fee, ts) asset = IssuedAsset(issue.id()) setDApp <- SetScriptTransaction.selfSigned(1.toByte, dAppAcc, Some(dApp(asset)), fee, ts) - invoke = () => InvokeScriptTransaction.selfSigned(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invoke = () => Signed.invokeScript(1.toByte, invoker, dAppAcc.toAddress, None, Nil, fee, Waves, ts) } yield (List(genesis, genesis2, genesis3, createAlias, issue, setDApp), invoke, asset, receiver.toAddress) }.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/package.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/package.scala index 0b2f577a7cf..0aa2fe47989 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/package.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/package.scala @@ -10,22 +10,21 @@ import com.wavesplatform.lang.v1.compiler.Terms.{BLOCK, FUNCTION_CALL, LET} import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.FeeValidation._ import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.TxVersion -import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.{TransactionType, TxVersion} +import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, SetScriptTransaction} import org.scalacheck.Gen package object ci { private def invokeFee(freeCall: Boolean) = if (freeCall) - FeeUnit * FeeConstants(InvokeExpressionTransaction.typeId) + FeeUnit * FeeConstants(TransactionType.InvokeExpression) else - FeeUnit * FeeConstants(InvokeScriptTransaction.typeId) + FeeUnit * FeeConstants(TransactionType.InvokeScript) def ciFee(sc: Int = 0, nonNftIssue: Int = 0, freeCall: Boolean = false): Gen[Long] = Gen.choose( - invokeFee(freeCall) + sc * ScriptExtraFee + nonNftIssue * FeeConstants(IssueTransaction.typeId) * FeeUnit, - invokeFee(freeCall) + (sc + 1) * ScriptExtraFee - 1 + nonNftIssue * FeeConstants(IssueTransaction.typeId) * FeeUnit + invokeFee(freeCall) + sc * ScriptExtraFee + nonNftIssue * FeeConstants(TransactionType.Issue) * FeeUnit, + invokeFee(freeCall) + (sc + 1) * ScriptExtraFee - 1 + nonNftIssue * FeeConstants(TransactionType.Issue) * FeeUnit ) def simpleContract(funcName: String): Either[String, DApp] = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala index eaa2b814d2e..8d1c2c1cb60 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala @@ -13,16 +13,17 @@ import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.{Terms, TestCompiler} import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.settings.TestFunctionalitySettings +import com.wavesplatform.state.{IntegerDataEntry, StringDataEntry} import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.state.{IntegerDataEntry, StringDataEntry} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.utils.Signed import org.scalatest.EitherValues class InvokeScriptTransactionCrosscontractInvokeDiffTest @@ -117,8 +118,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned( + invokeTx = Signed.invokeScript( TxVersion.V3, invoker, mainAcc.toAddress, @@ -126,9 +126,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest payments, fee, Waves, - ts + 10 - ) - .explicitGet() + ts + 10) } yield (Seq(gTx1, gTx2, gTx3, ssTxMain, ssTxSecond, dataTxSecond, dataTxSecond2), invokeTx, secondAcc.toAddress) forAll(scenario) { @@ -205,8 +203,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned( + invokeTx = Signed.invokeScript( TxVersion.V3, invoker, mainAcc.toAddress, @@ -214,9 +211,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest payments, fee, Waves, - ts + 10 - ) - .explicitGet() + ts + 10) } yield (Seq(gTx1, gTx2, ssTxMain, dataTxMain, dataTxMain2), invokeTx, mainAcc.toAddress) forAll(scenario) { @@ -383,8 +378,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(10L, Waves)) - invokeTx = InvokeScriptTransaction - .selfSigned( + invokeTx = Signed.invokeScript( TxVersion.V3, invoker, mainAcc.toAddress, @@ -392,9 +386,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest payments, fee * 100, Waves, - ts + 10 - ) - .explicitGet() + ts + 10) } yield ( Seq(gTx1, gTx2, gTx3, gTx4, ssTxMain, ssTxSecond, ssTxThird, paymentIssue, transferIssue), invokeTx, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala index 37e72f9322e..5e0736adb4f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala @@ -1,5 +1,6 @@ package com.wavesplatform.state.diffs.ci.sync +import com.wavesplatform.TransactionGenBase import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -12,9 +13,9 @@ import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import com.wavesplatform.{TestTime, TransactionGenBase} class SyncDAppBalanceCheckTest extends PropSpec with WithDomain with TransactionGenBase { @@ -54,7 +55,7 @@ class SyncDAppBalanceCheckTest extends PropSpec with WithDomain with Transaction gTx3 = GenesisTransaction.create(dApp2.toAddress, ENOUGH_AMT, ts).explicitGet() ssTx1 = SetScriptTransaction.selfSigned(1.toByte, dApp1, Some(dApp1Script(dApp2.toAddress)), fee, ts).explicitGet() ssTx2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp2Script), fee, ts).explicitGet() - invokeTx = () => InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invokeTx = () => Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx2), invokeTx) property("temporary negative balance of sync call produce error only after set height") { @@ -74,7 +75,7 @@ class SyncDAppBalanceCheckTest extends PropSpec with WithDomain with Transaction val invoke2 = invoke() d.appendBlock() (the[RuntimeException] thrownBy d.appendBlock(invoke2)).getMessage should include( - s"Sync call leads to temporary negative balance = -100 for address ${invoke2.dAppAddressOrAlias}" + s"Sync call leads to temporary negative balance = -100 for address ${invoke2.dApp}" ) } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppComplexityCountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppComplexityCountTest.scala index 4bb8b900fe4..7087857ba95 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppComplexityCountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppComplexityCountTest.scala @@ -17,14 +17,15 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.state.Portfolio import com.wavesplatform.state.diffs.BlockDiffer.CurrentBlockFeePart import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.state.diffs.{ENOUGH_AMT, ci, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.state.diffs.{ENOUGH_AMT, ci} +import com.wavesplatform.test.{PropSpec, _} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, InvokeTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.{InvokeTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} import org.scalacheck.Gen @@ -161,8 +162,8 @@ class SyncDAppComplexityCountTest extends PropSpec with WithDomain { else Nil - invokeScriptTx = InvokeScriptTransaction - .selfSigned( + invokeScriptTx = Signed + .invokeScript( TxVersion.V3, invoker, dAppAccs.last.toAddress, @@ -172,7 +173,6 @@ class SyncDAppComplexityCountTest extends PropSpec with WithDomain { Waves, ts + 10 ) - .explicitGet() invokeExpressionTx = ci.toInvokeExpression(setScriptTxs.head, invoker, Some(fee)) } yield @@ -216,17 +216,17 @@ class SyncDAppComplexityCountTest extends PropSpec with WithDomain { else diff.errorMessage(invokeTx.id()) shouldBe None - val dAppAddress = invokeTx.dAppAddressOrAlias.asInstanceOf[Address] + val dAppAddress = invokeTx.dApp.asInstanceOf[Address] val basePortfolios = Map( TestBlock.defaultSigner.toAddress -> Portfolio(CurrentBlockFeePart(invokeTx.fee)), - invokeTx.senderAddress -> Portfolio(-invokeTx.fee) + invokeTx.sender.toAddress -> Portfolio(-invokeTx.fee) ) val paymentsPortfolios = Map( - invokeTx.senderAddress -> Portfolio(assets = Map(asset -> -1)), + invokeTx.sender.toAddress -> Portfolio(assets = Map(asset -> -1)), dAppAddress -> Portfolio(assets = Map(asset -> 1)) ) val throughTransfersPortfolios = Map( - invokeTx.senderAddress -> Portfolio(assets = Map(asset -> 1)), + invokeTx.sender.toAddress -> Portfolio(assets = Map(asset -> 1)), lastCallingDApp -> Portfolio(assets = Map(asset -> -1)) ) val throughPaymentsPortfolios = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppForbidOldVersionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppForbidOldVersionsTest.scala index fecba99e89d..d931541007d 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppForbidOldVersionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppForbidOldVersionsTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci.sync -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.{DBCacheSettings, WithDomain, WithState} @@ -10,9 +9,10 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.{ENOUGH_AMT, ci} import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ -import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -68,7 +68,7 @@ class SyncDAppForbidOldVersionsTest gTx3 = GenesisTransaction.create(proxyDApp.toAddress, ENOUGH_AMT, ts).explicitGet() ssTx = SetScriptTransaction.selfSigned(1.toByte, callingDApp, Some(callingDAppScript(version)), fee, ts).explicitGet() ssTx2 = SetScriptTransaction.selfSigned(1.toByte, proxyDApp, Some(proxyDAppScript(callingDApp.toAddress)), fee, ts).explicitGet() - invokeScriptTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, proxyDApp.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invokeScriptTx = Signed.invokeScript(TxVersion.V3, invoker, proxyDApp.toAddress, None, Nil, fee, Waves, ts) invokeExpressionTx = ci.toInvokeExpression(ssTx2, invoker) invokeTx = if (invokeExpression) invokeExpressionTx else invokeScriptTx } yield (Seq(gTx1, gTx2, gTx3, ssTx, ssTx2), invokeTx, proxyDApp.toAddress, callingDApp.toAddress) @@ -79,7 +79,7 @@ class SyncDAppForbidOldVersionsTest invokeExpression <- Seq(false, true) } { val (preparingTxs, invoke, proxyDApp, callingDApp) = scenario(callingDAppVersion, invokeExpression).sample.get - val (settings, source, target) = if (invokeExpression) (RideV6, invoke.senderAddress, callingDApp) else (RideV5, proxyDApp, callingDApp) + val (settings, source, target) = if (invokeExpression) (RideV6, invoke.sender.toAddress, callingDApp) else (RideV5, proxyDApp, callingDApp) withDomain(settings) { d => d.appendBlock(preparingTxs: _*) (the[RuntimeException] thrownBy d.appendBlock(invoke)).getMessage should include( diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppMultiVersionTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppMultiVersionTest.scala index 2bafe814521..bcba2410911 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppMultiVersionTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppMultiVersionTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci.sync -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -10,9 +9,10 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ -import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed class SyncDAppMultiVersionTest extends PropSpec with WithDomain { import DomainPresets._ @@ -50,7 +50,7 @@ class SyncDAppMultiVersionTest extends PropSpec with WithDomain { gTx3 = GenesisTransaction.create(dApp2.toAddress, ENOUGH_AMT, ts).explicitGet() ssTx1 = SetScriptTransaction.selfSigned(1.toByte, dApp1, Some(dApp1Script(version1, dApp2.toAddress)), fee, ts).explicitGet() ssTx2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp2Script(version2)), fee, ts).explicitGet() - invokeTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx2), invokeTx) property("sync call can be performed between V5 and V6 dApps") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppRecursionTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppRecursionTest.scala index 8987d2fd8c0..e0cca9786dd 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppRecursionTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppRecursionTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.ci.sync -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -11,12 +10,13 @@ import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.FunctionHeader.User import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BOOLEAN, FUNCTION_CALL} import com.wavesplatform.lang.v1.compiler.TestCompiler +import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.smart._ +import com.wavesplatform.transaction.utils.Signed class SyncDAppRecursionTest extends PropSpec with WithDomain { import DomainPresets._ @@ -98,9 +98,8 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { .selfSigned(1.toByte, dApp1, dApp(dApp2.toAddress, invokeExpression = invokeExpression).asInstanceOf[ExprScript], fee, Waves, ts) .explicitGet() else - InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp1.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + Signed + .invokeScript(1.toByte, dApp1, dApp1.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, setDApp1, setDApp2), invoke) Seq(true, false).foreach { invokeExpression => @@ -136,9 +135,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { .selfSigned(1.toByte, dApp1, dApp(dApp2.toAddress, invokeExpression = invokeExpression).asInstanceOf[ExprScript], fee, Waves, ts) .explicitGet() else - InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, setDApp1, setDApp2, setDApp3), invoke) Seq(true, false).foreach { invokeExpression => @@ -150,7 +147,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { )( _ should produce( s"The invocation stack contains multiple invocations " + - s"of the dApp at address ${invoke.senderAddress} with " + + s"of the dApp at address ${invoke.sender.toAddress} with " + s"invocations of another dApp between them" ) ) @@ -174,9 +171,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp1 = SetScriptTransaction.selfSigned(1.toByte, dApp1, Some(dApp(dApp1.toAddress)), fee, ts).explicitGet() setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(dApp3.toAddress)), fee, ts).explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp2.toAddress, reentrant = reentrant)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, setDApp1, setDApp2, setDApp3), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -186,7 +181,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { features )( _ should produce( - s"The invocation stack contains multiple invocations of the dApp at address ${invoke.dAppAddressOrAlias} with invocations of another dApp between them" + s"The invocation stack contains multiple invocations of the dApp at address ${invoke.dApp} with invocations of another dApp between them" ) ) } @@ -218,9 +213,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp3 = SetScriptTransaction .selfSigned(1.toByte, dApp3, Some(dApp(dApp2.toAddress, reentrant = true, sendEnd = true)), fee, ts) .explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, setDApp1, setDApp2, setDApp3), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -230,7 +223,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { features )( _ should produce( - s"The invocation stack contains multiple invocations of the dApp at address ${invoke.dAppAddressOrAlias} with invocations of another dApp between them" + s"The invocation stack contains multiple invocations of the dApp at address ${invoke.dApp} with invocations of another dApp between them" ) ) } @@ -252,9 +245,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(dApp3.toAddress)), fee, ts).explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp4.toAddress)), fee, ts).explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp3.toAddress)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, setDApp1, setDApp2, setDApp3, setDApp4), setDApp3, invoke) val (preparingTxs, setDApp3, invoke) = preconditions.sample.get @@ -286,9 +277,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(dApp3.toAddress)), fee, ts).explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp4.toAddress, reentrant = true)), fee, ts).explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp3.toAddress, sendEnd = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, setDApp1, setDApp2, setDApp3, setDApp4), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -320,9 +309,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(dApp3.toAddress, reentrant = true)), fee, ts).explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp4.toAddress)), fee, ts).explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp2.toAddress, sendEnd = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, setDApp1, setDApp2, setDApp3, setDApp4), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -359,9 +346,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { ) .explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp2.toAddress, sendChangeDApp = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, setDApp1, setDApp2, setDApp3), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -393,9 +378,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(dApp(dApp3.toAddress, reentrant = true)), fee, ts).explicitGet() setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp4.toAddress)), fee, ts).explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp3.toAddress, sendEnd = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, setDApp1, setDApp2, setDApp3, setDApp4), invoke, dApp3.toAddress) forAll(preconditions) { @@ -434,9 +417,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { setDApp3 = SetScriptTransaction.selfSigned(1.toByte, dApp3, Some(dApp(dApp4.toAddress)), fee, ts).explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp2.toAddress, sendChangeDApp = true)), fee, ts).explicitGet() setDApp5 = SetScriptTransaction.selfSigned(1.toByte, dApp5, Some(dApp(dApp2.toAddress, sendEnd = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, genesis5, setDApp1, setDApp2, setDApp3, setDApp4, setDApp5), invoke) val (preparingTxs, invoke) = preconditions.sample.get @@ -475,9 +456,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { .selfSigned(1.toByte, dApp4, Some(dApp(dApp2.toAddress, sendChangeDApp = true, sendForceInvoke = true)), fee, ts) .explicitGet() setDApp5 = SetScriptTransaction.selfSigned(1.toByte, dApp5, Some(dApp(dApp2.toAddress, sendEnd = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, genesis5, setDApp1, setDApp2, setDApp3, setDApp4, setDApp5), invoke, dApp2.toAddress) val (preparingTxs, invoke, errorAddress) = preconditions.sample.get @@ -517,9 +496,7 @@ class SyncDAppRecursionTest extends PropSpec with WithDomain { .explicitGet() setDApp4 = SetScriptTransaction.selfSigned(1.toByte, dApp4, Some(dApp(dApp2.toAddress)), fee, ts).explicitGet() setDApp5 = SetScriptTransaction.selfSigned(1.toByte, dApp5, Some(dApp(dApp3.toAddress, sendChangeDApp = true)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction - .selfSigned(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) - .explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp2.toAddress, fc, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, genesis3, genesis4, genesis5, setDApp1, setDApp2, setDApp3, setDApp4, setDApp5), invoke) val (preparingTxs, invoke) = preconditions.sample.get diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala index 0c96db0bec5..809edc8eadf 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala @@ -1,5 +1,6 @@ package com.wavesplatform.state.diffs.freecall +import com.wavesplatform.TransactionGen import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -12,12 +13,11 @@ import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, NewAssetInfo} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test.{PropSpec, TestTime} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, SetScriptTransaction} import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} -import com.wavesplatform.{TestTime, TransactionGen} import org.scalatest.{Assertion, EitherValues} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -153,7 +153,7 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T } private def feeErrorMessage(invoke: InvokeExpressionTransaction, issue: Boolean = false, verifier: Boolean = false) = { - val expectingFee = FeeConstants(invoke.typeId) * FeeUnit + (if (issue) 1 else 0) * MinIssueFee + (if (verifier) 1 else 0) * ScriptExtraFee + val expectingFee = FeeConstants(invoke.tpe) * FeeUnit + (if (issue) 1 else 0) * MinIssueFee + (if (verifier) 1 else 0) * ScriptExtraFee val issueErr = if (issue) " with 1 assets issued" else "" val verifierErr = if (verifier) " with 1 total scripts invoked" else "" s"Fee in WAVES for InvokeExpressionTransaction (${invoke.fee} in WAVES)$issueErr$verifierErr does not exceed minimal value of $expectingFee WAVES." @@ -177,8 +177,8 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T withDomain(RideV6) { d => d.appendBlock(genesisTxs: _*) d.appendBlock(invoke) - d.blockchain.accountData(invoke.senderAddress, "check").get shouldBe BooleanDataEntry("check", true) - d.blockchain.accountData(invoke.senderAddress, "transactionId").get shouldBe BinaryDataEntry("transactionId", invoke.txId) + d.blockchain.accountData(invoke.sender.toAddress, "check").get shouldBe BooleanDataEntry("check", true) + d.blockchain.accountData(invoke.sender.toAddress, "transactionId").get shouldBe BinaryDataEntry("transactionId", invoke.txId) d.liquidDiff.issuedAssets.size shouldBe 1 checkAsset(invoke, d.liquidDiff.issuedAssets.head._2) } @@ -283,7 +283,7 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T } } - property("available versions") { + ignore("available versions") { // TODO check is commented in CommonValidation val unsupportedVersion = InvokeExpressionTransaction.supportedVersions.max + 1 val (genesisTxs, invoke) = scenario(version = unsupportedVersion.toByte) withDomain(RideV6) { d => diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/package.scala b/node/src/test/scala/com/wavesplatform/state/diffs/package.scala index 6e090d3a2a2..2b4c14025d4 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/package.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/package.scala @@ -3,5 +3,5 @@ package com.wavesplatform.state package object diffs { val ENOUGH_AMT: Long = Long.MaxValue / 3 - def produce(errorMessage: String, requireFailed: Boolean = false): DiffProduceError = new DiffProduceError(errorMessage, requireFailed) + def produceRejectOrFailedDiff(errorMessage: String, requireFailed: Boolean = false): DiffProduceError = new DiffProduceError(errorMessage, requireFailed) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala index 47f106c2eac..f3dccd2ff7d 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala @@ -11,15 +11,15 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} @@ -112,7 +112,7 @@ class DiffComplexityCountTest setDApp <- SetScriptTransaction.selfSigned(1.toByte, account1, Some(dApp(asset)), fee, ts) payments = Seq(Payment(1, asset), Payment(1, asset)) invokeFromScripted = () => - InvokeScriptTransaction.selfSigned(1.toByte, account2, account1.toAddress, None, payments, fee, Waves, ts).explicitGet() + Signed.invokeScript(1.toByte, account2, account1.toAddress, None, payments, fee, Waves, ts) } yield (List(genesis, genesis2, issue, transfer1, setVerifier, setDApp), invokeFromScripted) }.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala index 51fecf93b68..60dd4af1639 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala @@ -6,17 +6,17 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.history.Domain import com.wavesplatform.lang.directives.values.V4 import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.settings.{Constants, TestFunctionalitySettings} +import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.EmptyDataEntry import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} import com.wavesplatform.state.diffs.ci.ciFee +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, Transaction, TransactionType, TxWithFee} import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, Transaction, TxWithFee} -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.utils.Signed class SmartAccountFeeTest extends PropSpec with WithDomain { @@ -82,8 +82,8 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { accountWithPaidVerifier <- accountGen accountWithSmallVerifier <- accountGen accountWithEmptyVerifier <- accountGen - transferFee = FeeUnit * FeeConstants(TransferTransaction.typeId) - setScriptFee = FeeUnit * FeeConstants(SetScriptTransaction.typeId) + transferFee = FeeUnit * FeeConstants(TransactionType.Transfer) + setScriptFee = FeeUnit * FeeConstants(TransactionType.SetScript) invokeFee <- ciFee() } yield { for { @@ -94,8 +94,7 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { setScript2 <- SetScriptTransaction.selfSigned(1.toByte, accountWithSmallVerifier, Some(scriptWithSmallVerifier), setScriptFee, ts) setScript3 <- SetScriptTransaction.selfSigned(1.toByte, accountWithEmptyVerifier, Some(scriptWithEmptyVerifier), setScriptFee, ts) invokeFromPaidVerifier = () => - InvokeScriptTransaction - .selfSigned( + Signed.invokeScript( 1.toByte, accountWithPaidVerifier, accountWithSmallVerifier.toAddress, @@ -105,10 +104,8 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { Waves, ts ) - .explicitGet() invokeFromSmallVerifier = () => - InvokeScriptTransaction - .selfSigned( + Signed.invokeScript( 1.toByte, accountWithSmallVerifier, accountWithPaidVerifier.toAddress, @@ -118,10 +115,8 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { Waves, ts ) - .explicitGet() invokeFromEmptyVerifier = () => - InvokeScriptTransaction - .selfSigned( + Signed.invokeScript( 1.toByte, accountWithEmptyVerifier, accountWithPaidVerifier.toAddress, @@ -131,7 +126,6 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { Waves, ts ) - .explicitGet() transferFromSmallVerifier = () => TransferTransaction .selfSigned( @@ -223,8 +217,8 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { e.getMessage should startWith "TransactionValidationError(cause = GenericError(Transaction sent from smart account. " + s"Requires $ScriptExtraFee extra fee.. " + - s"Fee for ${Constants.TransactionNames(tx.typeId)} (${tx.fee} in WAVES) " + - s"does not exceed minimal value of ${FeeConstants(tx.typeId) * FeeUnit + ScriptExtraFee} WAVES.)" + s"Fee for ${tx.tpe.transactionName} (${tx.fee} in WAVES) " + + s"does not exceed minimal value of ${FeeConstants(tx.tpe) * FeeUnit + ScriptExtraFee} WAVES.)" } private def assertNoError(tx: Transaction, d: Domain) = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAssetEvalTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAssetEvalTest.scala index c7ef616c301..7a2b9d31a3f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAssetEvalTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAssetEvalTest.scala @@ -9,7 +9,7 @@ import com.wavesplatform.lang.utils._ import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SetAssetScriptTransaction} import com.wavesplatform.transaction.transfer._ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumInvokeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumInvokeTest.scala new file mode 100644 index 00000000000..1eff3566a51 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumInvokeTest.scala @@ -0,0 +1,104 @@ +package com.wavesplatform.state.diffs.smart.eth + +import com.esaulpaugh.headlong.abi.{Function, Tuple} +import com.esaulpaugh.headlong.util.FastHex +import com.wavesplatform.account.Address +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.db.WithDomain +import com.wavesplatform.lang.directives.values.V6 +import com.wavesplatform.lang.script.Script +import com.wavesplatform.lang.v1.compiler.TestCompiler +import com.wavesplatform.state.Portfolio +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.state.diffs.ci.ciFee +import com.wavesplatform.state.diffs.smart.predef.{assertProvenPart, provenPart} +import com.wavesplatform.test.{PropSpec, TestTime} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.{ABIConverter, Asset, EthereumTransaction, GenesisTransaction} +import com.wavesplatform.utils.EthHelpers + +class EthereumInvokeTest extends PropSpec with WithDomain with EthHelpers { + import DomainPresets._ + + private val time = new TestTime + private def ts = time.getTimestamp() + + private val passingArg = 123L + private val paymentAmount = 456L + + private def assetScript(tx: EthereumTransaction, dApp: Address) = TestCompiler(V6).compileAsset { + s""" + | match tx { + | case t: InvokeScriptTransaction => ${checkEthInvoke(tx, dApp)} + | case _ => true + | } + """.stripMargin + } + + private def checkEthInvoke(tx: EthereumTransaction, dApp: Address): String = + s""" + | ${provenPart(tx, emptyBodyBytes = true, checkProofs = false)} + | let dAppAddress = match t.dApp { + | case a: Address => a.bytes == base58'$dApp' + | case _: Alias => throw() + | } + | let feeAssetId = t.feeAssetId == unit + | let checkFunc = t.function == "default" + | let checkArgs = t.args == [$passingArg] + | let payments = t.payments == [ AttachedPayment(this.id, $paymentAmount) ] + | ${assertProvenPart("t", proofs = false)} && dAppAddress && feeAssetId && checkFunc && checkArgs && payments + """.stripMargin + + private def dAppScript(asset: Asset) = TestCompiler(V6).compileContract( + s""" + | @Callable(i) + | func default(value: Int) = { + | let check = + | value == $passingArg && + | i.payments == [ AttachedPayment(base58'$asset', $paymentAmount) ] + | [ BooleanEntry("check", check) ] + | } + """.stripMargin + ) + + private def hexData(script: Script, asset: IssuedAsset) = { + val signature = ABIConverter(script).funcByMethodId.collectFirst { case (_, f) if f.name == "default" => f }.get + val args = new Tuple(passingArg, Array[Tuple](new Tuple(asset.id.arr, paymentAmount))) + val call = new Function(signature.ethSignature).encodeCall(args).array() + FastHex.encodeToString(call, 0, call.length) + } + + property("invoke with scripted payment") { + val fee = ciFee().sample.get + val dApp = accountGen.sample.get + val dummyInvoke = EthereumTransaction.Invocation(dApp.toAddress, "") + val dummyEthInvoke = EthereumTransaction(dummyInvoke, TestEthUnderlying, TestEthSignature, 'T'.toByte) // needed to pass into asset script + val aScript = assetScript(dummyEthInvoke, dApp.toAddress) + val issue = IssueTransaction.selfSigned(2.toByte, dApp, "Asset", "", ENOUGH_AMT, 8, true, Some(aScript), fee, ts).explicitGet() + val asset = IssuedAsset(issue.id()) + val script = dAppScript(asset) + val invoke = EthereumTransaction.Invocation(dApp.toAddress, hexData(script, asset)) + val ethInvoke = dummyEthInvoke.copy(invoke) + val invoker = ethInvoke.senderAddress() + val transfer = TransferTransaction.selfSigned(2.toByte, dApp, invoker, asset, ENOUGH_AMT, Waves, fee, ByteStr.empty, ts).explicitGet() + val gTx1 = GenesisTransaction.create(invoker, ENOUGH_AMT, ts).explicitGet() + val gTx2 = GenesisTransaction.create(dApp.toAddress, ENOUGH_AMT, ts).explicitGet() + val setDApp = SetScriptTransaction.selfSigned(1.toByte, dApp, Some(script), fee, ts).explicitGet() + + withDomain(RideV6) { d => + d.appendBlock(gTx1, gTx2, setDApp, issue, transfer) + d.appendBlock(ethInvoke) + + d.liquidDiff.errorMessage(ethInvoke.id()) shouldBe None + d.liquidDiff.portfolios(dApp.toAddress) shouldBe Portfolio.build(asset, paymentAmount) + d.liquidDiff.portfolios(ethInvoke.senderAddress()) shouldBe Portfolio(-ethInvoke.underlying.getGasPrice.longValue(), + assets = Map(asset -> -paymentAmount)) + d.liquidDiff.scriptsRun shouldBe 2 + d.liquidDiff.accountData(dApp.toAddress).data("check").value shouldBe true + } + } +} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumTransferSmartTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumTransferSmartTest.scala new file mode 100644 index 00000000000..b8160655e91 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/eth/EthereumTransferSmartTest.scala @@ -0,0 +1,119 @@ +package com.wavesplatform.state.diffs.smart.eth + +import com.wavesplatform.account.Address +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.db.WithDomain +import com.wavesplatform.lang.directives.values.V6 +import com.wavesplatform.lang.v1.compiler.TestCompiler +import com.wavesplatform.state.Portfolio +import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.state.diffs.ci.ciFee +import com.wavesplatform.state.diffs.smart.predef.{assertProvenPart, provenPart} +import com.wavesplatform.test.{PropSpec, TestTime} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.{ERC20Address, EthereumTransaction, GenesisTransaction} +import com.wavesplatform.utils.EthHelpers + +class EthereumTransferSmartTest extends PropSpec with WithDomain with EthHelpers { + import DomainPresets._ + + private val time = new TestTime + private def ts = time.getTimestamp() + + private val transferAmount = 1234 + + private def script(tx: EthereumTransaction, recipient: Address) = TestCompiler(V6).compileExpression( + s""" + | let t = transferTransactionById(base58'${tx.id()}').value() + | ${checkEthTransfer(tx, "unit", recipient)} + """.stripMargin + ) + + private def assetScript(tx: EthereumTransaction, recipient: Address) = TestCompiler(V6).compileAsset { + s""" + | match tx { + | case t: TransferTransaction => + | if (t.version == 0) + | then { + | ${checkEthTransfer(tx, "this.id", recipient)} + | } else { + | t.amount == $ENOUGH_AMT + | } + | + | case _ => true + | } + """.stripMargin + } + + private def checkEthTransfer(tx: EthereumTransaction, asset: String, recipient: Address): String = + s""" + | ${provenPart(tx, emptyBodyBytes = true, checkProofs = false)} + | let amount = t.amount == $transferAmount + | let feeAssetId = t.feeAssetId == unit + | let assetId = t.assetId == $asset + | let attachment = t.attachment == base58'${ByteStr.empty}' + | let recipient = match (t.recipient) { + | case a: Address => a.bytes == base58'$recipient' + | case a: Alias => throw("unexpected") + | } + | ${assertProvenPart("t", proofs = false)} && amount && assetId && feeAssetId && recipient && attachment + """.stripMargin + + property("transferTransactionById") { + val fee = ciFee().sample.get + val recipient = accountGen.sample.get + val transfer = EthereumTransaction.Transfer(None, transferAmount, recipient.toAddress) + val ethTransfer = EthereumTransaction(transfer, TestEthUnderlying, TestEthSignature, 'T'.toByte) + val gTx1 = GenesisTransaction.create(ethTransfer.senderAddress(), ENOUGH_AMT, ts).explicitGet() + val gTx2 = GenesisTransaction.create(recipient.toAddress, ENOUGH_AMT, ts).explicitGet() + val verifier = Some(script(ethTransfer, recipient.toAddress)) + val setVerifier = () => SetScriptTransaction.selfSigned(1.toByte, recipient, verifier, fee, ts).explicitGet() + + withDomain(RideV6) { d => + d.appendBlock(gTx1, gTx2, setVerifier()) + d.appendBlock(ethTransfer) + + d.liquidDiff.portfolios(recipient.toAddress) shouldBe Portfolio.waves(transferAmount) + d.liquidDiff.portfolios(ethTransfer.senderAddress()) shouldBe Portfolio.waves(-ethTransfer.underlying.getGasPrice.longValue() - transferAmount) + + d.appendBlock() + d.appendBlock(setVerifier()) + d.liquidDiff.scriptsRun shouldBe 1 + } + } + + property("scripted asset") { + val fee = ciFee().sample.get + val recipient = accountGen.sample.get + + val dummyTransfer = EthereumTransaction.Transfer(None, transferAmount, recipient.toAddress) + val dummyEthTransfer = EthereumTransaction(dummyTransfer, TestEthUnderlying, TestEthSignature, 'T'.toByte) // needed to pass into asset script + + val sender = dummyEthTransfer.senderAddress() + val aScript = assetScript(dummyEthTransfer, recipient.toAddress) + val issue = IssueTransaction.selfSigned(2.toByte, recipient, "Asset", "", ENOUGH_AMT, 8, true, Some(aScript), fee, ts).explicitGet() + val asset = IssuedAsset(issue.id()) + val preTransfer = TransferTransaction.selfSigned(2.toByte, recipient, sender, asset, ENOUGH_AMT, Waves, fee, ByteStr.empty, ts).explicitGet() + + val ethTransfer = dummyEthTransfer.copy(dummyTransfer.copy(Some(ERC20Address(asset.id.take(20))))) + + val gTx1 = GenesisTransaction.create(sender, ENOUGH_AMT, ts).explicitGet() + val gTx2 = GenesisTransaction.create(recipient.toAddress, ENOUGH_AMT, ts).explicitGet() + + withDomain(RideV6) { d => + d.appendBlock(gTx1, gTx2, issue, preTransfer) + d.appendBlock(ethTransfer) + + d.liquidDiff.errorMessage(ethTransfer.id()) shouldBe None + d.liquidDiff.portfolios(recipient.toAddress) shouldBe Portfolio.build(asset, transferAmount) + d.liquidDiff.portfolios(ethTransfer.senderAddress()) shouldBe Portfolio(-ethTransfer.underlying.getGasPrice.longValue(), + assets = Map(asset -> -transferAmount)) + + d.liquidDiff.scriptsComplexity should be > 0L + } + } +} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala index 0151e213485..c755ae0379b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala @@ -14,7 +14,7 @@ import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.metrics.Instrumented import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.transfer._ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/AddressTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/AddressTest.scala index 6b49fe8840c..f9bb37e84ef 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/AddressTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/AddressTest.scala @@ -8,9 +8,8 @@ import com.wavesplatform.lang.directives.DirectiveDictionary import com.wavesplatform.lang.directives.values.{StdLibVersion, V4} import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BYTESTR, CaseObj} import com.wavesplatform.lang.v1.evaluator.ctx.impl.unit -import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart.predef -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.TxValidationError.InvalidAddress import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/BrokenUnicodeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/BrokenUnicodeTest.scala index 9026e8cccbd..e130eedfdbe 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/BrokenUnicodeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/BrokenUnicodeTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.smart.predef -import com.wavesplatform.TestTime import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -12,10 +11,11 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.utils.Signed import org.scalacheck.Gen import org.scalatest.EitherValues @@ -206,18 +206,9 @@ class BrokenUnicodeTest extends PropSpec with WithDomain with EitherValues { .selfSigned(TxVersion.V2, a._1, recipient.toAddress, Waves, 1, Waves, fee, ByteStr.empty, ts) .explicitGet() ) - checkFixDApp = dAppWithFix.map( - a => - InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, a._1.toAddress, None, Nil, fee, Waves, ts) - .explicitGet() - ) - checkNoFixDApp = dAppWithNoFix.map( - a => - InvokeScriptTransaction - .selfSigned(TxVersion.V2, invoker, a._1.toAddress, None, Nil, fee, Waves, ts) - .explicitGet() - ) + checkFixDApp = dAppWithFix + .map(a => Signed.invokeScript(TxVersion.V2, invoker, a._1.toAddress, None, Nil, fee, Waves, ts)) + checkNoFixDApp = dAppWithNoFix.map(a => Signed.invokeScript(TxVersion.V2, invoker, a._1.toAddress, None, Nil, fee, Waves, ts)) } yield ( invokerGenesis :: genesisTxs, setNoFixVerifier ::: setNoFixDApp, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/CommonFunctionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/CommonFunctionsTest.scala index 1a43f9dbcd8..fed0cc8ff19 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/CommonFunctionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/CommonFunctionsTest.scala @@ -6,8 +6,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.Testing._ import com.wavesplatform.lang.v1.compiler.Terms.CONST_BYTESTR import com.wavesplatform.lang.v1.evaluator.ctx.impl._ -import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.{DataTransaction, Proofs} import org.scalacheck.Gen @@ -121,7 +120,7 @@ class CommonFunctionsTest extends PropSpec { s""" |match tx { | case tx : TransferTransaction => tx.id == base58'${transfer.id().toString}' - | case tx : IssueTransaction => tx.fee == ${transfer.assetFee._2} + | case tx : IssueTransaction => tx.fee == ${transfer.fee} | case tx : MassTransferTransaction => tx.timestamp == ${transfer.timestamp} | case _ => throw() | } @@ -141,7 +140,7 @@ class CommonFunctionsTest extends PropSpec { |let t = 100 |match tx { | case t: TransferTransaction => t.id == base58'${transfer.id().toString}' - | case t: IssueTransaction => t.fee == ${transfer.assetFee._2} + | case t: IssueTransaction => t.fee == ${transfer.fee} | case t: MassTransferTransaction => t.timestamp == ${transfer.timestamp} | case _ => throw() | } @@ -182,7 +181,7 @@ class CommonFunctionsTest extends PropSpec { | case tx: TransferTransaction | IssueTransaction => { | match tx { | case tx: TransferTransaction => tx.id == base58'${transfer.id().toString}' - | case tx: IssueTransaction => tx.fee == ${transfer.assetFee._2} + | case tx: IssueTransaction => tx.fee == ${transfer.fee} | } | } | case _ => throw() @@ -211,7 +210,7 @@ class CommonFunctionsTest extends PropSpec { property("data constructors") { forAll(transferV2Gen, longEntryGen(dataAsciiKeyGen)) { (t, entry) => val compareClause = (t.recipient: @unchecked) match { - case addr: Address => s"tx.recipient == Address(base58'${addr.stringRepr}')" + case addr: Address => s"tx.recipient == Address(base58'$addr')" case alias: Alias => s"""tx.recipient == Alias("${alias.name}")""" } val transferResult = runScript( diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala index 32901ebe6cc..ad2ae3c9c6b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala @@ -6,38 +6,40 @@ import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, Base64, EitherExt2} import com.wavesplatform.db.WithDomain +import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.BlockchainFeatures.BlockV5 import com.wavesplatform.lagonaki.mocks.TestBlock._ import com.wavesplatform.lang.Global import com.wavesplatform.lang.Testing._ -import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.directives.{DirectiveDictionary, DirectiveSet} +import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.script.ContractScript import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.utils._ import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.{ContractCompiler, ExpressionCompiler, Terms, TestCompiler} import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 -import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} +import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.state._ +import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation} import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} import com.wavesplatform.state.diffs.smart.smartEnabledFS -import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ +import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TransactionType, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.serialization.impl.PBTransactionSerializer +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils._ import org.scalacheck.Gen import shapeless.Coproduct -class ContextFunctionsTest extends PropSpec with WithDomain { +class ContextFunctionsTest extends PropSpec with WithDomain with EthHelpers { import DomainPresets._ def compactDataTransactionGen(sender: KeyPair): Gen[DataTransaction] = @@ -198,7 +200,7 @@ class ContextFunctionsTest extends PropSpec with WithDomain { } } - property("base64 amplification") { + ignore("base64 amplification") { val script = """ |let a = base58'7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy' @@ -510,18 +512,16 @@ class ContextFunctionsTest extends PropSpec with WithDomain { SetScriptTransaction.selfSigned(1.toByte, masterAcc, Some(compiledScript), 1000000L, transferTx.timestamp + 5).explicitGet() val fc = Terms.FUNCTION_CALL(FunctionHeader.User("compareBlocks"), List.empty) - val ci = InvokeScriptTransaction - .selfSigned( - 1.toByte, - masterAcc, - masterAcc.toAddress, - Some(fc), - Seq.empty, - FeeValidation.FeeUnit * (FeeValidation.FeeConstants(InvokeScriptTransaction.typeId) + FeeValidation.ScriptExtraFee), - Waves, - System.currentTimeMillis() - ) - .explicitGet() + val ci = Signed.invokeScript( + 1.toByte, + masterAcc, + masterAcc.toAddress, + Some(fc), + Seq.empty, + FeeValidation.FeeUnit * (FeeValidation.FeeConstants(TransactionType.InvokeScript) + FeeValidation.ScriptExtraFee), + Waves, + System.currentTimeMillis() + ) append(Seq(setScriptTx)).explicitGet() append(Seq(ci)).explicitGet() @@ -762,18 +762,16 @@ class ContextFunctionsTest extends PropSpec with WithDomain { val setScriptTx = SetScriptTransaction.selfSigned(1.toByte, recipient, Some(compiledScript), 1000000L, transferTx.timestamp + 5).explicitGet() - val ci = InvokeScriptTransaction - .selfSigned( + val ci = Signed.invokeScript( 1.toByte, masterAcc, recipient.toAddress, None, Seq.empty, - FeeUnit * (FeeConstants(InvokeScriptTransaction.typeId) + ScriptExtraFee), + FeeUnit * (FeeConstants(TransactionType.InvokeScript) + ScriptExtraFee), Waves, System.currentTimeMillis() ) - .explicitGet() append(genesis).explicitGet() append(Seq(dataTransaction)).explicitGet() @@ -782,4 +780,30 @@ class ContextFunctionsTest extends PropSpec with WithDomain { } } } + + property("addressFromPublicKey native") { + val (masterAcc, _, genesis, setScriptTransaction, dataTransaction, transferTx, transfer2) = preconditionsAndPayments.sample.get + val fs = smartEnabledFS.copy(preActivatedFeatures = smartEnabledFS.preActivatedFeatures + (BlockchainFeatures.RideV6.id -> 0)) + + assertDiffAndState(fs) { append => + append(genesis).explicitGet() + append(Seq(setScriptTransaction, dataTransaction)).explicitGet() + append(Seq(transferTx)).explicitGet() + + val script = TestCompiler(V6) + .compileExpression( + s""" + | addressFromPublicKey(base58'${transferTx.sender}') == Address(base58'${transferTx.sender.toAddress}') && + | addressFromPublicKey(base58'$TestEthPublicKey') == Address(base58'${TestEthPublicKey.toAddress}') + """.stripMargin + ) + + val setScriptTx = SetScriptTransaction + .selfSigned(1.toByte, masterAcc, Some(script), 1000000L, transferTx.timestamp + 5) + .explicitGet() + + append(Seq(setScriptTx)).explicitGet() + append(Seq(transfer2)).explicitGet() + } + } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/DAppVerifierRestrictionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/DAppVerifierRestrictionsTest.scala index 83a696670ae..40ae98806c7 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/DAppVerifierRestrictionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/DAppVerifierRestrictionsTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.smart.predef -import com.wavesplatform.TestTime import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain import com.wavesplatform.lang.directives.values.V5 diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/GenericRideActivationTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/GenericRideActivationTest.scala index 548f59285b7..7fe722ed0e5 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/GenericRideActivationTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/GenericRideActivationTest.scala @@ -7,18 +7,14 @@ import com.wavesplatform.lang.directives.values.{StdLibVersion, V3, V4} import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.GenesisTransaction -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.{TestTime, TransactionGen} +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed import org.scalatest.EitherValues -class GenericRideActivationTest - extends PropSpec - with TransactionGen - with WithDomain - with EitherValues { +class GenericRideActivationTest extends PropSpec with WithDomain with EitherValues { import DomainPresets._ @@ -43,7 +39,7 @@ class GenericRideActivationTest gTx2 = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts).explicitGet() ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(dApp(version)), fee, ts).explicitGet() ssTx2 = SetScriptTransaction.selfSigned(1.toByte, invoker, Some(verifier(version)), fee, ts).explicitGet() - invoke = InvokeScriptTransaction.selfSigned(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invoke = Signed.invokeScript(1.toByte, invoker, master.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2), Seq(ssTx, ssTx2), invoke) property("RIDE versions activation") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/IsDataStorageUntouchedTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/IsDataStorageUntouchedTest.scala index a3db4eda017..b70ab2bc20c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/IsDataStorageUntouchedTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/IsDataStorageUntouchedTest.scala @@ -1,18 +1,18 @@ package com.wavesplatform.state.diffs.smart.predef -import com.wavesplatform.TestTime import com.wavesplatform.account.Address import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain import com.wavesplatform.lang.directives.values.V5 import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.compiler.TestCompiler +import com.wavesplatform.state.{BooleanDataEntry, EmptyDataEntry} import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.state.{BooleanDataEntry, EmptyDataEntry} -import com.wavesplatform.test.PropSpec -import com.wavesplatform.transaction.Asset.Waves -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.test._ import com.wavesplatform.transaction.{DataTransaction, GenesisTransaction, TxVersion} +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.smart.SetScriptTransaction +import com.wavesplatform.transaction.utils.Signed class IsDataStorageUntouchedTest extends PropSpec with WithDomain { @@ -45,7 +45,7 @@ class IsDataStorageUntouchedTest extends PropSpec with WithDomain { dataTx = DataTransaction.selfSigned(TxVersion.V2, master, Seq(BooleanDataEntry("q", true)), 15000000, ts).explicitGet() deleteDataTx = DataTransaction.selfSigned(TxVersion.V2, master, Seq(EmptyDataEntry("q")), 15000000, ts).explicitGet() ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(contract), fee, ts).explicitGet() - invokeTx = InvokeScriptTransaction.selfSigned(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, ssTx), dataTx, deleteDataTx, invokeTx, master.toAddress) property("isDataStorageUntouched true") { @@ -117,15 +117,15 @@ class IsDataStorageUntouchedTest extends PropSpec with WithDomain { genesis2 = GenesisTransaction.create(dApp2.toAddress, ENOUGH_AMT, ts).explicitGet() setDApp1 = SetScriptTransaction.selfSigned(1.toByte, dApp1, Some(syncDApp(dApp2.toAddress)), fee, ts).explicitGet() setDApp2 = SetScriptTransaction.selfSigned(1.toByte, dApp2, Some(contract), fee, ts).explicitGet() - invoke = InvokeScriptTransaction.selfSigned(1.toByte, dApp1, dApp1.toAddress, None, Nil, fee, Waves, ts).explicitGet() + invoke = Signed.invokeScript(1.toByte, dApp1, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (List(genesis1, genesis2, setDApp1, setDApp2), invoke) val (genesisTxs, invokeTx) = scenario.sample.get withDomain(RideV5) { d => d.appendBlock(genesisTxs: _*).id() d.appendBlock(invokeTx) - d.blockchain.accountData(invokeTx.dAppAddressOrAlias.asInstanceOf[Address], "start") shouldBe Some(BooleanDataEntry("start", true)) - d.blockchain.accountData(invokeTx.dAppAddressOrAlias.asInstanceOf[Address], "end") shouldBe Some(BooleanDataEntry("end", false)) + d.blockchain.accountData(invokeTx.dApp.asInstanceOf[Address], "start") shouldBe Some(BooleanDataEntry("start", true)) + d.blockchain.accountData(invokeTx.dApp.asInstanceOf[Address], "end") shouldBe Some(BooleanDataEntry("end", false)) } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala index 85d5c2f3a1b..b1cdbc2bdb2 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala @@ -24,11 +24,11 @@ class ObsoleteTransactionBindingsTest extends PropSpec with WithState { |let genTotal = match genTx { | case gen: GenesisTransaction => | let genId = gen.id == base58'${g.id().toString}' - | let genFee = gen.fee == ${g.assetFee._2} + | let genFee = gen.fee == ${g.fee} | let genTimestamp = gen.timestamp== ${g.timestamp} | let genVersion = gen.version == 1 | let genAmount = gen.amount == ${g.amount} - | let genRecipient = gen.recipient == Address(base58'${g.recipient.stringRepr}') + | let genRecipient = gen.recipient == Address(base58'${g.recipient}') | genId && genFee && genTimestamp && genVersion && genAmount && genRecipient | case _ => false | } @@ -36,11 +36,11 @@ class ObsoleteTransactionBindingsTest extends PropSpec with WithState { |let payTotal = match payTx { | case pay: PaymentTransaction => | let payId = pay.id == base58'${p.id().toString}' - | let payFee = pay.fee == ${p.assetFee._2} + | let payFee = pay.fee == ${p.fee} | let payTimestamp = pay.timestamp== ${p.timestamp} | let payVersion = pay.version == 1 | let payAmount = pay.amount == ${p.amount} - | let payRecipient = pay.recipient == Address(base58'${p.recipient.stringRepr}') + | let payRecipient = pay.recipient == Address(base58'${p.recipient}') | | let bodyBytes = pay.bodyBytes == base64'${ByteStr(p.bodyBytes.apply()).base64}' | let sender = pay.sender == addressFromPublicKey(base58'${p.sender}') diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala index 0654369b248..ef1f08ca2d5 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala @@ -13,9 +13,8 @@ import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.compiler.Terms.EVALUATED import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.lang.v1.parser.Parser -import com.wavesplatform.state.diffs._ import com.wavesplatform.state.{BinaryDataEntry, Blockchain, BooleanDataEntry, EmptyDataEntry, IntegerDataEntry, StringDataEntry} -import com.wavesplatform.test.FreeSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Transaction import com.wavesplatform.transaction.smart.script.{ScriptCompiler, ScriptRunner} import com.wavesplatform.utils.EmptyBlockchain diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala index ee6bb88daf5..347110c0490 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala @@ -6,7 +6,7 @@ import com.wavesplatform.common.utils.{Base58, EitherExt2} import com.wavesplatform.crypto import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lang.Testing.evaluated -import com.wavesplatform.lang.directives.values._ +import com.wavesplatform.lang.directives.values.{Asset => AssetType, _} import com.wavesplatform.lang.directives.{DirectiveDictionary, DirectiveSet} import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.compiler.{ExpressionCompiler, TestCompiler} @@ -18,12 +18,13 @@ import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.lang.v1.{ContractLimits, compiler} import com.wavesplatform.lang.{Common, Global} import com.wavesplatform.state._ +import com.wavesplatform.state.diffs.ci._ import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.exchange.{Order, OrderType} import com.wavesplatform.transaction.smart.BlockchainContext.In import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, WavesEnvironment, buildThisValue} -import com.wavesplatform.transaction.{DataTransaction, Proofs, ProvenTransaction, TxVersion, VersionedTransaction} +import com.wavesplatform.transaction.{DataTransaction, Proofs, TxVersion} import com.wavesplatform.utils.EmptyBlockchain import monix.eval.Coeval import org.scalacheck.Gen @@ -31,40 +32,12 @@ import org.scalamock.scalatest.PathMockFactory import org.scalatest.EitherValues import play.api.libs.json.Json import shapeless.Coproduct -import com.wavesplatform.state.diffs.ci._ import scala.util.Random class TransactionBindingsTest extends PropSpec with PathMockFactory with EitherValues { private val T = 'T'.toByte - def letProof(p: Proofs, prefix: String)(i: Int) = - s"let ${prefix.replace(".", "")}proof$i = $prefix.proofs[$i] == base58'${p.proofs.applyOrElse(i, (_: Int) => ByteStr.empty).toString}'" - - def provenPart(t: ProvenTransaction): String = { - val version = t match { - case v: VersionedTransaction => v.version - case _ => 1 - } - s""" - | let id = t.id == base58'${t.id().toString}' - | let fee = t.fee == ${t.assetFee._2} - | let timestamp = t.timestamp == ${t.timestamp} - | let bodyBytes = blake2b256(t.bodyBytes) == base64'${ByteStr(crypto.fastHash(t.bodyBytes.apply().array)).base64}' - | let sender = t.sender == addressFromPublicKey(base58'${t.sender}') - | let senderPublicKey = t.senderPublicKey == base58'${t.sender}' - | let version = t.version == $version - | ${Range(0, 8).map(letProof(t.proofs, "t")).mkString("\n")} - """.stripMargin - } - - def assertProofs(p: String): String = { - val prefix = p.replace(".", "") - s"${prefix}proof0 && ${prefix}proof1 && ${prefix}proof2 && ${prefix}proof3 && ${prefix}proof4 && ${prefix}proof5 && ${prefix}proof6 && ${prefix}proof7" - } - def assertProvenPart(prefix: String) = - s"id && fee && timestamp && sender && senderPublicKey && ${assertProofs(prefix)} && bodyBytes && version" - property("TransferTransaction binding") { forAll(Gen.oneOf(transferV1Gen, transferV2Gen)) { t => // `version` is not properly bound yet @@ -313,7 +286,7 @@ class TransactionBindingsTest extends PropSpec with PathMockFactory with EitherV | case ad : Address => ad.bytes | case _ : Alias => base58'' | } - | let dappAddress = dAppAddressBytes == base58'${Base58.encode(t.dAppAddressOrAlias.bytes)}' + | let dappAddress = dAppAddressBytes == base58'${Base58.encode(t.dApp.bytes)}' | | let paymentAmount = if(${t.payments.nonEmpty}) | then extract(t.payment).amount == ${t.payments.headOption.map(_.amount).getOrElse(-1)} @@ -736,11 +709,11 @@ class TransactionBindingsTest extends PropSpec with PathMockFactory with EitherV import com.wavesplatform.lang.v1.CTX._ val expr = Parser.parseExpr(script).get.value - val directives = DirectiveSet(V2, Asset, Expression).explicitGet() + val directives = DirectiveSet(V2, AssetType, Expression).explicitGet() val ctx = PureContext.build(V2, fixUnicodeFunctions = true).withEnvironment[Environment] |+| CryptoContext.build(Global, V2).withEnvironment[Environment] |+| - WavesContext.build(Global, DirectiveSet(V2, Asset, Expression).explicitGet()) + WavesContext.build(Global, DirectiveSet(V2, AssetType, Expression).explicitGet()) val environment = new WavesEnvironment( chainId, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala index 3fd2c532439..8b69d9fea70 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala @@ -2,6 +2,7 @@ package com.wavesplatform.state.diffs.smart import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base64, EitherExt2} +import com.wavesplatform.crypto import com.wavesplatform.lang.directives.DirectiveSet import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.utils._ @@ -14,7 +15,7 @@ import com.wavesplatform.state.Blockchain import com.wavesplatform.transaction.smart.BlockchainContext.In import com.wavesplatform.transaction.smart.{BlockchainContext, buildThisValue} import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{DataTransaction, Transaction} +import com.wavesplatform.transaction.{Authorized, DataTransaction, EthereumTransaction, Proofs, ProvenTransaction, Transaction, VersionedTransaction} import com.wavesplatform.utils.EmptyBlockchain import monix.eval.Coeval import shapeless.Coproduct @@ -196,4 +197,42 @@ package object predef { | let crypto = bks && sig && str58 && str64 | crypto""".stripMargin + def letProof(p: Proofs, prefix: String)(i: Int): String = + s"let ${prefix.replace(".", "")}proof$i = $prefix.proofs[$i] == base58'${p.proofs.applyOrElse(i, (_: Int) => ByteStr.empty).toString}'" + + def provenPart(t: Transaction with Authorized, emptyBodyBytes: Boolean = false, checkProofs: Boolean = true): String = { + val version = t match { + case _: EthereumTransaction => 0 + case v: VersionedTransaction => v.version + case _ => 1 + } + val proofs = t match { + case p: ProvenTransaction => p.proofs + case _ => Proofs(Seq()) + } + val bodyBytesCheck = + if (emptyBodyBytes) + "t.bodyBytes.size() == 0" + else + s""" blake2b256(t.bodyBytes) == base64'${ByteStr(crypto.fastHash(t.bodyBytes.apply().array)).base64}' """ + + s""" + | let id = t.id == base58'${t.id().toString}' + | let fee = t.fee == ${t.fee} + | let timestamp = t.timestamp == ${t.timestamp} + | let bodyBytes = $bodyBytesCheck + | let sender = t.sender == addressFromPublicKey(base58'${t.sender}') + | let senderPublicKey = t.senderPublicKey == base58'${t.sender}' + | let version = t.version == $version + | ${ if (checkProofs) Range(0, 8).map(letProof(proofs, "t")).mkString("\n") else ""} + """.stripMargin + } + + def assertProofs(p: String): String = { + val prefix = p.replace(".", "") + s"${prefix}proof0 && ${prefix}proof1 && ${prefix}proof2 && ${prefix}proof3 && ${prefix}proof4 && ${prefix}proof5 && ${prefix}proof6 && ${prefix}proof7" + } + + def assertProvenPart(prefix: String, proofs: Boolean = true): String = + s"id && fee && timestamp && sender && senderPublicKey && ${if (proofs) assertProofs(prefix) + " &&" else ""} bodyBytes && version" } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/AddressFromRecipientScenarioTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/AddressFromRecipientScenarioTest.scala index 1ecbfae5ccd..4163cd7d7b4 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/AddressFromRecipientScenarioTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/AddressFromRecipientScenarioTest.scala @@ -7,7 +7,7 @@ import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BYTESTR, CaseObj} import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart.predef._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.transfer._ import com.wavesplatform.transaction.{CreateAliasTransaction, GenesisTransaction} @@ -25,7 +25,7 @@ class AddressFromRecipientScenarioTest extends PropSpec with WithState { fee <- smallFeeGen aliasTx <- createAliasGen(other, alias, fee, ts) transferViaAddress <- transferGeneratorP(master, other.toAddress, Waves, Waves) - transferViaAlias <- transferGeneratorP(master, AddressOrAlias.fromBytes(alias.bytes, 0).explicitGet()._1, Waves, Waves) + transferViaAlias <- transferGeneratorP(master, AddressOrAlias.fromBytes(alias.bytes).explicitGet(), Waves, Waves) } yield (Seq(genesis1, genesis2), aliasTx, transferViaAddress, transferViaAlias) val script = """ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala index ad9c0678df9..272b90c0594 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala @@ -13,24 +13,24 @@ import com.wavesplatform.lang.directives.values.{Asset => AssetType, _} import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.FunctionHeader.User -import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.compiler.{ExpressionCompiler, TestCompiler} -import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext +import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} +import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext import com.wavesplatform.lang.v1.parser._ import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings} import com.wavesplatform.state._ import com.wavesplatform.state.diffs._ -import com.wavesplatform.transaction.Asset._ +import com.wavesplatform.test._ import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.Asset._ import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.lease._ import com.wavesplatform.transaction.smart._ import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils._ -import com.wavesplatform.TestTime -import com.wavesplatform.test.PropSpec class BalancesV4Test extends PropSpec with WithState { @@ -69,7 +69,7 @@ class BalancesV4Test extends PropSpec with WithState { CreateAliasTransaction.selfSigned(TxVersion.V2, acc1, Alias.create("alias").explicitGet(), MinFee, ts).explicitGet() ) setScript = SetScriptTransaction.selfSigned(1.toByte, dapp, Some(script("alias")), SetScriptFee, ts).explicitGet() - ci = InvokeScriptTransaction.selfSigned(1.toByte, master, dapp.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, ts + 3).explicitGet() + ci = Signed.invokeScript(1.toByte, master, dapp.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, ts + 3) lease1 = LeaseTransaction.selfSigned(2.toByte, acc1, dapp.toAddress, 10 * Constants.UnitsInWave, MinFee, ts + 2).explicitGet() lease2 = LeaseTransaction.selfSigned(2.toByte, acc1, dapp.toAddress, 10 * Constants.UnitsInWave, MinFee, ts + 3).explicitGet() leaseD = LeaseTransaction.selfSigned(2.toByte, dapp, acc1.toAddress, 1 * Constants.UnitsInWave, MinFee, ts + 3).explicitGet() @@ -201,7 +201,7 @@ class BalancesV4Test extends PropSpec with WithState { val setScript = SetScriptTransaction .selfSigned(1.toByte, acc1, Some(dappScript(ByteStr(acc2.toAddress.bytes), issue.id())), SetScriptFee, nextTs) .explicitGet() - val ci = InvokeScriptTransaction.selfSigned(1.toByte, acc1, acc1.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, nextTs).explicitGet() + val ci = Signed.invokeScript(1.toByte, acc1, acc1.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, nextTs) assertDiffAndState(Seq(TestBlock.create(Seq(g1, g2, alias, issue, setScript))), TestBlock.create(Seq(ci)), rideV4Activated) { case (d, s) => @@ -285,7 +285,7 @@ class BalancesV4Test extends PropSpec with WithState { val setScript = SetScriptTransaction .selfSigned(1.toByte, acc1, Some(dappScript(ByteStr(acc2.toAddress.bytes), issue.id())), SetScriptFee, nextTs) .explicitGet() - val ci = InvokeScriptTransaction.selfSigned(1.toByte, acc2, acc1.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, nextTs).explicitGet() + val ci = Signed.invokeScript(1.toByte, acc2, acc1.toAddress, functionCall, Nil, InvokeScriptTxFee, Waves, nextTs) assertDiffAndState(Seq(TestBlock.create(Seq(g1, g2, issue, setScript))), TestBlock.create(Seq(ci)), rideV4Activated) { case (d, s) => diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala index c3c65ef8d40..5e0a86c121f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala @@ -3,6 +3,7 @@ package com.wavesplatform.state.diffs.smart.scenarios import com.wavesplatform.account.PublicKey import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 +import com.wavesplatform.crypto import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.directives.values.{Expression, V1} @@ -13,12 +14,11 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart._ +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction._ import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.transfer._ -import com.wavesplatform.crypto -import com.wavesplatform.test.PropSpec import org.scalacheck.Gen class MultiSig2of3Test extends PropSpec with WithState { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala index 38668122be8..686a2c82dc5 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala @@ -18,7 +18,7 @@ import com.wavesplatform.state._ import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart._ import com.wavesplatform.state.diffs.smart.predef.chainId -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.WavesEnvironment diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OneProofForNonScriptedAccountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OneProofForNonScriptedAccountTest.scala index 91a87087b68..c6138ef44f0 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OneProofForNonScriptedAccountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OneProofForNonScriptedAccountTest.scala @@ -6,9 +6,9 @@ import com.wavesplatform.db.WithState import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.compiler.Terms._ +import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.smart.smartEnabledFS -import com.wavesplatform.state.diffs.{ENOUGH_AMT, produce} -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.transfer._ import com.wavesplatform.transaction.{GenesisTransaction, Proofs} diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala index 916877b1d92..1d7411f03c3 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala @@ -7,9 +7,8 @@ import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.utils._ import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.parser.Parser -import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ class OnlyTransferIsAllowedTest extends PropSpec with WithState { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala index d8663dfc021..06f0bf1b03a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala @@ -13,7 +13,7 @@ import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.state.diffs.TransactionDiffer.TransactionValidationError import com.wavesplatform.state.diffs._ import com.wavesplatform.state.diffs.smart.smartEnabledFS -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.TxValidationError.ScriptExecutionError import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.transfer._ diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala index 66274b716d6..5b83d346d4c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala @@ -7,7 +7,7 @@ import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.settings.TestFunctionalitySettings -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.smart.SetScriptTransaction diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala index 57a292da456..54c0fb57b65 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala @@ -7,9 +7,8 @@ import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.utils._ import com.wavesplatform.lang.v1.compiler.ExpressionCompiler import com.wavesplatform.lang.v1.parser.Parser -import com.wavesplatform.state.diffs.produce import com.wavesplatform.state.diffs.smart._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.lease.LeaseTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction diff --git a/node/src/test/scala/com/wavesplatform/state/reader/StateReaderEffectiveBalancePropertyTest.scala b/node/src/test/scala/com/wavesplatform/state/reader/StateReaderEffectiveBalancePropertyTest.scala index 72d1d02d66f..5a1d812e94a 100644 --- a/node/src/test/scala/com/wavesplatform/state/reader/StateReaderEffectiveBalancePropertyTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/reader/StateReaderEffectiveBalancePropertyTest.scala @@ -7,7 +7,7 @@ import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} import com.wavesplatform.settings.TestFunctionalitySettings.Enabled import com.wavesplatform.state.LeaseBalance import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.GenesisTransaction import com.wavesplatform.transaction.lease.LeaseTransaction import org.scalacheck.Gen diff --git a/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala b/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala new file mode 100644 index 00000000000..f3ac3899d29 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala @@ -0,0 +1,71 @@ +package com.wavesplatform.state.rollback + +import com.wavesplatform.db.WithDomain +import com.wavesplatform.test.FlatSpec +import com.wavesplatform.transaction.utils.EthTxGenerator +import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.TxHelpers +import com.wavesplatform.utils.EthHelpers + +class EthereumTransactionRollbackSpec extends FlatSpec with WithDomain with EthHelpers { + // KeyTags.values.foreach(v => println(v.toString + " " + v.id.toHexString)) + + "Ethereum transfer" should "rollback" in withDomain(DomainPresets.RideV6) { d => + val transaction = EthTxGenerator.generateEthTransfer(TxHelpers.defaultEthSigner, TxHelpers.secondAddress, 1, Waves) + + withClue("genesis") { + d.helpers.creditWavesToDefaultSigner(1 + 100000) + d.balance(TxHelpers.defaultEthAddress) shouldBe (1 + 100000) + d.balance(TxHelpers.secondAddress) shouldBe 0 + } + + val (initHeight, initStateSnapshot) = d.makeStateHard() + withClue("after transaction") { + d.appendBlock(transaction) + d.balance(TxHelpers.defaultEthAddress) shouldBe 0 + d.balance(TxHelpers.secondAddress) shouldBe 1 + } + + withClue("after rollback") { + d.rollbackTo(initHeight) + d.balance(TxHelpers.defaultEthAddress) shouldBe (1 + 100000) + d.balance(TxHelpers.secondAddress) shouldBe 0 + d.hardStateSnapshot() shouldBe initStateSnapshot + d.liquidState shouldBe None + } + } + + "Ethereum invoke" should "rollback" in withDomain(DomainPresets.RideV6) { d => + d.helpers.creditWavesToDefaultSigner() + d.helpers.creditWavesFromDefaultSigner(TxHelpers.secondAddress) + + val asset = d.helpers.issueAsset() + val script = TxHelpers.scriptV5(s""" + | @Callable(i) + | func foo() = { + | [ + | IntegerEntry("key", 1), + | BooleanEntry("key", true), + | StringEntry("key", "str"), + | BinaryEntry("key", base58''), + | DeleteEntry("key"), + | ScriptTransfer(i.caller, 1, unit), + | ScriptTransfer(i.caller, 1, base58'$asset'), + | Issue("name", "description", 1000, 4, true, unit, 0), + | Reissue(base58'$asset', 1, false), + | Burn(base58'$asset', 1), + | SponsorFee(base58'$asset', 1) + | ] + | } + |""".stripMargin) + d.helpers.setScript(TxHelpers.defaultSigner, script) + + val (initHeight, initStateSnapshot) = d.makeStateHard() + val invoke = TxHelpers.invoke(TxHelpers.defaultAddress, "foo", fee = 1_0000_0000) + d.appendBlock(invoke) + + d.rollbackTo(initHeight) + d.hardStateSnapshot() shouldBe initStateSnapshot + d.liquidState shouldBe None + } +} diff --git a/node/src/test/scala/com/wavesplatform/TestTime.scala b/node/src/test/scala/com/wavesplatform/test/TestTime.scala similarity index 74% rename from node/src/test/scala/com/wavesplatform/TestTime.scala rename to node/src/test/scala/com/wavesplatform/test/TestTime.scala index 6ba9934e7e9..f907f78599e 100644 --- a/node/src/test/scala/com/wavesplatform/TestTime.scala +++ b/node/src/test/scala/com/wavesplatform/test/TestTime.scala @@ -1,10 +1,10 @@ -package com.wavesplatform +package com.wavesplatform.test import com.wavesplatform.utils.Time import scala.concurrent.duration.FiniteDuration -class TestTime(var t: Long = System.currentTimeMillis()) extends Time { +case class TestTime(private var t: Long = System.currentTimeMillis()) extends Time { def setTime(tt: Long): this.type = { t = tt this diff --git a/node/src/test/scala/com/wavesplatform/transaction/BurnTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/BurnTransactionSpecification.scala index dbce8b00e2b..90810495de6 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/BurnTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/BurnTransactionSpecification.scala @@ -7,12 +7,13 @@ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.assets.BurnTransaction import com.wavesplatform.crypto import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.serialization.impl.BurnTxSerializer import play.api.libs.json.Json class BurnTransactionSpecification extends PropSpec { property("Burn serialization roundtrip") { - forAll(burnGen) { tx: BurnTransaction => - val recovered = tx.builder.parseBytes(tx.bytes()).get + forAll(burnGen) { tx => + val recovered = BurnTxSerializer.parseBytes(tx.bytes()).get recovered.bytes() shouldEqual tx.bytes() } } diff --git a/node/src/test/scala/com/wavesplatform/transaction/ChainIdSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/ChainIdSpecification.scala index 63db22f0f40..9505157a1ee 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/ChainIdSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/ChainIdSpecification.scala @@ -39,7 +39,7 @@ class ChainIdSpecification extends PropSpec { tx.chainId should not be AddressScheme.current.chainId val protoTx = PBTransactions.protobuf(tx) - val recoveredTxEi = PBTransactions.vanilla(PBSignedTransaction.parseFrom(protoTx.toByteArray)) + val recoveredTxEi = PBTransactions.vanilla(PBSignedTransaction.parseFrom(protoTx.toByteArray), unsafe = true) recoveredTxEi.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/transaction/CreateAliasTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/CreateAliasTransactionSpecification.scala index 811acd7d2b2..ee6a6ac081f 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/CreateAliasTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/CreateAliasTransactionSpecification.scala @@ -4,13 +4,14 @@ import com.wavesplatform.account.{Alias, KeyPair, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.serialization.impl.CreateAliasTxSerializer import play.api.libs.json.Json class CreateAliasTransactionSpecification extends PropSpec { property("CreateAliasTransaction serialization roundtrip") { forAll(createAliasGen) { tx: CreateAliasTransaction => - val recovered = tx.builder.parseBytes(tx.bytes()).get + val recovered = CreateAliasTxSerializer.parseBytes(tx.bytes()).get recovered shouldEqual tx } } diff --git a/node/src/test/scala/com/wavesplatform/transaction/DataTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/DataTransactionSpecification.scala index 6e1bab21c04..a25b3c257b9 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/DataTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/DataTransactionSpecification.scala @@ -10,6 +10,7 @@ import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, DataEntry, Em import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.crypto import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.serialization.impl.DataTxSerializer import org.scalacheck.{Arbitrary, Gen} import org.scalatest._ import play.api.libs.json.Json @@ -71,7 +72,7 @@ class DataTransactionSpecification extends PropSpec { | ] |}""".stripMargin) - val tx = DataTransaction.serializer.parseBytes(bytes).get + val tx = DataTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/ExchangeTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/ExchangeTransactionSpecification.scala index 8b382770b91..2e5905e4366 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/ExchangeTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/ExchangeTransactionSpecification.scala @@ -9,6 +9,7 @@ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.{GenericError, OrderValidationError} import com.wavesplatform.transaction.assets.exchange.AssetPair.extractAssetId import com.wavesplatform.transaction.assets.exchange.{Order, _} +import com.wavesplatform.transaction.serialization.impl.ExchangeTxSerializer import com.wavesplatform.{NTPTime, crypto} import org.scalacheck.Gen import play.api.libs.json.Json @@ -109,7 +110,7 @@ class ExchangeTransactionSpecification extends PropSpec with NTPTime { |""".stripMargin ) - val tx = ExchangeTransaction.serializer.parseBytes(bytes).get + val tx = ExchangeTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.sellOrder.signature, tx.sellOrder.bodyBytes(), tx.sellOrder.sender), "sellOrder signature should be valid") assert(crypto.verify(tx.buyOrder.signature, tx.buyOrder.bodyBytes(), tx.buyOrder.sender), "buyOrder signature should be valid") @@ -179,7 +180,7 @@ class ExchangeTransactionSpecification extends PropSpec with NTPTime { |""".stripMargin ) - val tx = ExchangeTransaction.serializer.parseBytes(bytes).get + val tx = ExchangeTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.sellOrder.signature, tx.sellOrder.bodyBytes(), tx.sellOrder.sender), "sellOrder signature should be valid") assert(crypto.verify(tx.buyOrder.signature, tx.buyOrder.bodyBytes(), tx.buyOrder.sender), "buyOrder signature should be valid") diff --git a/node/src/test/scala/com/wavesplatform/transaction/GenesisTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/GenesisTransactionSpecification.scala index de06e514b2b..4fa6feb6913 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/GenesisTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/GenesisTransactionSpecification.scala @@ -43,7 +43,7 @@ class GenesisTransactionSpecification extends PropSpec { source should equal(dest) val proto = PBTransactions.protobuf(source) - val fromProto = PBTransactions.vanilla(proto).explicitGet() + val fromProto = PBTransactions.vanilla(proto, unsafe = false).explicitGet() val fromProtoUnsafe = PBTransactions.vanillaUnsafe(proto) fromProto shouldBe source fromProtoUnsafe shouldBe source diff --git a/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptComplexitySpec.scala b/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptComplexitySpec.scala index 72632706f3b..8cb75fff7e2 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptComplexitySpec.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptComplexitySpec.scala @@ -13,8 +13,9 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utx.UtxPoolImpl class InvokeScriptComplexitySpec extends FreeSpec with WithDomain with NTPTime { @@ -97,8 +98,7 @@ class InvokeScriptComplexitySpec extends FreeSpec with WithDomain with NTPTime { issueTx ) - val invocation = InvokeScriptTransaction - .selfSigned( + val invocation = Signed.invokeScript( TxVersion.V2, invoker, dApp1KP.toAddress, @@ -117,7 +117,6 @@ class InvokeScriptComplexitySpec extends FreeSpec with WithDomain with NTPTime { Waves, ntpTime.getTimestamp() ) - .explicitGet() utx.putIfNew(invocation, true).resultE.explicitGet() shouldBe true utx.size shouldBe 1 diff --git a/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptTransactionSpecification.scala index 26dd5d5715b..084fb927acc 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/InvokeScriptTransactionSpecification.scala @@ -5,6 +5,7 @@ import com.wavesplatform.account._ import com.wavesplatform.api.http.requests.{InvokeScriptRequest, SignedInvokeScriptRequest} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base64, _} +import com.wavesplatform.crypto import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.compiler.Terms.{ARR, CONST_BIGINT, CONST_LONG, CaseObj} import com.wavesplatform.lang.v1.compiler.Types.CASETYPEREF @@ -12,13 +13,13 @@ import com.wavesplatform.lang.v1.{ContractLimits, FunctionHeader, Serde} import com.wavesplatform.protobuf.transaction._ import com.wavesplatform.protobuf.{Amount, transaction} import com.wavesplatform.serialization.Deser +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.NonPositiveAmount import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, Verifier} -import com.wavesplatform.crypto -import com.wavesplatform.test._ -import play.api.libs.json.{JsObject, Json} +import com.wavesplatform.transaction.utils.Signed +import play.api.libs.json.{JsArray, JsObject, JsString, Json} class InvokeScriptTransactionSpecification extends PropSpec { @@ -29,7 +30,7 @@ class InvokeScriptTransactionSpecification extends PropSpec { val bytes = transaction.bytes() val deser = InvokeScriptTransaction.parseBytes(bytes).get deser.sender shouldEqual transaction.sender - deser.dAppAddressOrAlias shouldEqual transaction.dAppAddressOrAlias + deser.dApp shouldEqual transaction.dApp deser.funcCallOpt shouldEqual transaction.funcCallOpt deser.payments shouldEqual transaction.payments deser.fee shouldEqual transaction.fee @@ -51,15 +52,23 @@ class InvokeScriptTransactionSpecification extends PropSpec { tx.version, transaction.PBTransaction.Data.InvokeScript( InvokeScriptTransactionData( - Some(PBRecipients.create(tx.dAppAddressOrAlias)), + Some(PBRecipients.create(tx.dApp)), ByteString.copyFrom(Deser.serializeOption(tx.funcCallOpt)(Serde.serialize(_))), tx.payments.map(p => Amount.of(PBAmounts.toPBAssetId(p.assetId), p.amount)) ) ) ) - val proof = crypto.sign(caller.privateKey, PBTransactions.vanilla(PBSignedTransaction(Some(unsigned))).explicitGet().bodyBytes()) - val signed = PBSignedTransaction(Some(unsigned), Seq(ByteString.copyFrom(proof.arr))) - val convTx = PBTransactions.vanilla(signed).explicitGet() + + val proof = crypto.sign( + caller.privateKey, + PBTransactions + .vanilla(PBSignedTransaction(PBSignedTransaction.Transaction.WavesTransaction(unsigned)), unsafe = false) + .explicitGet() + .asInstanceOf[ProvenTransaction] + .bodyBytes() + ) + val signed = PBSignedTransaction(PBSignedTransaction.Transaction.WavesTransaction(unsigned), Seq(ByteString.copyFrom(proof.arr))) + val convTx = PBTransactions.vanilla(signed, unsafe = false).explicitGet() val unsafeConvTx = PBTransactions.vanillaUnsafe(signed) val modTx = tx.copy(sender = caller.publicKey, proofs = Proofs(List(proof))) convTx.json() shouldBe modTx.json() @@ -104,7 +113,7 @@ class InvokeScriptTransactionSpecification extends PropSpec { } """) - val tx = InvokeScriptTransaction.serializer.parseBytes(bytes).get + val tx = InvokeScriptTransaction.parseBytes(bytes).get tx.json() shouldBe json ByteStr(tx.bytes()) shouldBe ByteStr(bytes) AddressScheme.current = DefaultAddressScheme @@ -138,23 +147,21 @@ class InvokeScriptTransactionSpecification extends PropSpec { } """) - val tx = InvokeScriptTransaction - .selfSigned( - 1.toByte, - KeyPair("test3".getBytes("UTF-8")), - KeyPair("test4".getBytes("UTF-8")).toAddress, - Some( - Terms.FUNCTION_CALL( - FunctionHeader.User("foo"), - List(Terms.CONST_BYTESTR(ByteStr(Base64.tryDecode("YWxpY2U=").get)).explicitGet()) - ) - ), - Seq(InvokeScriptTransaction.Payment(7, IssuedAsset(ByteStr.decodeBase58(publicKey).get))), - 100000, - Waves, - 1526910778245L - ) - .explicitGet() + val tx = Signed.invokeScript( + 1.toByte, + KeyPair("test3".getBytes("UTF-8")), + KeyPair("test4".getBytes("UTF-8")).toAddress, + Some( + Terms.FUNCTION_CALL( + FunctionHeader.User("foo"), + List(Terms.CONST_BYTESTR(ByteStr(Base64.tryDecode("YWxpY2U=").get)).explicitGet()) + ) + ), + Seq(InvokeScriptTransaction.Payment(7, IssuedAsset(ByteStr.decodeBase58(publicKey).get))), + 100000, + Waves, + 1526910778245L + ) (tx.json() - "proofs") shouldEqual (js.asInstanceOf[JsObject] - "proofs") @@ -182,20 +189,19 @@ class InvokeScriptTransactionSpecification extends PropSpec { } """) - val tx = InvokeScriptTransaction - .selfSigned( - 1.toByte, - KeyPair("test3".getBytes("UTF-8")), - KeyPair("test4".getBytes("UTF-8")).toAddress, - None, - Seq(InvokeScriptTransaction.Payment(7, IssuedAsset(ByteStr.decodeBase58(publicKey).get))), - 100000, - Waves, - 1526910778245L - ) - .explicitGet() + val tx = Signed.invokeScript( + 1.toByte, + KeyPair("test3".getBytes("UTF-8")), + KeyPair("test4".getBytes("UTF-8")).toAddress, + None, + Seq(InvokeScriptTransaction.Payment(7, IssuedAsset(ByteStr.decodeBase58(publicKey).get))), + 100000, + Waves, + 1526910778245L + ) - (tx.json() - "proofs") shouldEqual (js.asInstanceOf[JsObject] - "proofs") + (tx.json() - "proofs") shouldEqual (js.asInstanceOf[JsObject] - "proofs" + + ("call" -> JsObject(Map("function" -> JsString("default"), "args" -> JsArray())))) TransactionFactory.fromSignedRequest(js) shouldBe Right(tx) AddressScheme.current = DefaultAddressScheme @@ -204,6 +210,7 @@ class InvokeScriptTransactionSpecification extends PropSpec { property("Signed InvokeScriptTransactionRequest parser") { AddressScheme.current = new AddressScheme { override val chainId: Byte = 'D' } val req = SignedInvokeScriptRequest( + None, Some(1.toByte), senderPublicKey = publicKey, fee = 1, @@ -235,7 +242,8 @@ class InvokeScriptTransactionSpecification extends PropSpec { 1, Waves, 1, - Proofs.empty + Proofs.empty, + AddressScheme.current.chainId ) should produce("more than 22 arguments") } @@ -256,7 +264,8 @@ class InvokeScriptTransactionSpecification extends PropSpec { 1, Waves, 1, - Proofs.empty + Proofs.empty, + AddressScheme.current.chainId ) .explicitGet() } @@ -277,7 +286,8 @@ class InvokeScriptTransactionSpecification extends PropSpec { 1, Waves, 1, - Proofs.empty + Proofs.empty, + AddressScheme.current.chainId ) should produce("is unsupported") } @@ -297,13 +307,14 @@ class InvokeScriptTransactionSpecification extends PropSpec { 1, Waves, 1, - Proofs.empty + Proofs.empty, + AddressScheme.current.chainId ) should produce("is unsupported") } property("can't be more 5kb") { val largeString = "abcde" * 1024 - val pk = PublicKey.fromBase58String(publicKey).explicitGet() + val pk = PublicKey.fromBase58String(publicKey).explicitGet() InvokeScriptTransaction.create( 1.toByte, pk, @@ -313,13 +324,15 @@ class InvokeScriptTransactionSpecification extends PropSpec { 1, Waves, 1, - Proofs.empty + Proofs.empty, + AddressScheme.current.chainId ) should produce("TooBigArray") } property("can't have zero amount") { AddressScheme.current = new AddressScheme { override val chainId: Byte = 'D' } val req = SignedInvokeScriptRequest( + None, Some(1.toByte), senderPublicKey = publicKey, fee = 1, @@ -343,6 +356,7 @@ class InvokeScriptTransactionSpecification extends PropSpec { property("can't have negative amount") { AddressScheme.current = new AddressScheme { override val chainId: Byte = 'D' } val req = SignedInvokeScriptRequest( + None, Some(1.toByte), senderPublicKey = publicKey, fee = 1, diff --git a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV1Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV1Specification.scala index 557ce9b50dd..b653e6d2d48 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV1Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV1Specification.scala @@ -6,12 +6,13 @@ import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.utils._ import com.wavesplatform.crypto import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.serialization.impl.IssueTxSerializer import play.api.libs.json.Json class IssueTransactionV1Specification extends PropSpec { property("Issue serialization roundtrip") { forAll(issueGen) { issue: IssueTransaction => - val recovered = issue.builder.parseBytes(issue.bytes()).get + val recovered = IssueTxSerializer.parseBytes(issue.bytes()).get recovered.bytes() shouldEqual issue.bytes() } } @@ -40,7 +41,7 @@ class IssueTransactionV1Specification extends PropSpec { } """) - val tx = IssueTransaction.serializer.parseBytes(bytes).get + val tx = IssueTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala index 6de882fde21..00aad6005ca 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala @@ -16,6 +16,7 @@ import com.wavesplatform.lang.{Global, utils} import com.wavesplatform.state.HistoryTest import com.wavesplatform.test.PropSpec import com.wavesplatform.transaction.assets.IssueTransaction +import com.wavesplatform.transaction.serialization.impl.IssueTxSerializer import com.wavesplatform.utils._ import com.wavesplatform.{WithDB, crypto} import org.scalatest.EitherValues @@ -72,7 +73,7 @@ class IssueTransactionV2Specification | } |""".stripMargin) - val tx = IssueTransaction.serializer.parseBytes(bytes).get + val tx = IssueTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/LeaseCancelTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/LeaseCancelTransactionSpecification.scala index 8047e6bdb0c..559077cd822 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/LeaseCancelTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/LeaseCancelTransactionSpecification.scala @@ -12,7 +12,7 @@ class LeaseCancelTransactionSpecification extends PropSpec { property("Lease cancel serialization roundtrip") { forAll(leaseCancelGen) { tx: LeaseCancelTransaction => - val recovered = tx.builder.parseBytes(tx.bytes()).get.asInstanceOf[LeaseCancelTransaction] + val recovered = LeaseCancelTxSerializer.parseBytes(tx.bytes()).get assertTxs(recovered, tx) } } diff --git a/node/src/test/scala/com/wavesplatform/transaction/LeaseTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/LeaseTransactionSpecification.scala index cd07d2f1f42..03fd8e2566a 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/LeaseTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/LeaseTransactionSpecification.scala @@ -5,13 +5,14 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, EitherExt2} import com.wavesplatform.test.PropSpec import com.wavesplatform.transaction.lease.LeaseTransaction +import com.wavesplatform.transaction.serialization.impl.LeaseTxSerializer import play.api.libs.json.Json class LeaseTransactionSpecification extends PropSpec { property("Lease transaction serialization roundtrip") { forAll(leaseGen) { tx: LeaseTransaction => - val recovered = tx.builder.parseBytes(tx.bytes()).get.asInstanceOf[LeaseTransaction] + val recovered = LeaseTxSerializer.parseBytes(tx.bytes()).get assertTxs(recovered, tx) } } @@ -36,7 +37,7 @@ class LeaseTransactionSpecification extends PropSpec { |} |""".stripMargin) - val tx = LeaseTransaction.serializer.parseBytes(bytes) + val tx = LeaseTxSerializer.parseBytes(bytes) tx.get.json() shouldBe json } @@ -49,7 +50,7 @@ class LeaseTransactionSpecification extends PropSpec { private def assertTxs(first: LeaseTransaction, second: LeaseTransaction): Unit = { first.sender shouldEqual second.sender - first.recipient.stringRepr shouldEqual second.recipient.stringRepr + first.recipient shouldEqual second.recipient first.amount shouldEqual second.amount first.fee shouldEqual second.fee first.proofs shouldEqual second.proofs @@ -129,7 +130,7 @@ class LeaseTransactionSpecification extends PropSpec { // hack in an assetId bytes(3) = 1: Byte val bytesWithAssetId = bytes.take(4) ++ assetId ++ bytes.drop(4) - val parsed = tx.builder.parseBytes(bytesWithAssetId) + val parsed = LeaseTxSerializer.parseBytes(bytesWithAssetId) parsed.isFailure shouldBe true parsed.failed.get.getMessage.contains("Leasing assets is not supported yet") shouldBe true } diff --git a/node/src/test/scala/com/wavesplatform/transaction/MassTransferTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/MassTransferTransactionSpecification.scala index 73e2b390bf5..dd8bea94177 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/MassTransferTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/MassTransferTransactionSpecification.scala @@ -7,6 +7,7 @@ import com.wavesplatform.crypto import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.TxValidationError.GenericError +import com.wavesplatform.transaction.serialization.impl.MassTransferTxSerializer import com.wavesplatform.transaction.transfer.MassTransferTransaction.{MaxTransferCount, ParsedTransfer, Transfer} import com.wavesplatform.transaction.transfer._ import play.api.libs.json.Json @@ -67,7 +68,7 @@ class MassTransferTransactionSpecification extends PropSpec { } """) - val tx = MassTransferTransaction.serializer.parseBytes(bytes).get + val tx = MassTransferTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/OrderSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/OrderSpecification.scala index ef7a3a7050f..04bdfe5fa23 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/OrderSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/OrderSpecification.scala @@ -1,12 +1,11 @@ package com.wavesplatform.transaction +import com.wavesplatform.NTPTime import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.state.diffs._ +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.exchange.{AssetPair, Order, OrderType} import com.wavesplatform.transaction.smart.Verifier -import com.wavesplatform.NTPTime -import com.wavesplatform.test.PropSpec import org.scalatest._ import scala.util.Random diff --git a/node/src/test/scala/com/wavesplatform/transaction/ProtoVersionTransactionsSpec.scala b/node/src/test/scala/com/wavesplatform/transaction/ProtoVersionTransactionsSpec.scala index 8a4ad775eb1..552b776424e 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/ProtoVersionTransactionsSpec.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/ProtoVersionTransactionsSpec.scala @@ -14,9 +14,10 @@ import com.wavesplatform.transaction.assets._ import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction} +import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer +import com.wavesplatform.transaction.utils.Signed import com.wavesplatform.utils.StringBytes import org.scalacheck.Gen @@ -109,8 +110,7 @@ class ProtoVersionTransactionsSpec extends FreeSpec { val dapp = accountOrAliasGen.sample.get val feeAssetId = bytes32gen.map(ByteStr(_)).sample.get - val invokeScriptTx = InvokeScriptTransaction - .selfSigned( + val invokeScriptTx = Signed.invokeScript( TxVersion.V2, Account, dapp, @@ -120,7 +120,6 @@ class ProtoVersionTransactionsSpec extends FreeSpec { IssuedAsset(feeAssetId), Now ) - .explicitGet() val base64Str = Base64.encode(PBUtils.encodeDeterministic(PBTransactions.protobuf(invokeScriptTx))) decode(base64Str) shouldBe invokeScriptTx @@ -197,7 +196,7 @@ class ProtoVersionTransactionsSpec extends FreeSpec { } def decode(base64Str: String): Transaction = { - PBTransactions.vanilla(PBSignedTransaction.parseFrom(Base64.decode(base64Str))).explicitGet() + PBTransactions.vanilla(PBSignedTransaction.parseFrom(Base64.decode(base64Str)), unsafe = false).explicitGet() } } } diff --git a/node/src/test/scala/com/wavesplatform/transaction/ReissueTransactionV1Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/ReissueTransactionV1Specification.scala index 74c3023d6aa..28e999a1397 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/ReissueTransactionV1Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/ReissueTransactionV1Specification.scala @@ -7,13 +7,14 @@ import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.assets.ReissueTransaction import com.wavesplatform.crypto import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.serialization.impl.ReissueTxSerializer import play.api.libs.json.Json class ReissueTransactionV1Specification extends PropSpec { property("Reissue serialization roundtrip") { forAll(reissueGen) { tx: ReissueTransaction => - val recovered = tx.builder.parseBytes(tx.bytes()).get + val recovered = ReissueTxSerializer.parseBytes(tx.bytes()).get recovered.bytes() shouldEqual tx.bytes() } } @@ -38,7 +39,7 @@ class ReissueTransactionV1Specification extends PropSpec { | "timestamp" : 31761529735035 |}""".stripMargin) - val tx = ReissueTransaction.serializer.parseBytes(bytes).get + val tx = ReissueTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala index 50667a5c426..d5cd628e1f7 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala @@ -4,17 +4,18 @@ import com.wavesplatform.account.PublicKey import com.wavesplatform.block.Block import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base64, EitherExt2} +import com.wavesplatform.crypto import com.wavesplatform.db.WithState import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.BlockchainFeatures._ import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} import com.wavesplatform.settings.{Constants, FunctionalitySettings, TestFunctionalitySettings} import com.wavesplatform.state.diffs._ +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} +import com.wavesplatform.transaction.serialization.impl.SponsorFeeTxSerializer import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.crypto -import com.wavesplatform.test.PropSpec import org.scalacheck.Gen import play.api.libs.json.Json @@ -56,7 +57,7 @@ class SponsorFeeTransactionSpecification extends PropSpec with WithState { |} |""".stripMargin) - val tx = SponsorFeeTransaction.serializer.parseBytes(bytes).get + val tx = SponsorFeeTxSerializer.parseBytes(bytes).get tx.json() shouldBe json assert(crypto.verify(tx.signature, tx.bodyBytes(), tx.sender), "signature should be valid") } diff --git a/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV1Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV1Specification.scala index a6464c96baa..ab0f802929d 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV1Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV1Specification.scala @@ -3,9 +3,9 @@ package com.wavesplatform.transaction import com.wavesplatform.account.{Address, PublicKey} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, EitherExt2} -import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.serialization.impl.TransferTxSerializer import com.wavesplatform.transaction.transfer._ import play.api.libs.json.Json @@ -21,7 +21,7 @@ class TransferTransactionV1Specification extends PropSpec { recovered.timestamp shouldEqual transfer.timestamp recovered.amount shouldEqual transfer.amount recovered.fee shouldEqual transfer.fee - recovered.recipient.stringRepr shouldEqual transfer.recipient.stringRepr + recovered.recipient shouldEqual transfer.recipient recovered.bytes() shouldEqual transfer.bytes() } @@ -52,7 +52,7 @@ class TransferTransactionV1Specification extends PropSpec { |""".stripMargin ) - val tx = TransferTransaction.serializer.parseBytes(bytes) + val tx = TransferTxSerializer.parseBytes(bytes) tx.get.json() shouldBe json } diff --git a/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV2Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV2Specification.scala index 98f139c74d6..c04df29f6c6 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV2Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/TransferTransactionV2Specification.scala @@ -5,6 +5,7 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, EitherExt2} import com.wavesplatform.test.PropSpec import com.wavesplatform.transaction.Asset.Waves +import com.wavesplatform.transaction.serialization.impl.TransferTxSerializer import com.wavesplatform.transaction.transfer._ import play.api.libs.json.Json @@ -41,7 +42,7 @@ class TransferTransactionV2Specification extends PropSpec { |""".stripMargin ) - val tx = TransferTransaction.serializer.parseBytes(bytes) + val tx = TransferTxSerializer.parseBytes(bytes) tx.get.json() shouldBe json } diff --git a/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala b/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala index 1533dca413b..9e0a041d71b 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala @@ -13,22 +13,25 @@ import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.state.StringDataEntry import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.assets.exchange.{AssetPair, ExchangeTransaction, Order, OrderType} import com.wavesplatform.transaction.assets.{IssueTransaction, ReissueTransaction} +import com.wavesplatform.transaction.assets.exchange.{AssetPair, ExchangeTransaction, Order, OrderType} import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction} import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, InvokeScriptTransaction, SetScriptTransaction} import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.utils.Signed object TxHelpers { def signer(i: Int): KeyPair = KeyPair(Ints.toByteArray(i)) def address(i: Int): Address = signer(i).toAddress val defaultSigner: KeyPair = signer(0) - val defaultAddress: Address = defaultSigner.toAddress + def defaultAddress: Address = defaultSigner.toAddress val secondSigner: KeyPair = signer(1) - val secondAddress: Address = secondSigner.toAddress + def secondAddress: Address = secondSigner.toAddress + + val matcher: KeyPair = defaultSigner private[this] var lastTimestamp = System.currentTimeMillis() def timestamp: Long = { @@ -36,10 +39,17 @@ object TxHelpers { lastTimestamp } - def genesis(address: Address, amount: Long = 100_000_000.waves): GenesisTransaction = + def genesis(address: Address, amount: Long = 100000000.waves): GenesisTransaction = GenesisTransaction.create(address, amount, timestamp).explicitGet() - def transfer(from: KeyPair = defaultSigner, to: AddressOrAlias = secondAddress, amount: Long = 1.waves, asset: Asset = Waves, fee: Long = TestValues.fee, version: Byte = TxVersion.V1): TransferTransaction = + def transfer( + from: KeyPair = defaultSigner, + to: AddressOrAlias = secondAddress, + amount: Long = 1.waves, + asset: Asset = Waves, + fee: Long = TestValues.fee, + version: Byte = TxVersion.V1 + ): TransferTransaction = TransferTransaction.selfSigned(version, from, to, asset, amount, Waves, fee, ByteStr.empty, timestamp).explicitGet() def issue(amount: Long = 1000, script: Script = null): IssueTransaction = @@ -78,11 +88,11 @@ object TxHelpers { ) } - def exchange(order1: Order, order2: Order): ExchangeTransaction = { + def exchange(order1: Order, order2: Order, version: TxVersion = TxVersion.V2, timestamp: TxTimestamp = this.timestamp): ExchangeTransaction = { ExchangeTransaction .signed( - TxVersion.V2, - defaultSigner.privateKey, + version, + matcher.privateKey, order1, order2, order1.amount, @@ -100,6 +110,13 @@ object TxHelpers { script } + def scriptV5(scriptText: String): Script = script(s""" + |{-# STDLIB_VERSION 5 #-} + |{-# CONTENT_TYPE DAPP #-} + | + |$scriptText + |""".stripMargin) + def setScript(acc: KeyPair, script: Script): SetScriptTransaction = { SetScriptTransaction.selfSigned(TxVersion.V1, acc, Some(script), TestValues.fee, timestamp).explicitGet() } @@ -113,7 +130,7 @@ object TxHelpers { feeAssetId: Asset = Waves ): InvokeScriptTransaction = { val fc = FUNCTION_CALL(FunctionHeader.User(func), args.toList) - InvokeScriptTransaction.selfSigned(TxVersion.V1, defaultSigner, dApp, Some(fc), payments, fee, feeAssetId, timestamp).explicitGet() + Signed.invokeScript(TxVersion.V1, defaultSigner, dApp, Some(fc), payments, fee, feeAssetId, timestamp) } def invokeExpression( diff --git a/node/src/test/scala/com/wavesplatform/transaction/assets/Erc20NoConflictIssueTest.scala b/node/src/test/scala/com/wavesplatform/transaction/assets/Erc20NoConflictIssueTest.scala new file mode 100644 index 00000000000..c29f3735a3d --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/transaction/assets/Erc20NoConflictIssueTest.scala @@ -0,0 +1,43 @@ +package com.wavesplatform.transaction.assets + +import com.wavesplatform.test.FreeSpec +import com.wavesplatform.BlockchainStubHelpers +import com.wavesplatform.lang.v1.traits.domain.Issue +import com.wavesplatform.state.diffs.produceRejectOrFailedDiff +import com.wavesplatform.transaction.{ERC20Address, TxHelpers} +import com.wavesplatform.transaction.Asset.IssuedAsset +import org.scalamock.scalatest.PathMockFactory +import org.scalatest.matchers.should.Matchers + +class Erc20NoConflictIssueTest extends FreeSpec with Matchers with BlockchainStubHelpers with PathMockFactory { + "Erc20 should be unique" - { + "in invoke" in { + val tx = TxHelpers.invoke(TxHelpers.defaultAddress, "test", fee = 100900000) + val assetId = IssuedAsset(Issue.calculateId(1, "test", isReissuable = true, "test", 1, 1, tx.id())) + + val blockchain = createBlockchainStub { b => + (b.resolveERC20Address _).when(ERC20Address(assetId)).returns(Some(assetId)) // Only erc20 entry in the blockchain + b.stub.setScript( + TxHelpers.defaultAddress, + TxHelpers.scriptV5(""" + |@Callable(i) + |func test() = { + | [Issue("test", "test", 1, 1, true, unit, 1)] + |} + |""".stripMargin) + ) + } + val differ = blockchain.stub.transactionDiffer().andThen(_.resultE) + differ(tx) should produceRejectOrFailedDiff(s"Asset $assetId is already issued") + } + + "in plain issue tx" in { + val tx = TxHelpers.issue() + val blockchain = createBlockchainStub { b => + (b.resolveERC20Address _).when(ERC20Address(tx.asset)).returns(Some(tx.asset)) // Only erc20 entry in the blockchain + } + val differ = blockchain.stub.transactionDiffer().andThen(_.resultE) + differ(tx) should produceRejectOrFailedDiff(s"Asset ${tx.asset} is already issued") + } + } +} diff --git a/node/src/test/scala/com/wavesplatform/transaction/assets/exchange/EthOrderSpec.scala b/node/src/test/scala/com/wavesplatform/transaction/assets/exchange/EthOrderSpec.scala new file mode 100644 index 00000000000..9367deaa181 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/transaction/assets/exchange/EthOrderSpec.scala @@ -0,0 +1,255 @@ +package com.wavesplatform.transaction.assets.exchange + +import com.wavesplatform.account.PublicKey +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.test.{FlatSpec, TestTime} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.BlockchainStubHelpers +import com.wavesplatform.common.utils._ +import com.wavesplatform.state.diffs.TransactionDiffer +import com.wavesplatform.transaction.{Proofs, TxHelpers, TxVersion} +import com.wavesplatform.utils.{DiffMatchers, EthEncoding, EthHelpers, EthSetChainId} +import org.scalamock.scalatest.PathMockFactory +import org.scalatest.BeforeAndAfterAll + +class EthOrderSpec + extends FlatSpec + with BeforeAndAfterAll + with PathMockFactory + with BlockchainStubHelpers + with EthHelpers + with EthSetChainId + with DiffMatchers { + val ethBuyOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xe5ff562bfb0296e95b631365599c87f1c5002597bf56a131f289765275d2580f5344c62999404c37cd858ea037328ac91eca16ad1ce69c345ebb52fde70b66251c" + ) + ) + + val ethSellOrder = Order( + Order.V4, + TestEthPublicKey, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.SELL, + 1, + 100L, + 1, + 123, + 100000, + Waves, + eip712Signature = EthSignature( + "0xc8ba2bdafd27742546b3be34883efc51d6cdffbb235798d7b51876c6854791f019b0522d7a39b6f2087cba46ae86919b71a2d9d7920dfc8e00246d8f02a258f21b" + ) + ) + + "ETH signed order" should "recover signer public key correctly" in { + val testOrder = Order( + Order.V1, + PublicKey(EthStubBytes32), + PublicKey(EthStubBytes32), + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), IssuedAsset(ByteStr(EthStubBytes32))), + OrderType.BUY, + 1, + 1, + 123, + 321, + 1, + IssuedAsset(ByteStr(EthStubBytes32)) + ) + + val signature = + EthEncoding.toBytes( + "0x54119bc5b24d9363b7a1a31a71a2e6194dfeedc5e9644893b0a04bb57004e5b14342c1ce29ee00877da49180fd6d7fb332ff400231f809da7ed0dcb07c504e2d1c" + ) + + val result = EthOrders.recoverEthSignerKey(testOrder, signature) + result shouldBe TestEthPublicKey + result.toAddress shouldBe TestEthPublicKey.toAddress + } + + it should "be of version 4" in { + val testOrder = Order( + Order.V1, + PublicKey(EthStubBytes32), + PublicKey(EthStubBytes32), + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 1, + 123, + 321, + 1, + Waves, + eip712Signature = EthSignature( + "0xb557dae4c614146dd35ba6fd80e4702a75d33ffcb8af09e80e0c1a7386b8ffcb5b76bd8037f6484de809a80a5b39a224301c76e8bad9b1a9e7ada53ba6fa7e361c" + ) + ) + + testOrder.isValid(123).labels shouldBe Set("eip712Signature available only in V4") + } + + it should "be not contain proofs" in { + val testOrder = Order( + Order.V4, + PublicKey(EthStubBytes32), + PublicKey(EthStubBytes32), + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 1, + 123, + 321, + 1, + Waves, + Proofs(ByteStr.empty), + eip712Signature = EthSignature( + "0xb557dae4c614146dd35ba6fd80e4702a75d33ffcb8af09e80e0c1a7386b8ffcb5b76bd8037f6484de809a80a5b39a224301c76e8bad9b1a9e7ada53ba6fa7e361c" + ) + ) + + testOrder.isValid(123).labels shouldBe Set("eip712Signature excludes proofs") + } + + it should "work in exchange transaction" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(100)) + val transaction = TxHelpers.exchange(ethBuyOrder, ethSellOrder, TxVersion.V3, 100) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + } + + it should "work in exchange transaction with old order" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + } + + val buyOrder = Order.selfSigned( + Order.V3, + TxHelpers.defaultSigner, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 100L, + 1, + 123, + 100000, + Waves + ) + + val differ = TransactionDiffer(Some(1L), 100L)(blockchain, _) + val transaction = TxHelpers.exchange(buyOrder, ethSellOrder, TxVersion.V3, 100) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + } + + it should "not work in exchange transaction with changed signature" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + } + + val differ = TransactionDiffer(Some(1L), 100L)(blockchain, _) + val transaction = TxHelpers + .exchange(ethBuyOrder, ethSellOrder, TxVersion.V3, 100) + .copy( + order2 = ethSellOrder.copy( + eip712Signature = EthSignature( + "0x1717804a1d60149988821546732442eabc69f46b2764e231eaeef48351d9f36577278c3f29fe3d61500932190dba8c045b19acda117a4690bfd3d2c28bb67bf91c" + ) + ) + ) + + differ(transaction).resultE should matchPattern { + case Left(err) if err.toString.contains("Proof doesn't validate as signature") => + } + } + + it should "work in exchange transaction with asset script" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + + // TODO: something more smart ? + val script = TxHelpers.script(""" + |match tx { + | case e: ExchangeTransaction => true + | case _ => false + |}""".stripMargin) + + sh.issueAsset(ByteStr(EthStubBytes32), Some(script)) + } + + val buyOrder = Order.selfSigned( + Order.V3, + TxHelpers.defaultSigner, + TxHelpers.matcher.publicKey, + AssetPair(IssuedAsset(ByteStr(EthStubBytes32)), Waves), + OrderType.BUY, + 1, + 100L, + 1, + 123, + 100000, + Waves + ) + + val differ = TransactionDiffer(Some(1L), 100L)(blockchain, _) + val transaction = TxHelpers.exchange(buyOrder, ethSellOrder, TxVersion.V3, 100) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + } + + it should "work in exchange transaction with matcher script" in { + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.creditBalance(TxHelpers.matcher.toAddress, *) + sh.creditBalance(TestEthPublicKey.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """ + |{-# STDLIB_VERSION 5 #-} + |{-# CONTENT_TYPE EXPRESSION #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + | + | + |match tx { + | case e: ExchangeTransaction => if (e.buyOrder.proofs[0] == base58'' && e.sellOrder.proofs[0] == base58'') then true else throw("Only ethereum") + | case _: Order => true + | case _ => false + |}""".stripMargin + ) + sh.setScript(TxHelpers.matcher.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(100)) + val transaction = TxHelpers.exchange(ethBuyOrder, ethSellOrder, TxVersion.V3, 100) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + } +} diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/EthereumTransactionSpec.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/EthereumTransactionSpec.scala new file mode 100644 index 00000000000..35c885f9682 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/EthereumTransactionSpec.scala @@ -0,0 +1,539 @@ +package com.wavesplatform.transaction.smart + +import scala.concurrent.duration._ + +import cats.syntax.monoid._ +import com.wavesplatform.{BlockchainStubHelpers, TestValues} +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils._ +import com.wavesplatform.features.BlockchainFeatures +import com.wavesplatform.state.diffs.produceRejectOrFailedDiff +import com.wavesplatform.state.Portfolio +import com.wavesplatform.test.{FlatSpec, TestTime} +import com.wavesplatform.transaction.{ERC20Address, EthereumTransaction, TxHelpers} +import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment +import com.wavesplatform.transaction.utils.EthConverters._ +import com.wavesplatform.transaction.utils.EthTxGenerator +import com.wavesplatform.transaction.utils.EthTxGenerator.Arg +import com.wavesplatform.utils.{DiffMatchers, EthEncoding, EthHelpers, EthSetChainId, JsonMatchers} +import org.scalamock.scalatest.PathMockFactory +import org.scalatest.BeforeAndAfterAll +import org.web3j.crypto.RawTransaction +import play.api.libs.json.Json + +class EthereumTransactionSpec + extends FlatSpec + with BeforeAndAfterAll + with PathMockFactory + with BlockchainStubHelpers + with EthHelpers + with EthSetChainId + with DiffMatchers + with JsonMatchers { + + val TestAsset: IssuedAsset = TestValues.asset + + "Ethereum transfer" should "work with long.max" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val senderAddress = TxHelpers.defaultSigner.toEthWavesAddress + val recipientAddress = TxHelpers.secondSigner.toAddress + + val blockchain = createBlockchainStub { b => + b.stub.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6, BlockchainFeatures.Ride4DApps) + b.stub.issueAsset(TestAsset.id) + b.stub.creditBalance(senderAddress, Waves, Long.MaxValue) + b.stub.creditBalance(senderAddress, TestAsset, Long.MaxValue) + (b.resolveERC20Address _).when(ERC20Address(TestAsset.id.take(20))).returning(Some(TestAsset)) + } + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())).andThen(_.resultE.explicitGet()) + + val LongMaxMinusFee = Long.MaxValue - 200000 + val transfer = EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, LongMaxMinusFee, Waves) + val assetTransfer = EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, Long.MaxValue, TestAsset) + + (differ(transfer) |+| differ(assetTransfer)).portfolios shouldBe Map( + senderAddress -> Portfolio(-Long.MaxValue, assets = Map(TestAsset -> -Long.MaxValue)), + recipientAddress -> Portfolio(LongMaxMinusFee, assets = Map(TestAsset -> Long.MaxValue)) + ) + } + + it should "use chainId in signer key recovery" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val senderAddress = TxHelpers.defaultSigner.toEthWavesAddress + val recipientAddress = TxHelpers.secondSigner.toAddress('W'.toByte) // Other network + + val blockchain = createBlockchainStub { b => + b.stub.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + b.stub.creditBalance(senderAddress, Waves) + b.stub.creditBalance(senderAddress, TestAsset) + (b.resolveERC20Address _).when(ERC20Address(TestAsset.id.take(20))).returning(Some(TestAsset)) + } + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())).andThen(_.resultE.explicitGet()) + + val transfer = EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, 1, Waves) + val assetTransfer = EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, 1, TestAsset) + + intercept[RuntimeException](differ(transfer)).toString should include("negative waves balance") + intercept[RuntimeException](differ(assetTransfer)).toString should include("negative waves balance") + } + + it should "not accept zero transfers" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val recipientAddress = TxHelpers.secondSigner.toAddress + intercept[RuntimeException](EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, 0, Waves)).toString should include( + "Transaction cancellation is not supported" + ) + intercept[RuntimeException](EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, 0, TestAsset)).toString should include( + "NonPositiveAmount" + ) + intercept[RuntimeException](EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, -1, Waves)).toString should include( + "NegativeAmount" + ) + intercept[UnsupportedOperationException](EthTxGenerator.generateEthTransfer(senderAccount, recipientAddress, -1, TestAsset)) + } + + it should "not accept value + data" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val recipientAddress = TxHelpers.secondSigner.toAddress + + intercept[RuntimeException]( + EthTxGenerator.signRawTransaction(senderAccount, recipientAddress.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis()).bigInteger, + EthereumTransaction.GasPrice, + BigInt(100000).bigInteger, + EthEncoding.toHexString(recipientAddress.publicKeyHash), + (BigInt(100) * EthereumTransaction.AmountMultiplier).bigInteger, + "0x0000000000" + ) + ) + ).toString should include( + "Transaction should have either data or value" + ) + } + + it should "not accept fee < 100k" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val recipientAddress = TxHelpers.secondSigner.toAddress + + val differ = createBlockchainStub { b => + (() => b.height).when().returning(3001) + b.stub.activateAllFeatures() + b.stub.creditBalance(senderAccount.toWavesAddress, *) + }.stub.transactionDiffer().andThen(_.resultE.explicitGet()) + + val transaction = EthTxGenerator.signRawTransaction(senderAccount, recipientAddress.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis()).bigInteger, + EthereumTransaction.GasPrice, + BigInt(99999).bigInteger, // fee + EthEncoding.toHexString(recipientAddress.publicKeyHash), + (BigInt(100) * EthereumTransaction.AmountMultiplier).bigInteger, + "" + ) + ) + intercept[RuntimeException](differ(transaction)).toString should include( + "Fee for EthereumTransaction (99999 in WAVES) does not exceed minimal value of 100000 WAVES" + ) + } + + it should "not accept bad time" in { + val senderAccount = TxHelpers.defaultSigner.toEthKeyPair + val recipientAddress = TxHelpers.secondSigner.toAddress + + val differ = createBlockchainStub { b => + (() => b.height).when().returning(3001) + b.stub.activateAllFeatures() + b.stub.creditBalance(senderAccount.toWavesAddress, *) + }.stub.transactionDiffer().andThen(_.resultE.explicitGet()) + + val transactionFromFuture = EthTxGenerator.signRawTransaction(senderAccount, recipientAddress.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis() + 1.6.hours.toMillis).bigInteger, + EthereumTransaction.GasPrice, + BigInt(100000).bigInteger, // fee + EthEncoding.toHexString(recipientAddress.publicKeyHash), + (BigInt(100) * EthereumTransaction.AmountMultiplier).bigInteger, + "" + ) + ) + intercept[RuntimeException](differ(transactionFromFuture)).toString should include( + "is more than 5400000ms in the future" + ) + + val transactionFromPast = EthTxGenerator.signRawTransaction(senderAccount, recipientAddress.chainId)( + RawTransaction.createTransaction( + BigInt(System.currentTimeMillis() - 3.hours.toMillis).bigInteger, + EthereumTransaction.GasPrice, + BigInt(100000).bigInteger, // fee + EthEncoding.toHexString(recipientAddress.publicKeyHash), + (BigInt(100) * EthereumTransaction.AmountMultiplier).bigInteger, + "" + ) + ) + intercept[RuntimeException](differ(transactionFromPast)).toString should include( + "is more than 7200000ms in the past" + ) + } + + it should "not be accepted before RideV6 activation" in { + val blockchain = createBlockchainStub { blockchain => + // Activate all features except ride v6 + val features = BlockchainFeatures.implemented.collect { case id if id != BlockchainFeatures.RideV6.id => BlockchainFeatures.feature(id) }.flatten + blockchain.stub.activateFeatures(features.toSeq: _*) + } + val differ = blockchain.stub.transactionDiffer().andThen(_.resultE) + + val transaction = EthTxGenerator.generateEthTransfer(TxHelpers.defaultEthSigner, TxHelpers.secondAddress, 123, Waves) + differ(transaction) should produceRejectOrFailedDiff("Ride V6 feature has not been activated yet") + } + + "Ethereum invoke" should "work with all types of arguments" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func deposit(amount: Int, bs: ByteVector, str: String, bool: Boolean, list: List[Int], union: ByteVector|String) = { + | [ + | ScriptTransfer(i.caller, amount, unit) + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "deposit", + Seq( + Arg.Integer(123), + Arg.Bytes(ByteStr.empty), + Arg.Str("123"), + Arg.Bool(true), + Arg.List(Arg.Integer(0), Seq(Arg.Integer(123))), + Arg.Union(0, Seq(Arg.Str("123"), Arg.Bytes(ByteStr.empty))) + ), + Seq(Payment(321, IssuedAsset(ByteStr(EthStubBytes32)))) + ) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + Json.toJson(diff.scriptResults.values.head) should matchJson("""{ + | "data" : [ ], + | "transfers" : [ { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : null, + | "amount" : 123 + | } ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + |}""".stripMargin) + } + + it should "work with no arguments" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func deposit() = { + | [ + | ScriptTransfer(i.caller, 123, unit) + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "deposit", + Seq(), + Seq(Payment(321, IssuedAsset(ByteStr(EthStubBytes32)))) + ) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + Json.toJson(diff.scriptResults.values.head) should matchJson("""{ + | "data" : [ ], + | "transfers" : [ { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : null, + | "amount" : 123 + | } ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + |}""".stripMargin) + } + + it should "work with no payments" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func deposit() = { + | [ + | ScriptTransfer(i.caller, 123, unit) + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke(invokerAccount, dAppAccount.toAddress, "deposit", Seq(), Seq()) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + Json.toJson(diff.scriptResults.values.head) should matchJson("""{ + | "data" : [ ], + | "transfers" : [ { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : null, + | "amount" : 123 + | } ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + |}""".stripMargin) + } + + it should "fail with max+1 payments" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """{-# STDLIB_VERSION 5 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func deposit() = { + | [ + | ScriptTransfer(i.caller, 123, unit) + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "deposit", + Seq(), + (1 to com.wavesplatform.lang.v1.ContractLimits.MaxAttachedPaymentAmountV5 + 1).map(InvokeScriptTransaction.Payment(_, Waves)) + ) + differ(transaction).resultE should produceRejectOrFailedDiff("Script payment amount=11 should not exceed 10") + } + + it should "work with default function" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(ByteStr(EthStubBytes32)) + + val script = TxHelpers.script( + """{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func default() = { + | [ + | ScriptTransfer(i.caller, 123, unit) + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "default", + Seq(), + Seq(Payment(321, IssuedAsset(ByteStr(EthStubBytes32)))) + ) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + Json.toJson(diff.scriptResults.values.head) should matchJson("""{ + | "data" : [ ], + | "transfers" : [ { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : null, + | "amount" : 123 + | } ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + |}""".stripMargin) + } + + it should "return money in transfers asset+waves" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(TestAsset.id) + + val script = TxHelpers.script( + s"""{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func default() = { + | [ + | ScriptTransfer(i.caller, 123, unit), + | ScriptTransfer(i.caller, 123, base58'$TestAsset') + | ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "default", + Seq(), + Nil + ) + val diff = differ(transaction).resultE.explicitGet() + diff should containAppliedTx(transaction.id()) + Json.toJson(diff.scriptResults.values.head) should matchJson(s"""{ + | "data" : [ ], + | "transfers" : [ { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : null, + | "amount" : 123 + | }, + | { + | "address" : "3G9uRSP4uVjTFjGZixYW4arBZUKWHxjnfeW", + | "asset" : "$TestAsset", + | "amount" : 123 + | }], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + |}""".stripMargin) + } + + it should "test minimum fee" in { + val invokerAccount = TxHelpers.defaultSigner.toEthKeyPair + val dAppAccount = TxHelpers.secondSigner + val blockchain = createBlockchainStub { blockchain => + val sh = StubHelpers(blockchain) + sh.activateFeatures(BlockchainFeatures.BlockV5, BlockchainFeatures.RideV6) + sh.creditBalance(invokerAccount.toWavesAddress, *) + sh.creditBalance(dAppAccount.toAddress, *) + sh.issueAsset(TestAsset.id) + + val script = TxHelpers.script( + s"""{-# STDLIB_VERSION 4 #-} + |{-# SCRIPT_TYPE ACCOUNT #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable (i) + |func default() = { + | [ ] + |} + |""".stripMargin + ) + sh.setScript(dAppAccount.toAddress, script) + } + + val differ = blockchain.stub.transactionDiffer(TestTime(System.currentTimeMillis())) + val transaction = EthTxGenerator.generateEthInvoke( + invokerAccount, + dAppAccount.toAddress, + "default", + Seq(), + Nil, + fee = 499999 + ) + + intercept[RuntimeException](differ(transaction).resultE.explicitGet()).toString should include( + "Fee in WAVES for InvokeScriptTransaction (499999 in WAVES) does not exceed minimal value of 500000 WAVES" + ) + } +} diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/VerifierSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/VerifierSpecification.scala index f10e2dd3224..e628926bc25 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/VerifierSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/VerifierSpecification.scala @@ -10,7 +10,6 @@ import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.compiler.Terms import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 -import com.wavesplatform.state.diffs.produce import com.wavesplatform.test._ import com.wavesplatform.transaction.Asset import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala index df4ab086994..cc6a43533e5 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala @@ -9,8 +9,7 @@ import com.wavesplatform.lang.v1.compiler.Terms._ import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.evaluator.FunctionIds._ import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext -import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ import org.scalatest.{EitherValues, Inside} class ScriptCompilerV1Test extends PropSpec with EitherValues with Inside { diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptReaderTest.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptReaderTest.scala index 0f93979e3b2..abef8bbac23 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptReaderTest.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptReaderTest.scala @@ -8,7 +8,7 @@ import com.wavesplatform.lang.script.{ContractScript, ScriptReader} import com.wavesplatform.lang.v1.Serde import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.testing.TypedScriptGen -import com.wavesplatform.state.diffs.produce +import com.wavesplatform.test._ import com.wavesplatform.test.PropSpec import org.scalacheck.{Arbitrary, Gen} import org.scalatest.{EitherValues, Inside} diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptV1Test.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptV1Test.scala index afa6e3b50ab..c2529a67a9e 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptV1Test.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptV1Test.scala @@ -10,8 +10,7 @@ import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.evaluator.FunctionIds._ import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext import com.wavesplatform.lang.v1.testing.TypedScriptGen -import com.wavesplatform.state.diffs._ -import com.wavesplatform.test.PropSpec +import com.wavesplatform.test._ class ScriptV1Test extends PropSpec with TypedScriptGen { diff --git a/node/src/test/scala/com/wavesplatform/utils/DiffMatchers.scala b/node/src/test/scala/com/wavesplatform/utils/DiffMatchers.scala new file mode 100644 index 00000000000..d1a084859e2 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/utils/DiffMatchers.scala @@ -0,0 +1,25 @@ +package com.wavesplatform.utils + +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.state.Diff +import org.scalatest.matchers.{Matcher, MatchResult} + +trait DiffMatchers { + def containAppliedTx(transactionId: ByteStr) = new DiffAppliedTxMatcher(transactionId, true) + def containFailedTx(transactionId: ByteStr) = new DiffAppliedTxMatcher(transactionId, false) + + class DiffAppliedTxMatcher(transactionId: ByteStr, shouldBeApplied: Boolean) extends Matcher[Diff] { + override def apply(diff: Diff): MatchResult = { + val isApplied = diff.transactions.get(transactionId) match { + case Some(nt) if nt.applied => true + case _ => false + } + + MatchResult( + shouldBeApplied == isApplied, + s"$transactionId was not ${if (shouldBeApplied) "applied" else "failed"}: $diff", + s"$transactionId was ${if (shouldBeApplied) "applied" else "failed"}: $diff" + ) + } + } +} diff --git a/node/src/test/scala/com/wavesplatform/utils/EmptyBlockchain.scala b/node/src/test/scala/com/wavesplatform/utils/EmptyBlockchain.scala index 376a4268291..acb0d6dca11 100644 --- a/node/src/test/scala/com/wavesplatform/utils/EmptyBlockchain.scala +++ b/node/src/test/scala/com/wavesplatform/utils/EmptyBlockchain.scala @@ -10,8 +10,8 @@ import com.wavesplatform.state._ import com.wavesplatform.state.reader.LeaseDetails import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.TxValidationError.GenericError -import com.wavesplatform.transaction.transfer.TransferTransaction -import com.wavesplatform.transaction.{Asset, Transaction} +import com.wavesplatform.transaction.transfer.TransferTransactionLike +import com.wavesplatform.transaction.{Asset, ERC20Address, Transaction} trait EmptyBlockchain extends Blockchain { override lazy val settings: BlockchainSettings = BlockchainSettings.fromRootConfig(ConfigFactory.load()) @@ -42,7 +42,7 @@ trait EmptyBlockchain extends Blockchain { override def wavesAmount(height: Int): BigInt = 0 - override def transferById(id: ByteStr): Option[(Int, TransferTransaction)] = None + override def transferById(id: ByteStr): Option[(Int, TransferTransactionLike)] = None override def transactionInfo(id: ByteStr): Option[(Int, Transaction, Boolean)] = None @@ -75,6 +75,8 @@ trait EmptyBlockchain extends Blockchain { override def balance(address: Address, mayBeAssetId: Asset): Long = 0 override def leaseBalance(address: Address): LeaseBalance = LeaseBalance.empty + + override def resolveERC20Address(address: ERC20Address): Option[IssuedAsset] = None } object EmptyBlockchain extends EmptyBlockchain diff --git a/node/src/test/scala/com/wavesplatform/utils/EthHelpers.scala b/node/src/test/scala/com/wavesplatform/utils/EthHelpers.scala new file mode 100644 index 00000000000..133937bdfb5 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/utils/EthHelpers.scala @@ -0,0 +1,86 @@ +package com.wavesplatform.utils + +import java.math.BigInteger + +import com.wavesplatform.account.{Address, AddressScheme, PublicKey} +import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.test.TestTime +import com.wavesplatform.transaction.{EthereumTransaction, TxHelpers} +import org.scalatest.{BeforeAndAfterAll, Suite} +import org.web3j.crypto.Sign.SignatureData +import org.web3j.crypto.{Bip32ECKeyPair, RawTransaction} +import org.web3j.utils.Numeric + +trait EthHelpers { + val EthStubBytes32: Array[Byte] = Array.fill(32)(EthChainId.byte) + + object EthPublicKey { + def apply(str: String): PublicKey = PublicKey(EthEncoding.toBytes(str)) + } + + object EthSignature { + def apply(str: String): Option[ByteStr] = Some(ByteStr(EthEncoding.toBytes(str))) + } + + val TestEthPublicKey: PublicKey = EthPublicKey( + "0xd10a150ba9a535125481e017a09c2ac6a1ab43fc43f7ab8f0d44635106672dd7de4f775c06b730483862cbc4371a646d86df77b3815593a846b7272ace008c42" + ) + + private val time = new TestTime + private def ts = time.getTimestamp() + + val TestEthUnderlying: RawTransaction = + RawTransaction.createTransaction( + BigInteger.valueOf(ts), + EthereumTransaction.GasPrice, + EthereumTransaction.GasPrice, + "", + (BigInt(123) * EthereumTransaction.AmountMultiplier).bigInteger, + "" + ) + + val TestEthSignature = new SignatureData( + 28.toByte, + Numeric.hexStringToByteArray("0x0464eee9e2fe1a10ffe48c78b80de1ed8dcf996f3f60955cb2e03cb21903d930"), + Numeric.hexStringToByteArray("0x06624da478b3f862582e85b31c6a21c6cae2eee2bd50f55c93c4faad9d9c8d7f") + ) + + object EthChainId { + val byte: Byte = 'E'.toByte + + def set(): Unit = { + AddressScheme.current = new AddressScheme { + val chainId: Byte = EthChainId.byte + } + } + + def unset(): Unit = { + AddressScheme.current = new AddressScheme { + val chainId: Byte = 'T'.toByte + } + } + + def withEChainId[T](f: => T): T = { + this.set() + try f + finally this.unset() + } + } + + implicit class TxHelpersEthExt(helpers: TxHelpers.type) { + import com.wavesplatform.transaction.utils.EthConverters._ + def defaultEthSigner: Bip32ECKeyPair = helpers.defaultSigner.toEthKeyPair + def defaultEthAddress: Address = helpers.defaultSigner.toEthWavesAddress + } +} + +trait EthSetChainId extends BeforeAndAfterAll with EthHelpers { self: Suite => + abstract override protected def beforeAll(): Unit = { + EthChainId.set() + super.beforeAll() + } + abstract override protected def afterAll(): Unit = { + EthChainId.unset() + super.afterAll() + } +} diff --git a/node/src/test/scala/com/wavesplatform/utx/UtxFailedTxsSpec.scala b/node/src/test/scala/com/wavesplatform/utx/UtxFailedTxsSpec.scala index aa6a0cf0d15..152ab155acf 100644 --- a/node/src/test/scala/com/wavesplatform/utx/UtxFailedTxsSpec.scala +++ b/node/src/test/scala/com/wavesplatform/utx/UtxFailedTxsSpec.scala @@ -12,8 +12,7 @@ import com.wavesplatform.lang.v1.ContractLimits import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.mining.MultiDimensionalMiningConstraint import com.wavesplatform.settings.{FunctionalitySettings, TestFunctionalitySettings} -import com.wavesplatform.state.diffs.produce -import com.wavesplatform.test.FlatSpec +import com.wavesplatform.test._ import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.transaction.assets.exchange.OrderType import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment diff --git a/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala b/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala index 798444a5202..db8068a6727 100644 --- a/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala @@ -2,10 +2,6 @@ package com.wavesplatform.utx import java.nio.file.{Files, Path} -import scala.collection.mutable.ListBuffer -import scala.concurrent.duration._ -import scala.util.Random - import cats.data.NonEmptyList import com.wavesplatform import com.wavesplatform._ @@ -14,18 +10,18 @@ import com.wavesplatform.block.{Block, SignedBlockHeader} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.consensus.TransactionsOrdering -import com.wavesplatform.database.{openDB, LevelDBWriter, TestStorageFactory} +import com.wavesplatform.database.{LevelDBWriter, TestStorageFactory, openDB} import com.wavesplatform.db.WithDomain import com.wavesplatform.events.UtxEvent import com.wavesplatform.features.BlockchainFeatures -import com.wavesplatform.history.{randomSig, settingsWithFeatures, DefaultWavesSettings} import com.wavesplatform.history.Domain.BlockchainUpdaterExt +import com.wavesplatform.history.{DefaultWavesSettings, randomSig, settingsWithFeatures} import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.directives.values.StdLibVersion.V6 import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript -import com.wavesplatform.lang.v1.compiler.{CompilerContext, ExpressionCompiler, TestCompiler} import com.wavesplatform.lang.v1.compiler.Terms.EXPR +import com.wavesplatform.lang.v1.compiler.{CompilerContext, ExpressionCompiler, TestCompiler} import com.wavesplatform.lang.v1.estimator.ScriptEstimatorV1 import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.mining._ @@ -33,23 +29,28 @@ import com.wavesplatform.settings._ import com.wavesplatform.state._ import com.wavesplatform.state.diffs._ import com.wavesplatform.state.utils.TestLevelDB -import com.wavesplatform.test.FreeSpec -import com.wavesplatform.transaction.{Asset, Transaction, _} +import com.wavesplatform.test.{FreeSpec, _} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.TxValidationError.{GenericError, SenderIsBlacklisted} -import com.wavesplatform.transaction.smart.{InvokeScriptTransaction, SetScriptTransaction} +import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.smart.script.ScriptCompiler -import com.wavesplatform.transaction.transfer._ import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer +import com.wavesplatform.transaction.transfer._ +import com.wavesplatform.transaction.utils.Signed +import com.wavesplatform.transaction.{Asset, Transaction, _} import com.wavesplatform.utils.Time import com.wavesplatform.utx.UtxPool.PackStrategy import monix.reactive.subjects.PublishSubject import org.iq80.leveldb.DB -import org.scalacheck.{Arbitrary, Gen} import org.scalacheck.Gen._ +import org.scalacheck.{Arbitrary, Gen} import org.scalamock.scalatest.MockFactory -import org.scalatest.concurrent.Eventually import org.scalatest.EitherValues +import org.scalatest.concurrent.Eventually + +import scala.collection.mutable.ListBuffer +import scala.concurrent.duration._ +import scala.util.Random private object UtxPoolSpecification { private val ignoreSpendableBalanceChanged = PublishSubject[(Address, Asset)]() @@ -127,7 +128,7 @@ class UtxPoolSpecification private def massTransferWithRecipients(sender: KeyPair, recipients: List[PublicKey], maxAmount: Long, time: Time) = { val amount = maxAmount / (recipients.size + 1) val transfers = recipients.map(r => ParsedTransfer(r.toAddress, amount)) - val minFee = FeeValidation.FeeConstants(TransferTransaction.typeId) + FeeValidation.FeeConstants(MassTransferTransaction.typeId) * transfers.size + val minFee = FeeValidation.FeeConstants(TransactionType.Transfer) + FeeValidation.FeeConstants(TransactionType.MassTransfer) * transfers.size val txs = for { fee <- chooseNum(minFee, amount) } yield MassTransferTransaction .selfSigned(1.toByte, sender, Waves, transfers, fee, time.getTimestamp(), ByteStr.empty) .explicitGet() @@ -136,7 +137,7 @@ class UtxPoolSpecification private def invokeScript(sender: KeyPair, dApp: Address, time: Time) = Gen.choose(500000L, 600000L).map { fee => - InvokeScriptTransaction.selfSigned(TxVersion.V1, sender, dApp, None, Seq.empty, fee, Waves, time.getTimestamp()).explicitGet() + Signed.invokeScript(TxVersion.V1, sender, dApp, None, Seq.empty, fee, Waves, time.getTimestamp()) } private def dAppSetScript(sender: KeyPair, time: Time) = { @@ -257,9 +258,9 @@ class UtxPoolSpecification txs.length, PoolDefaultMaxBytes, 1000, - Set(sender.toAddress.stringRepr), + Set(sender.toAddress.toString), Set.empty, - Set(sender.toAddress.stringRepr), + Set(sender.toAddress.toString), allowTransactionsFromSmartAccounts = true, allowSkipChecks = false ) @@ -453,7 +454,7 @@ class UtxPoolSpecification 1, Set.empty, Set.empty, - Set(sender2.toAddress.stringRepr, sender3.toAddress.stringRepr), + Set(sender2.toAddress.toString, sender3.toAddress.toString), allowTransactionsFromSmartAccounts = true, allowSkipChecks = allowSkipChecks ) @@ -525,7 +526,7 @@ class UtxPoolSpecification 1, Set.empty, Set.empty, - Set(sender2.toAddress.stringRepr, sender3.toAddress.stringRepr), + Set(sender2.toAddress.toString, sender3.toAddress.toString), allowTransactionsFromSmartAccounts = true, allowSkipChecks = allowSkipChecks ) diff --git a/node/src/test/scala/com/wavesplatform/utx/UtxPriorityPoolSpecification.scala b/node/src/test/scala/com/wavesplatform/utx/UtxPriorityPoolSpecification.scala index 5e82558c564..bbdd6948459 100644 --- a/node/src/test/scala/com/wavesplatform/utx/UtxPriorityPoolSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/utx/UtxPriorityPoolSpecification.scala @@ -82,6 +82,7 @@ class UtxPriorityPoolSpecification val tb = TestBlock.create(Nil) (blockchain.blockHeader _).when(*).returning(Some(SignedBlockHeader(tb.header, tb.signature))) (blockchain.transactionMeta _).when(*).returning(None) + (blockchain.resolveERC20Address _).when(*).returning(None) blockchain } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 43c637dee5a..208df902137 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,12 +1,12 @@ import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._ import sbt.Keys._ -import sbt.{Def, _} +import sbt._ //noinspection TypeAnnotation object Dependencies { // Node protobuf schemas private[this] val protoSchemasLib = - "com.wavesplatform" % "protobuf-schemas" % "1.4.0-SNAPSHOT" classifier "protobuf-src" intransitive () + "com.wavesplatform" % "protobuf-schemas" % "1.4.0" classifier "protobuf-src" intransitive () def akkaModule(module: String): ModuleID = "com.typesafe.akka" %% s"akka-$module" % "2.6.16" @@ -14,32 +14,34 @@ object Dependencies { private def kamonModule(module: String) = "io.kamon" %% s"kamon-$module" % "2.2.3" - private def jacksonModule(group: String, module: String) = s"com.fasterxml.jackson.$group" % s"jackson-$module" % "2.12.3" + private def jacksonModule(group: String, module: String, version: String = "2.12.3") = s"com.fasterxml.jackson.$group" % s"jackson-$module" % version private def catsModule(module: String, version: String = "2.6.1") = Def.setting("org.typelevel" %%% s"cats-$module" % version) + private def web3jModule(module: String) = "org.web3j" % module % "4.8.7" + def monixModule(module: String): Def.Initialize[ModuleID] = Def.setting("io.monix" %%% s"monix-$module" % "3.4.0") - val kindProjector = compilerPlugin("org.typelevel" % "kind-projector" % "0.13.0" cross CrossVersion.full) + val kindProjector = compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full) val akkaHttp = akkaHttpModule("akka-http") val jacksonModuleScala = jacksonModule("module", "module-scala").withCrossVersion(CrossVersion.Binary()) val googleGuava = "com.google.guava" % "guava" % "30.1.1-jre" val kamonCore = kamonModule("core") val machinist = "org.typelevel" %% "machinist" % "0.6.8" - val logback = "ch.qos.logback" % "logback-classic" % "1.2.5" + val logback = "ch.qos.logback" % "logback-classic" % "1.2.6" val janino = "org.codehaus.janino" % "janino" % "3.1.6" val asyncHttpClient = "org.asynchttpclient" % "async-http-client" % "2.12.3" val curve25519 = "com.wavesplatform" % "curve25519-java" % "0.6.4" - val nettyHandler = "io.netty" % "netty-handler" % "4.1.67.Final" + val nettyHandler = "io.netty" % "netty-handler" % "4.1.68.Final" val catsEffect = catsModule("effect", "2.1.3") val catsCore = catsModule("core") val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.7") - val scalaTest = "org.scalatest" %% "scalatest" % "3.2.9" % Test + val scalaTest = "org.scalatest" %% "scalatest" % "3.2.10" % Test - val sttp3 = "com.softwaremill.sttp.client3" % "core_2.13" % "3.3.13" + val sttp3 = "com.softwaremill.sttp.client3" % "core_2.13" % "3.3.14" // v1.67 introduced unnecessary conversions which slowed down hash computation by a factor of 3-4: // https://github.com/bcgit/bc-java/blob/r1rv67/core/src/main/java/org/bouncycastle/crypto/digests/KeccakDigest.java#L318 @@ -59,7 +61,7 @@ object Dependencies { jacksonModule("core", "annotations"), jacksonModule("core", "databind"), jacksonModule("dataformat", "dataformat-yaml"), - jacksonModule("dataformat", "dataformat-properties"), + jacksonModule("dataformat", "dataformat-properties", "2.12.5"), jacksonModule("jaxrs", "jaxrs-base"), jacksonModule("jaxrs", "jaxrs-json-provider"), kamonCore, @@ -98,7 +100,7 @@ object Dependencies { // explicit dependency can likely be removed when monix 3 is released monixModule("eval").value, catsCore.value.exclude("org.scala-js", "scalajs-library_2.13"), - ("com.lihaoyi" %%% "fastparse" % "2.3.2").exclude("org.scala-js", "scalajs-library_2.13"), + ("com.lihaoyi" %%% "fastparse" % "2.3.3").exclude("org.scala-js", "scalajs-library_2.13"), ("org.parboiled" %%% "parboiled" % "2.3.0").exclude("org.scala-js", "scalajs-library_2.13"), shapeless.value.exclude("org.scala-js", "scalajs-library_2.13"), ("org.typelevel" %% "cats-mtl-core" % "0.7.1").exclude("org.scalacheck", "scalacheck_2.13"), @@ -107,7 +109,10 @@ object Dependencies { bouncyCastleProvider, "com.wavesplatform" % "zwaves" % "0.1.0-SNAPSHOT", "com.wavesplatform" % "zwaves-bn256" % "0.1.5-SNAPSHOT", - "org.web3j" % "crypto" % "5.0.0" + web3jModule("crypto"), + web3jModule("abi"), + web3jModule("rlp"), + "com.esaulpaugh" % "headlong" % "5.4.0" ) ++ langCompilerPlugins.value ++ scalapbRuntime.value ++ protobuf.value ) @@ -120,7 +125,7 @@ object Dependencies { lazy val test = scalaTest +: Seq( logback, - "org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0", + "org.scalatestplus" %% "scalacheck-1-15" % "3.2.10.0", "org.scalacheck" %% "scalacheck" % "1.15.4", "org.mockito" % "mockito-all" % "1.10.19", "org.scalamock" %% "scalamock" % "5.1.0" @@ -135,7 +140,7 @@ object Dependencies { private def leveldbJava(module: String = "") = "org.iq80.leveldb" % s"leveldb${if (module.nonEmpty) "-" else ""}$module" % "0.12" private[this] val levelDBJNA = { - val levelDbVersion = "1.23.0" + val levelDbVersion = "1.23.1" Seq( "com.wavesplatform.leveldb-jna" % "leveldb-jna-core" % levelDbVersion, "com.wavesplatform.leveldb-jna" % "leveldb-jna-native" % levelDbVersion, @@ -148,12 +153,12 @@ object Dependencies { ("org.rudogma" %%% "supertagged" % "2.0-RC2").exclude("org.scala-js", "scalajs-library_2.13"), "commons-net" % "commons-net" % "3.8.0", "org.apache.commons" % "commons-lang3" % "3.12.0", - "com.iheart" %% "ficus" % "1.5.0", + "com.iheart" %% "ficus" % "1.5.1", "net.logstash.logback" % "logstash-logback-encoder" % "6.6" % Runtime, kamonCore, kamonModule("system-metrics"), kamonModule("influxdb"), - "org.influxdb" % "influxdb-java" % "2.21", + "org.influxdb" % "influxdb-java" % "2.22", googleGuava, "com.google.code.findbugs" % "jsr305" % "3.0.2" % Compile, // javax.annotation stubs "com.typesafe.play" %% "play-json" % "2.9.2", diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/ErrorMessageEnvironment.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/ErrorMessageEnvironment.scala index af5e44720fc..855fab9604e 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/ErrorMessageEnvironment.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/ErrorMessageEnvironment.scala @@ -31,6 +31,7 @@ case class ErrorMessageEnvironment[F[_]](message: String) extends Environment[F] override def txId: ByteStr = unavailable override def transferTransactionFromProto(b: Array[Byte]): F[Option[Tx.Transfer]] = unavailable override def addressFromString(address: String): Either[String, Recipient.Address] = unavailable + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = unavailable override def accountScript(addressOrAlias: Recipient): F[Option[Script]] = unavailable override def callScript( dApp: Address, diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/WebEnvironment.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/WebEnvironment.scala index 4cee90bf652..c8826216d07 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/WebEnvironment.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/WebEnvironment.scala @@ -29,7 +29,7 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend private val mappings = ImplicitMappings(settings.chainId) import mappings._ - override implicit def chainId: Byte = settings.chainId + override implicit def chainId: Byte = settings.chainId override def tthis: Environment.Tthis = Coproduct[Environment.Tthis](Address(ByteStr.decodeBase58(settings.address).get)) override def height: Future[Long] = @@ -44,18 +44,18 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend implicit val assetInfoResponseDecoder: Decoder[AssetInfoResponse] = new Decoder[AssetInfoResponse] { final def apply(c: HCursor): Decoder.Result[AssetInfoResponse] = for { - assetId <- c.downField("assetId").as[ByteString] - name <- c.downField("name").as[String] - description <- c.downField("description").as[String] - quantity <- c.downField("quantity").as[Long] - decimals <- c.downField("decimals").as[Int] - issuer <- c.downField("issuer").as[ByteString] - issuerPublicKey <- c.downField("issuerPublicKey").as[ByteString] - reissuable <- c.downField("reissuable").as[Boolean] - scripted <- c.downField("scripted").as[Boolean] + assetId <- c.downField("assetId").as[ByteString] + name <- c.downField("name").as[String] + description <- c.downField("description").as[String] + quantity <- c.downField("quantity").as[Long] + decimals <- c.downField("decimals").as[Int] + issuer <- c.downField("issuer").as[ByteString] + issuerPublicKey <- c.downField("issuerPublicKey").as[ByteString] + reissuable <- c.downField("reissuable").as[Boolean] + scripted <- c.downField("scripted").as[Boolean] minSponsoredAssetFee <- c.downField("minSponsoredAssetFee").as[Option[Long]] } yield { - new AssetInfoResponse(assetId, name, description, quantity, decimals, issuer, issuerPublicKey, reissuable, scripted, minSponsoredAssetFee) + new AssetInfoResponse(assetId, name, description, quantity, decimals, issuer, issuerPublicKey, reissuable, scripted, minSponsoredAssetFee) } } override def assetInfoById(id: Array[Byte]): Future[Option[ScriptAssetInfo]] = @@ -75,12 +75,12 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend implicit val blockInfoResponseDecoder: Decoder[BlockInfoResponse] = new Decoder[BlockInfoResponse] { final def apply(c: HCursor): Decoder.Result[BlockInfoResponse] = for { - timestamp <- c.downField("timestamp").as[Long] - height <- c.downField("height").as[Int] - nxt <- c.downField("nxt-consensus").as[NxtData] - generator <- c.downField("generator").as[ByteString] + timestamp <- c.downField("timestamp").as[Long] + height <- c.downField("height").as[Int] + nxt <- c.downField("nxt-consensus").as[NxtData] + generator <- c.downField("generator").as[ByteString] generatorPublicKey <- c.downField("generatorPublicKey").as[ByteString] - vrf <- c.downField("VRF").as[Option[ByteString]] + vrf <- c.downField("VRF").as[Option[ByteString]] } yield BlockInfoResponse(timestamp, height, nxt, generator, generatorPublicKey, vrf) } @@ -114,9 +114,9 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend } override def accountBalanceOf( - recipient: Recipient, - assetId: Option[Array[Byte]] - ): Future[Either[String, Long]] = + recipient: Recipient, + assetId: Option[Array[Byte]] + ): Future[Either[String, Long]] = for { address <- extractAddress(recipient) entity <- getEntity[Either[String, *], BalanceResponse, Long]((assetId match { @@ -126,8 +126,8 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend } yield entity override def accountWavesBalanceOf( - recipient: Recipient - ): Future[Either[String, Environment.BalanceDetails]] = + recipient: Recipient + ): Future[Either[String, Environment.BalanceDetails]] = for { address <- extractAddress(recipient) entity <- client.get[Either[String, *], Environment.BalanceDetails](s"/addresses/balance/details/$address") @@ -142,18 +142,26 @@ private[repl] case class WebEnvironment(settings: NodeConnectionSettings) extend override def addressFromString(address: String): Either[String, Address] = mappings.addressFromString(address) - override def inputEntity: InputEntity = ??? - override def transactionById(id: Array[Byte]): Future[Option[Tx]] = ??? - override def multiPaymentAllowed: Boolean = ??? - override def txId: ByteStr = ??? + override def addressFromPublicKey(publicKey: ByteStr): Either[String, Address] = + mappings.addressFromPublicKey(publicKey) + + override def inputEntity: InputEntity = ??? + override def transactionById(id: Array[Byte]): Future[Option[Tx]] = ??? + override def multiPaymentAllowed: Boolean = ??? + override def txId: ByteStr = ??? override def transferTransactionFromProto(b: Array[Byte]): Future[Option[Tx.Transfer]] = ??? - private def getEntity[F[_]: Functor: ResponseWrapper, A : Decoder, B](url: String)(implicit ev: A => B): Future[F[B]] = + private def getEntity[F[_]: Functor: ResponseWrapper, A: Decoder, B](url: String)(implicit ev: A => B): Future[F[B]] = client.get[F, A](url).map(_.map(ev)) - override def accountScript(addressOrAlias: Recipient): Future[Option[Script]] = ??? - override def callScript(dApp: Address, func: String, args: List[EVALUATED], payments: Seq[(Option[Array[Byte]], Long)], availableComplexity: Int, reentrant: Boolean): Coeval[Future[(Either[ValidationError, EVALUATED], Int)]] = ??? + override def accountScript(addressOrAlias: Recipient): Future[Option[Script]] = ??? + override def callScript(dApp: Address, + func: String, + args: List[EVALUATED], + payments: Seq[(Option[Array[Byte]], Long)], + availableComplexity: Int, + reentrant: Boolean): Coeval[Future[(Either[ValidationError, EVALUATED], Int)]] = ??? } object WebEnvironment { diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ChainDependentMapper.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ChainDependentMapper.scala index fcd5fddd570..f1fe333fdd4 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ChainDependentMapper.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ChainDependentMapper.scala @@ -78,7 +78,7 @@ private[node] class ChainDependentMapper(chainId: Byte) { vrf = b.VRF.map(_.byteStr) ) - private def pkToAddress(publicKey: ByteString): ByteStr = { + def pkToAddress(publicKey: ByteString): ByteStr = { val withoutChecksum = ByteBuffer.allocate(1 + 1 + HashLength) .put(AddressVersion.toByte) diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ImplicitMappings.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ImplicitMappings.scala index 8e67212411e..0609c8fb047 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ImplicitMappings.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/ImplicitMappings.scala @@ -1,5 +1,6 @@ package com.wavesplatform.lang.v1.repl.node.http.response +import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.v1.repl.node.http.response.model._ import com.wavesplatform.lang.v1.traits.domain.Recipient.Address import com.wavesplatform.lang.v1.traits.domain.{BlockInfo, ScriptAssetInfo, Tx} @@ -43,4 +44,7 @@ case class ImplicitMappings(chainId: Byte) { implicit val addressFromString: String => Either[String, Address] = chainDependentMapper.addressFromString + + implicit val addressFromPublicKey: ByteStr => Either[String, Address] = + b => Right(Address(chainDependentMapper.pkToAddress(ByteString(b.arr)))) } diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/TransferTxSerializer.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/TransferTxSerializer.scala index c02bce51a80..d4b29af18d0 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/TransferTxSerializer.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/node/http/response/TransferTxSerializer.scala @@ -82,10 +82,10 @@ object TransferTxSerializer { val feeAssetAmount = feeAssetId.fold(feeAmount)(feeAmount.withAssetId) val transaction = new SignedTransaction( - Some(Transaction(chainId, sender, Some(feeAssetAmount), timestamp, version, data)), + SignedTransaction.Transaction.WavesTransaction(Transaction(chainId, sender, Some(feeAssetAmount), timestamp, version, data)), proofs ) - transaction.getTransaction.toByteArray + transaction.getWavesTransaction.toByteArray } private def serializeArrayWithLength(b: Array[Byte]): Array[Byte] = {