Class: Web3::Hpb::HpbModule
- Inherits:
-
Object
- Object
- Web3::Hpb::HpbModule
show all
- Includes:
- Utility
- Defined in:
- lib/web3/hpb/hpb_module.rb
Constant Summary
collapse
- PREFIX =
'hpb_'
Instance Method Summary
collapse
Methods included from Utility
#from_hex, #hex, #remove_0x_head, #wei_to_hpb
Constructor Details
#initialize(web3_rpc) ⇒ HpbModule
Returns a new instance of HpbModule.
10
11
12
|
# File 'lib/web3/hpb/hpb_module.rb', line 10
def initialize web3_rpc
@web3_rpc = web3_rpc
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
40
41
42
|
# File 'lib/web3/hpb/hpb_module.rb', line 40
def method_missing m, *args
@web3_rpc.request "#{PREFIX}#{m}", args[0]
end
|
Instance Method Details
#blockNumber ⇒ Object
24
25
26
|
# File 'lib/web3/hpb/hpb_module.rb', line 24
def blockNumber
from_hex @web3_rpc.request("#{PREFIX}#{__method__}")
end
|
#contract(abi) ⇒ Object
36
37
38
|
# File 'lib/web3/hpb/hpb_module.rb', line 36
def contract abi
Web3::Hpb::Contract.new abi, @web3_rpc
end
|
#getBalance(address, block = 'latest', convert_to_hpb = true) ⇒ Object
14
15
16
17
|
# File 'lib/web3/hpb/hpb_module.rb', line 14
def getBalance address, block = 'latest', convert_to_hpb = true
wei = @web3_rpc.request("#{PREFIX}#{__method__}", [address, block]).to_i 16
convert_to_hpb ? wei_to_hpb(wei) : wei
end
|
#getBlockByNumber(block, full = true, convert_to_object = true) ⇒ Object
19
20
21
22
|
# File 'lib/web3/hpb/hpb_module.rb', line 19
def getBlockByNumber block, full = true, convert_to_object = true
resp = @web3_rpc.request("#{PREFIX}#{__method__}", [hex(block), full])
convert_to_object ? Block.new(resp) : resp
end
|
#getTransactionByHash(tx_hash) ⇒ Object
28
29
30
|
# File 'lib/web3/hpb/hpb_module.rb', line 28
def getTransactionByHash tx_hash
Transaction.new @web3_rpc.request("#{PREFIX}#{__method__}", [tx_hash])
end
|
#getTransactionReceipt(tx_hash) ⇒ Object
32
33
34
|
# File 'lib/web3/hpb/hpb_module.rb', line 32
def getTransactionReceipt tx_hash
TransactionReceipt.new @web3_rpc.request("#{PREFIX}#{__method__}", [tx_hash])
end
|