public async Task <MultiBlockAPIResult> GetConsolidationBlocks(string AccountId, string Signature, long startHeight) { var result = new MultiBlockAPIResult(); if (!await VerifyClientAsync(AccountId, Signature)) { result.ResultCode = APIResultCodes.APISignatureValidationFailed; return(result); } try { var blocks = await BlockChain.Singleton.GetConsolidationBlocksAsync(startHeight); if (blocks != null) { result.SetBlocks(blocks.ToArray()); result.ResultCode = APIResultCodes.Success; } else { result.ResultCode = APIResultCodes.BlockNotFound; } } catch (Exception e) { Console.WriteLine("Exception in GetConsolidationBlocks: " + e.Message); result.ResultCode = APIResultCodes.UnknownError; } return(result); }
public async Task <MultiBlockAPIResult> GetBlocksByConsolidation(string AccountId, string Signature, string consolidationHash) { var result = new MultiBlockAPIResult(); if (!await VerifyClientAsync(AccountId, Signature)) { result.ResultCode = APIResultCodes.APISignatureValidationFailed; return(result); } var consBlock = (await BlockChain.Singleton.FindBlockByHashAsync(consolidationHash)) as ConsolidationBlock; if (consBlock == null) { result.ResultCode = APIResultCodes.BlockNotFound; return(result); } var mt = new MerkleTree(); var blocks = new Block[consBlock.blockHashes.Count]; for (int i = 0; i < blocks.Length; i++) { blocks[i] = await BlockChain.Singleton.FindBlockByHashAsync(consBlock.blockHashes[i]); mt.AppendLeaf(MerkleHash.Create(blocks[i].Hash)); } var merkelTreeHash = mt.BuildTree().ToString(); if (consBlock.MerkelTreeHash == merkelTreeHash) { result.SetBlocks(blocks); result.ResultCode = APIResultCodes.Success; return(result); } else { // never replicate error data result.ResultCode = APIResultCodes.BlockValidationFailed; return(result); } }