コード例 #1
0
ファイル: TxIn.cs プロジェクト: yu-kopylov/bitcoin-utilities
 public void Write(BitcoinStreamWriter writer)
 {
     previousOutput.Write(writer);
     writer.WriteCompact((ulong) signatureScript.Length);
     writer.Write(signatureScript);
     writer.Write(sequence);
 }
コード例 #2
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.WriteCompact((ulong) inventory.Count);
     foreach (InventoryVector vector in inventory)
     {
         vector.Write(writer);
     }
 }
コード例 #3
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(protocolVersion);
     writer.WriteCompact((ulong) locatorHashes.Count);
     foreach (byte[] hash in locatorHashes)
     {
         writer.Write(hash);
     }
     writer.Write(hashStop);
 }
コード例 #4
0
ファイル: TxOut.cs プロジェクト: yu-kopylov/bitcoin-utilities
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(value);
     writer.WriteCompact((ulong) pubkeyScript.Length);
     writer.Write(pubkeyScript);
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        private static byte[] GetMessageHash(string message)
        {
            byte[] messagePrefix = Encoding.ASCII.GetBytes("Bitcoin Signed Message:\n");
            byte[] messageBytes = Encoding.UTF8.GetBytes(message);

            MemoryStream mem = new MemoryStream();
            using (BitcoinStreamWriter writer = new BitcoinStreamWriter(mem))
            {
                writer.WriteCompact((ulong) messagePrefix.Length);
                writer.Write(messagePrefix, 0, messagePrefix.Length);

                writer.WriteCompact((ulong) messageBytes.Length);
                writer.Write(messageBytes, 0, messageBytes.Length);
            }

            byte[] text = mem.ToArray();
            return CryptoUtils.DoubleSha256(text);
        }
コード例 #7
0
 public void Write(BitcoinStreamWriter writer)
 {
     blockHeader.Write(writer);
     writer.Write(totalTransactions);
     writer.WriteCompact((ulong) hashes.Count);
     foreach (byte[] hash in hashes)
     {
         writer.Write(hash);
     }
     writer.WriteCompact((ulong) flags.Length);
     writer.Write(flags);
 }