Module: EPM::RPC
Instance Method Summary collapse
- #post_rpc(post_body) ⇒ Object
- #post_rpc_with_params(name, params) ⇒ Object
-
#rpc_arg_list(name) ⇒ Object
Returns the argument list under a particular method.
-
#rpc_default(name, arg_name, params) ⇒ Object
Returns the default, given other inputs.
-
#rpc_from_args(name, method, args, opt_vals) ⇒ Object
Takes actual option map and argument list to determine ‘params`.
Instance Method Details
#post_rpc(post_body) ⇒ Object
60 61 62 63 |
# File 'lib/epm/rpc.rb', line 60 def post_rpc post_body url = URI.parse "http://localhost:#{(EPM::setup)['json-port']}" return EPM::Server.http_post_request url, post_body.to_json end |
#post_rpc_with_params(name, params) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/epm/rpc.rb', line 53 def post_rpc_with_params name, params # TODO ethereal compatibility here? return post_rpc 'method' => name, 'params' => params, 'id' => 'epm-rpc', 'jsonrpc' => '2.0' end |
#rpc_arg_list(name) ⇒ Object
Returns the argument list under a particular method.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/epm/rpc.rb', line 31 def rpc_arg_list name case name when 'transact' return [["aDest", :a], ["bData", :d], ["sec", :p], ["xGas", :v], ["xGasPrice", :v], ["xValue", :v]] when 'create' return [["bCode", :d], ["sec", :p], ["xEndowment", :v], ["xGas", :v], ["xGasPrice", :v]] when 'storageAt' return [['a', :a], ['x', :i]] when 'lll' return [['s', :s]] when 'balanceAt', 'check', 'isContractAt', 'secretToAddress', 'txCountAt' return [['a', :a]] when 'block', 'coinbase', 'gasPrice', 'isListening', 'isMining', 'key', 'keys', 'lastBlock', 'peerCount', 'procedures' return [] else return 'Unknown RPC command.' end end |
#rpc_default(name, arg_name, params) ⇒ Object
Returns the default, given other inputs.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/epm/rpc.rb', line 11 def rpc_default name, arg_name, params case arg_name when 'sec' return (EPM::setup)['address-private-key'] when 'aOrigin' return (EPM::setup)['address-public-key'] when 'aSender' return (params['aOrigin'] or (EPM::setup)['address-public-key']) when 'xEndowment', 'xValue' return '0' when 'bData' return '' when 'xGas' return '100000' when 'xGasPrice' return '100000000000000' end end |
#rpc_from_args(name, method, args, opt_vals) ⇒ Object
Takes actual option map and argument list to determine ‘params`.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/epm/rpc.rb', line 66 def rpc_from_args name, method, args, opt_vals params = {} for a in method # Go through all arguments, and use them.(keywords before real) val = (opt_vals[a[0]] or args.shift) if val != nil && val != '' case a[1] # Respond to kind of parameter. when :d, :p, :v, :i params[a[0]] = val when :a params[a[0]] = (EPM::HexData.hex_guard val) else raise 'Unidentified kind of data' end else params[a[0]] = rpc_default(name, a[0], params) end end return params end |