Exemple #1
0
 public void Load(Stream stream, ConsensusFactory consensusFactory, ChainSerializationFormat format)
 {
     if (consensusFactory == null)
     {
         throw new ArgumentNullException(nameof(consensusFactory));
     }
     Load(new BitcoinStream(stream, false)
     {
         ConsensusFactory = consensusFactory
     }, format);
 }
Exemple #2
0
        public IDisposable ConsensusFactoryScope(ConsensusFactory consensusFactory)
        {
            var old = ConsensusFactory;

            return(new Scope(() =>
            {
                ConsensusFactory = consensusFactory;
            }, () =>
            {
                ConsensusFactory = old;
            }));
        }
        public static PSBT Load(byte[] rawBytes, ConsensusFactory consensusFactory)
        {
            if (rawBytes == null)
            {
                throw new ArgumentNullException(nameof(rawBytes));
            }
            var stream = new BitcoinStream(rawBytes);

            stream.ConsensusFactory = consensusFactory;
            var ret = new PSBT(stream, null);

            return(ret);
        }
Exemple #4
0
        public static Block Load(byte[] hex, ConsensusFactory consensusFactory)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            var block = consensusFactory.CreateBlock();

            block.ReadWrite(hex, consensusFactory);
            return(block);
        }
Exemple #5
0
        public static Block Parse(string hex, ConsensusFactory consensusFactory)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            var block = consensusFactory.CreateBlock();

            block.ReadWrite(Encoders.Hex.DecodeData(hex), consensusFactory);
            return(block);
        }
Exemple #6
0
        public static Block CreateBlock(BlockHeader header, ConsensusFactory consensusFactory)
        {
            var           ms = new MemoryStream(100);
            BitcoinStream bs = new BitcoinStream(ms, true);

            bs.ConsensusFactory = consensusFactory;
            bs.ReadWrite(header);

            var block = consensusFactory.CreateBlock();

            ms.Position = 0;
            bs          = new BitcoinStream(ms, false);
            block.Header.ReadWrite(bs);
            return(block);
        }
Exemple #7
0
        public BlockHeader(string hex, ConsensusFactory consensusFactory)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            BitcoinStream bs = new BitcoinStream(Encoders.Hex.DecodeData(hex))
            {
                ConsensusFactory = consensusFactory
            };

            this.ReadWrite(bs);
        }
Exemple #8
0
        public BlockHeader(byte[] data, ConsensusFactory consensusFactory)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            BitcoinStream bs = new BitcoinStream(data)
            {
                ConsensusFactory = consensusFactory
            };

            this.ReadWrite(bs);
        }
        public static PSBT Parse(string hexOrBase64, ConsensusFactory consensusFactory)
        {
            if (hexOrBase64 == null)
            {
                throw new ArgumentNullException(nameof(hexOrBase64));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            byte[] raw;
            if (HexEncoder.IsWellFormed(hexOrBase64))
            {
                raw = Encoders.Hex.DecodeData(hexOrBase64);
            }
            else
            {
                raw = Encoders.Base64.DecodeData(hexOrBase64);
            }

            return(Load(raw, consensusFactory));
        }
Exemple #10
0
 public Block CreateNextBlockWithCoinbase(PubKey pubkey, Money value, ConsensusFactory consensusFactory)
 {
     return(CreateNextBlockWithCoinbase(pubkey, value, DateTimeOffset.UtcNow, consensusFactory));
 }
Exemple #11
0
        public Block CreateNextBlockWithCoinbase(PubKey pubkey, Money value, DateTimeOffset now, ConsensusFactory consensusFactory)
        {
            Block block = consensusFactory.CreateBlock();

            block.Header.Nonce         = RandomUtils.GetUInt32();
            block.Header.HashPrevBlock = this.GetHash();
            block.Header.BlockTime     = now;
            var tx = block.AddTransaction(consensusFactory.CreateTransaction());

            tx.Inputs.Add(scriptSig: new Script(Op.GetPushOp(RandomUtils.GetBytes(30))));
            tx.Outputs.Add(new TxOut()
            {
                Value        = value,
                ScriptPubKey = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(pubkey)
            });
            return(block);
        }
Exemple #12
0
 public static void ReadWrite(this IBitcoinSerializable serializable, byte[] bytes, ConsensusFactory consensusFactory, uint?version = null)
 {
     ReadWrite(serializable, new MemoryStream(bytes), false, consensusFactory, version);
 }
Exemple #13
0
 public ConcurrentChain(byte[] bytes, ConsensusFactory consensusFactory, ChainSerializationFormat format)
 {
     Load(bytes, consensusFactory, format);
 }
Exemple #14
0
 public ConcurrentChain(byte[] bytes, ConsensusFactory consensusFactory) : this(bytes, consensusFactory, null)
 {
 }
Exemple #15
0
 public void Load(byte[] chain, ConsensusFactory consensusFactory)
 {
     Load(chain, consensusFactory, null);
 }
Exemple #16
0
 public void Load(byte[] chain, ConsensusFactory consensusFactory, ChainSerializationFormat format)
 {
     Load(new MemoryStream(chain), consensusFactory, format);
 }
Exemple #17
0
 public static Block CreateBlock(ConsensusFactory consensusFactory)
 {
     return(consensusFactory.CreateBlock());
 }
Exemple #18
0
        public static void ReadWrite(this IBitcoinSerializable serializable, Stream stream, bool serializing, ConsensusFactory consensusFactory, uint?version = null)
        {
            BitcoinStream s = new BitcoinStream(stream, serializing)
            {
                ProtocolVersion = version
            };

            if (consensusFactory != null)
            {
                s.ConsensusFactory = consensusFactory;
            }
            serializable.ReadWrite(s);
        }