コード例 #1
0
 public static async Task <DryRunContractReturn> DeserializeAsync(Account account, Contract c, string function, DryRunResult obj, CancellationToken token)
 {
     if (obj != null && obj.CallObj != null && !string.IsNullOrEmpty(obj.CallObj.ReturnType))
     {
         await DeserializeAsync(account, c, function, obj.CallObj, token).ConfigureAwait(false);
     }
     return(new DryRunContractReturn(obj, c));
 }
コード例 #2
0
        public void CallPayAndSplitMethod()
        {
            Account    account = nativeClient.GetAccount(baseKeyPair.PublicKey);
            BigInteger balanceRecipient1;
            BigInteger balanceRecipient2;
            BigInteger balanceRecipient3;

            try
            {
                balanceRecipient1 = nativeClient.GetAccount(initialReceiver1.PublicKey).Balance;
                balanceRecipient2 = nativeClient.GetAccount(initialReceiver2.PublicKey).Balance;
                balanceRecipient3 = nativeClient.GetAccount(initialReceiver3.PublicKey).Balance;
                // if one of the accounts wasn't active we get an error and know that the
                // accounts
                // don't have any balance
            }
            catch (Exception)
            {
                balanceRecipient1 = 0;
                balanceRecipient2 = 0;
                balanceRecipient3 = 0;
            }

            ulong    nonce        = account.Nonce + 1;
            decimal  paymentValue = "1".ToAettos(Unit.AE);
            Calldata calldata     = nativeClient.EncodeCalldata(logger, paymentSplitterSource, "payAndSplit", null);

            logger.LogInformation("Contract ID: " + localDeployedContractId);
            List <Dictionary <AccountParameter, object> > accounts = new List <Dictionary <AccountParameter, object> >();
            Dictionary <AccountParameter, object>         ac       = new Dictionary <AccountParameter, object>()
            {
                { AccountParameter.PUBLIC_KEY, baseKeyPair.PublicKey }
            };

            accounts.Add(ac);
            DryRunResults dryRunResults = nativeClient.PerformDryRunTransactions(logger, accounts, null, new List <UnsignedTx>()
            {
                nativeClient.CreateUnsignedContractCallTx(logger, baseKeyPair.PublicKey, nonce, calldata.CallData, null, localDeployedContractId, new BigInteger(paymentValue))
            });

            logger.LogInformation("callContractAfterDryRunOnLocalNode: " + JsonConvert.SerializeObject(dryRunResults));
            Assert.AreEqual(1, dryRunResults.Results.Count);
            DryRunResult dryRunResult = dryRunResults.Results.First();

            Assert.AreEqual("ok", dryRunResult.Result);
            ContractCallTransaction contractAfterDryRunTx = nativeClient.CreateContractCallTransaction(Constants.BaseConstants.ABI_VERSION, calldata.CallData, localDeployedContractId, dryRunResult.CallObj.GasUsed, dryRunResult.CallObj.GasPrice, nonce, baseKeyPair.PublicKey, 0);

            contractAfterDryRunTx.Model.Amount = new BigInteger(paymentValue);

            UnsignedTx unsignedTxNative = contractAfterDryRunTx.CreateUnsignedTransaction();
            Tx         signedTxNative   = nativeClient.SignTransaction(unsignedTxNative, baseKeyPair.PrivateKey);

            // post the signed contract call tx
            PostTxResponse postTxResponse = nativeClient.PostTx(logger, signedTxNative);

            Assert.AreEqual(postTxResponse.TXHash, Utils.Encoding.ComputeTxHash(signedTxNative.TX));
            logger.LogInformation("CreateContractTx hash: " + postTxResponse.TXHash);

            // we wait until the tx is available and the payment should have been splitted
            TxInfoObject txInfoObject = nativeClient.WaitForTxInfoObject(logger, postTxResponse.TXHash);

            logger.LogInformation("PayAndSplit transaction - hash " + postTxResponse.TXHash + " - " + txInfoObject);
            if ("revert".Equals(txInfoObject.CallInfo.ReturnType))
            {
                Assert.Fail("transaction reverted: " + nativeClient.DecodeCalldata(logger, txInfoObject.CallInfo.ReturnValue, "string"));
            }

            Assert.AreEqual(balanceRecipient1 + new BigInteger(paymentValue * 0.4m), nativeClient.GetAccount(initialReceiver1.PublicKey).Balance);
            Assert.AreEqual(balanceRecipient2 + new BigInteger(paymentValue * 0.4m), nativeClient.GetAccount(initialReceiver2.PublicKey).Balance);
            Assert.AreEqual(balanceRecipient3 + new BigInteger(paymentValue * 0.2m), nativeClient.GetAccount(initialReceiver3.PublicKey).Balance);
        }
コード例 #3
0
 internal DryRunContractReturn(DryRunResult res, Contract c) : base(res.CallObj, null, c)
 {
     Type   = res.Type;
     Result = res.Result;
     Reason = res.Reason;
 }