Module: MoneroRPC::Wallet
- Included in:
- Client
- Defined in:
- lib/monero_rpc/wallet.rb
Instance Method Summary collapse
- #balance ⇒ Object
- #create_address(label = "") ⇒ Object
-
#create_wallet(filename, password, language = "English") ⇒ Object
(also: #create)
creates a wallet and uses it if wallet exists, will automatically uses it!.
- #get_address ⇒ Object (also: #address)
- #get_addresses(account_index = 0, address_index = [0]) ⇒ Object
- #get_all_incoming_transfers(args = {}) ⇒ Object
- #get_all_outgoing_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
(also: #open)
returns current balance if open successfull.
- #query_key(type) ⇒ Object
- #split_integrated_address(address) ⇒ Object
-
#stop_wallet ⇒ Object
(also: #close)
stops current MoneroRPC process!.
- #unlocked_balance ⇒ Object
- #valid_address?(address) ⇒ Boolean
- #view_key ⇒ Object
Instance Method Details
#balance ⇒ Object
28 29 30 |
# File 'lib/monero_rpc/wallet.rb', line 28 def balance XMR.new(getbalance["balance"]) end |
#create_address(label = "") ⇒ Object
3 4 5 |
# File 'lib/monero_rpc/wallet.rb', line 3 def create_address(label="") request("create_address", label: label) end |
#create_wallet(filename, password, language = "English") ⇒ Object Also known as: create
creates a wallet and uses it if wallet exists, will automatically uses it!
140 141 142 143 144 145 |
# File 'lib/monero_rpc/wallet.rb', line 140 def create_wallet(filename, password, language="English") # TODO # language correct format? = { filename: filename, password: password, language: language } !! request("create_wallet", ) end |
#get_address ⇒ Object Also known as: address
7 8 9 |
# File 'lib/monero_rpc/wallet.rb', line 7 def get_address get_addresses(0, [0]).first["address"] end |
#get_addresses(account_index = 0, address_index = [0]) ⇒ Object
12 13 14 |
# 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 = {}) ⇒ Object
116 117 118 119 120 121 122 123 |
# 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 = {}) ⇒ Object
125 126 127 128 129 130 131 132 |
# 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) ⇒ Object
75 76 77 78 |
# 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) ⇒ Object
68 69 70 71 72 73 |
# 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) ⇒ Object
134 135 136 |
# 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 = {}) ⇒ Object
in - boolean; out - boolean; pending - boolean; failed - boolean; pool - boolean; filter_by_height - boolean; min_height - unsigned int; max_height - unsigned int;
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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) = {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 = request("get_transfers", ) 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 ⇒ Object
36 37 38 |
# File 'lib/monero_rpc/wallet.rb', line 36 def getaddress request("getaddress")["address"] end |
#getbalance ⇒ Object
24 25 26 |
# File 'lib/monero_rpc/wallet.rb', line 24 def getbalance request("getbalance") end |
#getheight ⇒ Object
40 41 42 |
# File 'lib/monero_rpc/wallet.rb', line 40 def getheight request("getheight")["height"] end |
#incoming_transfers(type) ⇒ Object
62 63 64 65 66 |
# 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 = "") ⇒ Object
52 53 54 55 56 |
# 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 ⇒ Object
49 |
# File 'lib/monero_rpc/wallet.rb', line 49 def mnemonic_seed; query_key(:mnemonic); end |
#open_wallet(filename, password = "") ⇒ Object Also known as: open
returns current balance if open successfull
149 150 151 152 153 154 155 156 |
# File 'lib/monero_rpc/wallet.rb', line 149 def open_wallet(filename, password="") = { filename: filename, password: password} if request("open_wallet", ) balance else false end end |
#query_key(type) ⇒ Object
44 45 46 47 |
# 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) ⇒ Object
58 59 60 |
# File 'lib/monero_rpc/wallet.rb', line 58 def split_integrated_address(address) request("split_integrated_address", {integrated_address: address}) end |
#stop_wallet ⇒ Object Also known as: close
stops current MoneroRPC process!
160 161 162 |
# File 'lib/monero_rpc/wallet.rb', line 160 def stop_wallet close! end |
#unlocked_balance ⇒ Object
32 33 34 |
# File 'lib/monero_rpc/wallet.rb', line 32 def unlocked_balance XMR.new(getbalance["unlocked_balance"]) end |
#valid_address?(address) ⇒ Boolean
16 17 18 19 20 21 22 |
# 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 ⇒ Object
48 |
# File 'lib/monero_rpc/wallet.rb', line 48 def view_key; query_key(:view_key); end |