pub trait PoolIdentification {
// Required methods
fn identify_coinbase_tag(
&self,
pools: &[Pool],
) -> Option<IdentificationResult>;
fn identify_coinbase_output_address(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult>;
fn coinbase_script_as_utf8(&self) -> String;
fn coinbase_output_addresses(&self, network: Network) -> Vec<Address>;
// Provided method
fn identify_pool(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult> { ... }
}
Expand description
Trait for Bitcoin mining pool identification based on metadata like coinbase tags or coinbase output addresses.
Required Methods§
Sourcefn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
fn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
Checks coinbase tags from against the UTF-8 encoded coinbase script_sig to identify mining pools.
These coinbase tags are not authenticated and can easily be faked by a malicious party.
The coinbase tag for the ViaBTC pool is, for example, /ViaBTC/
. An
UTF-8 encoded coinbase looks, for example, like (line breaks removed):
l</ViaBTC/Mined by leehoo4444/,��mmA�G��CT�)�טb^��̵�g��,Eܩ(
Sourcefn identify_coinbase_output_address(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult>
fn identify_coinbase_output_address( &self, network: Network, pools: &[Pool], ) -> Option<IdentificationResult>
Checks the coinbase output address against a list of known pool
addresses and returns a found pool. If no output address matches, then
None
is returned.
Sourcefn coinbase_script_as_utf8(&self) -> String
fn coinbase_script_as_utf8(&self) -> String
Returns the coinbase script encoded as lossy UTF-8 String (any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �). Line-breaks are removed as well.
Sourcefn coinbase_output_addresses(&self, network: Network) -> Vec<Address>
fn coinbase_output_addresses(&self, network: Network) -> Vec<Address>
Returns the coinbase output addresses for all output types that can be represented as addresses. This excludes, for example, P2PK or OP_RETURN outputs. Addresses are ordered by value (descending).
Provided Methods§
Sourcefn identify_pool(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult>
fn identify_pool( &self, network: Network, pools: &[Pool], ) -> Option<IdentificationResult>
Checks both the coinbase output address and coinbase tags against known values to identify a mining pool. The coinbase output address is checked first, as it is harder to fake than the coinbase tag. Coinbase tags are not authenticated and can easily be faked by a malicious party.
If both methods can’t identify the pool, then None
is returned.
/// # Examples
use bitcoin::{Transaction, Network};
use bitcoin_pool_identification::{IdentificationMethod, Pool, PoolIdentification, default_data, DEFAULT_MAINNET_POOL_LIST};
use bitcoin::hex::FromHex;
// Bitcoin mainnet coinbase transaction of block 670828 mined by ViaBTC:
// 71093a08fe47c9d0c08921049f1a317541d78470376d7029c5e27fda2205361b
let rawtx = Vec::from_hex("010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5f036c3c0a1c2f5669614254432f4d696e6564206279206c6565686f6f343434342f2cfabe6d6d41f647100ea398435411f0297fd9d798625e1b82c82451f7c6ccb59c0c67ec07100000000000000010d02cfe0845dca9281bb0ee077c090000ffffffff04bdb8892b000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3a2f21f07f3619ef6521a90de396c2617f2edc5bda4fd04aba89632f2c002f79bc0000000000000000266a24b9e11b6d2dd1c7233a019c512c5f1e105e185a6ea0a47824b5ae390cc7cec5c01714588b0000000000000000266a24aa21a9ed23418324183dba97076f21aadc97aeeb1782c6859faf8e141c601e5c856c55440120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
let tx: Transaction = bitcoin::consensus::deserialize(&rawtx).unwrap();
let pools = default_data(Network::Bitcoin);
let pool = tx.identify_pool(Network::Bitcoin, &pools).unwrap().pool;
assert_eq!(pool.name, "ViaBTC".to_string());
Implementations on Foreign Types§
Source§impl PoolIdentification for Block
impl PoolIdentification for Block
Source§fn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
fn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
Checks coinbase tags from against the UTF-8 encoded coinbase script_sig to identify mining pools.
These coinbase tags are not authenticated and can easily be faked by a malicious party.
The coinbase tag for the ViaBTC pool is, for example, /ViaBTC/
. An
UTF-8 encoded coinbase looks, for example, like (line breaks removed):
l</ViaBTC/Mined by leehoo4444/,��mmA�G��CT�)�טb^��̵�g��,Eܩ(
Source§fn identify_coinbase_output_address(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult>
fn identify_coinbase_output_address( &self, network: Network, pools: &[Pool], ) -> Option<IdentificationResult>
Checks the coinbase output addresses against a list of known pool
addresses and returns a found pool. If no output address matches, then
None
is returned.
Source§fn coinbase_script_as_utf8(&self) -> String
fn coinbase_script_as_utf8(&self) -> String
Returns the coinbase script encoded as lossy UTF-8 String (any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �). Line-breaks are removed as well.
Source§impl PoolIdentification for Transaction
impl PoolIdentification for Transaction
Source§fn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
fn identify_coinbase_tag(&self, pools: &[Pool]) -> Option<IdentificationResult>
Checks coinbase tags from against the UTF-8 encoded coinbase script_sig to identify mining pools.
These coinbase tags are not authenticated and can easily be faked by a malicious party.
The coinbase tag for the ViaBTC pool is, for example, /ViaBTC/
. An
UTF-8 encoded coinbase looks, for example, like (line breaks removed):
l</ViaBTC/Mined by leehoo4444/,��mmA�G��CT�)�טb^��̵�g��,Eܩ(
§Panics
The caller MUST make sure the transaction is a coinbase transaction This can be done, for example, with [Transaction::is_coin_base()]. This is asserted and will panic.
§Examples
use bitcoin::{Transaction, Network};
use bitcoin_pool_identification::{Pool, PoolIdentification, DEFAULT_MAINNET_POOL_LIST, default_data};
use bitcoin::hex::FromHex;
// Bitcoin mainnet coinbase transaction of block 670828 mined by ViaBTC:
// 71093a08fe47c9d0c08921049f1a317541d78470376d7029c5e27fda2205361b
let rawtx = Vec::from_hex("010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5f036c3c0a1c2f5669614254432f4d696e6564206279206c6565686f6f343434342f2cfabe6d6d41f647100ea398435411f0297fd9d798625e1b82c82451f7c6ccb59c0c67ec07100000000000000010d02cfe0845dca9281bb0ee077c090000ffffffff04bdb8892b000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3a2f21f07f3619ef6521a90de396c2617f2edc5bda4fd04aba89632f2c002f79bc0000000000000000266a24b9e11b6d2dd1c7233a019c512c5f1e105e185a6ea0a47824b5ae390cc7cec5c01714588b0000000000000000266a24aa21a9ed23418324183dba97076f21aadc97aeeb1782c6859faf8e141c601e5c856c55440120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
let tx: Transaction = bitcoin::consensus::deserialize(&rawtx).unwrap();
let pools = default_data(Network::Bitcoin);
let pool = tx.identify_coinbase_tag(&pools).unwrap().pool;
assert_eq!(pool.name, "ViaBTC");
Source§fn identify_coinbase_output_address(
&self,
network: Network,
pools: &[Pool],
) -> Option<IdentificationResult>
fn identify_coinbase_output_address( &self, network: Network, pools: &[Pool], ) -> Option<IdentificationResult>
Checks the coinbase output address against a list of known pool
addresses and returns a found pool. If no output address matches, then
None
is returned.
§Panics
The caller MUST make sure the transaction is a coinbase transaction This can be done, for example, with Transaction::is_coinbase().
§Examples
use bitcoin::{Transaction, Network};
use bitcoin_pool_identification::{IdentificationMethod, Pool, PoolIdentification, DEFAULT_MAINNET_POOL_LIST, default_data};
use bitcoin::hex::FromHex;
// Bitcoin mainnet coinbase transaction of block 670828 mined by ViaBTC:
// 71093a08fe47c9d0c08921049f1a317541d78470376d7029c5e27fda2205361b
let rawtx = Vec::from_hex("010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5f036c3c0a1c2f5669614254432f4d696e6564206279206c6565686f6f343434342f2cfabe6d6d41f647100ea398435411f0297fd9d798625e1b82c82451f7c6ccb59c0c67ec07100000000000000010d02cfe0845dca9281bb0ee077c090000ffffffff04bdb8892b000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3a2f21f07f3619ef6521a90de396c2617f2edc5bda4fd04aba89632f2c002f79bc0000000000000000266a24b9e11b6d2dd1c7233a019c512c5f1e105e185a6ea0a47824b5ae390cc7cec5c01714588b0000000000000000266a24aa21a9ed23418324183dba97076f21aadc97aeeb1782c6859faf8e141c601e5c856c55440120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
let tx: Transaction = bitcoin::consensus::deserialize(&rawtx).unwrap();
let pools = default_data(Network::Bitcoin);
let pool = tx.identify_coinbase_output_address(Network::Bitcoin, &pools);
assert_eq!(pool, None);
Source§fn coinbase_script_as_utf8(&self) -> String
fn coinbase_script_as_utf8(&self) -> String
Returns the coinbase script encoded as lossy UTF-8 String (any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �). Line-breaks are removed as well.
§Panics
The caller MUST make sure the transaction is a coinbase transaction This can be done, for example, with Transaction::is_coinbase(). This is asserted and will panic.
Source§fn coinbase_output_addresses(&self, network: Network) -> Vec<Address>
fn coinbase_output_addresses(&self, network: Network) -> Vec<Address>
Returns the coinbase output addresses for all output types that can be represented as addresses. This excludes, for example, P2PK or OP_RETURN outputs. Addresses are ordered by value (descending).
§Panics
The caller MUST make sure the transaction is a coinbase transaction This can be done, for example, with Transaction::is_coinbase().