class Blockchain::Wallet

Attributes

guid[R]

Public Class Methods

bitcoins_to_satoshi(bitcoins) click to toggle source
# File lib/blockchain/wallet.rb, line 22
def self.bitcoins_to_satoshi(bitcoins)
  bitcoins * (10 ** 8)
end
new(guid, password, second_password) click to toggle source
Calls superclass method WebAPI::new
# File lib/blockchain/wallet.rb, line 10
def initialize(guid, password, second_password)
  super("https://blockchain.info/merchant/#{guid}/")
  @guid = guid
  @password = password
  @second_password = second_password
end
satoshi_to_bitcoins(satoshi) click to toggle source
# File lib/blockchain/wallet.rb, line 18
def self.satoshi_to_bitcoins(satoshi)
  satoshi / (10 ** 8)
end

Public Instance Methods

address_balance(address, confirmations = 0) click to toggle source
# File lib/blockchain/wallet.rb, line 31
def address_balance(address, confirmations = 0)
  url = build_url("address_balance", {:password => @password, :address => address, :confirmations => confirmations})
  handle(url) { |answer| answer }
end
addresses() click to toggle source
# File lib/blockchain/wallet.rb, line 26
def addresses
  url = build_url("list", {:password => @password})
  handle(url) { |answer| answer.addresses }
end
archive_address(address) click to toggle source
# File lib/blockchain/wallet.rb, line 41
def archive_address(address)
  url = build_url("archive_address", {:password => @password, :second_password => @second_password, :address => address})
  handle(url) { |answer| answer.archived == address }
end
auto_consolidate(days) click to toggle source
# File lib/blockchain/wallet.rb, line 51
def auto_consolidate(days)
  url = build_url("auto_consolidate", {:password => @password, :second_password => @second_password, :days => days})
  handle(url) { |answer| answer.consolidated }
end
new_address(label = nil) click to toggle source
# File lib/blockchain/wallet.rb, line 36
def new_address(label = nil)
  url = build_url("new_address", {:password => @password, :second_password => @second_password, :label => label})
  handle(url) { |answer| answer }
end
payment(address, amount, from = nil, shared = nil, fee = nil, note = nil) click to toggle source
# File lib/blockchain/wallet.rb, line 56
def payment(address, amount, from = nil, shared = nil, fee = nil, note = nil)
  url = build_url("payment", {:password => @password, :second_password => @second_password, :to => address, :amount => Wallet::bitcoins_to_satoshi(amount),
                              :from => from, :shared => shared, :fee => fee, :note => note})
  handle(url) { |answer| answer }
end
sendmany(recipients, from = nil, shared = nil, fee = nil, note = nil) click to toggle source
# File lib/blockchain/wallet.rb, line 62
def sendmany(recipients, from = nil, shared = nil, fee = nil, note = nil)
  url = build_url("sendmany", {:password => @password, :second_password => @second_password, :recipients => recipients,
                              :from => from, :shared => shared, :fee => fee, :note => note})
  handle(url) { |answer| answer }
end
unarchive_address(address) click to toggle source
# File lib/blockchain/wallet.rb, line 46
def unarchive_address(address)
  url = build_url("unarchive_address", {:password => @password, :second_password => @second_password, :address => address})
  handle(url) { |answer| answer.active == address }
end

Private Instance Methods

check_error(answer) click to toggle source
# File lib/blockchain/wallet.rb, line 89
def check_error(answer)
  error = answer['error']
  raise WebApiException, error if error
end
execute_request(url) click to toggle source
# File lib/blockchain/wallet.rb, line 82
def execute_request(url)
  json=open(URI.encode(url), :read_timeout => 10, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
  parse_JSON(json)
rescue Exception => ex
  raise BlockchainException, ex.message
end
handle(url) { |immutable_struct(*keys.map(&:to_sym)).new(*values)| ... } click to toggle source
# File lib/blockchain/wallet.rb, line 75
def handle(url)
  answer = execute_request(url)
  check_error(answer)
  answer['balance'] = Wallet::satoshi_to_bitcoins(answer['balance']) if answer['balance']
  yield ImmutableStruct.new(*answer.keys.map(&:to_sym)).new(*answer.values)
end
parse_JSON(json) click to toggle source
# File lib/blockchain/wallet.rb, line 94
def parse_JSON(json)
  Oj.load(json, :class_cache => true)
end