コード例 #1
0
ファイル: Transaction.cs プロジェクト: w1r2p1/Paymetheus
        public static Transaction Deserialize(byte[] rawTransaction)
        {
            if (rawTransaction == null)
            {
                throw new ArgumentNullException(nameof(rawTransaction));
            }

            int version;

            Input[]  inputs;
            Output[] outputs;
            uint     lockTime;

            var cursor = new ByteCursor(rawTransaction);

            try
            {
                version = cursor.ReadInt32();
                var inputCount = cursor.ReadCompact();
                if (inputCount > TransactionRules.MaxInputs)
                {
                    var reason = $"Input count {inputCount} exceeds maximum value {TransactionRules.MaxInputs}";
                    throw new EncodingException(typeof(Transaction), cursor, reason);
                }
                inputs = new Input[inputCount];
                for (int i = 0; i < (int)inputCount; i++)
                {
                    var previousHash     = new Sha256Hash(cursor.ReadBytes(Sha256Hash.Length));
                    var previousIndex    = cursor.ReadUInt32();
                    var previousOutPoint = new OutPoint(previousHash, previousIndex);
                    var signatureScript  = cursor.ReadVarBytes(TransactionRules.MaxPayload);
                    var sequence         = cursor.ReadUInt32();
                    inputs[i] = new Input(previousOutPoint, signatureScript, sequence);
                }
                var outputCount = cursor.ReadCompact();
                if (outputCount > TransactionRules.MaxOutputs)
                {
                    var reason = $"Output count {outputCount} exceeds maximum value {TransactionRules.MaxOutputs}";
                    throw new EncodingException(typeof(Transaction), cursor, reason);
                }
                outputs = new Output[outputCount];
                for (int i = 0; i < (int)outputCount; i++)
                {
                    var amount   = (Amount)cursor.ReadInt64();
                    var pkScript = cursor.ReadVarBytes(TransactionRules.MaxPayload);
                    outputs[i] = new Output(amount, pkScript);
                }
                lockTime = cursor.ReadUInt32();
            }
            catch (Exception ex) when(!(ex is EncodingException))
            {
                throw new EncodingException(typeof(Transaction), cursor, ex);
            }

            return(new Transaction(version, inputs, outputs, lockTime));
        }
コード例 #2
0
ファイル: Transaction.cs プロジェクト: w1r2p1/Paymetheus
            public OutPoint(Sha256Hash hash, uint index)
            {
                if (hash == null)
                {
                    throw new ArgumentNullException(nameof(hash));
                }

                Hash  = hash;
                Index = index;
            }
コード例 #3
0
 public BlockIdentity(Sha256Hash hash, int height)
 {
     Hash   = hash;
     Height = height;
 }