public IEnumerable <(Action, PackedTransaction)> GetListAction(GetBlockResponse block) { logger.Info(String.Format("Block number {0} produced on {1}", block.BlockNum, block.Timestamp)); foreach (TransactionReceipt transactionReceipt in block.Transactions) { if (transactionReceipt.Status != TRANSACTION_STATUS_EXECUTED || transactionReceipt.Trx is String) { continue; } PackedTransaction packedTransaction = JsonHelper.DeserializeObject <PackedTransaction>(transactionReceipt.Trx.ToString()); foreach (Action action in packedTransaction.Transaction.Actions) { yield return(action, packedTransaction); } } }
public void ParseValidTransferAction(Action action, PackedTransaction packedTransaction, GetBlockResponse blockResponse) { TransferData transferData = JsonHelper.DeserializeObject <TransferData>(action.Data.ToString()); if (String.IsNullOrEmpty(transferData.Quantity)) { return; } if (transferData.Symbol() == CryptoCurrency.VAKA) { // If receiver doesn't exist in wallet table then stop if (!_walletBusiness.CheckExistedAndUpdateByAddress(transferData.To, transferData.Amount(), transferData.Symbol())) { return; } // Save to table in db _vakacoinBusiness.CreateDepositTransaction(packedTransaction.Id, (int)blockResponse.BlockNum, transferData.Symbol(), transferData.Amount(), transferData.From, transferData.To, 0, Status.STATUS_SUCCESS); //create pending email var createEmailResult = CreatePendingEmail(transferData); if (createEmailResult.Status == Status.STATUS_SUCCESS) { logger.Info("Create pending email success"); } else { logger.Error("Create Pending email error!!!" + createEmailResult.Message); } logger.Info(String.Format("{0} was received {1}", transferData.To, transferData.Quantity)); } }
public async Task <OperationResult <PushTransactionResults> > BroadcastActionsAsync(BaseAction[] baseActions, List <byte[]> privateKeys, CancellationToken token) { var initOpRez = await AbiJsonToBinAsync(baseActions, token).ConfigureAwait(false); if (initOpRez.IsError) { return(new OperationResult <PushTransactionResults>(initOpRez)); } var infoResp = await GetInfoAsync(token).ConfigureAwait(false); if (infoResp.IsError) { return(new OperationResult <PushTransactionResults>(infoResp)); } var info = infoResp.Result; var blockArgs = new GetBlockParams { BlockNumOrId = info.HeadBlockId }; var getBlock = await GetBlockAsync(blockArgs, token).ConfigureAwait(false); if (getBlock.IsError) { return(new OperationResult <PushTransactionResults>(getBlock)); } var block = getBlock.Result; var trx = new SignedTransaction { Actions = baseActions, RefBlockNum = (ushort)(block.BlockNum & 0xffff), RefBlockPrefix = block.RefBlockPrefix, Expiration = block.Timestamp.Value.AddSeconds(30) }; var packedTrx = MessageSerializer.Serialize <SignedTransaction>(trx); var chainId = Hex.HexToBytes(info.ChainId); var msg = new byte[chainId.Length + packedTrx.Length + 32]; Array.Copy(chainId, msg, chainId.Length); Array.Copy(packedTrx, 0, msg, chainId.Length, packedTrx.Length); var sha256 = Sha256Manager.GetHash(msg); var pack = new PackedTransaction { PackedTrx = packedTrx, Signatures = new string[privateKeys.Count], PackedContextFreeData = new Bytes(), Compression = CompressionType.None }; for (var i = 0; i < privateKeys.Count; i++) { var key = privateKeys[i]; var sig = Secp256K1Manager.SignCompressedCompact(sha256, key); var sigHex = Base58.EncodeSig(sig); pack.Signatures[i] = sigHex; } return(await PushTransactionAsync(pack, token).ConfigureAwait(false)); }
public async Task <OperationResult <PushTransactionResults> > BroadcastActionsAsync(BaseAction[] baseActions, PublicKey[] publicKeys, Func <SignedTransaction, PublicKey[], string, CancellationToken, Task <OperationResult <SignedTransaction> > > signFunc, CancellationToken token) { var initOpRez = await AbiJsonToBinAsync(baseActions, token).ConfigureAwait(false); if (initOpRez.IsError) { return(new OperationResult <PushTransactionResults>(initOpRez)); } var infoResp = await GetInfoAsync(token).ConfigureAwait(false); if (infoResp.IsError) { return(new OperationResult <PushTransactionResults>(infoResp)); } var info = infoResp.Result; var blockArgs = new GetBlockParams { BlockNumOrId = info.HeadBlockId }; var getBlock = await GetBlockAsync(blockArgs, token).ConfigureAwait(false); if (getBlock.IsError) { return(new OperationResult <PushTransactionResults>(getBlock)); } var block = getBlock.Result; var trx = new SignedTransaction { Actions = baseActions, RefBlockNum = (ushort)(block.BlockNum & 0xffff), RefBlockPrefix = block.RefBlockPrefix, Expiration = block.Timestamp.Value.AddSeconds(30) }; var strx = await signFunc.Invoke(trx, publicKeys, info.ChainId, token).ConfigureAwait(false); if (strx.IsError) { return(new OperationResult <PushTransactionResults>(strx)); } var packedTrx = MessageSerializer.Serialize <SignedTransaction>(trx); var chainId = Hex.HexToBytes(info.ChainId); var msg = new byte[chainId.Length + packedTrx.Length + 32]; Array.Copy(chainId, msg, chainId.Length); Array.Copy(packedTrx, 0, msg, chainId.Length, packedTrx.Length); var pack = new PackedTransaction { PackedTrx = packedTrx, PackedContextFreeData = new Bytes(), Compression = CompressionType.None, Signatures = strx.Result.Signatures }; return(await PushTransactionAsync(pack, token).ConfigureAwait(false)); }
/// <summary> /// This method expects a transaction in JSON format and will attempt to apply it to the blockchain /// /// curl http://localhost:8888/v1/chain/push_transaction -X POST -d '{"ref_block_num":"100","ref_block_prefix":"137469861","expiration":"2017-09-25T06:28:49","scope":["initb","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["initb","initc"],"authorization":[{"account":"initb","permission":"active"}],"data":"000000000041934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]}' /// </summary> /// <param name="args"></param> /// <param name="token"></param> /// <returns></returns> public async Task <OperationResult <PushTransactionResults> > PushTransaction(PackedTransaction args, CancellationToken token) { var endpoint = $"{ChainUrl}/v1/chain/push_transaction"; return(await CustomPostRequest <PushTransactionResults>(endpoint, args, token)); }