class Rallet::Wallets::Common

Extracted from github.com/sinisterchipmunk/bitcoin-client/blob/master/lib/bitcoin-client/client.rb Date 4 Jan 2015

Attributes

client[R]

Public Class Methods

new(service_url, rpc_version = 1.1) click to toggle source

Sample user:pass@localhost:2082

# File lib/rallet/wallets/common.rb, line 11
def initialize(service_url, rpc_version = 1.1)
  @client = RPC::JSON::Client.new(service_url, rpc_version)
end

Public Instance Methods

account(bitcoinaddress)
Alias for: getaccount
account=(bitcoinaddress, account)
Alias for: setaccount
account_address(account)
Alias for: getaccountaddress
accounts(minconf = 1)
Alias for: listaccounts
addresses_by_account(account)
backupwallet(destination) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 16
def backupwallet(destination)
  @client.send 'backupwallet', destination
end
balance(account = nil, minconf = 1)
Alias for: getbalance
bestblockhash()
Alias for: getbestblockhash
block_by_count(height)
Alias for: getblockbycount
block_count()
Alias for: getblockcount
block_hash(index)
Alias for: getblockhash
block_number()
Alias for: getblocknumber
connection_count()
Alias for: getconnectioncount
createmultisig(nrequired, keys) click to toggle source

Creates a multi-signature address and returns a json object

# File lib/rallet/wallets/common.rb, line 21
def createmultisig(nrequired, keys)
    @client.send 'createmultisig', nrequired, keys
end
createrawtransaction(transactionid = nil, address_amount) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 27
def createrawtransaction(transactionid = nil, address_amount)
    @client.send 'createrawtransaction', transactionid, address_amount
end
decoderawtransaction(hexstring) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 32
def decoderawtransaction(hexstring)
    @client.send 'decoderawtransaction', hexstring
end
difficulty()
Alias for: getdifficulty
generate=(generate, genproclimit = -1)
Alias for: setgenerate
generate?()
Alias for: getgenerate
get_work(data = nil)
Alias for: getwork
getaccount(bitcoinaddress) click to toggle source

Returns the account associated with the given address.

# File lib/rallet/wallets/common.rb, line 37
def getaccount(bitcoinaddress)
  @client.send 'getaccount', bitcoinaddress
end
Also aliased as: account
getaccountaddress(account) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 42
def getaccountaddress(account)
  @client.send 'getaccountaddress', account
end
Also aliased as: account_address
getaddressesbyaccount(account) click to toggle source

Returns the list of addresses for the given account.

# File lib/rallet/wallets/common.rb, line 47
def getaddressesbyaccount(account)
  @client.send 'getaddressesbyaccount', account
end
Also aliased as: addresses_by_account
getbalance(account = nil, minconf = 1) click to toggle source

If account is not specified, returns the server’s total available balance. If account is specified, returns the balance in the account.

# File lib/rallet/wallets/common.rb, line 53
def getbalance(account = nil, minconf = 1)
  @client.send 'getbalance', account, minconf
end
Also aliased as: balance
getbestblockhash() click to toggle source
# File lib/rallet/wallets/common.rb, line 57
def getbestblockhash
  @client.send 'getbestblockhash'
end
Also aliased as: bestblockhash
getblock(hash) click to toggle source

Dumps the block existing with specified hash.

# File lib/rallet/wallets/common.rb, line 68
def getblock(hash)
  block = @client.send 'getblock', hash
  block["time"] = Time.at(block["time"]).utc
  block
end
getblockbycount(height) click to toggle source

Dumps the block existing at specified height. Note: this is not available in the official release

# File lib/rallet/wallets/common.rb, line 63
def getblockbycount(height)
  @client.send 'getblockbycount', height
end
Also aliased as: block_by_count
getblockcount() click to toggle source

Returns the number of blocks in the longest block chain.

# File lib/rallet/wallets/common.rb, line 75
def getblockcount
  @client.send 'getblockcount'
end
Also aliased as: block_count
getblockhash(index) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 85
def getblockhash(index)
  @client.send 'getblockhash', index
end
Also aliased as: block_hash
getblocknumber() click to toggle source

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

# File lib/rallet/wallets/common.rb, line 80
def getblocknumber
  @client.send 'getblocknumber'
end
Also aliased as: block_number
getconnectioncount() click to toggle source

Returns the number of connections to other nodes.

# File lib/rallet/wallets/common.rb, line 90
def getconnectioncount
  @client.send 'getconnectioncount'
end
Also aliased as: connection_count
getdifficulty() click to toggle source

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

# File lib/rallet/wallets/common.rb, line 95
def getdifficulty
  @client.send 'getdifficulty'
end
Also aliased as: difficulty
getgenerate() click to toggle source

Returns true or false whether bitcoind is currently generating hashes

# File lib/rallet/wallets/common.rb, line 100
def getgenerate
  @client.send 'getgenerate'
end
Also aliased as: generate?
gethashespersec() click to toggle source

Returns a recent hashes per second performance measurement while generating.

# File lib/rallet/wallets/common.rb, line 105
def gethashespersec
  @client.send 'gethashespersec'
end
Also aliased as: hashes_per_sec
getinfo() click to toggle source

Returns an object containing various state info.

# File lib/rallet/wallets/common.rb, line 110
def getinfo
  @client.send 'getinfo'
end
Also aliased as: info
getmininginfo() click to toggle source

Returns an object containing mining info.

# File lib/rallet/wallets/common.rb, line 120
def getmininginfo
  @client.send 'getmininginfo'
end
getnewaddress(account = nil) click to toggle source

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.

# File lib/rallet/wallets/common.rb, line 126
def getnewaddress(account = nil)
  @client.send 'getnewaddress', account
end
Also aliased as: new_address
getpeerinfo() click to toggle source

Returns data about each connected network node.

# File lib/rallet/wallets/common.rb, line 115
def getpeerinfo
  @client.send 'getpeerinfo'
end
Also aliased as: peerinfo
getrawmempool() click to toggle source

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

# File lib/rallet/wallets/common.rb, line 153
def getrawmempool
   @client.send 'getrawmempool'
end
Also aliased as: raw_mempool
getrawtransaction(txid, verbose = 0) click to toggle source

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.

# File lib/rallet/wallets/common.rb, line 148
def getrawtransaction(txid, verbose = 0)
  @client.send 'getrawtransaction', txid, verbose
end
Also aliased as: rawtransaction
getreceivedbyaccount(account, minconf = 1) click to toggle source

Returns the total amount received by addresses with account in transactions with at least minconf confirmations.

# File lib/rallet/wallets/common.rb, line 132
def getreceivedbyaccount(account, minconf = 1)
  @client.send 'getreceivedbyaccount', account, minconf
end
Also aliased as: received_by_account
getreceivedbyaddress(bitcoinaddress, minconf = 1) click to toggle source

Returns the total amount received by bitcoinaddress in transactions with at least minconf confirmations.

# File lib/rallet/wallets/common.rb, line 137
def getreceivedbyaddress(bitcoinaddress, minconf = 1)
  @client.send 'getreceivedbyaddress', bitcoinaddress, minconf
end
Also aliased as: received_by_address
gettransaction(txid) click to toggle source

Get detailed information about txid

# File lib/rallet/wallets/common.rb, line 142
def gettransaction(txid)
  @client.send 'gettransaction', txid
end
Also aliased as: transaction
getwork(data = nil) click to toggle source

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.

# File lib/rallet/wallets/common.rb, line 164
def getwork(data = nil)
  @client.send 'getwork', data
end
Also aliased as: work, get_work
hashes_per_sec()
Alias for: gethashespersec
help(command = nil) click to toggle source

List commands, or get help for a command.

# File lib/rallet/wallets/common.rb, line 169
def help(command = nil)
  @client.send 'help', command
end
importprivkey(bitcoinprivkey, label = nil, rescan = true) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 174
def importprivkey(bitcoinprivkey, label = nil, rescan = true)
  @client.send 'importprivkey', bitcoinprivkey, label, rescan
end
info()
Alias for: getinfo
list_received_by_account(minconf = 1, includeempty = false)
list_received_by_address(minconf = 1, includeempty = false)
list_transactions(account = '' , count = 10, from = 0)
Alias for: listtransactions
listaccounts(minconf = 1) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 179
def listaccounts(minconf = 1)
  @client.send 'listaccounts', minconf
end
Also aliased as: accounts
listreceivedbyaccount(minconf = 1, includeempty = false) click to toggle source

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
# File lib/rallet/wallets/common.rb, line 189
def listreceivedbyaccount(minconf = 1, includeempty = false)
  @client.send 'listreceivedbyaccount', minconf, includeempty
end
Also aliased as: list_received_by_account
listreceivedbyaddress(minconf = 1, includeempty = false) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 201
def listreceivedbyaddress(minconf = 1, includeempty = false)
  @client.send 'listreceivedbyaddress', minconf, includeempty
end
Also aliased as: list_received_by_address
listsinceblock(hash) click to toggle source

Returns transactions since <hash> block

# File lib/rallet/wallets/common.rb, line 211
def listsinceblock(hash)
  @client.send 'listsinceblock', hash
end
listtransactions(account = '' , count = 10, from = 0) click to toggle source

Returns up to count most recent transactions for account account.

# File lib/rallet/wallets/common.rb, line 206
def listtransactions(account = '' , count = 10, from = 0)
  @client.send 'listtransactions', account, count, from
end
Also aliased as: transactions, list_transactions
move(fromaccount, toaccount, amount, minconf = 1, comment = nil) click to toggle source

Move from one account in your wallet to another.

# File lib/rallet/wallets/common.rb, line 217
def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
  @client.send 'move', fromaccount, toaccount, amount, minconf, comment
end
new_address(account = nil)
Alias for: getnewaddress
peerinfo()
Alias for: getpeerinfo
raw_mempool()
Alias for: getrawmempool
rawtransaction(txid, verbose = 0)
Alias for: getrawtransaction
received_by_account(account, minconf = 1)
received_by_address(bitcoinaddress, minconf = 1)
search_raw_transactions(bitcoinaddress, verbose=1)
searchrawtransactions(bitcoinaddress, verbose=1) click to toggle source

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.

# File lib/rallet/wallets/common.rb, line 222
def searchrawtransactions(bitcoinaddress, verbose=1)
  @client.send 'searchrawtransactions', bitcoinaddress, verbose
end
Also aliased as: search_raw_transactions
send_from(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
Alias for: sendfrom
send_many(fromaccount, addresses_amounts, minconf = 1, comment = nil)
Alias for: sendmany
send_to_address(bitcoinaddress, amount, comment = nil, comment_to = nil)
Alias for: sendtoaddress
sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil) click to toggle source

amount is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.

# File lib/rallet/wallets/common.rb, line 227
def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
  @client.send 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
end
Also aliased as: send_from
sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil) click to toggle source
# File lib/rallet/wallets/common.rb, line 240
def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil)
  @client.send 'sendmany', fromaccount, addresses_amounts, minconf, comment
end
Also aliased as: send_many
sendrawtransaction(hexstring) click to toggle source

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

# File lib/rallet/wallets/common.rb, line 232
def sendrawtransaction(hexstring)
  @client.send 'sendrawtransaction', hexstring
end
sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil) click to toggle source

amount is a real and is rounded to 8 decimal places

# File lib/rallet/wallets/common.rb, line 236
def sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil)
  @client.send 'sendtoaddress', bitcoinaddress, amount, comment, comment_to
end
Also aliased as: send_to_address
set_account(bitcoinaddress, account)
Alias for: setaccount
set_generate(generate, genproclimit = -1)
Alias for: setgenerate
setaccount(bitcoinaddress, account) click to toggle source

Sets the account associated with the given address.

# File lib/rallet/wallets/common.rb, line 245
def setaccount(bitcoinaddress, account)
  @client.send 'setaccount', bitcoinaddress, account
end
Also aliased as: account=, set_account
setgenerate(generate, genproclimit = -1) click to toggle source

generate is true or false to turn generation on or off. Generation is limited to genproclimit processors, -1 is unlimited.

# File lib/rallet/wallets/common.rb, line 251
def setgenerate(generate, genproclimit = -1)
  @client.send 'setgenerate', generate, genproclimit
end
Also aliased as: generate=, set_generate
sign_message(bitcoinaddress, message)
Alias for: signmessage
signmessage(bitcoinaddress, message) click to toggle source

Sign a message using bitcoinaddress.

# File lib/rallet/wallets/common.rb, line 271
def signmessage(bitcoinaddress, message)
  @client.send 'signmessage', bitcoinaddress, message
end
Also aliased as: sign_message
signrawtransaction(hexstring, transaction = nil, privatekey =nil, sighashtype = "ALL") click to toggle source

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

# File lib/rallet/wallets/common.rb, line 256
def signrawtransaction(hexstring, transaction = nil, privatekey =nil, sighashtype = "ALL")
  @client.send 'signrawtransaction', hexstring, transaction, privatekey, sighashtype
end
stop() click to toggle source

Stop bitcoin server.

# File lib/rallet/wallets/common.rb, line 261
def stop
  @client.send 'stop'
end
transaction(txid)
Alias for: gettransaction
transactions(account = '' , count = 10, from = 0)
Alias for: listtransactions
validate_address(bitcoinaddress)
Alias for: validateaddress
validateaddress(bitcoinaddress) click to toggle source

Return information about bitcoinaddress.

# File lib/rallet/wallets/common.rb, line 266
def validateaddress(bitcoinaddress)
  @client.send 'validateaddress', bitcoinaddress
end
Also aliased as: validate_address
verify_message(bitcoinaddress, signature, message)
Alias for: verifymessage
verifymessage(bitcoinaddress, signature, message) click to toggle source

Verify signature made by bitcoinaddress.

# File lib/rallet/wallets/common.rb, line 276
def verifymessage(bitcoinaddress, signature, message)
  @client.send 'verifymessage', bitcoinaddress, signature, message
end
Also aliased as: verify_message
walletlock() click to toggle source

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.

# File lib/rallet/wallets/common.rb, line 289
def walletlock
  @client.send 'walletlock'
end
walletpassphrase(passphrase, timeout) click to toggle source

Stores the wallet decryption key in memory for timeout seconds.

# File lib/rallet/wallets/common.rb, line 281
def walletpassphrase(passphrase, timeout)
  @client.send 'walletpassphrase', passphrase, timeout
end
work(data = nil)
Alias for: getwork