public async Task <AuthorizationAPIResult> ReceiveTransferAsync(ReceiveTransferBlock receiveBlock) { if (!CheckServiceStatus()) { return(null); } return(await _trans.ReceiveTransferAsync(receiveBlock)); }
public async Task <SimpleJsonAPIResult> AuthorizeAsync(string blockType, string jsonBlock) { BlockTypes types; try { types = (BlockTypes)Enum.Parse(typeof(BlockTypes), blockType); } catch (Exception) { return(new SimpleJsonAPIResult { ResultCode = APIResultCodes.InvalidBlockType }); } var br = new BlockAPIResult { BlockData = jsonBlock, ResultBlockType = types }; var block = br.GetBlock(); if (block == null) { return(new SimpleJsonAPIResult { ResultCode = APIResultCodes.InvalidBlockData }); } // block is valid. send it to consensus network AuthorizationAPIResult result; switch (types) { case BlockTypes.SendTransfer: result = await _trans.SendTransferAsync(block as SendTransferBlock); break; case BlockTypes.ReceiveTransfer: result = await _trans.ReceiveTransferAsync(block as ReceiveTransferBlock); break; case BlockTypes.OpenAccountWithReceiveTransfer: result = await _trans.ReceiveTransferAndOpenAccountAsync(block as OpenWithReceiveTransferBlock); break; case BlockTypes.TokenGenesis: result = await _trans.CreateTokenAsync(block as TokenGenesisBlock); break; default: result = null; break; } if (result == null) { return new SimpleJsonAPIResult { ResultCode = APIResultCodes.UnsupportedBlockType } } ; return(new SimpleJsonAPIResult { ResultCode = result.ResultCode }); }
private async Task <AuthorizationAPIResult> ReceiveTransferAsync(NewTransferAPIResult2 new_transfer_info) { // *** Slava - July 19, 2020 - I am not sure if we need this call anymore? //await FindTokenPrecision(new_transfer_info.Transfer.TokenCode); // *** if (await GetLocalAccountHeightAsync() == 0) // if this is new account with no blocks { return(await OpenStandardAccountWithReceiveBlockAsync(new_transfer_info)); } var svcBlockResult = await _node.GetLastServiceBlockAsync(); if (svcBlockResult.ResultCode != APIResultCodes.Success) { throw new Exception("Unable to get latest service block."); } TransactionBlock latestBlock = await GetLatestBlockAsync(); var receiveBlock = new ReceiveTransferBlock { AccountID = _accountId, VoteFor = latestBlock.VoteFor, ServiceHash = svcBlockResult.GetBlock().Hash, SourceHash = new_transfer_info.SourceHash, Balances = new Dictionary <string, long>(), Fee = 0, FeeType = AuthorizationFeeTypes.NoFee, FeeCode = LyraGlobal.OFFICIALTICKERCODE, NonFungibleToken = new_transfer_info.NonFungibleToken }; var latestBalances = latestBlock.Balances.ToDecimalDict(); var recvBalances = latestBlock.Balances.ToDecimalDict(); foreach (var chg in new_transfer_info.Transfer.Changes) { if (recvBalances.ContainsKey(chg.Key)) { recvBalances[chg.Key] += chg.Value; } else { recvBalances.Add(chg.Key, chg.Value); } } receiveBlock.Balances = recvBalances.ToLongDict(); await receiveBlock.InitializeBlockAsync(latestBlock, _signer); if (!receiveBlock.ValidateTransaction(latestBlock)) { throw new Exception("ValidateTransaction failed"); } //receiveBlock.Signature = Signatures.GetSignature(PrivateKey, receiveBlock.Hash); var result = await _trans.ReceiveTransferAsync(receiveBlock); if (result.ResultCode == APIResultCodes.Success) { LastBlock = receiveBlock; } else { LastBlock = null; } return(result); }