Class: Bitcoin::Client
- Inherits:
-
Object
- Object
- Bitcoin::Client
- Defined in:
- lib/bitcoin/client.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Instance Method Summary collapse
-
#backupwallet(destination) ⇒ Object
Safely copies wallet.dat to destination, which can be a directory or a path with filename.
-
#getaccount(bitcoinaddress) ⇒ Object
(also: #account)
Returns the account associated with the given address.
-
#getaccountaddress(account) ⇒ Object
(also: #account_address)
Returns the current bitcoin address for receiving payments to this account.
-
#getaddressesbyaccount(account) ⇒ Object
(also: #addresses_by_account)
Returns the list of addresses for the given account.
-
#getbalance(account = nil, minconf = 1) ⇒ Object
(also: #balance)
If
account
is not specified, returns the server’s total available balance. -
#getblock(hash) ⇒ Object
Dumps the block existing with specified hash.
-
#getblockbycount(height) ⇒ Object
(also: #block_by_count)
Dumps the block existing at specified height.
-
#getblockcount ⇒ Object
(also: #block_count)
Returns the number of blocks in the longest block chain.
-
#getblocknumber ⇒ Object
(also: #block_number)
Returns the block number of the latest block in the longest block chain.
-
#getconnectioncount ⇒ Object
(also: #connection_count)
Returns the number of connections to other nodes.
-
#getdifficulty ⇒ Object
(also: #difficulty)
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
-
#getgenerate ⇒ Object
(also: #generate?)
Returns true or false whether bitcoind is currently generating hashes.
-
#gethashespersec ⇒ Object
(also: #hashes_per_sec)
Returns a recent hashes per second performance measurement while generating.
-
#getinfo ⇒ Object
(also: #info)
Returns an object containing various state info.
-
#getmininginfo ⇒ Object
Returns an object containing mining info.
-
#getnewaddress(account = nil) ⇒ Object
(also: #new_address)
Returns a new bitcoin address for receiving payments.
-
#getreceivedbyaccount(account, minconf = 1) ⇒ Object
(also: #received_by_account)
Returns the total amount received by addresses with
account
in transactions with at leastminconf
confirmations. -
#getreceivedbyaddress(bitcoinaddress, minconf = 1) ⇒ Object
(also: #received_by_address)
Returns the total amount received by
bitcoinaddress
in transactions with at leastminconf
confirmations. -
#gettransaction(txid) ⇒ Object
(also: #transaction)
Get detailed information about
txid
. -
#getwork(data = nil) ⇒ Object
(also: #work, #get_work)
If
data
is not specified, returns formatted hash data to work on:. -
#help(command = nil) ⇒ Object
List commands, or get help for a command.
- #host ⇒ Object
- #host=(a) ⇒ Object
-
#initialize(user, pass, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#listaccounts(minconf = 1) ⇒ Object
(also: #accounts)
Returns Object that has account names as keys, account balances as values.
-
#listreceivedbyaccount(minconf = 1, includeempty = false) ⇒ Object
(also: #list_received_by_account)
Returns an array of objects containing:.
-
#listreceivedbyaddress(minconf = 1, includeempty = false) ⇒ Object
(also: #list_received_by_address)
Returns an array of objects containing:.
-
#listtransactions(account, count = 10) ⇒ Object
(also: #transactions, #list_transactions)
Returns up to
count
most recent transactions for accountaccount
. -
#move(fromaccount, toaccount, amount, minconf = 1, comment = nil) ⇒ Object
Move from one account in your wallet to another.
- #options ⇒ Object
- #pass ⇒ Object
- #pass=(a) ⇒ Object
- #port ⇒ Object
- #port=(a) ⇒ Object
-
#sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil) ⇒ Object
(also: #send_from)
amount
is a real and is rounded to 8 decimal places. - #sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil) ⇒ Object (also: #send_many)
-
#sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil) ⇒ Object
(also: #send_to_address)
amount
is a real and is rounded to 8 decimal places. -
#setaccount(bitcoinaddress, account) ⇒ Object
(also: #account=, #set_account)
Sets the account associated with the given address.
-
#setgenerate(generate, genproclimit = -1)) ⇒ Object
(also: #generate=, #set_generate)
generate
is true or false to turn generation on or off. -
#signmessage(bitcoinaddress, message) ⇒ Object
(also: #sign_message)
Sign a message using
bitcoinaddress
. - #ssl ⇒ Object
- #ssl=(a) ⇒ Object
- #ssl? ⇒ Boolean
-
#stop ⇒ Object
Stop bitcoin server.
- #user ⇒ Object
- #user=(a) ⇒ Object
-
#validateaddress(bitcoinaddress) ⇒ Object
(also: #validate_address)
Return information about
bitcoinaddress
. -
#verifymessage(bitcoinaddress, signature, message) ⇒ Object
(also: #verify_message)
Verify signature made by
bitcoinaddress
. -
#walletlock ⇒ Object
Removes the wallet encryption key from memory, locking the wallet.
-
#walletpassphrase(passphrase, timeout) ⇒ Object
Stores the wallet decryption key in memory for
timeout
seconds.
Constructor Details
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
2 3 4 |
# File 'lib/bitcoin/client.rb', line 2 def api @api end |
Instance Method Details
#backupwallet(destination) ⇒ Object
Safely copies wallet.dat to destination, which can be a directory or a path with filename.
24 25 26 |
# File 'lib/bitcoin/client.rb', line 24 def backupwallet(destination) @api.request 'backupwallet', destination end |
#getaccount(bitcoinaddress) ⇒ Object Also known as: account
Returns the account associated with the given address.
29 30 31 |
# File 'lib/bitcoin/client.rb', line 29 def getaccount(bitcoinaddress) @api.request 'getaccount', bitcoinaddress end |
#getaccountaddress(account) ⇒ Object Also known as: account_address
Returns the current bitcoin address for receiving payments to this account.
34 35 36 |
# File 'lib/bitcoin/client.rb', line 34 def getaccountaddress(account) @api.request 'getaccountaddress', account end |
#getaddressesbyaccount(account) ⇒ Object Also known as: addresses_by_account
Returns the list of addresses for the given account.
39 40 41 |
# File 'lib/bitcoin/client.rb', line 39 def getaddressesbyaccount(account) @api.request 'getaddressesbyaccount', account end |
#getbalance(account = nil, minconf = 1) ⇒ Object Also known as: balance
If account
is not specified, returns the server’s total available balance. If account
is specified, returns the balance in the account.
45 46 47 |
# File 'lib/bitcoin/client.rb', line 45 def getbalance(account = nil, minconf = 1) @api.request 'getbalance', account, minconf end |
#getblock(hash) ⇒ Object
Dumps the block existing with specified hash.
56 57 58 59 60 |
# File 'lib/bitcoin/client.rb', line 56 def getblock(hash) block = @api.request 'getblock', hash block["time"] = Time.at(block["time"]).utc block end |
#getblockbycount(height) ⇒ Object Also known as: block_by_count
Dumps the block existing at specified height. Note: this is not available in the official release
51 52 53 |
# File 'lib/bitcoin/client.rb', line 51 def getblockbycount(height) @api.request 'getblockbycount', height end |
#getblockcount ⇒ Object Also known as: block_count
Returns the number of blocks in the longest block chain.
63 64 65 |
# File 'lib/bitcoin/client.rb', line 63 def getblockcount @api.request 'getblockcount' end |
#getblocknumber ⇒ Object Also known as: block_number
Returns the block number of the latest block in the longest block chain.
68 69 70 |
# File 'lib/bitcoin/client.rb', line 68 def getblocknumber @api.request 'getblocknumber' end |
#getconnectioncount ⇒ Object Also known as: connection_count
Returns the number of connections to other nodes.
73 74 75 |
# File 'lib/bitcoin/client.rb', line 73 def getconnectioncount @api.request 'getconnectioncount' end |
#getdifficulty ⇒ Object Also known as: difficulty
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
78 79 80 |
# File 'lib/bitcoin/client.rb', line 78 def getdifficulty @api.request 'getdifficulty' end |
#getgenerate ⇒ Object Also known as: generate?
Returns true or false whether bitcoind is currently generating hashes
83 84 85 |
# File 'lib/bitcoin/client.rb', line 83 def getgenerate @api.request 'getgenerate' end |
#gethashespersec ⇒ Object Also known as: hashes_per_sec
Returns a recent hashes per second performance measurement while generating.
88 89 90 |
# File 'lib/bitcoin/client.rb', line 88 def gethashespersec @api.request 'gethashespersec' end |
#getinfo ⇒ Object Also known as: info
Returns an object containing various state info.
93 94 95 |
# File 'lib/bitcoin/client.rb', line 93 def getinfo @api.request 'getinfo' end |
#getmininginfo ⇒ Object
Returns an object containing mining info.
98 99 100 |
# File 'lib/bitcoin/client.rb', line 98 def getmininginfo @api.request 'getmininginfo' end |
#getnewaddress(account = nil) ⇒ Object Also known as: new_address
Returns a new bitcoin address for receiving payments. If account
is specified (recommended), it is added to the address book so payments received with the address will be credited to account
.
104 105 106 |
# File 'lib/bitcoin/client.rb', line 104 def getnewaddress(account = nil) @api.request 'getnewaddress', account end |
#getreceivedbyaccount(account, minconf = 1) ⇒ Object Also known as: received_by_account
Returns the total amount received by addresses with account
in transactions with at least minconf
confirmations.
110 111 112 |
# File 'lib/bitcoin/client.rb', line 110 def getreceivedbyaccount(account, minconf = 1) @api.request 'getreceivedbyaccount', account, minconf end |
#getreceivedbyaddress(bitcoinaddress, minconf = 1) ⇒ Object Also known as: received_by_address
Returns the total amount received by bitcoinaddress
in transactions with at least minconf
confirmations.
115 116 117 |
# File 'lib/bitcoin/client.rb', line 115 def getreceivedbyaddress(bitcoinaddress, minconf = 1) @api.request 'getreceivedbyaddress', bitcoinaddress, minconf end |
#gettransaction(txid) ⇒ Object Also known as: transaction
Get detailed information about txid
120 121 122 |
# File 'lib/bitcoin/client.rb', line 120 def gettransaction(txid) @api.request 'gettransaction', txid end |
#getwork(data = nil) ⇒ Object Also known as: work, get_work
If data
is not specified, returns formatted hash data to work on:
:midstate => precomputed hash state after hashing the first half of the data
:data => block data
:hash1 => formatted hash buffer for second hash
:target => little endian hash target
If data
is specified, tries to solve the block and returns true if it was successful.
132 133 134 |
# File 'lib/bitcoin/client.rb', line 132 def getwork(data = nil) @api.request 'getwork', data end |
#help(command = nil) ⇒ Object
List commands, or get help for a command.
137 138 139 |
# File 'lib/bitcoin/client.rb', line 137 def help(command = nil) @api.request 'help', command end |
#host ⇒ Object
5 |
# File 'lib/bitcoin/client.rb', line 5 def host; api.host; end |
#host=(a) ⇒ Object
11 |
# File 'lib/bitcoin/client.rb', line 11 def host=(a); api.host = a; end |
#listaccounts(minconf = 1) ⇒ Object Also known as: accounts
Returns Object that has account names as keys, account balances as values.
142 143 144 |
# File 'lib/bitcoin/client.rb', line 142 def listaccounts(minconf = 1) @api.request 'listaccounts', minconf end |
#listreceivedbyaccount(minconf = 1, includeempty = false) ⇒ Object Also known as: list_received_by_account
Returns an array of objects containing:
:account => the account of the receiving addresses
:amount => total amount received by addresses with this account
:confirmations => number of confirmations of the most recent transaction included
152 153 154 |
# File 'lib/bitcoin/client.rb', line 152 def listreceivedbyaccount(minconf = 1, includeempty = false) @api.request 'listreceivedbyaccount', minconf, includeempty end |
#listreceivedbyaddress(minconf = 1, includeempty = false) ⇒ Object Also known as: list_received_by_address
Returns an array of objects containing:
:address => receiving address
:account => the account of the receiving address
:amount => total amount received by the address
:confirmations => number of confirmations of the most recent transaction included
To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true
164 165 166 |
# File 'lib/bitcoin/client.rb', line 164 def listreceivedbyaddress(minconf = 1, includeempty = false) @api.request 'listreceivedbyaddress', minconf, includeempty end |
#listtransactions(account, count = 10) ⇒ Object Also known as: transactions, list_transactions
Returns up to count
most recent transactions for account account
.
169 170 171 |
# File 'lib/bitcoin/client.rb', line 169 def listtransactions(account, count = 10) @api.request 'listtransactions', account, count end |
#move(fromaccount, toaccount, amount, minconf = 1, comment = nil) ⇒ Object
Move from one account in your wallet to another.
174 175 176 |
# File 'lib/bitcoin/client.rb', line 174 def move(fromaccount, toaccount, amount, minconf = 1, comment = nil) @api.request 'move', fromaccount, toaccount, amount, minconf, comment end |
#options ⇒ Object
15 16 17 |
# File 'lib/bitcoin/client.rb', line 15 def api. end |
#pass ⇒ Object
4 |
# File 'lib/bitcoin/client.rb', line 4 def pass; api.pass; end |
#pass=(a) ⇒ Object
10 |
# File 'lib/bitcoin/client.rb', line 10 def pass=(a); api.pass = a; end |
#port ⇒ Object
6 |
# File 'lib/bitcoin/client.rb', line 6 def port; api.port; end |
#port=(a) ⇒ Object
12 |
# File 'lib/bitcoin/client.rb', line 12 def port=(a); api.port = a; end |
#sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil) ⇒ Object Also known as: send_from
amount
is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.
179 180 181 |
# File 'lib/bitcoin/client.rb', line 179 def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil) @api.request 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to end |
#sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil) ⇒ Object Also known as: send_many
188 189 190 |
# File 'lib/bitcoin/client.rb', line 188 def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil) @api.request 'sendmany', fromaccount, addresses_amounts, minconf, comment end |
#sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil) ⇒ Object Also known as: send_to_address
amount
is a real and is rounded to 8 decimal places
184 185 186 |
# File 'lib/bitcoin/client.rb', line 184 def sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil) @api.request 'sendtoaddress', bitcoinaddress, amount, comment, comment_to end |
#setaccount(bitcoinaddress, account) ⇒ Object Also known as: account=, set_account
Sets the account associated with the given address.
193 194 195 |
# File 'lib/bitcoin/client.rb', line 193 def setaccount(bitcoinaddress, account) @api.request 'setaccount', bitcoinaddress, account end |
#setgenerate(generate, genproclimit = -1)) ⇒ Object Also known as: generate=, set_generate
generate
is true or false to turn generation on or off. Generation is limited to genproclimit
processors, -1 is unlimited.
199 200 201 |
# File 'lib/bitcoin/client.rb', line 199 def setgenerate(generate, genproclimit = -1) @api.request 'setgenerate', generate, genproclimit end |
#signmessage(bitcoinaddress, message) ⇒ Object Also known as: sign_message
Sign a message using bitcoinaddress
.
214 215 216 |
# File 'lib/bitcoin/client.rb', line 214 def (bitcoinaddress, ) @api.request 'signmessage', bitcoinaddress, end |
#ssl ⇒ Object
7 |
# File 'lib/bitcoin/client.rb', line 7 def ssl; api.ssl; end |
#ssl=(a) ⇒ Object
13 |
# File 'lib/bitcoin/client.rb', line 13 def ssl=(a); api.ssl = a; end |
#ssl? ⇒ Boolean
8 |
# File 'lib/bitcoin/client.rb', line 8 def ssl?; api.ssl?; end |
#stop ⇒ Object
Stop bitcoin server.
204 205 206 |
# File 'lib/bitcoin/client.rb', line 204 def stop @api.request 'stop' end |
#user ⇒ Object
3 |
# File 'lib/bitcoin/client.rb', line 3 def user; api.user; end |
#user=(a) ⇒ Object
9 |
# File 'lib/bitcoin/client.rb', line 9 def user=(a); api.user = a; end |
#validateaddress(bitcoinaddress) ⇒ Object Also known as: validate_address
Return information about bitcoinaddress
.
209 210 211 |
# File 'lib/bitcoin/client.rb', line 209 def validateaddress(bitcoinaddress) @api.request 'validateaddress', bitcoinaddress end |
#verifymessage(bitcoinaddress, signature, message) ⇒ Object Also known as: verify_message
Verify signature made by bitcoinaddress
.
219 220 221 |
# File 'lib/bitcoin/client.rb', line 219 def (bitcoinaddress, signature, ) @api.request 'verifymessage', bitcoinaddress, signature, end |
#walletlock ⇒ Object
Removes the wallet encryption key from memory, locking the wallet. After calling this method, you will need to call walletpassphrase again before being able to call any methods which require the wallet to be unlocked.
232 233 234 |
# File 'lib/bitcoin/client.rb', line 232 def walletlock @api.request 'walletlock' end |
#walletpassphrase(passphrase, timeout) ⇒ Object
Stores the wallet decryption key in memory for timeout
seconds.
224 225 226 |
# File 'lib/bitcoin/client.rb', line 224 def walletpassphrase(passphrase, timeout) @api.request 'walletpassphrase', passphrase, timeout end |