Module sv::messages[][src]

Expand description

Peer-to-peer network protocol messages

Examples

Decode a network message

use sv::messages::Message;
use sv::network::Network;
use std::io::Cursor;

let bytes = [
    227, 225, 243, 232, 104, 101, 97, 100, 101, 114, 115,
    0, 0, 0, 0, 0, 1, 0, 0, 0, 20, 6, 224, 88, 0,
];
let magic = Network::Mainnet.magic();
let message = Message::read(&mut Cursor::new(&bytes), magic).unwrap();

match message {
    Message::Headers(headers) => { /* Handle headers message */ },
    _ => { /* All other messages */ }
}

Construct a transaction:

use sv::messages::{OutPoint, Tx, TxIn, TxOut};
use sv::transaction::p2pkh::{create_lock_script, create_unlock_script};
use sv::util::{hash160, Hash256};

// Use real values here
let signature = [0; 72];
let public_key = [0; 33];
let prev_output = OutPoint {
    hash: Hash256([0; 32]),
    index: 0,
};

let inputs = vec![TxIn {
    prev_output,
    unlock_script: create_unlock_script(&signature, &public_key),
    sequence: 0,
}];

let outputs = vec![TxOut {
    satoshis: 1000,
    lock_script: create_lock_script(&hash160(&public_key)),
}];

let tx = Tx {
    version: 2,
    inputs,
    outputs,
    lock_time: 0,
};

Modules

Message commands for the header

Structs

Known node addresses

Block of transactions

Block header

Specifies which blocks to return

Specifies the minimum transaction fee this node accepts

Adds a data element to the bloom filter

Loads a bloom filter using the specified parameters

Collection of block headers

Inventory payload describing objects a node knows about

Inventory vector describing an object being requested or announced

A block header and partial merkle tree for SPV nodes to validate transactions

Header that begins all messages

Network address for a node on the network

Node network address extended with a last connected time

Reference to a transaction output

Ping or pong payload

Rejected message

Specifies whether compact blocks are supported

Bitcoin transaction

Transaction input

Transaction output

Version payload defining a node’s capabilities

Enums

Bitcoin peer-to-peer message with its payload

Constants

Filter is updated to include the serialized outpoint if any data elements matched in its script pubkey

Filter is not adjusted when a match is found

Filter is updated simialr to BLOOM_UPDATE_ALL but only for P2PK or multisig transactions

The coinbase transaction input will have this hash

The coinbase transaction input will have this index

Hash of a block header.

Hash of a block header. Indicates the reply should be a cmpctblock message.

May be ignored

Hash of a block header. Indicates the reply should be a merkleblock message.

Hash of a transaction

Maximum size of a data element in the FilterAdd message

Maximum number of objects in an inv message

Max message payload size (32MB)

Maximum number of satoshis possible

Minimum protocol version supported by this library

Service flag that node is a full node and implements all protocol features

Service flag that node is a full node and implements all protocol features

Service flag that node is not a full node. Used for SPV wallets.

Checksum to use when there is an empty payload

Return results until either there are 2000 for getheaders or 500 or getblocks, or no more left

Protocol version supported by this library

Unknown IP address to use as a default

Traits

Message payload that is writable to bytes

Functions

Returns the hash for a header at a particular index utilizing prev_hash if possible