Module: StartcoinClient::DSL

Defined in:
lib/startcoin_client/dsl.rb

Instance Method Summary collapse

Instance Method Details

#backupwallet(destination) ⇒ Object

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



56
57
58
# File 'lib/startcoin_client/dsl.rb', line 56

def backupwallet(destination)
  bitcoin.backupwallet destination
end

#bitcoinObject



2
3
4
5
6
7
8
# File 'lib/startcoin_client/dsl.rb', line 2

def bitcoin
  if self.class.respond_to?(:bitcoin)
    @client ||= StartcoinClient::Client.new(self.class.bitcoin.user, self.class.bitcoin.pass, self.class.bitcoin.options)
  else
    @client ||= StartcoinClient::Client.new(nil, nil)
  end
end

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

Returns the account associated with the given address.



61
62
63
# File 'lib/startcoin_client/dsl.rb', line 61

def getaccount(bitcoinaddress)
  bitcoin.getaccount bitcoinaddress
end

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

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



66
67
68
# File 'lib/startcoin_client/dsl.rb', line 66

def getaccountaddress()
  bitcoin.getaccountaddress 
end

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

Returns the list of addresses for the given account.



71
72
73
# File 'lib/startcoin_client/dsl.rb', line 71

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



77
78
79
# File 'lib/startcoin_client/dsl.rb', line 77

def getbalance( = nil, minconf = 1)
  bitcoin.getbalance , minconf
end

#getbestblockhashObject

Returns the hash of the best (tip) block in the longest block chain.



82
83
84
# File 'lib/startcoin_client/dsl.rb', line 82

def getbestblockhash
  bitcoin.getbestblockhash
end

#getblock(hash) ⇒ Object

Dumps the block existing with specified hash.



93
94
95
# File 'lib/startcoin_client/dsl.rb', line 93

def getblock(hash)
  bitcoin.getblock hash
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



88
89
90
# File 'lib/startcoin_client/dsl.rb', line 88

def getblockbycount(height)
  bitcoin.getblockbycount height
end

#getblockcountObject Also known as: block_count

Returns the number of blocks in the longest block chain.



98
99
100
# File 'lib/startcoin_client/dsl.rb', line 98

def getblockcount
  bitcoin.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



108
109
110
# File 'lib/startcoin_client/dsl.rb', line 108

def getblockhash(index)
  bitcoin.getblockhash index
end

#getblocknumberObject Also known as: block_number

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



103
104
105
# File 'lib/startcoin_client/dsl.rb', line 103

def getblocknumber
  bitcoin.getblocknumber
end

#getconnectioncountObject Also known as: connection_count

Returns the number of connections to other nodes.



113
114
115
# File 'lib/startcoin_client/dsl.rb', line 113

def getconnectioncount
  bitcoin.getconnectioncount
end

#getdifficultyObject Also known as: difficulty

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



118
119
120
# File 'lib/startcoin_client/dsl.rb', line 118

def getdifficulty
  bitcoin.getdifficulty
end

#getgenerateObject Also known as: generate?

Returns true or false whether bitcoind is currently generating hashes



123
124
125
# File 'lib/startcoin_client/dsl.rb', line 123

def getgenerate
  bitcoin.getgenerate
end

#gethashespersecObject Also known as: hashes_per_sec

Returns a recent hashes per second performance measurement while generating.



128
129
130
# File 'lib/startcoin_client/dsl.rb', line 128

def gethashespersec
  bitcoin.gethashespersec
end

#getinfoObject Also known as: info

Returns an object containing various state info.



133
134
135
# File 'lib/startcoin_client/dsl.rb', line 133

def getinfo
  bitcoin.getinfo
end

#getmininginfoObject Also known as: mininginfo

Returns an object containing various mining info.



143
144
145
# File 'lib/startcoin_client/dsl.rb', line 143

def getmininginfo
  bitcoin.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.



149
150
151
# File 'lib/startcoin_client/dsl.rb', line 149

def getnewaddress( = nil)
  bitcoin.getnewaddress 
end

#getpeerinfoObject Also known as: peerinfo

Returns data about each connected network node.



138
139
140
# File 'lib/startcoin_client/dsl.rb', line 138

def getpeerinfo
  bitcoin.getpeerinfo
end

#getrawmempoolObject Also known as: raw_mempool

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



177
178
179
# File 'lib/startcoin_client/dsl.rb', line 177

def getrawmempool
  bitcoin.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.



172
173
174
# File 'lib/startcoin_client/dsl.rb', line 172

def getrawtransaction(txid, verbose = 0)
  bitcoin.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.



155
156
157
# File 'lib/startcoin_client/dsl.rb', line 155

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



160
161
162
# File 'lib/startcoin_client/dsl.rb', line 160

def getreceivedbyaddress(bitcoinaddress, minconf = 1)
  bitcoin.getreceivedbyaddress bitcoinaddress, minconf
end

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

Get detailed information about txid



165
166
167
# File 'lib/startcoin_client/dsl.rb', line 165

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



189
190
191
# File 'lib/startcoin_client/dsl.rb', line 189

def getwork(data = nil)
  bitcoin.getwork data
end

#help(command = nil) ⇒ Object

List commands, or get help for a command.



194
195
196
# File 'lib/startcoin_client/dsl.rb', line 194

def help(command = nil)
  bitcoin.help command
end

#host(value = nil) ⇒ Object



38
39
40
# File 'lib/startcoin_client/dsl.rb', line 38

def host(value = nil)
  value ? bitcoin.host = value : bitcoin.host
end

#host=(value) ⇒ Object



18
19
20
# File 'lib/startcoin_client/dsl.rb', line 18

def host=(value)
  bitcoin.host = value
end

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

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



199
200
201
# File 'lib/startcoin_client/dsl.rb', line 199

def listaccounts(minconf = 1)
  bitcoin.listaccounts minconf
end

#listreceivedbyaccount(minconf = 1, includeempty = false) ⇒ Object Also known as: list_received_by_account

Returns an array of objects containing:

:account       => the  of the receiving addresses
:amount        => total amount received by addresses with this 
:confirmations => number of confirmations of the most recent transaction included


209
210
211
# File 'lib/startcoin_client/dsl.rb', line 209

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



221
222
223
# File 'lib/startcoin_client/dsl.rb', line 221

def listreceivedbyaddress(minconf = 1, includeempty = false)
  bitcoin.listreceivedbyaddress minconf, includeempty
end

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

Returns up to count most recent transactions for account account.



226
227
228
# File 'lib/startcoin_client/dsl.rb', line 226

def listtransactions( = '', count = 10, from = 0)
  bitcoin.listtransactions , count, from
end

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

Move from one account in your wallet to another.



231
232
233
# File 'lib/startcoin_client/dsl.rb', line 231

def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
  bitcoin.move fromaccount, toaccount, amount, minconf, comment
end

#password(value = nil) ⇒ Object



34
35
36
# File 'lib/startcoin_client/dsl.rb', line 34

def password(value = nil)
  value ? bitcoin.pass = value : bitcoin.pass
end

#password=(value) ⇒ Object



14
15
16
# File 'lib/startcoin_client/dsl.rb', line 14

def password=(value)
  bitcoin.pass = value
end

#port(value = nil) ⇒ Object



42
43
44
# File 'lib/startcoin_client/dsl.rb', line 42

def port(value = nil)
  value ? bitcoin.port = value : bitcoin.port
end

#port=(value) ⇒ Object



22
23
24
# File 'lib/startcoin_client/dsl.rb', line 22

def port=(value)
  bitcoin.port = value
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.



236
237
238
# File 'lib/startcoin_client/dsl.rb', line 236

def searchrawtransactions(bitcoinaddress, verbose=1)
  bitcoin.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.



241
242
243
# File 'lib/startcoin_client/dsl.rb', line 241

def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
  bitcoin.sendfrom fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
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



246
247
248
# File 'lib/startcoin_client/dsl.rb', line 246

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



251
252
253
# File 'lib/startcoin_client/dsl.rb', line 251

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



257
258
259
# File 'lib/startcoin_client/dsl.rb', line 257

def setgenerate(generate, genproclimit = -1)
  bitcoin.setgenerate generate, genproclimit
end

#ssl(value = nil) ⇒ Object



46
47
48
# File 'lib/startcoin_client/dsl.rb', line 46

def ssl(value = nil)
  value.nil? ? bitcoin.ssl : bitcoin.ssl = value
end

#ssl=(value) ⇒ Object



26
27
28
# File 'lib/startcoin_client/dsl.rb', line 26

def ssl=(value)
  bitcoin.ssl = value
end

#ssl?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/startcoin_client/dsl.rb', line 50

def ssl?
  bitcoin.ssl?
end

#stopObject

Stop bitcoin server.



262
263
264
# File 'lib/startcoin_client/dsl.rb', line 262

def stop
  bitcoin.stop
end

#username(value = nil) ⇒ Object



30
31
32
# File 'lib/startcoin_client/dsl.rb', line 30

def username(value = nil)
  value ? bitcoin.user = value : bitcoin.user
end

#username=(value) ⇒ Object



10
11
12
# File 'lib/startcoin_client/dsl.rb', line 10

def username=(value)
  bitcoin.user = value
end

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

Return information about bitcoinaddress.



267
268
269
# File 'lib/startcoin_client/dsl.rb', line 267

def validateaddress(bitcoinaddress)
  bitcoin.validateaddress
end