Class: Bitcoin::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, pass, options = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
# File 'lib/bitcoin/client.rb', line 19

def initialize(user, pass, options = {})
  @api = Bitcoin::API.new({ :user => user, :pass => pass }.merge(options))
end

Instance Attribute Details

#apiObject (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()
  @api.request 'getaccountaddress', 
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()
  @api.request 'getaddressesbyaccount', 
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( = nil, minconf = 1)
  @api.request 'getbalance', , 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

#getblockcountObject 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

#getblocknumberObject 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

#getconnectioncountObject 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

#getdifficultyObject 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

#getgenerateObject 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

#gethashespersecObject 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

#getinfoObject 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

#getmininginfoObject

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( = nil)
  @api.request 'getnewaddress', 
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(, minconf = 1)
  @api.request 'getreceivedbyaccount', , 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

#hostObject



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(, count = 10)
  @api.request 'listtransactions', , 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

#optionsObject



15
16
17
# File 'lib/bitcoin/client.rb', line 15

def options
  api.options
end

#passObject



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

#portObject



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, )
  @api.request 'setaccount', bitcoinaddress, 
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 signmessage(bitcoinaddress, message)
  @api.request 'signmessage', bitcoinaddress, message
end

#sslObject



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

Returns:

  • (Boolean)


8
# File 'lib/bitcoin/client.rb', line 8

def ssl?; api.ssl?; end

#stopObject

Stop bitcoin server.



204
205
206
# File 'lib/bitcoin/client.rb', line 204

def stop
  @api.request 'stop'
end

#userObject



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 verifymessage(bitcoinaddress, signature, message)
  @api.request 'verifymessage', bitcoinaddress, signature, message
end

#walletlockObject

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