예제 #1
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(version);
     writer.WriteArray(Inputs, (w, v) => v.Write(writer));
     writer.WriteArray(Outputs, (w, v) => v.Write(writer));
     writer.Write(lockTime);
 }
 public void Write(BitcoinStreamWriter writer)
 {
     writer.WriteArray(headers, (w, h) =>
     {
         h.Write(w);
         w.WriteCompact(0);
     });
 }
예제 #3
0
 public void Write(BitcoinStreamWriter writer)
 {
     blockHeader.Write(writer);
     writer.WriteArray(transactions, (w, t) => t.Write(w));
 }
        private bool CheckSig(byte[] script)
        {
            if (dataStack.Count < 2)
            {
                valid = false;
                return false;
            }

            byte[] pubKey = PopData();
            byte[] signatureBlock = PopData();

            //todo: validate length first
            byte hashtype = signatureBlock[signatureBlock.Length - 1];
            byte[] signature = new byte[signatureBlock.Length - 1];
            Array.Copy(signatureBlock, 0, signature, 0, signatureBlock.Length - 1);

            //todo: process hashtype

            MemoryStream mem = new MemoryStream();

            // todo: remove signatures from script
            // todo: also remove all OP_CODESEPARATORs from script
            byte[] subScript = script;
            if (lastCodeSeparator >= 0)
            {
                subScript = new byte[script.Length - lastCodeSeparator - 1];
                Array.Copy(script, lastCodeSeparator + 1, subScript, 0, script.Length - lastCodeSeparator - 1);
            }

            using (BitcoinStreamWriter writer = new BitcoinStreamWriter(mem))
            {
                //todo: check if transaction exists
                writer.Write(transaction.Version);
                writer.WriteCompact((ulong) transaction.Inputs.Length);
                for (int i = 0; i < transaction.Inputs.Length; i++)
                {
                    TxIn input = transaction.Inputs[i];
                    input.PreviousOutput.Write(writer);
                    if (transactionInputNumber == i)
                    {
                        writer.WriteCompact((ulong) subScript.Length);
                        writer.Write(subScript);
                    }
                    else
                    {
                        writer.WriteCompact(0);
                    }
                    writer.Write(input.Sequence);
                }
                writer.WriteArray(transaction.Outputs, (w, v) => v.Write(writer));
                writer.Write(transaction.LockTime);
                writer.Write((uint) hashtype);
            }

            byte[] signedData = mem.ToArray();

            return SignatureUtils.Verify(signedData, pubKey, signature);
        }
예제 #5
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.WriteArray(addressList, (w, a) => a.Write(w));
 }