From 268047233c8b0182644563f7bb3341c5fd97b0d2 Mon Sep 17 00:00:00 2001 From: Wesley Hinds Date: Fri, 10 Mar 2023 16:30:35 -0600 Subject: [PATCH] Updated examples to be more current and more simple. --- ex/example.pl | 105 +++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 69 deletions(-) diff --git a/ex/example.pl b/ex/example.pl index 240a09a..7aeee91 100755 --- a/ex/example.pl +++ b/ex/example.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl use Bitcoin::RPC::Client; @@ -20,97 +20,64 @@ password => $RPCPASSWORD, ); -# https://bitcoin.org/en/developer-reference#getinfo -$info = $btc->getinfo; -$blocks = $info->{blocks}; -print $blocks; - -# https://bitcoin.org/en/developer-reference#getbalance -$balance = $btc->getbalance("root", 1, JSON::true); +# When a scalar value is returned +# https://developer.bitcoin.org/reference/rpc/getbalance.html +$balance = $btc->getbalance("*", 1, JSON::true); print $balance; +print "\n"; -# https://bitcoin.org/en/developer-reference#getblockchaininfo -$info = $btc->getblockchaininfo; -print $info->{softforks}[0]->{id}; - - -### -# More on handling JSON data -### - -# Getting Data when JSON/hash is returned from getinfo -# https://bitcoin.org/en/developer-reference#getinfo +# Getting data when JSON/hash is returned from getblockchaininfo +# https://developer.bitcoin.org/reference/rpc/getblockchaininfo.html # #{ # "version": 130000, -# "protocolversion": 70014, -# "walletversion": 130000, -# "balance": 0.00000000, # "blocks": 584240, -# "proxy": "", -# "difficulty": 1, -# "paytxfee": 0.00500000, -# "relayfee": 0.00001000, -# "errors": "" +# "paytxfee": 0.00500000 #} -$info = $btc->getinfo; -$balance = $info->{balance}; -print $balance; -# 0.0 - +$info = $btc->getblockchaininfo; +$blocks = $info->{blocks}; +print $blocks; +print "\n"; +# 584240 + # JSON Objects # Let's say we want the timeframe value from getnetttotals -# https://bitcoin.org/en/developer-reference#getnettotals +# https://developer.bitcoin.org/reference/rpc/getnettotals.html # #{ # "totalbytesrecv": 7137052851, # "totalbytessent": 211648636140, # "uploadtarget": { # "timeframe": 86400, -# "target": 0, -# "target_reached": false, -# "serve_historical_blocks": true, -# "bytes_left_in_cycle": 0, -# "time_left_in_cycle": 0 +# "target": 0 # } #} $nettot = $btc->getnettotals; -$timeframe = $nettot->{uploadtarget}{timeframe}; +$timeframe = $nettot->{uploadtarget}->{timeframe}; print $timeframe; +print "\n"; # 86400 - + # JSON arrays -# Let's say we want the softfork IDs from getblockchaininfo -# https://bitcoin.org/en/developer-reference#getblockchaininfo -# +# Let's say we want the feerate_percentiles from getblockstats +# https://developer.bitcoin.org/reference/rpc/getblockstats.html #{ -# "chain": "main", -# "blocks": 464562, -# "headers": 464562, -# "pruned": false, -# "softforks": [ -# { -# "id": "bip34", -# "version": 2, -# "reject": { -# "status": true -# } -# }, -# { -# "id": "bip66", -# "version": 3, -# "reject": { -# "status": true -# } -# } -$bchain = $btc->getblockchaininfo; -@forks = @{ $bchain->{softforks} }; -foreach $f (@forks) { - print $f->{id}; +# "avgfee": 8967, +# "avgfeerate": 28, +# "feerate_percentiles": [1,1,3,62,65], +# "height": 584240, +# "maxfee": 850011 +#} +$bstats = $btc->getblockstats(584240); +@fps = @{ $bstats->{feerate_percentiles} }; +foreach $fr (@fps) { + print $fr; print "\n"; } -# bip34 -# bip66 - +# 1 +# 1 +# 3 +# 62 +# 65 exit(0);