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



63
64
65
# File 'lib/bitbank/account.rb', line 63

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

#addressObject

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

#balanceObject

Returns the balance in this account.



22
23
24
# File 'lib/bitbank/account.rb', line 22

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.



29
30
31
32
33
34
35
36
37
# File 'lib/bitbank/account.rb', line 29

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.



42
43
44
# File 'lib/bitbank/account.rb', line 42

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.



49
50
51
52
53
54
55
56
# File 'lib/bitbank/account.rb', line 49

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.



59
60
61
# File 'lib/bitbank/account.rb', line 59

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