public static UnsignedTx CreateUnsignedContractCallTx(this FlatClient client, ILogger logger, string callerId, ulong nonce, string calldata, BigInteger?gasPrice, string contractId, BigInteger amount) { ushort abiVersion = Constants.BaseConstants.ABI_VERSION; ulong ttl = 0; ulong gas = 1579000; ContractCallTransaction contractTx = client.CreateContractCallTransaction(abiVersion, calldata, contractId, gas, gasPrice ?? Constants.BaseConstants.MINIMAL_GAS_PRICE, nonce, callerId, ttl); contractTx.Model.Amount = amount; return(contractTx.CreateUnsignedTransaction()); }
private UnsignedTx CreateUnsignedContractCallTx(ulong nonce, string calldata, BigInteger?gasPrice) { string callerId = baseKeyPair.PublicKey; ushort abiVersion = Constants.BaseConstants.ABI_VERSION; ulong ttl = 0; ulong gas = 1579000; ContractCallTransaction contractTx = nativeClient.CreateContractCallTransaction(abiVersion, calldata, localDeployedContractId, gas, gasPrice ?? Constants.BaseConstants.MINIMAL_GAS_PRICE, nonce, callerId, ttl); return(contractTx.CreateUnsignedTransaction()); }
public void BuildCallContractTransactionTest() { Account account = nativeClient.GetAccount(baseKeyPair.PublicKey); string callerId = baseKeyPair.PublicKey; ushort abiVersion = Constants.BaseConstants.ABI_VERSION; ulong ttl = 20000; ulong gas = 1000; BigInteger gasPrice = 1000000000; ulong nonce = account.Nonce + 1; string callContractCalldata = TestConstants.EncodedServiceCall; ContractCallTransaction contractTx = nativeClient.CreateContractCallTransaction(abiVersion, callContractCalldata, localDeployedContractId, gas, gasPrice, nonce, callerId, ttl); ContractCallTransaction contractTxDebug = debugClient.CreateContractCallTransaction(abiVersion, callContractCalldata, localDeployedContractId, gas, gasPrice, nonce, callerId, ttl); contractTx.Fee = contractTxDebug.Fee = 1454500000000000; UnsignedTx unsignedTxNative = contractTx.CreateUnsignedTransaction(); logger.LogInformation("CreateContractTx hash (native unsigned): " + unsignedTxNative.TX); UnsignedTx unsignedTxDebug = contractTxDebug.CreateUnsignedTransaction(); logger.LogInformation("CreateContractTx hash (debug unsigned): " + unsignedTxDebug.TX); Assert.AreEqual(unsignedTxNative.TX, unsignedTxDebug.TX); }
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); }