module MoneroRPC::Wallet

Public Instance Methods

address()
Alias for: get_address
balance() click to toggle source
# File lib/monero_rpc/wallet.rb, line 28
def balance
  XMR.new(getbalance["balance"])
end
close()
Alias for: stop_wallet
create(filename, password, language="English")
Alias for: create_wallet
create_address(label="") click to toggle source
# File lib/monero_rpc/wallet.rb, line 3
def create_address(label="")
  request("create_address", label: label)
end
create_wallet(filename, password, language="English") click to toggle source

creates a wallet and uses it if wallet exists, will automatically uses it!

# File lib/monero_rpc/wallet.rb, line 140
def create_wallet(filename, password, language="English")
  # TODO
  # language correct format?
  options = { filename: filename, password: password, language: language }
  !! request("create_wallet", options)
end
Also aliased as: create
get_address() click to toggle source
# File lib/monero_rpc/wallet.rb, line 7
def get_address
  get_addresses(0, [0]).first["address"]
end
Also aliased as: address
get_addresses(account_index=0, address_index=[0]) click to toggle source
# File lib/monero_rpc/wallet.rb, line 12
def get_addresses(account_index=0, address_index=[0])
  request("get_address", {account_index: account_index, address_index: address_index})["addresses"]
end
get_all_incoming_transfers(args={}) click to toggle source
# File lib/monero_rpc/wallet.rb, line 116
def get_all_incoming_transfers(args={})
  pending = args.fetch(:pending, true)
  min_height = args.fetch(:min_height, 0)
  max_height = args.fetch(:max_height, 0)

  all = get_transfers(filter_by_height: true, min_height: min_height, max_height: max_height, in: true, out: false, pending: true, pool: true)
  [ all["in"], all["pending"], all["pool"]].flatten.compact
end
get_all_outgoing_transfers(args={}) click to toggle source
# File lib/monero_rpc/wallet.rb, line 125
def get_all_outgoing_transfers(args={})
  pending = args.fetch(:pending, true)
  min_height = args.fetch(:min_height, 0)
  max_height = args.fetch(:max_height, 0)

  all = get_transfers(filter_by_height: true, min_height: min_height, max_height: max_height, in: false, out: true, pending: pending, pool: true)
  [ all["out"], all["pending"], all["pool"]].flatten.compact
end
get_bulk_payments(payment_ids, min_block_height) click to toggle source
# File lib/monero_rpc/wallet.rb, line 75
def get_bulk_payments(payment_ids, min_block_height)
  payments = request("get_bulk_payments", {"payment_ids": payment_ids, "min_block_height": min_block_height})
  return payments
end
get_payments(payment_id) click to toggle source
# File lib/monero_rpc/wallet.rb, line 68
def get_payments(payment_id)
  payments = request("get_payments", {payment_id: payment_id})["payments"] || []
  # TODO
  # make it a MoneroRPC::Payment that hase a amount as XMR and confirmations (getheight - tx.block_height)
  payments.map{|x| Payment.from_raw(x) }
end
get_transfer_by_txid(txid) click to toggle source
# File lib/monero_rpc/wallet.rb, line 134
def get_transfer_by_txid(txid)
  request("get_transfer_by_txid", {txid: txid })
end
get_transfers(args={}) click to toggle source

in - boolean; out - boolean; pending - boolean; failed - boolean; pool - boolean; filter_by_height - boolean; min_height - unsigned int; max_height - unsigned int;

# File lib/monero_rpc/wallet.rb, line 89
def get_transfers(args={})
  f_in = args.fetch(:in, true)
  out = args.fetch(:out, false)
  pending = args.fetch(:pending, true)
  failed = args.fetch(:failed, false)
  pool = args.fetch(:pool, true)
  filter_by_height = args.fetch(:filter_by_height, false)
  min_height = args.fetch(:min_height, 0)
  max_height = args.fetch(:max_height, 0)

  options = {in: f_in, out: out, pending: pending, failed: failed, pool: pool, filter_by_height: filter_by_height, min_height: min_height}
  options[:max_height] = max_height if max_height > min_height

  h = Hash.new
  json = request("get_transfers", options)
  json.map{|k, v|
    h[k] = v.collect{|transfer|
      if k == "in"
        in_transfer_clazz.constantize.new(transfer)
      else
        out_transfer_clazz.constantize.new(transfer)
      end
    }
  }
  return h
end
getaddress() click to toggle source
# File lib/monero_rpc/wallet.rb, line 36
def getaddress
  request("getaddress")["address"]
end
getbalance() click to toggle source
# File lib/monero_rpc/wallet.rb, line 24
def getbalance
  request("getbalance")
end
getheight() click to toggle source
# File lib/monero_rpc/wallet.rb, line 40
def getheight
  request("getheight")["height"]
end
incoming_transfers(type) click to toggle source
# File lib/monero_rpc/wallet.rb, line 62
def incoming_transfers(type)
  raise ArgumentError unless ["all", "available", "unavailable"].include?(type.to_s)
  json = request("incoming_transfers", {transfer_type: type})
  json["transfers"] || []
end
make_integrated_address(payment_id = "") click to toggle source
# File lib/monero_rpc/wallet.rb, line 52
def make_integrated_address(payment_id = "")
  # TODO
  # Check if payment_id is correct format
  request("make_integrated_address", {payment_id: payment_id})
end
mnemonic_seed() click to toggle source
# File lib/monero_rpc/wallet.rb, line 49
def mnemonic_seed; query_key(:mnemonic); end
open(filename, password="")
Alias for: open_wallet
open_wallet(filename, password="") click to toggle source

returns current balance if open successfull

# File lib/monero_rpc/wallet.rb, line 149
def open_wallet(filename, password="")
  options = { filename: filename, password: password}
  if request("open_wallet", options)
    balance
  else
    false
  end
end
Also aliased as: open
query_key(type) click to toggle source
# File lib/monero_rpc/wallet.rb, line 44
def query_key(type)
  raise ArgumentError unless ["mnemonic", "view_key"].include?(type.to_s)
  request("query_key", {key_type: type})["key"]
end
split_integrated_address(address) click to toggle source
# File lib/monero_rpc/wallet.rb, line 58
def split_integrated_address(address)
  request("split_integrated_address", {integrated_address: address})
end
stop_wallet() click to toggle source

stops current MoneroRPC process!

# File lib/monero_rpc/wallet.rb, line 160
def stop_wallet
  close!
end
Also aliased as: close
unlocked_balance() click to toggle source
# File lib/monero_rpc/wallet.rb, line 32
def unlocked_balance
  XMR.new(getbalance["unlocked_balance"])
end
valid_address?(address) click to toggle source
# File lib/monero_rpc/wallet.rb, line 16
def valid_address?(address)
  begin
    request("validate_address", {address: address}).fetch("valid")
  rescue
    false
  end
end
view_key() click to toggle source
# File lib/monero_rpc/wallet.rb, line 48
def view_key; query_key(:view_key); end