Class: MoneroRPC::Client
- Inherits:
-
Object
- Object
- MoneroRPC::Client
- Defined in:
- lib/monero_rpc/client.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#in_transfer_clazz ⇒ Object
readonly
Returns the value of attribute in_transfer_clazz.
-
#out_transfer_clazz ⇒ Object
readonly
Returns the value of attribute out_transfer_clazz.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #close! ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #request(method, params = "") ⇒ Object
Methods included from Transfer
#create_transfer, #send_bulk_transfer
Methods included from Wallet
#balance, #create_address, #create_wallet, #get_address, #get_addresses, #get_all_incoming_transfers, #get_all_outgoing_transfers, #get_bulk_payments, #get_payments, #get_transfer_by_txid, #get_transfers, #getaddress, #getbalance, #getheight, #incoming_transfers, #make_integrated_address, #mnemonic_seed, #open_wallet, #query_key, #split_integrated_address, #stop_wallet, #unlocked_balance, #valid_address?, #view_key
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 |
# File 'lib/monero_rpc/client.rb', line 7 def initialize(args= {}) @host = args.fetch(:host, MoneroRPC.config.host) @port = args.fetch(:port, MoneroRPC.config.port) @username = args.fetch(:username, MoneroRPC.config.username) @password = args.fetch(:password, MoneroRPC.config.password) @debug = args.fetch(:debug, MoneroRPC.config.debug) @in_transfer_clazz = args.fetch(:in_transfer_clazz, MoneroRPC.config.in_transfer_clazz || "MoneroRPC::IncomingTransfer") @out_transfer_clazz = args.fetch(:out_transfer_clazz, MoneroRPC.config.out_transfer_clazz || "MoneroRPC::OutgoingTransfer") end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def debug @debug end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def host @host end |
#in_transfer_clazz ⇒ Object (readonly)
Returns the value of attribute in_transfer_clazz.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def in_transfer_clazz @in_transfer_clazz end |
#out_transfer_clazz ⇒ Object (readonly)
Returns the value of attribute out_transfer_clazz.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def out_transfer_clazz @out_transfer_clazz end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/monero_rpc/client.rb', line 5 def username @username end |
Instance Method Details
#close! ⇒ Object
17 18 19 |
# File 'lib/monero_rpc/client.rb', line 17 def close! request("stop_wallet") end |
#request(method, params = "") ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/monero_rpc/client.rb', line 21 def request(method, params="") # TODO # who can implement digest auth with net/http? # this is really ugly! data = '{"jsonrpc":"2.0","id":"0","method": "'+method+'", "params": '+params.to_json+' }' args = "" args << " -s" args << " -u #{username}:#{password} --digest" args << " -X POST #{base_uri}/json_rpc" args << " -d '#{data}'" args << " -H 'Content-Type: application/json'" p "curl #{args}" if debug json = JSON.parse(`curl #{args}`) # Error handling if json["error"] raise "#{json["error"]["message"]} | code: #{json["error"]["code"]}" end json["result"] end |