pub struct Client {
pub bitcoind_request_client: Client,
}Fields§
§bitcoind_request_client: ClientImplementations§
Source§impl Client
impl Client
Sourcepub fn new(url: &str, user: &str, pass: &str) -> Result<Self, Error>
pub fn new(url: &str, user: &str, pass: &str) -> Result<Self, Error>
Examples found in repository?
examples/example.rs (line 39)
32fn main() {
33 /////////////////////////////////////////////////////////////////////
34 //////////Blockchain Data //////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////////
36 let password = env::var("BITCOIND_PASSWORD").expect("BITCOIND_PASSWORD env variable not set");
37 let username = env::var("BITCOIND_USERNAME").expect("BITCOIND_USERNAME env variable not set");
38 let url = env::var("BITCOIND_URL").expect("BITCOIND_URL env variable not set");
39 let client = Client::new(&url, &username, &password).expect("failed to create client");
40
41 let block_height = get_block_height(&client);
42 println!("BLOCK HEIGHT: {:#?}", block_height);
43
44 // let seconds_since_last_block = get_time_since_last_block_in_seconds(&client);
45 // println!(
46 // "TIME SINCE LAST BLOCK: {}",
47 // format_duration(seconds_since_last_block)
48 // );
49
50 // let average_seconds_per_block_last_2016_blocks =
51 // get_average_block_time_for_last_2016_blocks(&client);
52 // println!(
53 // "AVERAGE BLOCK TIME (2016): {}",
54 // format_duration(average_seconds_per_block_last_2016_blocks as i64)
55 // );
56 // let average_seconds_per_block_since_last_difficulty_adjustment =
57 // get_average_block_time_for_since_last_difficulty_adjustement(&client);
58 // println!(
59 // "AVERAGE BLOCK TIME (SINCE LAST_DIFFICULTY ADJUSTMENT): {}",
60 // format_duration(average_seconds_per_block_since_last_difficulty_adjustment as i64)
61 // );
62
63 // // Errors out because: https://github.com/apoelstra/rust-jsonrpc/issues/67
64 // // let total_money_supply = get_total_money_supply(&client);
65 // // println!("TOTAL MONEY SUPPLY: {:#?}", total_money_supply);
66
67 // let chain_size = get_chain_size(&client);
68 // let chain_size_in_gbs = chain_size as f64 / 1_000_000_000.0;
69 // println!("CHAIN SIZE: {:#?}GB", chain_size_in_gbs);
70
71 // // Errors out because: https://github.com/apoelstra/rust-jsonrpc/issues/67
72 // // let utxo_set_size = get_utxo_set_size(&client);
73 // // println!("UTXO SET SIZE: {:#?}", utxo_set_size);
74
75 // /////////////////////////////////////////////////////////////////////
76 // //////////Blockchain Data //////////////////////////////////////////
77 // /////////////////////////////////////////////////////////////////////
78 // let total_transactions_count = get_total_transactions_count(&client);
79 // println!("TOTAL TRANSACTIONS COUNT: {:#?}", total_transactions_count);
80
81 // let tps_for_last_30_days = get_tps_for_last_30_days(&client);
82 // println!(
83 // "TRANSACTIONS PER SECOND (last 30 days): {:#?} tx/s",
84 // tps_for_last_30_days
85 // );
86
87 // // takes a long time
88 // let transactions_count_over_last_30_days = get_transactions_count_over_last_30_days(&client);
89 // println!(
90 // "TRANSACTIONS COUNT OVER LAST 30 DAYS: {:#?}",
91 // transactions_count_over_last_30_days
92 // );
93
94 // // takes a long time
95 // let total_fee_for_24_hours = get_total_fee_for_24_hours(&client);
96 // println!(
97 // "TOTAL FEE FOR LAST 24 hours: {:#?} btc",
98 // total_fee_for_24_hours as f64 / 100_000_000.0
99 // );
100
101 // let difficulty = get_difficulty(&client);
102 // let trillion: u64 = 1_000_000_000_000;
103 // let difficulty_per_trillion: f64 = difficulty as f64 / trillion as f64;
104 // println!("Difficulty: {:.2}x10^12", difficulty_per_trillion);
105
106 // let current_difficulty_epoch = get_current_difficulty_epoch(&client);
107 // println!("CURRENT EPOCH: {:?}", current_difficulty_epoch);
108 // let block_height_of_last_difficulty_adjustment =
109 // get_block_height_of_last_difficulty_adjustment(&client);
110 // println!(
111 // "BLOCK HEIGHT OF LAST DIFFICULTY: {:?}",
112 // block_height_of_last_difficulty_adjustment
113 // );
114
115 // let mempool_transaction_count = get_mempool_transactions_count(&client);
116 // println!("MEMPOOL TRANSACTION COUNT: {:?}", mempool_transaction_count);
117
118 // let hash_rate_since_last_difficulty_change =
119 // get_estimated_hash_rate_per_second_for_block_since_last_difficulty_change(&client);
120 // println!(
121 // "ESTIMATED HASH RATE SINCE LAST DIFFICULTY CHANGE: {}",
122 // hash_rate_since_last_difficulty_change
123 // );
124 // let hash_rate_for_last_2016_blocks =
125 // get_estimated_hash_rate_per_second_for_last_2016_blocks(&client);
126 // println!(
127 // "ESTIMATED HASH RATE FOR LAST 2016 BLOCKS: {}",
128 // hash_rate_for_last_2016_blocks
129 // );
130 // let hash_rate_for_last_epoch = get_estimated_hash_rate_per_second_for_last_epoch(&client);
131 // println!(
132 // "ESTIMATED HASH RATE FOR LAST EPOCH: {}",
133 // hash_rate_for_last_epoch
134 // );
135 // let blocks_till_difficulty_adjustment = get_blocks_count_until_retarget(&client);
136 // println!(
137 // "BLOCKS TILL DIFFICULTY ADJUSTMENT: {}",
138 // blocks_till_difficulty_adjustment
139 // );
140 // let estimated_seconds_until_retarget = get_estimated_seconds_until_retarget(&client);
141 // println!(
142 // "ESTIMATED SECONDS UNTIL RETARGET: {}",
143 // estimated_seconds_until_retarget
144 // );
145
146 // // takes a long time
147 // let blocks_mined_over_last_24_hours = get_blocks_mined_over_last_24_hours_count(&client);
148 // println!(
149 // "BLOCKS MINED OVER LAST 24 HOURS: {}",
150 // blocks_mined_over_last_24_hours
151 // );
152 // // takes a long time
153 // let average_fees_per_block_over_last_24_hours =
154 // get_average_fees_per_block_over_last_24_hours(&client);
155 // println!(
156 // "AVERAGE FEES PER BLOCK OVER LAST 24 HOURS: {} btc",
157 // average_fees_per_block_over_last_24_hours as f64 / 100_000_000.0
158 // );
159 // // takes a long time
160 // let average_fees_per_block_over_last_2016_blocks =
161 // get_average_fees_per_block_over_last_2016_blocks(&client);
162 // println!(
163 // "AVERAGE FEES PER BLOCK OVER LAST 2016 BLOCKS: {} btc",
164 // average_fees_per_block_over_last_2016_blocks as f64 / 100_000_000.0
165 // );
166
167 // //takes a long time
168 // let fees_as_a_percent_of_reward_for_last_24_hours_ =
169 // get_fees_as_a_percent_of_reward_for_last_24_hours(&client);
170 // println!(
171 // "FEES AS A PERCENT OF REWARD OVER THE LAST 24 HOURS: {}",
172 // fees_as_a_percent_of_reward_for_last_24_hours_
173 // );
174 // // takes a long time
175 let fees_as_a_percent_of_reward_for_last_2016_blocks =
176 get_fees_as_a_percent_of_reward_for_last_2016_blocks(&client);
177 println!(
178 "FEES AS A PERCENT OF REWARD OVER THE LAST 2016 BLOCKS: {}",
179 fees_as_a_percent_of_reward_for_last_2016_blocks
180 );
181
182 // let block_subsidy_of_most_recent_block = get_block_subsidy_of_most_recent_block(&client);
183 // println!(
184 // "BLOCK SUBSIDY OF MOST RECENT BLOCK: {} btc",
185 // block_subsidy_of_most_recent_block as f64 / 100_000_000.0
186 // );
187
188 // I expect about 37.4% Script hash transactions over the last 90 days
189 //let script_hash = get_percent_of_vouts_used_scripthash_over_last_90_days(&client);
190 //println!("scripthash (starts with 3)%: {:#?}", script_hash);
191
192 // I expect about 37.4% Script hash transactions over the last 90 days
193 // SEGWIT ADOPTION
194 // TODO: check the is_segwith_adress function and make sure it's exactly how you want to
195 // define what segwith type you're looking for
196 let (
197 percent_of_transactions_with_a_segwit_vout,
198 percent_of_transactions_with_a_segwit_vin_or_vout,
199 percent_based_on_transaction_hexes,
200 percent_of_payments_spending_segwit_per_day,
201 percent_of_segwit_spending_transactions_per_day,
202 ) = get_percent_of_vouts_used_segwit_over_last_24_hours(&client);
203 println!(
204 "segwit percent (vouts): {:#?}",
205 percent_of_transactions_with_a_segwit_vout
206 );
207 println!(
208 "segwit percent (vouts or vins): {:#?}",
209 percent_of_transactions_with_a_segwit_vin_or_vout,
210 );
211 // https://bitbo.io/
212 println!(
213 "segwit percent (transaction_hexes): {:#?}",
214 percent_based_on_transaction_hexes
215 );
216 // https://transactionfee.info/charts/payments-spending-segwit/
217 println!(
218 "percent of payments spending segwit_per_day: {:#?}",
219 percent_of_payments_spending_segwit_per_day
220 );
221 // https://transactionfee.info/charts/transactions-spending-segwit/
222 println!(
223 "percent of segwit spending transactions per day: {:#?}",
224 percent_of_segwit_spending_transactions_per_day
225 );
226 println!("total money supply: {:#?}", get_total_money_supply(&client));
227 println!("utxo set size: {:#?}", get_utxo_set_size(&client));
228 println!("total money supply: {:#?}", get_total_money_supply(&client));
229 println!("utxo set size: {:#?}", get_utxo_set_size(&client));
230}pub fn build_request<'a>( &self, command: &'a str, params: &'a Vec<Box<RawValue>>, ) -> Request<'a>
pub fn send_request( &self, request: Request<'_>, ) -> Result<JsonRPCResponse, Error>
Auto Trait Implementations§
impl !Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more