コード例 #1
0
ファイル: Tx.cs プロジェクト: yu-kopylov/bitcoin-utilities
 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);
 }
コード例 #2
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);
 }
コード例 #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
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write((int) type);
     writer.Write(hash);
 }
コード例 #5
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(Payload);
 }
コード例 #6
0
ファイル: TxOut.cs プロジェクト: yu-kopylov/bitcoin-utilities
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(value);
     writer.WriteCompact((ulong) pubkeyScript.Length);
     writer.Write(pubkeyScript);
 }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(hash);
     writer.Write(index);
 }
コード例 #10
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);
 }
コード例 #11
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.WriteText(rejectedCommand);
     writer.Write((byte) reason);
     writer.WriteText(reasonText);
     if (data != null)
     {
         writer.Write(data);
     }
 }
コード例 #12
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(nonce);
 }
コード例 #13
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(timestamp);
     writer.Write(services);
     writer.WriteAddress(address);
     writer.WriteBigEndian(port);
 }
コード例 #14
0
 public void Write(BitcoinStreamWriter writer)
 {
     writer.Write(version);
     writer.Write(prevBlock);
     writer.Write(merkleRoot);
     writer.Write(timestamp);
     writer.Write(nBits);
     writer.Write(nonce);
 }
コード例 #15
0
        public void Write(BitcoinStreamWriter writer)
        {
            writer.Write(protocolVersion);
            writer.Write(services);
            writer.Write(timestamp);

            writer.Write(remoteServices);
            writer.WriteAddress(remoteEndpoint.Address);
            writer.WriteBigEndian((ushort) remoteEndpoint.Port);

            writer.Write(localServices);
            writer.WriteAddress(localEndpoint.Address);
            writer.WriteBigEndian((ushort) localEndpoint.Port);

            writer.Write(nonce);

            writer.WriteText(UserAgent);
            writer.Write(startHeight);
            writer.Write(acceptBroadcasts);
        }