Пример #1
0
 public MemoryStore(NetworkParameters parameters)
     : base(parameters)
 {
     locker=new ReaderWriterLockDisposable();
     using(locker.AcquireWriterLock())
     { store=new Dictionary<string,StoredBlock>(); }
 }
Пример #2
0
 protected AMessage(NetworkParameters parameters)
 {
     Parameters=parameters;
     Parsed=true;
     ParseLazy=false;
     ParseRetain=false;
 }
Пример #3
0
		/**
		 * Used only in creation of the genesis block.
		 */
		TransactionInput(NetworkParameters params, Transaction parentTransaction, byte[] scriptBytes) {
			super(params);
			this.scriptBytes = scriptBytes;
			this.outpoint = new TransactionOutPoint(params, NO_SEQUENCE, (Transaction)null);
			this.sequence = NO_SEQUENCE;
			this.parentTransaction = parentTransaction;

			length = 40 + (scriptBytes == null ? 1 : VarInt.SizeInBytesOf(scriptBytes.Length) + scriptBytes.length);
		}
Пример #4
0
		/**
		 * Creates an UNSIGNED input that links to the given output
		 */
		TransactionInput(NetworkParameters params, Transaction parentTransaction, TransactionOutput output) {
			super(params);
			long outputIndex = output.getIndex();
			outpoint = new TransactionOutPoint(params, outputIndex, output.parentTransaction);
			scriptBytes = EMPTY_ARRAY;
			sequence = NO_SEQUENCE;
			this.parentTransaction = parentTransaction;

			length = 41;
		}
Пример #5
0
 /// <summary>
 /// Special case constructor, used for the genesis node, cloneAsHeader and unit tests.
 /// </summary>
 /// <param name="parameters"></param>
 public Block(NetworkParameters parameters)
     : base(parameters)
 {
     // Set up a few basic things. We are not complete after this though.
     version=1;
     difficultyTarget=(uint)0x1d07fff8L;
     TimeSeconds=UnixTimeHelper.ToUnixTime(DateTime.UtcNow);
     PreviousBlockHash=Sha256Hash.ZeroHash;
     Length=80;
 }
Пример #6
0
		public TransactionInput(NetworkParameters params, Transaction parentTransaction,
				byte[] scriptBytes,
				TransactionOutPoint outpoint) {
			super(params);
			this.scriptBytes = scriptBytes;
			this.outpoint = outpoint;
			this.sequence = NO_SEQUENCE;
			this.parentTransaction = parentTransaction;

			length = 40 + (scriptBytes == null ? 1 : VarInt.sizeOf(scriptBytes.length) + scriptBytes.length);
		}
Пример #7
0
		public TransactionOutPoint(NetworkParameters params, long index, Transaction fromTx) {
			super(params);
			this.index = index;
			if (fromTx != null) {
				this.hash = fromTx.getHash();
				this.fromTx = fromTx;
			} else {
				// This happens when constructing the genesis block.
				hash = Sha256Hash.ZERO_HASH;
			}
			length = MESSAGE_LENGTH;
		}
Пример #8
0
 /// <summary>
 /// Only for internal use
 /// </summary>
 private Script()
 {
     parameters=null;
 }
Пример #9
0
		public Transaction(NetworkParameters parameters):this(parameters,1,null)
		{ }
Пример #10
0
		/**
		 * Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.
		 * @param params NetworkParameters object.
		 * @param msg Bitcoin protocol formatted byte array containing message content.
		 * @param offset The location of the first msg byte within the array.
		 * @param parseLazy Whether to perform a full parse immediately or delay until a read is requested.
		 * @param parseRetain Whether to retain the backing byte array for quick reserialization.  
		 * If true and the backing byte array is invalidated due to modification of a field then 
		 * the cached bytes may be repopulated and retained if the message is serialized again in the future.
		 * @param length The length of message if known.  Usually this is provided when deserializing of the wire
		 * as the length will be provided as part of the header.  If unknown then set to Message.UNKNOWN_LENGTH
		 * @throws ProtocolException
		 * 
		 * throws ProtocolException
		 */
		public Transaction(NetworkParameters parameters,byte[] msg,int offset,AMessage parent,bool parseLazy,bool parseRetain,int length):base(parameters,msg,offset,parent,parseLazy,parseRetain,length)
		{ }
Пример #11
0
 /// <summary>
 /// Construct a Script using the given network parameters and a range of the programBytes array
 /// <exception cref="ScriptException"></exception>
 /// </summary>
 /// <param name="parameters">Network parameters.</param>
 /// <param name="programBytes">Array of program bytes from a transaction.</param>
 /// <param name="offset">How many bytes into programBytes to start reading from.</param>
 /// <param name="length">How many bytes to read.</param>
 public Script(NetworkParameters parameters,byte[] programBytes,int offset,int length)
 {
     this.parameters=parameters;
     parse(programBytes,offset,length);
 }
Пример #12
0
		public TransactionOutPoint(NetworkParameters params, long index, Sha256Hash hash) {
			super(params);
			this.index = index;
			this.hash = hash;
			length = MESSAGE_LENGTH;
		}
Пример #13
0
		/**
		 * Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.
		 * throws ProtocolException
		 */
		public Transaction(NetworkParameters parameters,byte[] msg,AMessage parent,bool parseLazy,bool parseRetain,int length):this(parameters,msg,0,parent,parseLazy,parseRetain,length)
		{ }
Пример #14
0
		/**
		/**
		 * Deserializes the message. This is usually part of a transaction message.
		 */
		public TransactionOutPoint(NetworkParameters params, byte[] payload, int offset) throws ProtocolException {
Пример #15
0
        /// <summary>
        /// <exception cref="ProtocolException"/>
        /// </summary>
        /// <param name="parameters">NetworkParameters object</param>
        /// <param name="msg">Bitcoin protocol formatted byte array containing message content</param>
        /// <param name="offset">The location of the first msg byte within the array</param>
        /// <param name="protocolVersion">Bitcoin protocol version</param>
        /// <param name="parseLazy">Whether to perform a full parse immediately or delay until a read is requested.</param>
        /// <param name="parseRetain">
        /// Whether to retain the backing byte array for quick reserialization.
        /// If true and the backing byte array is invalidated due to modification of a field then the cached bytes may be repopulated and retained if the message is serialized again in the future.
        /// </param>
        /// <param name="length">The length of message if known.  Usually this is provided when deserializing of the wire as the length will be provided as part of the header. If unknown then set to Message.UnknownLength</param>
        protected AMessage(NetworkParameters parameters,byte[] msg,int offset,uint protocolVersion,bool parseLazy,bool parseRetain,int length)
        {
            ParseLazy=parseLazy;
            ParseRetain=parseRetain;
            ProtocolVersion=protocolVersion;
            Parameters=parameters;
            Bytes=msg;
            Cursor=Offset=offset;
            Length=length;

            if(parseLazy)
            { ParseLite(); }
            else
            {
                ParseLite();
                Parse();
                Parsed=true;
            }

            #if SelfCheck
            if(SelfCheck)
            { selfCheck(msg,offset); }
            #endif

            if(!parseRetain && Parsed)
            { Bytes=null; }
        }
Пример #16
0
 /// <see cref="AMessage(NetworkParameters,byte[],int,uint,bool,bool,int)"/>
 protected AMessage(NetworkParameters parameters,byte[] msg,int offset)
     : this(parameters,msg,offset,NetworkParameters.ProtocolVersion,false,false,UnknownLength)
 {
 }
Пример #17
0
		/**
		 * Deserializes an input message. This is usually part of a transaction message.
		 */
		public TransactionInput(NetworkParameters params, Transaction parentTransaction,
								byte[] payload, int offset) throws ProtocolException {
Пример #18
0
        //public boolean equals(Object other) {
        //    if (!(other instanceof NetworkParameters)) return false;
        //    NetworkParameters o = (NetworkParameters) other;
        //    return o.getId().equals(getId());
        //}
        public Block CreateGenesis(NetworkParameters n)
        {
            Block genesisBlock=new Block(n);
            Transaction transaction=new Transaction(n);
            transaction.AddInput(
                new TransactionInput(n,transaction,Hex.Decode(n.GenesisBlockInputScriptSig))
            );

            ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
            Script.writeBytes(scriptPubKeyBytes,Hex.Decode(n.GenesisOutputScriptPubKey));
            scriptPubKeyBytes.write(Script.OP_CHECKSIG);
            t.addOutput(new TransactionOutput(n,transaction,Coin.FromCoins(50).Nanocoins,scriptPubKeyBytes.toByteArray()));

            genesisBlock.addTransaction(transaction);
            return genesisBlock;
        }
Пример #19
0
 /// <see cref="AMessage(NetworkParameters,byte[],int,uint,bool,bool,int)"/>
 protected AMessage(NetworkParameters parameters,byte[] msg,int offset,bool parseLazy,bool parseRetain,int length)
     : this(parameters,msg,offset,NetworkParameters.ProtocolVersion,parseLazy,parseRetain,length)
 {
 }
Пример #20
0
		public Transaction(NetworkParameters parameters,int version,Sha256Hash hash):base(parameters)
		{
			this.version=version & ((1L<<32)-1); // this field is unsigned - remove any sign extension
			inputs=new List<TransactionInput>();
			outputs=new List<TransactionOutput>();
			this.hash=hash;

			// We don't initialize appearsIn deliberately as it's only useful for transactions stored in the wallet.
			Length=8; //8 for std fields
		}
Пример #21
0
 /// <summary>
 /// Contruct a block object from the BitCoin wire format
 /// <exception cref="ProtocolException"/>
 /// </summary>
 /// <param name="parameters">NetworkParameters object</param>
 /// <param name="payloadBytes"></param>
 /// <param name="parseLazy">Whether to perform a full parse immediately or delay until a read is requested</param>
 /// <param name="parseRetain">
 /// Whether to retain the backing byte array for quick reserialization.
 /// If true and the backing byte array is invalidated due to modification of a field then the cached bytes may be repopulated and retained if the message is serialized again in the future.</param>
 /// <param name="length">
 /// The length of message if known. Usually this is provided when deserializing of the wire as the length will be provided as part of the header.
 /// If unknown then set to Message.UnknwonLength</param>
 public Block(NetworkParameters parameters,byte[] payloadBytes,bool parseLazy,bool parseRetain,int length)
     : base(parameters,payloadBytes,0,parseLazy,parseRetain,length)
 {
 }
Пример #22
0
		/**
		 * Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.
		 *///throws ProtocolException
		public Transaction(NetworkParameters parameters,byte[] payload):this(parameters,payload,0)
		{ }
Пример #23
0
 /// <summary>
 /// Constructs a block object from the Bitcoin wire format
 /// <exception cref="ProtocolException"/>
 /// </summary>
 /// <param name="parameters"></param>
 /// <param name="payloadBytes"></param>
 public Block(NetworkParameters parameters,byte[] payloadBytes)
     : base(parameters,payloadBytes,0,false,false,payloadBytes.Length)
 {
 }
Пример #24
0
		/**
		 * Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.
		 */
		public Transaction(NetworkParameters parameters,byte[] payload,int offset):base(parameters,payload,offset)
		{ }