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

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



56
57
58
# File 'lib/bitcoin/client.rb', line 56

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.



61
62
63
# File 'lib/bitcoin/client.rb', line 61

def getblocknumber
  @api.request 'getblocknumber'
end

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

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

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

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

#getinfoObject 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( = 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.



98
99
100
# File 'lib/bitcoin/client.rb', line 98

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.



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

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



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(, 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.



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

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



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, )
  @api.request 'setaccoint', 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.



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 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.



192
193
194
# File 'lib/bitcoin/client.rb', line 192

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.



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