-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
182 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
module ABI | ||
|
||
class Param | ||
def decl | ||
buf = String.new('') | ||
buf << "#{sig} " | ||
buf << "indexed " if @indexed | ||
buf << (@name ? @name : '_') | ||
## use inline comment - why? why not? | ||
if @internal_type && @internal_type != sig | ||
buf << " /* #{@internal_type} */" | ||
end | ||
buf | ||
end | ||
end ## class Param | ||
|
||
|
||
class Constructor | ||
def decl | ||
buf = "constructor" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.decl } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf << ";" | ||
buf | ||
end | ||
end ## class Constructor | ||
|
||
class Function | ||
def decl | ||
buf = "function #{@name}" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.decl } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf << " payable " if @payable | ||
buf << " view " if @constant && !@pure | ||
buf << " pure " if @constant && @pure | ||
|
||
if @outputs.empty? | ||
## do nothing | ||
else | ||
buf << " returns " | ||
params = @outputs.map {|param| param.decl } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf << ";" | ||
buf | ||
end | ||
end ## class Function | ||
|
||
|
||
class Event | ||
def decl | ||
buf = "event #{@name}" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.decl } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf << ";" | ||
buf | ||
end | ||
end ## class Event | ||
|
||
|
||
|
||
|
||
end ## module ABI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
### | ||
# to run use | ||
# ruby -I ./lib sandbox/test_parse2.rb | ||
|
||
$LOAD_PATH.unshift( "../abiparser/lib" ) | ||
require 'abi2sol' | ||
|
||
names = [ | ||
'AirSwap', | ||
'BunchaStructs', | ||
] | ||
|
||
names.each do |name| | ||
abi = ABI.read( "./abis//#{name}.abi.json" ) | ||
pp abi | ||
|
||
buf = abi.generate_interface( name: name ) | ||
puts buf | ||
write_text( "./tmp/#{name}.sol", buf ) | ||
end | ||
|
||
|
||
puts "bye" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module ABI | ||
class Event | ||
|
||
def self.parse( o ) | ||
## todo/fix: assert type function (or contructor) ?? | ||
name = o['name'] | ||
inputs = o['inputs'].map {|param| Param.parse( param ) } | ||
|
||
new( name, inputs: inputs ) | ||
end | ||
|
||
|
||
attr_reader :name, | ||
:inputs | ||
## :input_types | ||
|
||
def initialize( name, | ||
inputs: [] ) | ||
@name = name | ||
@inputs = inputs | ||
end | ||
|
||
|
||
def sig | ||
## note: signature | ||
## only includes name and inputs | ||
|
||
## | ||
## todo/fix: check if event sig includes indexed or/and | ||
## special prefix or such!!!! | ||
|
||
buf = "#{@name}" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.sig } | ||
buf << "(#{params.join(',')})" | ||
end | ||
buf | ||
end | ||
|
||
def sighash | ||
keccak256( sig )[0,4].hexdigest | ||
end | ||
|
||
|
||
|
||
|
||
def types | ||
## for debugging / analytics return all used types (input+output) | ||
@inputs.map {|param| param.type } | ||
end | ||
|
||
end ## class Event | ||
end ## module ABI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters