Module: Cryptobank
- Defined in:
- lib/cryptobank.rb,
lib/cryptobank/error.rb,
lib/cryptobank/version.rb
Overview
Implements Bitcoin API JSON-RPC to communicate with bitcoind
Constant Summary collapse
- HEADERS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.freeze
- Error =
Class.new(StandardError)
- VERSION =
"0.1.2"
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#account(bitcoin_address) ⇒ Object
getaccount A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”) returns a base58 string.
-
#add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '') ⇒ Object
addmultisigaddress.
-
#add_node ⇒ Object
addnode.
-
#added_node_info ⇒ Object
getaddednodeinfo.
-
#backup_wallet ⇒ Object
backupwallet.
-
#balance(account = nil) ⇒ Object
getbalance There are additional parameters on the RPC docs to be implemented bitcoin.org/en/developer-reference#getbalance.
-
#best_block_hash ⇒ Object
getbestblockhash.
-
#block(verbosity = nil) ⇒ Object
getblock.
-
#block_count ⇒ Object
getblockcount.
-
#block_hash ⇒ Object
getblockhash.
-
#block_template(template_request = nil) ⇒ Object
getblocktemplate.
- #configure {|_self| ... } ⇒ Object
-
#connection_count ⇒ Object
getconnectioncount.
-
#create_multisig ⇒ Object
createmultisig.
-
#create_raw_transaction ⇒ Object
createrawtransaction.
-
#decode_raw_transaction ⇒ Object
decoderawtransaction.
-
#difficulty ⇒ Object
getdifficulty.
-
#dump_priv_key ⇒ Object
dumpprivkey.
-
#encrypt_wallet ⇒ Object
encryptwallet.
-
#generate ⇒ Object
getgenerate.
- #get_account_addresses(account) ⇒ Object
-
#hashes_per_sec ⇒ Object
gethashespersec.
-
#info ⇒ Object
getinfo.
-
#memory_pool_info ⇒ Object
getmempoolinfo.
Instance Attribute Details
#host ⇒ Object
15 16 17 |
# File 'lib/cryptobank.rb', line 15 def host @host || 'localhost' end |
#password ⇒ Object
27 28 29 |
# File 'lib/cryptobank.rb', line 27 def password @password || 'rpcpassword' end |
#port ⇒ Object
19 20 21 |
# File 'lib/cryptobank.rb', line 19 def port @port || 8332 end |
#user ⇒ Object
23 24 25 |
# File 'lib/cryptobank.rb', line 23 def user @user || 'rpcuser' end |
Instance Method Details
#account(bitcoin_address) ⇒ Object
getaccount A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”) returns a base58 string
82 83 84 85 86 87 88 |
# File 'lib/cryptobank.rb', line 82 def account(bitcoin_address) payload = { method: 'getaccount' } payload[:params] = [bitcoin_address.to_string] request(payload) end |
#add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '') ⇒ Object
addmultisigaddress
36 37 38 39 40 41 42 |
# File 'lib/cryptobank.rb', line 36 def add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '') payload = { method: 'addmultisigaddress' } payload[:params] = [minimum_number_of_sigs.to_int, key_or_addresses.to_string, account.to_string] request(payload) end |
#add_node ⇒ Object
addnode
45 46 47 |
# File 'lib/cryptobank.rb', line 45 def add_node raise NotImplementedError end |
#added_node_info ⇒ Object
getaddednodeinfo
91 92 93 |
# File 'lib/cryptobank.rb', line 91 def added_node_info raise NotImplementedError end |
#backup_wallet ⇒ Object
backupwallet
50 51 52 |
# File 'lib/cryptobank.rb', line 50 def backup_wallet raise NotImplementedError end |
#balance(account = nil) ⇒ Object
getbalance There are additional parameters on the RPC docs to be implemented bitcoin.org/en/developer-reference#getbalance
97 98 99 100 101 102 103 |
# File 'lib/cryptobank.rb', line 97 def balance(account = nil) payload = { method: 'getbalance' } payload[:params] = [account] unless account.nil? request(payload) end |
#best_block_hash ⇒ Object
getbestblockhash
106 107 108 |
# File 'lib/cryptobank.rb', line 106 def best_block_hash raise NotImplementedError end |
#block(verbosity = nil) ⇒ Object
getblock
111 112 113 114 115 116 117 |
# File 'lib/cryptobank.rb', line 111 def block(verbosity = nil) payload = { method: 'getblock' } payload[:params] = [template_request] unless verbosity.nil? request(payload) end |
#block_count ⇒ Object
getblockcount
128 129 130 131 132 133 |
# File 'lib/cryptobank.rb', line 128 def block_count payload = { method: 'getblockcount' } request(payload) end |
#block_hash ⇒ Object
getblockhash
120 121 122 123 124 125 |
# File 'lib/cryptobank.rb', line 120 def block_hash payload = { method: 'getblockhash' } request(payload) end |
#block_template(template_request = nil) ⇒ Object
getblocktemplate
136 137 138 139 140 141 142 |
# File 'lib/cryptobank.rb', line 136 def block_template(template_request = nil) payload = { method: 'getblocktemplate' } payload[:params] = [template_request] unless template_request.nil? request(payload) end |
#configure {|_self| ... } ⇒ Object
31 32 33 |
# File 'lib/cryptobank.rb', line 31 def configure yield self end |
#connection_count ⇒ Object
getconnectioncount
145 146 147 148 149 150 |
# File 'lib/cryptobank.rb', line 145 def connection_count payload = { method: 'getconnectioncount' } request(payload) end |
#create_multisig ⇒ Object
createmultisig
55 56 57 |
# File 'lib/cryptobank.rb', line 55 def create_multisig raise NotImplementedError end |
#create_raw_transaction ⇒ Object
createrawtransaction
60 61 62 |
# File 'lib/cryptobank.rb', line 60 def create_raw_transaction raise NotImplementedError end |
#decode_raw_transaction ⇒ Object
decoderawtransaction
65 66 67 |
# File 'lib/cryptobank.rb', line 65 def decode_raw_transaction raise NotImplementedError end |
#difficulty ⇒ Object
getdifficulty
153 154 155 156 157 158 |
# File 'lib/cryptobank.rb', line 153 def difficulty payload = { method: 'getdifficulty' } request(payload) end |
#dump_priv_key ⇒ Object
dumpprivkey
70 71 72 |
# File 'lib/cryptobank.rb', line 70 def dump_priv_key raise NotImplementedError end |
#encrypt_wallet ⇒ Object
encryptwallet
75 76 77 |
# File 'lib/cryptobank.rb', line 75 def encrypt_wallet raise NotImplementedError end |
#generate ⇒ Object
getgenerate
161 162 163 164 165 166 |
# File 'lib/cryptobank.rb', line 161 def generate payload = { method: 'getgenerate' } request(payload) end |
#get_account_addresses(account) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/cryptobank.rb', line 168 def get_account_addresses(account) payload = { method: 'getaddressesbyaccount' } payload[:params] = [account] request(payload) end |
#hashes_per_sec ⇒ Object
gethashespersec
177 178 179 |
# File 'lib/cryptobank.rb', line 177 def hashes_per_sec raise NotImplementedError end |
#info ⇒ Object
getinfo
182 183 184 185 186 187 |
# File 'lib/cryptobank.rb', line 182 def info payload = { method: 'getwalletinfo' } request(payload) end |
#memory_pool_info ⇒ Object
getmempoolinfo
190 191 192 193 194 195 |
# File 'lib/cryptobank.rb', line 190 def memory_pool_info payload = { method: 'getmempoolinfo' } request(payload) end |