Module: Cryptobank

Defined in:
lib/cryptobank.rb,
lib/cryptobank/error.rb,
lib/cryptobank/version.rb

Overview

Implements Bitcoin API JSON-RPC to communicate with bitcoind

Constant Summary collapse

HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
}.freeze
Error =
Class.new(StandardError)
VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject



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

def host
  @host || 'localhost'
end

#passwordObject



27
28
29
# File 'lib/cryptobank.rb', line 27

def password
  @password || 'rpcpassword'
end

#portObject



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

def port
  @port || 8332
end

#userObject



23
24
25
# File 'lib/cryptobank.rb', line 23

def user
  @user || 'rpcuser'
end

Instance Method Details

#account(bitcoin_address) ⇒ Object

getaccount A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”) returns a base58 string



82
83
84
85
86
87
88
# File 'lib/cryptobank.rb', line 82

def (bitcoin_address)
  payload = {
    method: 'getaccount'
  }
  payload[:params] = [bitcoin_address.to_string]
  request(payload)
end

#add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '') ⇒ Object

addmultisigaddress



36
37
38
39
40
41
42
# File 'lib/cryptobank.rb', line 36

def add_multisig_address(minimum_number_of_sigs, key_or_addresses,  = '')
  payload = {
    method: 'addmultisigaddress'
  }
  payload[:params] = [minimum_number_of_sigs.to_int, key_or_addresses.to_string, .to_string]
  request(payload)
end

#add_nodeObject

addnode

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/cryptobank.rb', line 45

def add_node
  raise NotImplementedError
end

#added_node_infoObject

getaddednodeinfo

Raises:

  • (NotImplementedError)


91
92
93
# File 'lib/cryptobank.rb', line 91

def added_node_info
  raise NotImplementedError
end

#backup_walletObject

backupwallet

Raises:

  • (NotImplementedError)


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

def backup_wallet
  raise NotImplementedError
end

#balance(account = nil) ⇒ Object

getbalance There are additional parameters on the RPC docs to be implemented bitcoin.org/en/developer-reference#getbalance



97
98
99
100
101
102
103
# File 'lib/cryptobank.rb', line 97

def balance( = nil)
  payload = {
    method: 'getbalance'
  }
  payload[:params] = [] unless .nil?
  request(payload)
end

#best_block_hashObject

getbestblockhash

Raises:

  • (NotImplementedError)


106
107
108
# File 'lib/cryptobank.rb', line 106

def best_block_hash
  raise NotImplementedError
end

#block(verbosity = nil) ⇒ Object

getblock



111
112
113
114
115
116
117
# File 'lib/cryptobank.rb', line 111

def block(verbosity = nil)
  payload = {
    method: 'getblock'
  }
  payload[:params] = [template_request] unless verbosity.nil?
  request(payload)
end

#block_countObject

getblockcount



128
129
130
131
132
133
# File 'lib/cryptobank.rb', line 128

def block_count
  payload = {
    method: 'getblockcount'
  }
  request(payload)
end

#block_hashObject

getblockhash



120
121
122
123
124
125
# File 'lib/cryptobank.rb', line 120

def block_hash
  payload = {
    method: 'getblockhash'
  }
  request(payload)
end

#block_template(template_request = nil) ⇒ Object

getblocktemplate



136
137
138
139
140
141
142
# File 'lib/cryptobank.rb', line 136

def block_template(template_request = nil)
  payload = {
    method: 'getblocktemplate'
  }
  payload[:params] = [template_request] unless template_request.nil?
  request(payload)
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Cryptobank)

    the object that the method was called on



31
32
33
# File 'lib/cryptobank.rb', line 31

def configure
  yield self
end

#connection_countObject

getconnectioncount



145
146
147
148
149
150
# File 'lib/cryptobank.rb', line 145

def connection_count
  payload = {
    method: 'getconnectioncount'
  }
  request(payload)
end

#create_multisigObject

createmultisig

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/cryptobank.rb', line 55

def create_multisig
  raise NotImplementedError
end

#create_raw_transactionObject

createrawtransaction

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/cryptobank.rb', line 60

def create_raw_transaction
  raise NotImplementedError
end

#decode_raw_transactionObject

decoderawtransaction

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/cryptobank.rb', line 65

def decode_raw_transaction
  raise NotImplementedError
end

#difficultyObject

getdifficulty



153
154
155
156
157
158
# File 'lib/cryptobank.rb', line 153

def difficulty
  payload = {
    method: 'getdifficulty'
  }
  request(payload)
end

#dump_priv_keyObject

dumpprivkey

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/cryptobank.rb', line 70

def dump_priv_key
  raise NotImplementedError
end

#encrypt_walletObject

encryptwallet

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/cryptobank.rb', line 75

def encrypt_wallet
  raise NotImplementedError
end

#generateObject

getgenerate



161
162
163
164
165
166
# File 'lib/cryptobank.rb', line 161

def generate
  payload = {
    method: 'getgenerate'
  }
  request(payload)
end

#get_account_addresses(account) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/cryptobank.rb', line 168

def ()
  payload = {
    method: 'getaddressesbyaccount'
  }
  payload[:params] = []
  request(payload)
end

#hashes_per_secObject

gethashespersec

Raises:

  • (NotImplementedError)


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

def hashes_per_sec
  raise NotImplementedError
end

#infoObject

getinfo



182
183
184
185
186
187
# File 'lib/cryptobank.rb', line 182

def info
  payload = {
    method: 'getwalletinfo'
  }
  request(payload)
end

#memory_pool_infoObject

getmempoolinfo



190
191
192
193
194
195
# File 'lib/cryptobank.rb', line 190

def memory_pool_info
  payload = {
    method: 'getmempoolinfo'
  }
  request(payload)
end