Expand description
Peer-to-peer network protocol messages
§Examples
Decode a network message
use bch::messages::Message;
use bch::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 bch::messages::{OutPoint, Tx, TxIn, TxOut};
use bch::transaction::p2pkh::{create_pk_script, create_sig_script};
use bch::util::{hash160, Amount, Hash256, Units};
// 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,
sig_script: create_sig_script(&signature, &public_key),
sequence: 0,
}];
let outputs = vec![TxOut {
amount: Amount::from(1., Units::Bch),
pk_script: create_pk_script(&hash160(&public_key)),
}];
let tx = Tx {
version: 2,
inputs,
outputs,
lock_time: 0,
};
Modules§
- commands
- Message commands for the header
Structs§
- Addr
- Known node addresses
- Block
- Block of transactions
- Block
Header - Block header
- Block
Locator - Specifies which blocks to return
- FeeFilter
- Specifies the minimum transaction fee this node accepts
- Filter
Add - Adds a data element to the bloom filter
- Filter
Load - Loads a bloom filter using the specified parameters
- Headers
- Collection of block headers
- Inv
- Inventory payload describing objects a node knows about
- InvVect
- Inventory vector describing an object being requested or announced
- Merkle
Block - A block header and partial merkle tree for SPV nodes to validate transactions
- Message
Header - Header that begins all messages
- Node
Addr - Network address for a node on the network
- Node
Addr Ex - Node network address extended with a last connected time
- OutPoint
- Reference to a transaction output
- Ping
- Ping or pong payload
- Reject
- Rejected message
- Send
Cmpct - Specifies whether compact blocks are supported
- Tx
- Bitcoin transaction
- TxIn
- Transaction input
- TxOut
- Transaction output
- Version
- Version payload defining a node’s capabilities
Enums§
- Message
- Bitcoin peer-to-peer message with its payload
Constants§
- BLOOM_
UPDATE_ ALL - Filter is updated to include the serialized outpoint if any data elements matched in its script pubkey
- BLOOM_
UPDATE_ NONE - Filter is not adjusted when a match is found
- BLOOM_
UPDATE_ P2PUBKEY_ ONLY - Filter is updated simialr to BLOOM_UPDATE_ALL but only for P2PK or multisig transactions
- COINBASE_
OUTPOINT_ HASH - The coinbase transaction input will have this hash
- COINBASE_
OUTPOINT_ INDEX - The coinbase transaction input will have this index
- INV_
VECT_ BLOCK - Hash of a block header.
- INV_
VECT_ COMPACT_ BLOCK - Hash of a block header. Indicates the reply should be a cmpctblock message.
- INV_
VECT_ ERROR - May be ignored
- INV_
VECT_ FILTERED_ BLOCK - Hash of a block header. Indicates the reply should be a merkleblock message.
- INV_
VECT_ TX - Hash of a transaction
- MAX_
FILTER_ ADD_ DATA_ SIZE - Maximum size of a data element in the FilterAdd message
- MAX_
INV_ ENTRIES - Maximum number of objects in an inv message
- MAX_
PAYLOAD_ SIZE - Max message payload size (32MB)
- MAX_
SATOSHIS - Maximum number of satoshis possible
- MIN_
SUPPORTED_ PROTOCOL_ VERSION - Minimum protocol version supported by this library
- NODE_
BITCOIN_ CASH - Service flag that node is a full node and implements all protocol features
- NODE_
NETWORK - Service flag that node is a full node and implements all protocol features
- NODE_
NONE - Service flag that node is not a full node. Used for SPV wallets.
- NO_
CHECKSUM - Checksum to use when there is an empty payload
- NO_
HASH_ STOP - Return results until either there are 2000 for getheaders or 500 or getblocks, or no more left
- PROTOCOL_
VERSION - Protocol version supported by this library
- REJECT_
CHECKPOINT - REJECT_
DUPLICATE - REJECT_
DUST - REJECT_
INSUFFICIENT_ FEE - REJECT_
INVALID - REJECT_
MALFORMED - REJECT_
NONSTANDARD - REJECT_
OBSOLETE - UNKNOWN_
IP - Unknown IP address to use as a default
Traits§
- Payload
- Message payload that is writable to bytes
Functions§
- header_
hash - Returns the hash for a header at a particular index utilizing prev_hash if possible