Example #1
0
        public async Task <BlockAttachOperationStatus> AttachBlockToChainAsync(Chain chain, Block block)
        {
            var chainBlockLink = await _chainManager.GetChainBlockLinkAsync(block.GetHash());

            if (chainBlockLink == null)
            {
                chainBlockLink = new ChainBlockLink
                {
                    Height            = block.Header.Height,
                    BlockHash         = block.GetHash(),
                    PreviousBlockHash = block.Header.PreviousBlockHash
                };
            }
            else
            {
                chainBlockLink.IsLinked        = false;
                chainBlockLink.ExecutionStatus =
                    chainBlockLink.ExecutionStatus == ChainBlockLinkExecutionStatus.ExecutionSuccess
                        ? ChainBlockLinkExecutionStatus.ExecutionSuccess
                        : ChainBlockLinkExecutionStatus.ExecutionNone;
            }

            var status = await _chainManager.AttachBlockToChainAsync(chain, chainBlockLink);

            return(status);
        }