Sha256: c3d09f79d8cb509df4fb867ad1267312ebffcc39ae2801f58982786f3a42470c

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

module Bitbank
  class Account
    attr_reader :name

    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

    # Returns the current bitcoin address for receiving payments to this
    # account.
    def address
      @client.request('getaccountaddress', name)
    end

    # Returns the balance in this account.
    def balance
      @client.balance(name)
    end

    # Move funds from one account in your wallet to another.
    # First parameter can either by an account name or an actual account
    # object.
    def move(name_or_account, amount)
      to_name = if name_or_account.is_a?(Bitbank::Account)
        name_or_account.name
      else
        name_or_account
      end

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

    alias :transfer :move

    # Returns a new bitcoin address for receiving payments to this account.
    def new_address
      @client.new_address(name)
    end

    # 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.
    def pay(address, amount)
      txid = @client.request('sendfrom', name, address, amount)
      Transaction.new(@client, txid)
    end

    # Returns a list of the most recent transactions for this account.
    def transactions(count = 10)
      @client.transactions(name, count)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitbank-0.1.1 lib/bitbank/account.rb