Exemplo n.º 1
0
 public MemoryStore(NetworkParameters parameters)
     : base(parameters)
 {
     locker=new ReaderWriterLockDisposable();
     using(locker.AcquireWriterLock())
     { store=new Dictionary<string,StoredBlock>(); }
 }
Exemplo n.º 2
0
 protected AMessage(NetworkParameters parameters)
 {
     Parameters=parameters;
     Parsed=true;
     ParseLazy=false;
     ParseRetain=false;
 }
Exemplo n.º 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);
		}
Exemplo n.º 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;
		}
Exemplo n.º 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;
 }
Exemplo n.º 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);
		}
Exemplo n.º 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;
		}
Exemplo n.º 8
0
 /// <summary>
 /// Only for internal use
 /// </summary>
 private Script()
 {
     parameters=null;
 }
Exemplo n.º 9
0
		public Transaction(NetworkParameters parameters):this(parameters,1,null)
		{ }
Exemplo n.º 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)
		{ }
Exemplo n.º 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);
 }
Exemplo n.º 12
0
		public TransactionOutPoint(NetworkParameters params, long index, Sha256Hash hash) {
			super(params);
			this.index = index;
			this.hash = hash;
			length = MESSAGE_LENGTH;
		}
Exemplo n.º 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)
		{ }
Exemplo n.º 14
0
		/**
		/**
		 * Deserializes the message. This is usually part of a transaction message.
		 */
		public TransactionOutPoint(NetworkParameters params, byte[] payload, int offset) throws ProtocolException {
Exemplo n.º 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; }
        }
Exemplo n.º 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)
 {
 }
Exemplo n.º 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 {
Exemplo n.º 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;
        }
Exemplo n.º 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)
 {
 }
Exemplo n.º 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
		}
Exemplo n.º 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)
 {
 }
Exemplo n.º 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)
		{ }
Exemplo n.º 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)
 {
 }
Exemplo n.º 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)
		{ }