コード例 #1
0
        /// <summary>
        /// Commits the uncommitted block referenced by its block alias.
        /// The hash ID of the future committed block has to be given as argument to the
        /// function.
        /// </summary>
        /// <returns></returns>
        public bool CommitBlock(BlockAlias alias, BlockId blockId)
        {
            if (!RetrieveUncommittedBlock(alias, out var toCommit))
            {
                throw new ArgumentException($"ID {alias} does not exist or is already committed.");
            }

            // verify that parent of block to commit is committed itself
            if (!RetrieveCommittedBlock(toCommit.Parent, out _) && !blockId.Equals(BlockId.Genesis))
            {
                throw new ArgumentException($"Parent {toCommit.Parent} is not yet committed.");
            }

            var blockToCommit = toCommit;

            _uncommitted.Remove(toCommit);

            var newBlock = new CommittedBlock(blockToCommit.BlockHeight, blockId, blockToCommit.Alias,
                                              blockToCommit.Parent);

            _committed.Add(newBlock);

            return(true);
        }
コード例 #2
0
 private bool FindCommitted(Predicate <CommittedBlock> p, out CommittedBlock foundBlock)
 {
     foundBlock = _committed.FindLast(p);
     return(!foundBlock.Equals(default(CommittedBlock)));
 }
コード例 #3
0
 /// <summary>
 /// Returns the block metadata of the committed block
 /// identified by the alias given as argument.
 /// </summary>
 public bool RetrieveCommittedBlock(BlockAlias alias, out CommittedBlock block)
 {
     return(FindCommitted(b => b.Alias == alias, out block));
 }