Class: RPC::Wallet
- Inherits:
-
Object
- Object
- RPC::Wallet
- Defined in:
- lib/rpc/wallet.rb
Class Method Summary collapse
- .address ⇒ Object
- .balance ⇒ Object
- .create_address(label = "") ⇒ Object
-
.create_wallet(filename, password, language = "English") ⇒ Object
creates a wallet and uses it if wallet exists, will automatically uses it!.
- .get_address ⇒ Object
- .get_addresses ⇒ Object
- .get_all_incoming_transfers(args = {}) ⇒ Object
- .get_bulk_payments(payment_ids, min_block_height) ⇒ Object
- .get_payments(payment_id) ⇒ Object
- .get_transfer_by_txid(txid) ⇒ Object
-
.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;.
- .getaddress ⇒ Object
- .getbalance ⇒ Object
- .getheight ⇒ Object
- .incoming_transfers(type) ⇒ Object
- .make_integrated_address(payment_id = "") ⇒ Object
- .mnemonic_seed ⇒ Object
-
.open_wallet(filename, password = "") ⇒ Object
returns current balance if open successfull.
- .query_key(type) ⇒ Object
- .split_integrated_address(address) ⇒ Object
-
.stop_wallet ⇒ Object
stops current RPC process!.
- .unlocked_balance ⇒ Object
- .view_key ⇒ Object
Class Method Details
.address ⇒ Object
13 |
# File 'lib/rpc/wallet.rb', line 13 def self.address; getaddress; end |
.balance ⇒ Object
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? = { filename: filename, password: password, language: language } !! RPC::Client.request("create_wallet", ) end |
.get_address ⇒ Object
9 10 11 |
# File 'lib/rpc/wallet.rb', line 9 def self.get_address RPC::Client.request("get_address")["address"] end |
.get_addresses ⇒ Object
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) = {in: f_in, out: out, pending: pending, failed: failed, pool: pool, filter_by_height: filter_by_height, min_height: min_height} [:max_height] = max_height if max_height > min_height h = Hash.new json = RPC::Client.request("get_transfers", ) json.map{|k, v| h[k] = v.collect{|transfer| Module.const_get((RPC.config.transfer_clazz || "RPC::IncomingTransfer")).new(transfer) } } return h end |
.getaddress ⇒ Object
31 32 33 |
# File 'lib/rpc/wallet.rb', line 31 def self.getaddress RPC::Client.request("getaddress")["address"] end |
.getbalance ⇒ Object
19 20 21 |
# File 'lib/rpc/wallet.rb', line 19 def self.getbalance RPC::Client.request("getbalance") end |
.getheight ⇒ Object
35 36 37 |
# File 'lib/rpc/wallet.rb', line 35 def self.getheight RPC::Client.request("getheight")["height"] end |
.incoming_transfers(type) ⇒ Object
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_seed ⇒ Object
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="") = { filename: filename, password: password} if RPC::Client.request("open_wallet", ) balance else false end end |
.query_key(type) ⇒ Object
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_wallet ⇒ Object
stops current RPC process!
139 140 141 |
# File 'lib/rpc/wallet.rb', line 139 def self.stop_wallet RPC::Client.close! end |
.unlocked_balance ⇒ Object
27 28 29 |
# File 'lib/rpc/wallet.rb', line 27 def self.unlocked_balance XMR.new(getbalance["unlocked_balance"]) end |
.view_key ⇒ Object
43 |
# File 'lib/rpc/wallet.rb', line 43 def self.view_key; query_key(:view_key); end |