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
accountis not specified, returns the server’s total available balance. -
#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.
-
#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
accountin transactions with at leastminconfconfirmations. -
#getreceivedbyaddress(bitcoinaddress, minconf = 1) ⇒ Object
(also: #received_by_address)
Returns the total amount received by
bitcoinaddressin transactions with at leastminconfconfirmations. -
#gettransaction(txid) ⇒ Object
(also: #transaction)
Get detailed information about
txid. -
#getwork(data = nil) ⇒ Object
(also: #work, #get_work)
If
datais 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
countmost 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)
amountis 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)
amountis 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)
generateis 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.
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 |
#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.
56 57 58 |
# File 'lib/bitcoin/client.rb', line 56 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.
61 62 63 |
# File 'lib/bitcoin/client.rb', line 61 def getblocknumber @api.request 'getblocknumber' end |
#getconnectioncount ⇒ Object Also known as: connection_count
Returns the number of connections to other nodes.
66 67 68 |
# File 'lib/bitcoin/client.rb', line 66 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.
71 72 73 |
# File 'lib/bitcoin/client.rb', line 71 def getdifficulty @api.request 'getdifficulty' end |
#getgenerate ⇒ Object Also known as: generate?
Returns true or false whether bitcoind is currently generating hashes
76 77 78 |
# File 'lib/bitcoin/client.rb', line 76 def getgenerate @api.request 'getgenerate' end |
#gethashespersec ⇒ Object Also known as: hashes_per_sec
Returns a recent hashes per second performance measurement while generating.
81 82 83 |
# File 'lib/bitcoin/client.rb', line 81 def gethashespersec @api.request 'gethashespersec' end |
#getinfo ⇒ Object Also known as: info
Returns an object containing various state info.
86 87 88 |
# File 'lib/bitcoin/client.rb', line 86 def getinfo @api.request 'getinfo' 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.
92 93 94 |
# File 'lib/bitcoin/client.rb', line 92 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.
98 99 100 |
# File 'lib/bitcoin/client.rb', line 98 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.
103 104 105 |
# File 'lib/bitcoin/client.rb', line 103 def getreceivedbyaddress(bitcoinaddress, minconf = 1) @api.request 'getreceivedbyaddress', bitcoinaddress, minconf end |
#gettransaction(txid) ⇒ Object Also known as: transaction
Get detailed information about txid
108 109 110 |
# File 'lib/bitcoin/client.rb', line 108 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.
120 121 122 |
# File 'lib/bitcoin/client.rb', line 120 def getwork(data = nil) @api.request 'getwork', data end |
#help(command = nil) ⇒ Object
List commands, or get help for a command.
125 126 127 |
# File 'lib/bitcoin/client.rb', line 125 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.
130 131 132 |
# File 'lib/bitcoin/client.rb', line 130 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
140 141 142 |
# File 'lib/bitcoin/client.rb', line 140 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
152 153 154 |
# File 'lib/bitcoin/client.rb', line 152 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.
157 158 159 |
# File 'lib/bitcoin/client.rb', line 157 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.
162 163 164 |
# File 'lib/bitcoin/client.rb', line 162 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.
167 168 169 |
# File 'lib/bitcoin/client.rb', line 167 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
176 177 178 |
# File 'lib/bitcoin/client.rb', line 176 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
172 173 174 |
# File 'lib/bitcoin/client.rb', line 172 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.
181 182 183 |
# File 'lib/bitcoin/client.rb', line 181 def setaccount(bitcoinaddress, account) @api.request 'setaccoint', 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.
187 188 189 |
# File 'lib/bitcoin/client.rb', line 187 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.
202 203 204 |
# File 'lib/bitcoin/client.rb', line 202 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.
192 193 194 |
# File 'lib/bitcoin/client.rb', line 192 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.
197 198 199 |
# File 'lib/bitcoin/client.rb', line 197 def validateaddress(bitcoinaddress) @api.request 'validateaddress', bitcoinaddress end |
#verifymessage(bitcoinaddress, signature, message) ⇒ Object Also known as: verify_message
Verify signature made by bitcoinaddress.
207 208 209 |
# File 'lib/bitcoin/client.rb', line 207 def (bitcoinaddress, signature, ) @api.request 'verifymessage', bitcoinaddress, signature, end |