Пример #1
0
        public bool PutHeader(BlockHeader blockHeader)
        {
            ConsensusFactory consensusFactory = this.network.Consensus.ConsensusFactory;

            if (blockHeader is ProvenBlockHeader)
            {
                // If ProvenBlockHeader copy the header parameters.
                BlockHeader newHeader = consensusFactory.CreateBlockHeader();
                newHeader.Bits           = blockHeader.Bits;
                newHeader.Time           = blockHeader.Time;
                newHeader.Nonce          = blockHeader.Nonce;
                newHeader.Version        = blockHeader.Version;
                newHeader.HashMerkleRoot = blockHeader.HashMerkleRoot;
                newHeader.HashPrevBlock  = blockHeader.HashPrevBlock;

                blockHeader = newHeader;
            }

            lock (this.locker)
            {
                this.leveldb.Put(DBH.Key(HeaderTableName, blockHeader.GetHash().ToBytes()), blockHeader.ToBytes(consensusFactory));
            }

            return(true);
        }
Пример #2
0
 public ChainPartEntry(DynamicTableEntity entity, ConsensusFactory consensusFactory)
 {
     ChainOffset  = Helper.StringToHeight(entity.RowKey);
     BlockHeaders = new List <BlockHeader>();
     foreach (var prop in entity.Properties)
     {
         var header = consensusFactory.CreateBlockHeader();
         header.FromBytes(prop.Value.BinaryValue);
         BlockHeaders.Add(header);
     }
 }
Пример #3
0
        public bool PutHeader(BlockHeader blockHeader)
        {
            ConsensusFactory consensusFactory = this.network.Consensus.ConsensusFactory;

            if (blockHeader is ProvenBlockHeader)
            {
                // If ProvenBlockHeader copy the header parameters.
                BlockHeader newHeader = consensusFactory.CreateBlockHeader();
                newHeader.CopyFields(blockHeader);

                blockHeader = newHeader;
            }

            lock (this.locker)
            {
                this.leveldb.Put(HeaderTableName, blockHeader.GetHash().ToBytes(), blockHeader.ToBytes(consensusFactory));
            }

            return(true);
        }
Пример #4
0
        public async Task <object> Find(string data)
        {
            data = data.Trim();
            var b58 = NoException(() => WhatIsBase58.GetFromBitcoinString(data));

            if (b58 != null)
            {
                if (b58 is WhatIsAddress)
                {
                    var address = (WhatIsAddress)b58;
                    await TryFetchRedeemOrPubKey(address);
                }
                return(b58);
            }

            if (data.Length == 0x40)
            {
                try
                {
                    return(await Controller.JsonTransaction(uint256.Parse(data), false));
                }
                catch
                {
                }
            }
            var b = NoException(() => Controller.JsonBlock(BlockFeature.Parse(data), true, false));

            if (b != null)
            {
                return(b);
            }

            if (data.Length == 0x28) //Hash of pubkey or script
            {
                TxDestination dest    = new KeyId(data);
                var           address = new WhatIsAddress(dest.GetAddress(Network));
                if (await TryFetchRedeemOrPubKey(address))
                {
                    return(address);
                }

                dest    = new ScriptId(data);
                address = new WhatIsAddress(dest.GetAddress(Network));
                if (await TryFetchRedeemOrPubKey(address))
                {
                    return(address);
                }
            }


            var script = NoException(() => GetScriptFromBytes(data));

            if (script != null)
            {
                return(new WhatIsScript(script, Network));
            }
            script = NoException(() => GetScriptFromText(data));
            if (script != null)
            {
                return(new WhatIsScript(script, Network));
            }

            var sig = NoException(() => new TransactionSignature(Encoders.Hex.DecodeData(data)));

            if (sig != null)
            {
                return(new WhatIsTransactionSignature(sig));
            }

            var pubkeyBytes = NoException(() => Encoders.Hex.DecodeData(data));

            if (pubkeyBytes != null && PubKey.Check(pubkeyBytes, true))
            {
                var pubKey = NoException(() => new PubKey(data));
                if (pubKey != null)
                {
                    return(new WhatIsPublicKey(pubKey, Network));
                }
            }

            if (data.Length == 80 * 2)
            {
                var blockHeader = NoException(() =>
                {
                    var h = ConsensusFactory.CreateBlockHeader();
                    h.ReadWrite(Encoders.Hex.DecodeData(data), ConsensusFactory);
                    return(h);
                });
                if (blockHeader != null)
                {
                    return(new WhatIsBlockHeader(blockHeader));
                }
            }
            return(null);
        }