public static RawTransactionDTO FromRawTransaction(RawTransaction item) { return(new RawTransactionDTO() { Id = item.Id, }); }
public void CanDetectAddressMismatch() { RawTransaction rawTx = GetExpectedRawTransaction(true); var mismatchedAddress = new byte[] { 0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57, 0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0x01, }; var signature = new byte[] { 0x30, 0x45, 0x02, 0x21, 0x00, 0xc0, 0xd3, 0xa0, 0xa5, 0x77, 0x4e, 0x77, 0x62, 0x08, 0xd5, 0x1b, 0xfa, 0x06, 0xc5, 0xd0, 0x13, 0x75, 0x31, 0x49, 0xed, 0xb5, 0x67, 0x4a, 0xdc, 0x15, 0xe5, 0x63, 0xf2, 0x64, 0xe5, 0x37, 0x7d, 0x02, 0x20, 0x47, 0xaf, 0x52, 0x70, 0xec, 0x6f, 0x9a, 0x99, 0xc3, 0x33, 0x4c, 0x0a, 0x9c, 0x97, 0x28, 0x41, 0x6f, 0xd8, 0xd7, 0xfc, 0x11, 0x54, 0x49, 0x4b, 0x09, 0xed, 0x83, 0x92, 0xd1, 0xad, 0xc5, 0xa4, }; var rawTxWithMismatchedAddress = new RawTransaction( sender: mismatchedAddress, recipient: rawTx.Recipient, publicKey: rawTx.PublicKey, timestamp: rawTx.Timestamp, actions: rawTx.Actions, signature: signature ); var tx = new Transaction <BaseAction>(rawTxWithMismatchedAddress); Assert.Throws <InvalidTxPublicKeyException>(() => { tx.Validate(); }); }
public void DetectInvalidTxSignature() { RawTransaction rawTx = new RawTransaction( 0, _fx.TxFixture.Address1.ByteArray, _fx.Genesis.Hash.ByteArray, ImmutableArray <ImmutableArray <byte> > .Empty, _fx.TxFixture.PublicKey1.Format(false).ToImmutableArray(), DateTimeOffset.UtcNow.ToString( "yyyy-MM-ddTHH:mm:ss.ffffffZ", CultureInfo.InvariantCulture ), ImmutableArray <IValue> .Empty, new byte[10].ToImmutableArray() ); var invalidTx = new Transaction <DumbAction>(rawTx); Assert.Throws <InvalidTxSignatureException>(() => MineNext( MineGenesisBlock <DumbAction>(_fx.GetHashAlgorithm, _fx.Miner), _fx.GetHashAlgorithm, new List <Transaction <DumbAction> > { invalidTx, } ) ); }
public void CanConvertFromRawTransaction() { RawTransaction rawTx = GetExpectedRawTransaction(true); var tx = new Transaction <BaseAction>(rawTx); tx.Validate(); }
public async Task <SubmitTransactionResponse> TransferCoins(Account sender, string recipientAddress, ulong amount, ulong gasUnitPrice, ulong maxGasAmount) { var program = new Program(); program.Code = Convert.FromBase64String(Constant.ProgamBase64Codes.PeerToPeerTxn).ToByteString(); program.Arguments.Add(new TransactionArgument { Type = TransactionArgument.Types.ArgType.Address, Data = recipientAddress.ToByteString() }); program.Arguments.Add(new TransactionArgument { Type = TransactionArgument.Types.ArgType.U64, Data = amount.ToBytes().Reverse().ToByteString() }); var transaction = new RawTransaction(); transaction.ExpirationTime = (ulong)Math.Floor((decimal)DateTimeOffset.Now.ToUnixTimeMilliseconds() / 1000) + 100; transaction.GasUnitPrice = gasUnitPrice; transaction.MaxGasAmount = maxGasAmount; transaction.SequenceNumber = (await QueryBalance(sender.Address)).ElementAt(0).SequenceNumber; transaction.Program = program; transaction.SenderAccount = sender.Address.ToByteString(); var request = new SubmitTransactionRequest(); request.SignedTxn = new SignedTransaction { RawTxnBytes = transaction.SenderAccount, SenderPublicKey = sender.PublicKey, SenderSignature = sender.Signature }; return(await acClient.SubmitTransactionAsync(request)); }
public JsonResult GetTransferTransactionInfo([FromBody] JObject jsonData) { return(DoWithRetry(GetRetryValueFromJson(jsonData), retryCount => { try { var txId = jsonData.GetValue("txId").Value <string>(); bool findBlock = jsonData.ContainsKey("findBlock") && jsonData.GetValue("findBlock").Value <bool>(); LuxApiExtensions api = new LuxApiExtensions((NeoRPC)LuxApiFactory.GetLuxApi()); RawTransaction transaction = api.GetTransferTransaction(txId, findBlock); if (transaction != null) { dynamic result = new JObject(); result.txId = transaction.TxID; result.block = transaction.Block; result.asset = transaction.Contract; result.addrFrom = transaction.From; result.addrTo = transaction.To; result.amount = transaction.Amount; return JsonResultObject(result); } } catch (Exception e) { Log.Error(e.Message + "\n" + e.StackTrace); return JsonError($"Unable to get transaction information, {e.Message}"); } return null; })); }
private RawTransaction GetRawTransferTransaction(DataNode notificationData, string txId, bool findBlock) { var status = notificationData.GetNode("state"); var statusData = status.GetNodeByIndex(status.ChildCount - 1); var eventType = HexToString(statusData.GetNodeByIndex(0).GetString("value")); /** Only get transfer transactions */ if (!eventType.Equals("transfer")) { return(null); } var resultTx = new RawTransaction { TxID = txId, Contract = notificationData.GetString("contract"), EventType = HexToString(statusData.GetNodeByIndex(0).GetString("value")), From = new UInt160(statusData.GetNodeByIndex(1).GetString("value").HexToBytes()).ToAddress(), To = new UInt160(statusData.GetNodeByIndex(2).GetString("value").HexToBytes()).ToAddress() }; var amountValue = statusData.GetNodeByIndex(3).GetString("value"); var isAmountArray = statusData.GetNodeByIndex(3).GetString("type").Equals("ByteArray"); resultTx.Amount = isAmountArray ? new BigInteger(amountValue.HexToBytes()) : BigInteger.Parse(amountValue); if (findBlock) { resultTx.Block = GetTransactionBlock(txId.Substring(2)); } return(resultTx); }
public void RLPHexParser() { // based on https://github.com/vechain/thor/blob/d9f618b4974733e04949f7b9424001f5bd572baa/tx/transaction_test.go#L20 string to = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; var realTransaction = new RawTransaction { chainTag = 1, blockRef = "00000000aabbccdd", expiration = 32, clauses = new[] { new RawClause(to, "10000", "0x000000606060", false), new RawClause(to, "20000", "0x000000606060", false) }, gasPriceCoef = 128, gas = 21000, dependsOn = null, nonce = "12345678" }; var rlpTransaction = new RlpTransaction(realTransaction).AsRlpValues(); var vetEncoded = RlpEncoder.Encode(rlpTransaction); var out1 = vetEncoded.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); Assert.Equal("0xf8550184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec080", out1); var vethash = Hash.HashBlake2B(vetEncoded); // Should be 2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478 var vethashReadable = vethash.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); Assert.Equal("0x2a1c25ce0d66f45276a5f308b99bf410e2fc7d5b6ea37a49f2ab9f1da9446478", vethashReadable); }
public static RawTransaction Decode(string hexRawTransaction) { if (!StringUtils.IsHex(hexRawTransaction)) { return(null); } var rawTxBytes = ByteUtils.ToByteArray(hexRawTransaction); var list = RlpDecoder.Decode(rawTxBytes); if (list == null) { return(null); } var rlpContent = list.Values; //It should only has one element. if (rlpContent.Count != 1) { return(null); } var rawTransaction = new RawTransaction(); var listValues = ((RlpList)rlpContent[0]).Values; for (int index = 0; index < listValues.Count; index++) { FillTransaction(rawTransaction, listValues, index); } return(rawTransaction); }
public async Task <string> SendTransactionPtoP( byte[] senderPrivateKey, string sender, string reciver, ulong amount) { var senderAccount = await GetAccountInfoAsync(sender); RawTransaction rawTr = new RawTransaction() { ExpirationTime = (ulong)DateTimeOffset.UtcNow.AddSeconds(60).ToUnixTimeSeconds(), GasUnitPrice = 0, MaxGasAmount = 29925, SequenceNumber = senderAccount.SequenceNumber }; rawTr.Program = new Program(); rawTr.Program.Code = ByteString.CopyFrom(Utility.PtPTrxBytecode); rawTr.Program.Arguments.Add(new TransactionArgument() { Type = TransactionArgument.Types.ArgType.Address, Data = ByteString.CopyFrom(reciver.HexStringToByteArray()) }); rawTr.Program.Arguments.Add(new TransactionArgument() { Type = TransactionArgument.Types.ArgType.U64, Data = ByteString.CopyFrom(BitConverter.GetBytes(amount)) }); rawTr.SenderAccount = ByteString.CopyFrom(sender.HexStringToByteArray()); var result = await _service.SendTransactionAsync(senderPrivateKey, rawTr); return(result.ToString()); }
public async Task <string> SendTransaction( byte[] privateKey, RawTransaction rawTransaction) { var result = await _service.SendTransactionAsync(privateKey, rawTransaction); return(result.ToString()); }
/// <summary> /// /// </summary> /// <param name="transaction"></param> /// <returns></returns> private bool isValidChangeTx(TransactionDetail transaction) { // amount check if (transaction.Amount > ticketCost) { return(false); } // category check //if (transaction.Category != "send") if (transaction.Category != "receive") { return(false); } // adress check //if (btc.ValidateAddress(transaction.Address).IsMine) if (!btc.ValidateAddress(transaction.Address).IsMine) { return(false); } // check if it's linked to a ticket transaction RawTransaction rawtransaction = btc.GetRawTransactionObject(transaction.TxId); string rawtransactionTxId = rawtransaction.Vin[0].TxId; if (!getTransactionOfType(Type.Ticket).Any(t => t.TxId == rawtransactionTxId)) { return(false); } return(true); }
public async Task CreateTransaction() { var chainTag = await _vechainClient.GetChainTag(); var blockref = "0x001a7d4448f0948b"; // await _vechainClient.GetLatestBlockRef(); var trans = RawTransaction.CreateUnsigned(chainTag, blockref, new[] { new RawClause("0xd3ae78222beadb038203be21ed5ce7c9b1bff602", "1", "", false) }, "12345678", 720, 0, 21000, ""); var rlpTransaction = new RlpTransaction(trans).AsRlpValues(); var asHexString = RlpEncoder.Encode(rlpTransaction); var rawTransaction = asHexString.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); // 0x44C3e1Ce754129Eb74522E3CA5695B7Cfa6d2B19 var privateKey = new BigInteger("0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65".HexStringToByteArray()); var publicKey = ECDSASign.PublicKeyFromPrivate(privateKey); var customKey = new ECKeyPair(privateKey, publicKey); var result = trans.Sign(customKey).CalculateTxId(new Address(customKey.GetHexAddress())).Transfer(_vechainClient); }
public async Task <AdmissionControl.SubmitTransactionResponse> SendTransactionAsync( byte[] privateKey, RawTransaction rawTransaction) { var bytesTrx = rawTransaction.ToByteArray(); LibraHasher libraHasher = new LibraHasher(EHashType.RawTransaction); var hash = libraHasher.GetHash(bytesTrx); var key = Key.Import(SignatureAlgorithm.Ed25519, privateKey, KeyBlobFormat.RawPrivateKey); AdmissionControl.SubmitTransactionRequest req = new AdmissionControl.SubmitTransactionRequest(); req.SignedTxn = new SignedTransaction(); req.SignedTxn.RawTxnBytes = ByteString.CopyFrom(bytesTrx); req.SignedTxn.SenderPublicKey = ByteString.CopyFrom(key.Export(KeyBlobFormat.RawPublicKey)); var sig = SignatureAlgorithm.Ed25519.Sign(key, hash); req.SignedTxn.SenderSignature = ByteString.CopyFrom(sig); var result = await _client.SubmitTransactionAsync( req, new Metadata()); return(result); }
public static byte[] EncodeRawTransaction(RawTransaction rawTransaction) { var values = asRlpValues(rawTransaction); var rlpList = new RlpList(values); return(RlpEncoder.Encode(rlpList)); }
public RawTransaction Build() { var rawTransaction = new RawTransaction(); BeanRefUtils.SetFieldValue(rawTransaction, _refValue); rawTransaction.Clauses = _clauses; return(rawTransaction); }
public static TransferTransaction ToTransfer(this RawTransaction raw) { return(SetCommonFields(new TransferTransaction { FromAccountId = raw.FromAccount?.Id ?? 0, ToAccountId = raw.ToAccount?.Id ?? 0 }, raw)); }
public async Task <Transaction> SendAsync(string publicKey, string secretPhrase, string recipient, string recipientPublicKey, decimal amount, Message?comment = null) { RawTransaction raw = await SendMoneyAsync(publicKey, secretPhrase, recipient, recipientPublicKey, amount, comment ?? string.Empty); BroadcastedTransaction broadcasted = await BroadcastTransactionAsync(JsonConvert.SerializeObject(raw.Details.Attachment), Convert.BytesToHex(Convert.UnsignedBytesToSigned(Convert.HexToBytes(raw.Bytes), secretPhrase))); return(raw.Prepare(broadcasted, recipientPublicKey)); }
/// <summary> /// Sign the transaction by RLP encoding it and calculating the signature of the resulting byte[]. /// </summary> /// <param name="transaction">The transaction that will be signed.</param> /// <param name="key">The key with which the transaction will be signed.</param> /// <returns>The signed transaction</returns> public static RawTransaction Sign(this RawTransaction transaction, ECKeyPair key) { var rlp = RlpEncoder.Encode(new RlpTransaction(transaction).AsRlpValues()); SignatureData signatureData = ECDSASign.SignMessage(rlp, key, true); transaction.signature = signatureData.ToByteArray(); return(transaction); }
async static Task Yes() { BitcoinClient bitcoinClient = new BitcoinClient("http://127.0.0.1:8332", "alice:pass"); RawTransaction rawTransaction = new RawTransaction(bitcoinClient); string hex = "020000000001012ec9d65ba255e44b85810beac4cad16418fa5c263a1d9f45ab03a4001edf24650000000000ffffffff01e803000000000000160014f998998746cb1bb34377075a79d0d9c494569d2102473044022039fc28874fc1fbf14c4297a4160acfb9793d341f32c61ccc27818fff5d47433102203c091fa28c69e3b2a337b560e20823f0a1b0aa7069d5f98dbe325a6807caa19e012102fc6958eee747f2471d4f34d5e4d7639de5c1abc32dbf05d876554cd7af66608900000000"; string sendrawtransaction = await rawTransaction.SendRawTransaction(hex); Console.WriteLine(sendrawtransaction); }
/// <summary> /// /// </summary> /// <param name="allTransactions"></param> private void getChangeTxs(List <TransactionDetail> allTransactions) { lblStatus.Content = string.Format("getChangeTxs[{0}]", allTransactions.Count); //AddLine("Parsing[ChangeTx]: {0}", allTransactions.Count); foreach (TransactionDetail transaction in allTransactions) { if (isValidChangeTx(transaction)) { Transaction changeTx = getTransactionOfType(Type.Change).Where(t => t.TxId == transaction.TxId).FirstOrDefault(); if (changeTx == null) { changeTx = new Transaction() { Account = transaction.Account, Address = transaction.Address, Amount = transaction.Amount, BlockHash = transaction.BlockHash, BlockIndex = transaction.BlockIndex, BlockTime = transaction.BlockTime, Category = transaction.Category, Confirmations = 0, Fee = transaction.Fee, Time = transaction.Time, TimeReceived = transaction.TimeReceived, TxId = transaction.TxId, Type = Type.Change, State = State.Open }; RawTransaction rawtransaction = btc.GetRawTransactionObject(transaction.TxId); string rawtransactionTxId = rawtransaction.Vin[0].TxId; Transaction ticketTx = getTransactionOfType(Type.Ticket).Where(t => t.TxId == rawtransactionTxId).First(); ticketTx.ChildTx = changeTx; database.SaveChanges(); AddLine("{0}[{1}]: State changed to {2} ({3})", changeTx.GetType(), smallHashTag(changeTx.TxId), changeTx.State, changeTx.Type); } else if (changeTx.State == State.Open && transaction.Confirmations >= transactionConfirmations) { // fill the missing values ... Block block = btc.GetBlock(transaction.BlockHash); changeTx.Blocks = block; changeTx.Confirmations = transaction.Confirmations; changeTx.State = State.Valid; database.SaveChanges(); AddLine("{0}[{1}]: State changed to {2} ({3})", changeTx.GetType(), smallHashTag(changeTx.TxId), changeTx.State, changeTx.Type); } } } }
public IActionResult Post([FromBody] RawTransactionDTO item) { var RawTransaction = new RawTransaction() { //Title = item.Title, //Description = item.Description }; _repository.Add(RawTransaction); return(Ok(RawTransactionDTO.FromRawTransaction(RawTransaction))); }
/// <summary> /// Sign the raw transaction. /// </summary> /// <param name="rawTransaction"> /// <seealso cref="RawTransaction"/> </param> /// <returns> <seealso cref="RawTransaction"/> with signature. </returns> public static RawTransaction Sign(RawTransaction rawTransaction, ECKeyPair keyPair) { if (rawTransaction == null) { throw ClientArgumentException.Exception("raw transaction object is invalid"); } var signature = ECDSASign.SignMessage(rawTransaction.Encode(), keyPair, true); var signBytes = signature.ToByteArray(); rawTransaction.Signature = signBytes; return(rawTransaction); }
public static void ShouldBeLike(this RawTransaction createdTransaction, Transaction transaction) { createdTransaction.Id.Should().BePositive(); createdTransaction.Amount.Should().Be(transaction.Amount); createdTransaction.Description.Should().Be(transaction.Description); createdTransaction.Tags.Should().Be(transaction.Tags ?? ""); createdTransaction.Type.Should().Be(transaction.Type); createdTransaction.TransactionType.Should().Be(transaction.Type); createdTransaction.SortDate.Should().Be(transaction.Date.Date); createdTransaction.IsPending.Should().Be(false); createdTransaction.IsFutureDated.Should().Be(false); }
private async Task <int?> ImportTransaction(string authid, RawTransaction transaction) { try { await using var connection = await _databaseConnectionFactory.GetConnection(); var sql = @"INSERT INTO transaction ( auth_id, transaction_id, transaction_date, processed_date, reference, description, value, type) VALUES ( @AuthId, @TransactionId, @TransactionDate, @ProcessedDate, @Reference, @Description, @Value, @Type) RETURNING id"; var transactionId = await connection.ExecuteScalarAsync <int>(sql, new { AuthId = authid, transaction.TransactionId, transaction.TransactionDate, transaction.ProcessedDate, transaction.Reference, transaction.Description, transaction.Value, transaction.Type, }); return(transactionId); } catch (PostgresException e) { if (e.IsDuplicateException()) { Console.WriteLine($"Duplicate: {transaction.TransactionId}"); return(null); } throw new Exception(e.Message, e); } }
/// <summary> /// Transfer the transaction to the blockchain to be included in the next block. /// </summary> /// <param name="rawTransaction">The transaction to be included in the blockchain</param> /// <param name="client">The client that determines the interaction with the blockchain</param> /// <returns>The result of the transfer</returns> public static async Task <TransferResult> Transfer(this RawTransaction rawTransaction, VeChainClient client) { if (rawTransaction?.signature == null) { throw new ArgumentException("Unsigned transaction can not be sent"); } var bytes = rawTransaction.Encode(); var transactionString = bytes.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX); return(await client.SendTransaction(bytes)); }
private static void FillClauses(RawTransaction rawTransaction, RlpList list) { var clauses = list.Values; int clausesSize = clauses.Count; var rawClause = new RawClause[clausesSize]; rawTransaction.Clauses = rawClause; for (int clauseIndex = 0; clauseIndex < clausesSize; clauseIndex++) { var clauseContent = ((RlpList)clauses[clauseIndex]).Values; rawClause[clauseIndex] = new RawClause(); FillOneClause(rawClause, clauseIndex, clauseContent); } }
internal RawTransaction GetExpectedRawTransaction(bool includeSingature) { var privateKey = new PrivateKey(new byte[] { 0xcf, 0x36, 0xec, 0xf9, 0xe4, 0x7c, 0x87, 0x9a, 0x0d, 0xbf, 0x46, 0xb2, 0xec, 0xd8, 0x3f, 0xd2, 0x76, 0x18, 0x2a, 0xde, 0x02, 0x65, 0x82, 0x5e, 0x3b, 0x8c, 0x6b, 0xa2, 0x14, 0x46, 0x7b, 0x76, }); var tx = new RawTransaction( nonce: 0, signer: new byte[] { 0xc2, 0xa8, 0x60, 0x14, 0x07, 0x3d, 0x66, 0x2a, 0x4a, 0x9b, 0xfc, 0xf9, 0xcb, 0x54, 0x26, 0x3d, 0xfa, 0x4f, 0x5c, 0xbc, }.ToImmutableArray(), updatedAddresses: ImmutableArray <ImmutableArray <byte> > .Empty, publicKey: new byte[] { 0x04, 0x46, 0x11, 0x5b, 0x01, 0x31, 0xba, 0xcc, 0xf9, 0x4a, 0x58, 0x56, 0xed, 0xe8, 0x71, 0x29, 0x5f, 0x6f, 0x3d, 0x35, 0x2e, 0x68, 0x47, 0xcd, 0xa9, 0xc0, 0x3e, 0x89, 0xfe, 0x09, 0xf7, 0x32, 0x80, 0x87, 0x11, 0xec, 0x97, 0xaf, 0x6e, 0x34, 0x1f, 0x11, 0x0a, 0x32, 0x6d, 0xa1, 0xbd, 0xb8, 0x1f, 0x5a, 0xe3, 0xba, 0xdf, 0x76, 0xa9, 0x0b, 0x22, 0xc8, 0xc4, 0x91, 0xae, 0xd3, 0xaa, 0xa2, 0x96, }.ToImmutableArray(), genesisHash: ImmutableArray <byte> .Empty, timestamp: "2018-11-21T00:00:00.000000Z", actions: ImmutableArray <IValue> .Empty ); if (!includeSingature) { return(tx); } byte[] signature = { 0x30, 0x44, 0x02, 0x20, 0x2f, 0x2d, 0xbe, 0x5a, 0x91, 0x65, 0x59, 0xde, 0xdb, 0xe8, 0xd8, 0x4f, 0xa9, 0x20, 0xe2, 0x01, 0x29, 0x4d, 0x4f, 0x40, 0xea, 0x1e, 0x97, 0x44, 0x1f, 0xbf, 0xa2, 0x5c, 0x8b, 0xd0, 0x0e, 0x23, 0x02, 0x20, 0x3c, 0x06, 0x02, 0x1f, 0xb8, 0x3f, 0x67, 0x49, 0x92, 0x3c, 0x07, 0x59, 0x67, 0x96, 0xa8, 0x63, 0x04, 0xb0, 0xc3, 0xfe, 0xbb, 0x6c, 0x7a, 0x7b, 0x58, 0x58, 0xe9, 0x7d, 0x37, 0x67, 0xe1, 0xe9, }; return(tx.AddSignature(signature)); }
internal RawTransaction GetExpectedRawTransaction(bool includeSingature) { var tx = new RawTransaction( sender: new byte[] { 0xc2, 0xa8, 0x60, 0x14, 0x07, 0x3d, 0x66, 0x2a, 0x4a, 0x9b, 0xfc, 0xf9, 0xcb, 0x54, 0x26, 0x3d, 0xfa, 0x4f, 0x5c, 0xbc, }, recipient: new byte[] { 0xc2, 0xa8, 0x60, 0x14, 0x07, 0x3d, 0x66, 0x2a, 0x4a, 0x9b, 0xfc, 0xf9, 0xcb, 0x54, 0x26, 0x3d, 0xfa, 0x4f, 0x5c, 0xbc, }, publicKey: new byte[] { 0x04, 0x46, 0x11, 0x5b, 0x01, 0x31, 0xba, 0xcc, 0xf9, 0x4a, 0x58, 0x56, 0xed, 0xe8, 0x71, 0x29, 0x5f, 0x6f, 0x3d, 0x35, 0x2e, 0x68, 0x47, 0xcd, 0xa9, 0xc0, 0x3e, 0x89, 0xfe, 0x09, 0xf7, 0x32, 0x80, 0x87, 0x11, 0xec, 0x97, 0xaf, 0x6e, 0x34, 0x1f, 0x11, 0x0a, 0x32, 0x6d, 0xa1, 0xbd, 0xb8, 0x1f, 0x5a, 0xe3, 0xba, 0xdf, 0x76, 0xa9, 0x0b, 0x22, 0xc8, 0xc4, 0x91, 0xae, 0xd3, 0xaa, 0xa2, 0x96, }, timestamp: "2018-11-21T00:00:00.000000Z", actions: new List <IDictionary <string, object> >() ); if (!includeSingature) { return(tx); } byte[] signature = new byte[] { 0x30, 0x45, 0x02, 0x21, 0x00, 0x9b, 0x8e, 0xb8, 0xb8, 0x6b, 0x31, 0x8d, 0xb4, 0x86, 0xb5, 0x9a, 0x4f, 0x8e, 0x54, 0xea, 0xa6, 0x8f, 0x88, 0x73, 0x94, 0x63, 0xa9, 0x19, 0x36, 0x1a, 0x4b, 0x1a, 0x32, 0xcf, 0x22, 0xf2, 0x1e, 0x02, 0x20, 0x76, 0xbe, 0x7f, 0xbf, 0x76, 0xa2, 0x09, 0x71, 0xfe, 0xf9, 0x28, 0xc6, 0x44, 0x0e, 0xdf, 0xda, 0xf3, 0x82, 0x29, 0x7b, 0x0f, 0x09, 0xf4, 0x50, 0x9f, 0xb1, 0xb1, 0x1e, 0xab, 0x11, 0x4b, 0x3d, }; return(tx.AddSignature(signature)); }
// public async Task<bool> TransferCoins(Account sender, string receiverAddress, ulong amount, ulong gasUnitPrice = 0, ulong maxGasAmount = 1000000) public async Task <bool> TransferCoins(Account sender, string receiverAddress, ulong amount, ulong gasUnitPrice = 0, ulong maxGasAmount = 1000000) { try { var program = new Program(); program.Code = Convert.FromBase64String(Constant.ProgamBase64Codes.PeerToPeerTxn).ToByteString(); program.Arguments.Add(new TransactionArgument { Type = TransactionArgument.Types.ArgType.Address, Data = receiverAddress.ToByteString() }); program.Arguments.Add(new TransactionArgument { Type = TransactionArgument.Types.ArgType.U64, Data = amount.ToBytes().Reverse().ToByteString() }); var transaction = new RawTransaction(); transaction.ExpirationTime = (ulong)Math.Floor((decimal)DateTimeOffset.Now.ToUnixTimeMilliseconds() / 1000) + 100; transaction.GasUnitPrice = gasUnitPrice; transaction.MaxGasAmount = maxGasAmount; var accountState = await QueryBalance(sender.Address); transaction.SequenceNumber = accountState.SequenceNumber; transaction.Program = program; transaction.SenderAccount = sender.Address.ToByteString(); var hash = new SHA3_256().ComputeVariable(Constant.HashSaltValues.RawTransactionHashSalt.FromHexToBytes().Concat(transaction.ToByteArray()).ToArray()); var senderSignature = sender.KeyPair.Sign(hash); var request = new SubmitTransactionRequest { SignedTxn = new SignedTransaction { RawTxnBytes = transaction.ToByteString(), SenderPublicKey = sender.PublicKey, SenderSignature = senderSignature.ToByteString() } }; var response = await acClient.SubmitTransactionAsync(request); return(response.AcStatus.Code == AdmissionControlStatusCode.Accepted); } catch (Exception ex) { throw ex; } }