Module: Trx::Abi
- Extended by:
- Abi
- Included in:
- Abi
- Defined in:
- lib/trx/abi.rb,
lib/trx/abi/decoder.rb,
lib/trx/abi/encoder.rb,
lib/trx/abi/function.rb,
lib/trx/abi/contract_event.rb,
lib/trx/abi/function_input.rb,
lib/trx/abi/function_output.rb
Defined Under Namespace
Classes: ContractEvent, Decoder, Encoder, Function, FunctionInput, FunctionOutput
Instance Method Summary
collapse
Instance Method Details
#parse_abi(abi) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/trx/abi.rb', line 5
def parse_abi(abi)
constructor = abi.detect {|x| x["type"].downcase == "constructor"}
if constructor.present?
constructor_inputs = constructor["inputs"].map { |input| FunctionInput.new(input) }
else
constructor_inputs = []
end
functions = abi.select {|x| x["type"].downcase == "function" }.map { |fun| Function.new(fun) }
events = abi.select {|x| x["type"].downcase == "event" }.map { |evt| ContractEvent.new(evt) }
[constructor_inputs, functions, events]
end
|
#parse_array_type(type) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/trx/abi.rb', line 23
def parse_array_type(type)
match = /(.+)\[(\d*)\]\z/.match(type)
if match
[true, match[2].present? ? match[2].to_i : nil, match[1]]
else
[false, nil, nil]
end
end
|
#parse_type(type) ⇒ Object
17
18
19
20
21
|
# File 'lib/trx/abi.rb', line 17
def parse_type(type)
raise NotImplementedError if type.ends_with?("]")
match = /(\D+)(\d.*)?/.match(type)
[match[1], match[2]]
end
|