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) { previousOutput.Write(writer); writer.WriteCompact((ulong) signatureScript.Length); writer.Write(signatureScript); writer.Write(sequence); }
public void Write(BitcoinStreamWriter writer) { writer.Write(protocolVersion); writer.WriteCompact((ulong) locatorHashes.Count); foreach (byte[] hash in locatorHashes) { writer.Write(hash); } writer.Write(hashStop); }
public void Write(BitcoinStreamWriter writer) { writer.Write((int) type); writer.Write(hash); }
public void Write(BitcoinStreamWriter writer) { writer.Write(Payload); }
public void Write(BitcoinStreamWriter writer) { writer.Write(value); writer.WriteCompact((ulong) pubkeyScript.Length); writer.Write(pubkeyScript); }
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); }
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); }
public void Write(BitcoinStreamWriter writer) { writer.Write(hash); writer.Write(index); }
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); }
public void Write(BitcoinStreamWriter writer) { writer.WriteText(rejectedCommand); writer.Write((byte) reason); writer.WriteText(reasonText); if (data != null) { writer.Write(data); } }
public void Write(BitcoinStreamWriter writer) { writer.Write(nonce); }
public void Write(BitcoinStreamWriter writer) { writer.Write(timestamp); writer.Write(services); writer.WriteAddress(address); writer.WriteBigEndian(port); }
public void Write(BitcoinStreamWriter writer) { writer.Write(version); writer.Write(prevBlock); writer.Write(merkleRoot); writer.Write(timestamp); writer.Write(nBits); writer.Write(nonce); }
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); }