Class: RPC::Wallet

Inherits:
Object
  • Object
show all
Defined in:
lib/rpc/wallet.rb

Class Method Summary collapse

Class Method Details

.addressObject



13
# File 'lib/rpc/wallet.rb', line 13

def self.address; getaddress; end

.balanceObject



23
24
25
# File 'lib/rpc/wallet.rb', line 23

def self.balance
  XMR.new(getbalance["balance"])
end

.create_address(label = "") ⇒ Object



5
6
7
# File 'lib/rpc/wallet.rb', line 5

def self.create_address(label="")
  RPC::Client.request("create_address", label: label)
end

.create_wallet(filename, password, language = "English") ⇒ Object

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



119
120
121
122
123
124
# File 'lib/rpc/wallet.rb', line 119

def self.create_wallet(filename, password, language="English")
  # TODO
  # language correct format?
  options = { filename: filename, password: password, language: language }
  !! RPC::Client.request("create_wallet", options)
end

.get_addressObject



9
10
11
# File 'lib/rpc/wallet.rb', line 9

def self.get_address
  RPC::Client.request("get_address")["address"]
end

.get_addressesObject



15
16
17
# File 'lib/rpc/wallet.rb', line 15

def self.get_addresses
  RPC::Client.request("get_address")["addresses"]
end

.get_all_incoming_transfers(args = {}) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/rpc/wallet.rb', line 105

def self.get_all_incoming_transfers(args={})
  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_bulk_payments(payment_ids, min_block_height) ⇒ Object



70
71
72
73
# File 'lib/rpc/wallet.rb', line 70

def self.get_bulk_payments(payment_ids, min_block_height)
  payments = RPC::Client.request("get_bulk_payments", {"payment_ids": payment_ids, "min_block_height": min_block_height})
  return payments
end

.get_payments(payment_id) ⇒ Object



63
64
65
66
67
68
# File 'lib/rpc/wallet.rb', line 63

def self.get_payments(payment_id)
  payments = RPC::Client.request("get_payments", {payment_id: payment_id})["payments"] || []
  # TODO
  # make it a RPC::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) ⇒ Object



113
114
115
# File 'lib/rpc/wallet.rb', line 113

def self.get_transfer_by_txid(txid)
  RPC::Client.request("get_transfer_by_txid", {txid: txid })
end

.get_transfers(args = {}) ⇒ Object

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rpc/wallet.rb', line 84

def self.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 = RPC::Client.request("get_transfers", options)
  json.map{|k, v|
    h[k] = v.collect{|transfer| Module.const_get((RPC.config.transfer_clazz || "RPC::IncomingTransfer")).new(transfer) }
  }
  return h
end

.getaddressObject



31
32
33
# File 'lib/rpc/wallet.rb', line 31

def self.getaddress
  RPC::Client.request("getaddress")["address"]
end

.getbalanceObject



19
20
21
# File 'lib/rpc/wallet.rb', line 19

def self.getbalance
  RPC::Client.request("getbalance")
end

.getheightObject



35
36
37
# File 'lib/rpc/wallet.rb', line 35

def self.getheight
  RPC::Client.request("getheight")["height"]
end

.incoming_transfers(type) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
# File 'lib/rpc/wallet.rb', line 57

def self.incoming_transfers(type)
  raise ArgumentError unless ["all", "available", "unavailable"].include?(type.to_s)
  json = RPC::Client.request("incoming_transfers", {transfer_type: type})
  json["transfers"] || []
end

.make_integrated_address(payment_id = "") ⇒ Object



47
48
49
50
51
# File 'lib/rpc/wallet.rb', line 47

def self.make_integrated_address(payment_id = "")
  # TODO
  # Check if payment_id is correct format
  RPC::Client.request("make_integrated_address", {payment_id: payment_id})
end

.mnemonic_seedObject



44
# File 'lib/rpc/wallet.rb', line 44

def self.mnemonic_seed; query_key(:mnemonic); end

.open_wallet(filename, password = "") ⇒ Object

returns current balance if open successfull



128
129
130
131
132
133
134
135
# File 'lib/rpc/wallet.rb', line 128

def self.open_wallet(filename, password="")
  options = { filename: filename, password: password}
  if RPC::Client.request("open_wallet", options)
    balance
  else
    false
  end
end

.query_key(type) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/rpc/wallet.rb', line 39

def self.query_key(type)
  raise ArgumentError unless ["mnemonic", "view_key"].include?(type.to_s)
  RPC::Client.request("query_key", {key_type: type})["key"]
end

.split_integrated_address(address) ⇒ Object



53
54
55
# File 'lib/rpc/wallet.rb', line 53

def self.split_integrated_address(address)
  RPC::Client.request("split_integrated_address", {integrated_address: address})
end

.stop_walletObject

stops current RPC process!



139
140
141
# File 'lib/rpc/wallet.rb', line 139

def self.stop_wallet
  RPC::Client.close!
end

.unlocked_balanceObject



27
28
29
# File 'lib/rpc/wallet.rb', line 27

def self.unlocked_balance
  XMR.new(getbalance["unlocked_balance"])
end

.view_keyObject



43
# File 'lib/rpc/wallet.rb', line 43

def self.view_key; query_key(:view_key); end