Class: Rallet::Wallets::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/rallet/wallets/common.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_url) ⇒ Common



9
10
11
# File 'lib/rallet/wallets/common.rb', line 9

def initialize(service_url)
  @client = Rallet::Client.new(service_url)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/rallet/wallets/common.rb', line 6

def client
  @client
end

Instance Method Details

#backupwallet(destination) ⇒ Object

Safely copies wallet.dat to destination, which can be a directory or a path with filename.



14
15
16
# File 'lib/rallet/wallets/common.rb', line 14

def backupwallet(destination)
  @client.request 'backupwallet', destination
end

#createmultisig(nrequired, keys) ⇒ Object

Creates a multi-signature address and returns a json object



19
20
21
# File 'lib/rallet/wallets/common.rb', line 19

def createmultisig(nrequired, keys)
    @client.request 'createmultisig', nrequired, keys
end

#createrawtransaction(transactionid = nil, address_amount) ⇒ Object

nCreate a transaction spending given inputs (array of objects containing transaction id and output number), sending to given address(es)



25
26
27
# File 'lib/rallet/wallets/common.rb', line 25

def createrawtransaction(transactionid = nil, address_amount)
    @client.request 'createrawtransaction', transactionid, address_amount
end

#decoderawtransaction(hexstring) ⇒ Object

Return a JSON object representing the serialized, hex-encoded transaction.



30
31
32
# File 'lib/rallet/wallets/common.rb', line 30

def decoderawtransaction(hexstring)
    @client.request 'decoderawtransaction', hexstring
end

#getaccount(bitcoinaddress) ⇒ Object Also known as: account

Returns the account associated with the given address.



35
36
37
# File 'lib/rallet/wallets/common.rb', line 35

def getaccount(bitcoinaddress)
  @client.request 'getaccount', bitcoinaddress
end

#getaccountaddress(account) ⇒ Object Also known as: account_address

Returns the current bitcoin address for receiving payments to this account.



40
41
42
# File 'lib/rallet/wallets/common.rb', line 40

def getaccountaddress()
  @client.request 'getaccountaddress', 
end

#getaddressesbyaccount(account) ⇒ Object Also known as: addresses_by_account

Returns the list of addresses for the given account.



45
46
47
# File 'lib/rallet/wallets/common.rb', line 45

def getaddressesbyaccount()
  @client.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.



51
52
53
# File 'lib/rallet/wallets/common.rb', line 51

def getbalance( = nil, minconf = 1)
  @client.request 'getbalance', , minconf
end

#getbestblockhashObject Also known as: bestblockhash



55
56
57
# File 'lib/rallet/wallets/common.rb', line 55

def getbestblockhash
  @client.request 'getbestblockhash'
end

#getblock(hash) ⇒ Object

Dumps the block existing with specified hash.



66
67
68
69
70
# File 'lib/rallet/wallets/common.rb', line 66

def getblock(hash)
  block = @client.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



61
62
63
# File 'lib/rallet/wallets/common.rb', line 61

def getblockbycount(height)
  @client.request 'getblockbycount', height
end

#getblockcountObject Also known as: block_count

Returns the number of blocks in the longest block chain.



73
74
75
# File 'lib/rallet/wallets/common.rb', line 73

def getblockcount
  @client.request 'getblockcount'
end

#getblockhash(index) ⇒ Object Also known as: block_hash

Returns hash of block in best-block-chain at <index>; index 0 is the genesis block



83
84
85
# File 'lib/rallet/wallets/common.rb', line 83

def getblockhash(index)
  @client.request 'getblockhash', index
end

#getblocknumberObject Also known as: block_number

Returns the block number of the latest block in the longest block chain.



78
79
80
# File 'lib/rallet/wallets/common.rb', line 78

def getblocknumber
  @client.request 'getblocknumber'
end

#getconnectioncountObject Also known as: connection_count

Returns the number of connections to other nodes.



88
89
90
# File 'lib/rallet/wallets/common.rb', line 88

def getconnectioncount
  @client.request 'getconnectioncount'
end

#getdifficultyObject Also known as: difficulty

Returns the proof-of-work difficulty as a multiple of the minimum difficulty.



93
94
95
# File 'lib/rallet/wallets/common.rb', line 93

def getdifficulty
  @client.request 'getdifficulty'
end

#getgenerateObject Also known as: generate?

Returns true or false whether bitcoind is currently generating hashes



98
99
100
# File 'lib/rallet/wallets/common.rb', line 98

def getgenerate
  @client.request 'getgenerate'
end

#gethashespersecObject Also known as: hashes_per_sec

Returns a recent hashes per second performance measurement while generating.



103
104
105
# File 'lib/rallet/wallets/common.rb', line 103

def gethashespersec
  @client.request 'gethashespersec'
end

#getinfoObject Also known as: info

Returns an object containing various state info.



108
109
110
# File 'lib/rallet/wallets/common.rb', line 108

def getinfo
  @client.request 'getinfo'
end

#getmininginfoObject

Returns an object containing mining info.



118
119
120
# File 'lib/rallet/wallets/common.rb', line 118

def getmininginfo
  @client.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.



124
125
126
# File 'lib/rallet/wallets/common.rb', line 124

def getnewaddress( = nil)
  @client.request 'getnewaddress', 
end

#getpeerinfoObject Also known as: peerinfo

Returns data about each connected network node.



113
114
115
# File 'lib/rallet/wallets/common.rb', line 113

def getpeerinfo
  @client.request 'getpeerinfo'
end

#getrawmempoolObject Also known as: raw_mempool

Gets all mempool txs (pedning/waiting to be added in a block)



151
152
153
# File 'lib/rallet/wallets/common.rb', line 151

def getrawmempool
   @client.request 'getrawmempool'
end

#getrawtransaction(txid, verbose = 0) ⇒ Object Also known as: rawtransaction

Get raw transaction bout txid. It outputs the whole transaction chain by default in HEX. If you want JSON, set verbose to 1. When in the bitcoind config is set txindex=1, after reindexing, you can ask about any transaction (not included in your wallet), with this command.



146
147
148
# File 'lib/rallet/wallets/common.rb', line 146

def getrawtransaction(txid, verbose = 0)
  @client.request 'getrawtransaction', txid, verbose
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.



130
131
132
# File 'lib/rallet/wallets/common.rb', line 130

def getreceivedbyaccount(, minconf = 1)
  @client.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.



135
136
137
# File 'lib/rallet/wallets/common.rb', line 135

def getreceivedbyaddress(bitcoinaddress, minconf = 1)
  @client.request 'getreceivedbyaddress', bitcoinaddress, minconf
end

#gettransaction(txid) ⇒ Object Also known as: transaction

Get detailed information about txid



140
141
142
# File 'lib/rallet/wallets/common.rb', line 140

def gettransaction(txid)
  @client.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.



162
163
164
# File 'lib/rallet/wallets/common.rb', line 162

def getwork(data = nil)
  @client.request 'getwork', data
end

#help(command = nil) ⇒ Object

List commands, or get help for a command.



167
168
169
# File 'lib/rallet/wallets/common.rb', line 167

def help(command = nil)
  @client.request 'help', command
end

#importprivkey(bitcoinprivkey, label = nil, rescan = true) ⇒ Object

Adds a private key (as returned by dumpprivkey) to your wallet.



172
173
174
# File 'lib/rallet/wallets/common.rb', line 172

def importprivkey(bitcoinprivkey, label = nil, rescan = true)
  @client.request 'importprivkey', bitcoinprivkey, label, rescan
end

#listaccounts(minconf = 1) ⇒ Object Also known as: accounts

Returns Object that has account names as keys, account balances as values.



177
178
179
# File 'lib/rallet/wallets/common.rb', line 177

def listaccounts(minconf = 1)
  @client.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


187
188
189
# File 'lib/rallet/wallets/common.rb', line 187

def listreceivedbyaccount(minconf = 1, includeempty = false)
  @client.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



199
200
201
# File 'lib/rallet/wallets/common.rb', line 199

def listreceivedbyaddress(minconf = 1, includeempty = false)
  @client.request 'listreceivedbyaddress', minconf, includeempty
end

#listsinceblock(hash) ⇒ Object

Returns transactions since <hash> block



209
210
211
# File 'lib/rallet/wallets/common.rb', line 209

def listsinceblock(hash)
  @client.request 'listsinceblock', hash
end

#listtransactions(account = '', count = 10, from = 0) ⇒ Object Also known as: transactions, list_transactions

Returns up to count most recent transactions for account account.



204
205
206
# File 'lib/rallet/wallets/common.rb', line 204

def listtransactions( = '' , count = 10, from = 0)
  @client.request 'listtransactions', , count, from
end

#move(fromaccount, toaccount, amount, minconf = 1, comment = nil) ⇒ Object

Move from one account in your wallet to another.



215
216
217
# File 'lib/rallet/wallets/common.rb', line 215

def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
  @client.request 'move', fromaccount, toaccount, amount, minconf, comment
end

#searchrawtransactions(bitcoinaddress, verbose = 1) ⇒ Object Also known as: search_raw_transactions

Return count transactions with <address> present in their scriptSig, skipping skip at the beginning. The ordering is oldest transaction first; if skip is negative the order returned is newest transaction first and skip+1 transactions are skipped. If verbose=0 only txids are returned rather than the full transactions.



220
221
222
# File 'lib/rallet/wallets/common.rb', line 220

def searchrawtransactions(bitcoinaddress, verbose=1)
  @client.request 'searchrawtransactions', bitcoinaddress, verbose
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.



225
226
227
# File 'lib/rallet/wallets/common.rb', line 225

def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
  @client.request 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
end

#sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil) ⇒ Object Also known as: send_many



238
239
240
# File 'lib/rallet/wallets/common.rb', line 238

def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil)
  @client.request 'sendmany', fromaccount, addresses_amounts, minconf, comment
end

#sendrawtransaction(hexstring) ⇒ Object

Submits raw transaction (serialized, hex-encoded) to local node and network.



230
231
232
# File 'lib/rallet/wallets/common.rb', line 230

def sendrawtransaction(hexstring)
  @client.request 'sendrawtransaction', hexstring
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



234
235
236
# File 'lib/rallet/wallets/common.rb', line 234

def sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil)
  @client.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.



243
244
245
# File 'lib/rallet/wallets/common.rb', line 243

def setaccount(bitcoinaddress, )
  @client.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.



249
250
251
# File 'lib/rallet/wallets/common.rb', line 249

def setgenerate(generate, genproclimit = -1)
  @client.request 'setgenerate', generate, genproclimit
end

#signmessage(bitcoinaddress, message) ⇒ Object Also known as: sign_message

Sign a message using bitcoinaddress.



269
270
271
# File 'lib/rallet/wallets/common.rb', line 269

def signmessage(bitcoinaddress, message)
  @client.request 'signmessage', bitcoinaddress, message
end

#signrawtransaction(hexstring, transaction = nil, privatekey = nil, sighashtype = "ALL") ⇒ Object

Sign inputs for raw transaction (serialized, hex-encoded).



254
255
256
# File 'lib/rallet/wallets/common.rb', line 254

def signrawtransaction(hexstring, transaction = nil, privatekey =nil, sighashtype = "ALL")
  @client.request 'signrawtransaction', hexstring, transaction, privatekey, sighashtype
end

#stopObject

Stop bitcoin server.



259
260
261
# File 'lib/rallet/wallets/common.rb', line 259

def stop
  @client.request 'stop'
end

#validateaddress(bitcoinaddress) ⇒ Object Also known as: validate_address

Return information about bitcoinaddress.



264
265
266
# File 'lib/rallet/wallets/common.rb', line 264

def validateaddress(bitcoinaddress)
  @client.request 'validateaddress', bitcoinaddress
end

#verifymessage(bitcoinaddress, signature, message) ⇒ Object Also known as: verify_message

Verify signature made by bitcoinaddress.



274
275
276
# File 'lib/rallet/wallets/common.rb', line 274

def verifymessage(bitcoinaddress, signature, message)
  @client.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.



287
288
289
# File 'lib/rallet/wallets/common.rb', line 287

def walletlock
  @client.request 'walletlock'
end

#walletpassphrase(passphrase, timeout) ⇒ Object

Stores the wallet decryption key in memory for timeout seconds.



279
280
281
# File 'lib/rallet/wallets/common.rb', line 279

def walletpassphrase(passphrase, timeout)
  @client.request 'walletpassphrase', passphrase, timeout
end