Class: BitWallet::Account
- Inherits:
-
Object
- Object
- BitWallet::Account
- Defined in:
- lib/bit_wallet/account.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#wallet ⇒ Object
readonly
Returns the value of attribute wallet.
Instance Method Summary collapse
- #==(other_account) ⇒ Object
- #addresses ⇒ Object
- #balance(min_conf = BitWallet.min_conf) ⇒ Object
-
#initialize(wallet, name) ⇒ Account
constructor
A new instance of Account.
- #recent_transactions(options = {}) ⇒ Object
- #send_amount(amount, options = {}) ⇒ Object
- #send_many(account_values = {}) ⇒ Object
- #total_received ⇒ Object
Constructor Details
#initialize(wallet, name) ⇒ Account
Returns a new instance of Account.
7 8 9 10 11 12 |
# File 'lib/bit_wallet/account.rb', line 7 def initialize(wallet, name) @wallet = wallet @name = name fail ArgumentError, "account name cannot be nil" if name.nil? self.addresses.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/bit_wallet/account.rb', line 4 def name @name end |
#wallet ⇒ Object (readonly)
Returns the value of attribute wallet.
4 5 6 |
# File 'lib/bit_wallet/account.rb', line 4 def wallet @wallet end |
Instance Method Details
#==(other_account) ⇒ Object
41 42 43 |
# File 'lib/bit_wallet/account.rb', line 41 def ==(other_account) self.name == other_account.name end |
#addresses ⇒ Object
14 15 16 |
# File 'lib/bit_wallet/account.rb', line 14 def addresses @addresses ||= Addresses.new(self) end |
#balance(min_conf = BitWallet.min_conf) ⇒ Object
18 19 20 |
# File 'lib/bit_wallet/account.rb', line 18 def balance(min_conf=BitWallet.min_conf) client.getbalance(self.name, min_conf) end |
#recent_transactions(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bit_wallet/account.rb', line 45 def recent_transactions(={}) count = .delete(:limit) || 10 # FIXME: come up with adapters to abstract the differences between # bitcoind and blockchain.info API api_result = client.listtransactions(self.name, count) txs = api_result if api_result.is_a?(Hash) txs = api_result.with_indifferent_access.fetch(:transactions) end txs.map do |hash| Transaction.new self.wallet, hash end end |
#send_amount(amount, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bit_wallet/account.rb', line 22 def send_amount(amount, ={}) if [:to] [:to] = [:to].address if [:to].is_a?(Address) else fail ArgumentError, 'address must be specified' end client.sendfrom(self.name, [:to], amount, BitWallet.min_conf) rescue Bitcoin::Errors::RPCError => e parse_error e. end |
#send_many(account_values = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bit_wallet/account.rb', line 59 def send_many(account_values={}) addresses_values = {} account_values.each do |key, value| address = key.respond_to?(:address) ? key.address : key addresses_values[address] = value end txid = client.send_many(self.name, addresses_values, BitWallet.min_conf) txid rescue => e parse_error e. end |