public async Task <AuthorizationAPIResult> ReceiveTransferAndOpenAccountAsync(OpenWithReceiveTransferBlock openReceiveBlock) { if (!CheckServiceStatus()) { return(null); } return(await _trans.ReceiveTransferAndOpenAccountAsync(openReceiveBlock)); }
private async Task <AuthorizationAPIResult> OpenStandardAccountWithReceiveBlockAsync(NewTransferAPIResult2 new_transfer_info) { var svcBlockResult = await _node.GetLastServiceBlockAsync(); if (svcBlockResult.ResultCode != APIResultCodes.Success) { throw new Exception("Unable to get latest service block."); } var openReceiveBlock = new OpenWithReceiveTransferBlock { AccountType = AccountTypes.Standard, AccountID = _accountId, 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, VoteFor = null }; foreach (var chg in new_transfer_info.Transfer.Changes) { openReceiveBlock.Balances.Add(chg.Key, chg.Value.ToBalanceLong()); } await openReceiveBlock.InitializeBlockAsync(null, _signer); //openReceiveBlock.Signature = Signatures.GetSignature(PrivateKey, openReceiveBlock.Hash); var result = await _trans.ReceiveTransferAndOpenAccountAsync(openReceiveBlock); if (result.ResultCode == APIResultCodes.Success) { LastBlock = openReceiveBlock; } else { LastBlock = null; } return(result); }
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 }); }