class NanoRpcClient
A simple client for sending data to the RPC server. This is a low-level API; use NanoAccount
instead.
Public Class Methods
mrai_to_raw(mrai)
click to toggle source
Convert an amount of MRai to a raw Nano quantity. Params:
mrai
-
The quantity of MRai.
Returns: The quantity of raw Nano, stringified.
# File lib/clients.rb, line 48 def self.mrai_to_raw(mrai) BigDecimal(mrai) * BigDecimal("1000000000000000000000000000000") end
new(endpoint)
click to toggle source
Create a new client. Params:
endpoint
-
The location of the RPC server.
# File lib/clients.rb, line 13 def initialize(endpoint) @dispatcher = HTTP @endpoint = endpoint end
Public Instance Methods
method_missing(action, **kwargs)
click to toggle source
Missing methods will make requests to the RPC server using the method name as the action. The rest of the keyword arguments are passed as JSON data. Params:
action
-
The
action
field of the RPC request. kwargs
-
The keyword arguments passed to the method.
# File lib/clients.rb, line 36 def method_missing(action, **kwargs) kwargs["action"] = action.to_s # Stringify all keys req(kwargs.map{|k, v| [k.to_s, v]}.to_h) end
req(data)
click to toggle source
Make a request to the endpoint. Params:
data
-
A
Hash
to send to the RPC server.
Returns: The object returned by the server as a Hash
.
# File lib/clients.rb, line 23 def req(data) res = @dispatcher.post(@endpoint, :json => data).parse raise RpcError, res["error"] if res["error"] != nil res end