-
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
10 changed files
with
159 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ Manifest.txt | |
README.md | ||
Rakefile | ||
lib/abidoc.rb | ||
lib/abidoc/generate.rb | ||
lib/abidoc/model.rb | ||
lib/abidoc/version.rb |
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,85 @@ | ||
module ABI | ||
class Contract | ||
|
||
|
||
def generate_doc( title: 'Contract ABI', | ||
natspec: nil ) | ||
buf = '' | ||
buf << "# #{title}\n\n" | ||
|
||
if natspec && natspec.head.size > 0 | ||
natspec.head.each do |line| | ||
buf << (line.empty? ? "\n" : "#{line}\n") | ||
end | ||
end | ||
buf << "\n\n" | ||
|
||
|
||
if events.size > 0 | ||
buf << "\n" | ||
buf << "**#{events.size} Event Log Type(s)**\n\n" | ||
events.each do |event| | ||
buf << "- #{event.doc}\n" | ||
end | ||
end | ||
|
||
|
||
|
||
if @ctor | ||
buf << "\n" | ||
buf << "**Constructor**\n\n" | ||
buf << "- #{@ctor.doc}\n" | ||
## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n" | ||
end | ||
|
||
if payable_functions.size > 0 | ||
buf << "\n" | ||
buf << "**#{payable_functions.size} Payable Function(s)**\n\n" | ||
payable_functions.each do |func| | ||
buf << "- #{func.doc} _payable_\n" | ||
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n" | ||
end | ||
end | ||
|
||
if transact_functions.size > 0 | ||
buf << "\n" | ||
buf << "**#{transact_functions.size} Transact Functions(s)**\n\n" | ||
transact_functions.each do |func| | ||
buf << "- #{func.doc}\n" | ||
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n" | ||
end | ||
end | ||
|
||
|
||
if query_functions.size > 0 | ||
buf << "\n" | ||
buf << "**#{query_functions.size} Query Functions(s)**\n\n" | ||
query_functions.each do |func| | ||
if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ]) | ||
sect = natspec.storage[ func.name ] || natspec.functions[ func.name ] | ||
buf << "- #{sect[0]}" | ||
sect[1].each do |line| | ||
buf << (line.empty? ? " <br>" : " <br> #{line}") | ||
end | ||
buf << "\n" | ||
else | ||
buf << "- #{func.doc} _readonly_\n" | ||
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n" | ||
end | ||
end | ||
end | ||
|
||
if helper_functions.size > 0 | ||
buf << "\n" | ||
buf << "**#{helper_functions.size} Helper Functions(s)**\n\n" | ||
helper_functions.each do |func| | ||
buf << "- #{func.doc}\n" | ||
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n" | ||
end | ||
end | ||
|
||
buf | ||
end | ||
|
||
end ## class Contract | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module ABI | ||
|
||
class Param | ||
def doc | ||
buf = '' | ||
if @internal_type && @internal_type != sig | ||
buf << "#{@internal_type} " | ||
else | ||
buf << "#{sig} " | ||
end | ||
buf << (@name ? @name : '_') | ||
buf | ||
end | ||
end | ||
|
||
|
||
class Constructor | ||
def doc | ||
buf = "constructor" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.doc } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf | ||
end | ||
end ## class Constructor | ||
|
||
class Function | ||
def doc | ||
## note: text with markdown formatting | ||
buf = "function **#{@name}**" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.doc } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
if @outputs.empty? | ||
## do nothing | ||
else | ||
buf << " ⇒ " | ||
params = @outputs.map {|param| param.doc } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
buf | ||
end | ||
end ## class Function | ||
|
||
|
||
class Event | ||
def doc | ||
## note: text with markdown formatting | ||
buf = "event **#{@name}**" | ||
if @inputs.empty? | ||
buf << "()" | ||
else | ||
params = @inputs.map {|param| param.doc } | ||
buf << "(#{params.join(', ')})" | ||
end | ||
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
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