Class: Bitbank::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbank/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name, balance = nil, check = false) ⇒ Account

Returns a new instance of Account.


5
6
7
8
9
10
11
12
13
# File 'lib/bitbank/account.rb', line 5

def initialize(client, name, balance=nil, check=false)
  @client = client
  @name = name
  @balance = balance # currently unused

  # validate the address if a check is requested
  # (bitcoind creates it if it didn't previous exist)
  address if check
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/bitbank/account.rb', line 3

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object


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

def ==(other)
  name == other.name
end

#addressObject Also known as: primary_address

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


17
18
19
# File 'lib/bitbank/account.rb', line 17

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

#addressesObject

Returns the complete list of addresses for this account.


24
25
26
# File 'lib/bitbank/account.rb', line 24

def addresses
  @client.request('getaddressesbyaccount', name)
end

#balanceObject

Returns the balance in this account.


29
30
31
# File 'lib/bitbank/account.rb', line 29

def balance
  @client.balance(name)
end

#move(name_or_account, amount) ⇒ Object Also known as: transfer

Move funds from one account in your wallet to another. First parameter can either by an account name or an actual account object.


36
37
38
39
40
41
42
43
44
# File 'lib/bitbank/account.rb', line 36

def move(, amount)
  to_name = if .is_a?(Bitbank::Account)
    .name
  else
    
  end

  @client.request('move', name, to_name, amount)
end

#new_addressObject

Returns a new bitcoin address for receiving payments to this account.


49
50
51
# File 'lib/bitbank/account.rb', line 49

def new_address
  @client.new_address(name)
end

#pay(address, amount) ⇒ Object

Send funds from this account to the recipient identified by address. Note that amount is a real and is rounded to 8 decimal places. Returns the transaction if successful.


56
57
58
59
60
61
62
63
# File 'lib/bitbank/account.rb', line 56

def pay(address, amount)
  if @client.validate_address(address, true)
    txid = @client.request('sendfrom', name, address, amount)
    Transaction.new(@client, txid)
  else
    false
  end
end

#transactions(count = 10) ⇒ Object

Returns a list of the most recent transactions for this account.


66
67
68
# File 'lib/bitbank/account.rb', line 66

def transactions(count = 10)
  @client.transactions(name, count)
end