#node #bitcoin #query #request

bitcoin-node-query

查询您的比特币节点

10个版本

0.1.9 2022年10月10日
0.1.8 2022年8月28日

#327 in #request

Download history 6/week @ 2024-03-09 1/week @ 2024-03-16 17/week @ 2024-03-30 4/week @ 2024-04-06

每月下载量:70
用于 2 crates

MIT 许可证

35KB
548

☠️⚠️ 进行中 ⚠️☠️

Bitcoin Node Query

从比特币节点请求信息

此库提供了一些有用的函数,用于查询关于比特币网络的常用信息。

安装

将包添加到Cargo.toml文件

[dependencies]
bitcoin-node-query = "0.1.9"

用法

use bitcoin_node_query::{
  Client,
  get_block_height,
  get_time_since_last_block_in_seconds,
  get_average_block_time_for_last_2016_blocks
}

// Create a Client.
let bitcoind_password: &str = ...
let bitcoind_username: &str = ...
let bitcoind_url = "127.0.0.1:8332"
let client = Client::new(
        &bitcoind_url,
        &bitcoind_username,
        &bitcoind_password
    ).expect("failed to create client");

// get block height
let block_height = get_block_height(&client);
println!("Block height: {:#?}", block_height);

// Get how many seconds ago the last block was mined 
let seconds_since_last_block = get_time_since_last_block_in_seconds(&client);
println!(
    "Seconds since last block:",
    format_duration(seconds_since_last_block)
);

// Get the average seconds it took for each of the last 2016 blocks to be mined
let average_seconds_per_block_last_2016_blocks =
get_average_block_time_for_last_2016_blocks(&client);
println!(
    "Average block time for last 2016 blocks",
    format_duration(average_seconds_per_block_last_2016_blocks as i64)
);

API

文档中查找所有可用函数的列表

许可证

MIT © Joe Gesualdo

依赖项

~6–16MB
~219K SLoC