#api #blockchain #api-version #blockpulsar

bin+lib blockpulsar_client_rust

Rust client for Blockpulsar API

1 stable release

1.0.0 Aug 20, 2021

#80 in #api-version

Apache-2.0

39KB
906 lines

Blockpulsar Rust Client

Official Rust client for Blockpulsar API

Install

1. Edit the generated Cargo.toml file to add blockpulsar_client_rust as a dependency library:

[dependencies]
blockpulsar_client_rust="1.0.0"

2. Access the library in your code:

use blockpulsar_client_rust as bp;

3. Build the project with cargo build --release

Cargo will take care of managing the versions, building the dependencies when needed, and passing the correct arguments to the compiler to link together all of the dependencies.

Example

Set the api_key and secret_key keys obtaned from the website.

use blockpulsar_client_rust as bp;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let bp_client = bp::client::BlockpulsarClient::new("api_key", "secret_key");

  let bb_hash = bp_client.btc.get_best_block_hash().await;
  let block = bp_client.btc.get_block(&bb_hash).await;

  println!("{:?}", block);

  return Ok(());
}

Methods

// Returns the hash of the best (tip) block in the most-work fully-validated chain.
get_best_block_hash() -> String
// Get block.
//
// Args:
// -block_hash: The block hash
get_block(block_hash: &str) -> Block
// Returns an object containing various state info regarding blockchain processing.
get_blockchain_info() -> BlockchainInfo 
// Returns the height of the most-work fully-validated chain. The genesis block has height 0.
get_block_count() -> u32
// Returns hash of block in best-block-chain at height provided.
//
// Args:
// -height: The height index. The genesis block has height 0
get_block_hash(height: u32) -> String
// Get block header
//
// Args:
// -block_hash: The block hash
get_block_header(block_hash: &str) -> BlockHeader
// Compute per block statistics for a given window. All amounts are in satoshis.
//
// Args:
// -block_hash: The block hash
get_block_stats(block_hash: &str) -> BlockStats
// Return information about all known tips in the block tree, including the main chain
// as well as orphaned branches.
get_chain_tips() -> Vec<ChainTip>
// Compute statistics about the total number and rate of transactions in the chain.
//
// Args:
// -blockhash: (optional) The hash of the block that ends the window. Default is chain tip
// -nblocks: (optional) Size of the window in number of blocks.
get_chain_tx_stats(block_hash: &str, nblocks: u32) -> ChainTxStats
// Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
get_difficulty() -> f64
// Get memory pool ancestors.
//
// Args:
// -txid: The transaction id (must be in mempool)
get_mempool_ancestors(txid: &str) -> Vec<String>
// Get memory pool descendants.
//
// Args:
// -txid: The transaction id (must be in mempool)
get_mempool_descendants(txid: &str) -> Vec<String>
// Returns mempool data for given transaction.
//
// Args:
// -txid: The transaction id (must be in mempool)
get_mempool_entry(txid: &str) -> MempoolEntry
// Returns details on the active state of the transaction memory pool.
get_mempool_info() -> MempoolInfo
// Get raw memory pool data. A vector of TX IDs.
get_raw_mempool() -> Vec<String>
// Returns a json object containing mining-related information.
get_mining_info() -> MiningInfo
// Returns the estimated network hashes per second based on the last n blocks.
//
// Args:
// -nblocks: (optional) The number of blocks, or -1 for blocks since last difficulty change.
// -height: (optional) To estimate at the time of the given height.
get_network_hash_ps(nblocks: u32, height: i32) -> u128
// Get raw transaction. When called with a blockhash argument, getrawtransaction will
// return the transaction if the specified block is available and the transaction is found
// in that block.
//
// Args:
// -txid: The transaction ID
// -block_hash: The block in which to look for the transaction.
get_raw_transaction(txid: &str, block_hash: &str) -> RawTransaction
// Return information about the given bitcoin address.
//
// Args:
// -address: BTC address to be checked
validate_address(address: &str) -> ValidateAddress

Contributions

Contributions are welcome and can be made by submitting GitHub pull requests to this repository.
The blockpulsar_client_rs source code follows the Rust Style Guide and some modifed rules specified in .rustfmt.toml file.

Before making a commit or creating a PR please make sure to run the following command on the root directory

cargo +nightly fmt

License

This source code is available to everyone under the standard Apache-2.0 License.

Dependencies

~8–25MB
~405K SLoC