lib/platon/client.rb in platon-0.2.9 vs lib/platon/client.rb in platon-1.0.0

- old
+ new

@@ -8,32 +8,29 @@ RPC_COMMANDS = %w(web3_clientVersion web3_sha3 net_version net_peerCount net_listening platon_protocolVersion platon_syncing platon_gasPrice platon_accounts platon_blockNumber platon_getBalance platon_getStorageAt platon_getTransactionCount platon_getBlockTransactionCountByHash platon_getBlockTransactionCountByNumber platon_getCode platon_sign platon_sendTransaction platon_sendRawTransaction platon_call platon_estimateGas platon_getBlockByHash platon_getBlockByNumber platon_getTransactionByHash platon_getTransactionByBlockHashAndIndex platon_getTransactionByBlockNumberAndIndex platon_getTransactionReceipt platon_getUncleByBlockHashAndIndex platon_newFilter platon_newBlockFilter platon_newPendingTransactionFilter platon_uninstallFilter platon_getFilterChanges platon_getFilterLogs platon_getLogs platon_getWork platon_submitWork platon_submitHashrate db_putString db_getString db_putHex db_getHex shh_post shh_version shh_newIdentity shh_hasIdentity shh_newGroup shh_addToGroup shh_newFilter shh_uninstallFilter shh_getFilterChanges shh_getMessages) #PLATON_UNSUPPORT_COMMANDS = %w(platon_coinbase ,plton_mining,platon_hashrate,platon_getUncleCountByBlockHash,platon_getUncleCountByBlockNumber,platon_getUncleByBlockNumberAndIndex platon_getCompilers platon_compileLLL platon_compileSolidity platon_compileSerpent) PLATON_RPC_COMMANDS = %w(platon_evidences admin_getProgramVersion admin_getSchnorrNIZKProve) RPC_MANAGEMENT_COMMANDS = %w(admin_addPeer admin_datadir admin_nodeInfo admin_peers admin_setSolc admin_startRPC admin_startWS admin_stopRPC admin_stopWS debug_backtraceAt debug_blockProfile debug_cpuProfile debug_dumpBlock debug_gcStats debug_getBlockRlp debug_goTrace debug_memStats debug_seedHash debug_setHead debug_setBlockProfileRate debug_stacks debug_startCPUProfile debug_startGoTrace debug_stopCPUProfile debug_stopGoTrace debug_traceBlock debug_traceBlockByNumber debug_traceBlockByHash debug_traceBlockFromFile debug_traceTransaction debug_verbosity debug_vmodule debug_writeBlockProfile debug_writeMemProfile miner_hashrate miner_makeDAG miner_setExtra miner_setGasPrice miner_start miner_startAutoDAG miner_stop miner_stopAutoDAG personal_importRawKey personal_listAccounts personal_lockAccount personal_newAccount personal_unlockAccount personal_sendTransaction txpool_content txpool_inspect txpool_status) - attr_accessor :command, :id, :log, :logger, :default_account, :gas_price, :gas_limit, :ppos, :hrp,:chain_id + attr_accessor :command, :id, :logger, :default_account, :gas_price, :gas_limit, :ppos, :hrp,:chain_id - def initialize(chain_name=nil,log = false) + def initialize(chain_name=nil) @id = 0 - @log = log @batch = nil # @formatter = Platon::Formatter.new @gas_price = DEFAULT_GAS_PRICE @gas_limit = DEFAULT_GAS_LIMIT - if @log == true - @logger = Logger.new("/tmp/platon_ruby_http.log") - end + @ppos = Platon::Ppos.new self set_network(chain_name.downcase.to_sym) end - def self.create(host_or_ipcpath, log = false) - return IpcClient.new(host_or_ipcpath, log) if host_or_ipcpath.end_with? '.ipc' - return HttpClient.new(host_or_ipcpath, log) if host_or_ipcpath.start_with? 'http' + def self.create(host_or_ipcpath) + return IpcClient.new(host_or_ipcpath) if host_or_ipcpath.end_with? '.ipc' + return HttpClient.new(host_or_ipcpath) if host_or_ipcpath.start_with? 'http' raise ArgumentError.new('Unable to detect client type') end def set_network(network) config = { @@ -137,18 +134,16 @@ # args << "latest" # end payload = {jsonrpc: "2.0", method: command, params: encode_params(args), id: get_id} puts payload - @logger.info("Sending #{payload.to_json}") if @log + # @logger.info("Sending #{payload.to_json}") if @log if @batch @batch << payload return true else - # tmp = send_single(payload.to_json) - # output = JSON.parse(tmp) p output = JSON.parse(send_single(payload.to_json)) - @logger.info("Received #{output.to_json}") if @log + # @logger.info("Received #{output.to_json}") if @log reset_id raise IOError, output["error"]["message"] if output["error"] if %W(net_peerCount platon_protocolVersion platon_gasPrice platon_blockNumber platon_getBalance platon_getTransactionCount platon_getBlockTransactionCountByHash platon_getBlockTransactionCountByNumber platon_estimateGas).include?(command) return output["result"].to_i(16)