Class: AppChain::RPC
- Inherits:
-
Object
- Object
- AppChain::RPC
- Defined in:
- lib/appchain/rpc.rb
Constant Summary collapse
- METHOD_NAMES =
CITA v0.18 RPC list
%w( peerCount blockNumber sendRawTransaction getBlockByHash getBlockByNumber getTransaction getTransactionReceipt getLogs call getTransactionCount getCode getAbi getBalance newFilter newBlockFilter uninstallFilter getFilterChanges getFilterLogs getTransactionProof getMetaData getBlockHeader getStateProof ).freeze
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#call_rpc(method, jsonrpc: Http::DEFAULT_JSONRPC, params: Http::DEFAULT_PARAMS, id: Http::DEFAULT_ID) ⇒ Hash
Response body.
-
#initialize(url) ⇒ RPC
constructor
A new instance of RPC.
- #send_transaction(transaction, private_key) ⇒ Hash
-
#transfer(to:, private_key:, value:, quota: 30_000) ⇒ Hash
easy to transfer tokens.
Constructor Details
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
6 7 8 |
# File 'lib/appchain/rpc.rb', line 6 def http @http end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/appchain/rpc.rb', line 6 def url @url end |
Instance Method Details
#call_rpc(method, jsonrpc: Http::DEFAULT_JSONRPC, params: Http::DEFAULT_PARAMS, id: Http::DEFAULT_ID) ⇒ Hash
Returns response body.
51 52 53 54 |
# File 'lib/appchain/rpc.rb', line 51 def call_rpc(method, jsonrpc: Http::DEFAULT_JSONRPC, params: Http::DEFAULT_PARAMS, id: Http::DEFAULT_ID) resp = http.call_rpc(method, params: params, jsonrpc: jsonrpc, id: id) JSON.parse(resp.body) end |
#send_transaction(transaction, private_key) ⇒ Hash
58 59 60 61 |
# File 'lib/appchain/rpc.rb', line 58 def send_transaction(transaction, private_key) content = TransactionSigner.encode(transaction, private_key) send_raw_transaction(content) end |
#transfer(to:, private_key:, value:, quota: 30_000) ⇒ Hash
easy to transfer tokens
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/appchain/rpc.rb', line 71 def transfer(to:, private_key:, value:, quota: 30_000) valid_until_block = block_number["result"].hex + 88 = ("latest")["result"] version = ["version"] chain_id = if version.zero? ["chainId"] elsif version == 1 ["chainIdV1"] end transaction = Transaction.new(nonce: Utils.nonce, valid_until_block: valid_until_block, chain_id: chain_id, to: to, value: value, quota: quota, version: version) send_transaction(transaction, private_key) end |