Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Feb 9, 2023
1 parent 3984103 commit 0ddd175
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 121 deletions.
2 changes: 2 additions & 0 deletions abidoc/Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Manifest.txt
README.md
Rakefile
lib/abidoc.rb
lib/abidoc/generate.rb
lib/abidoc/model.rb
lib/abidoc/version.rb
2 changes: 1 addition & 1 deletion abidoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ and so on.

## Bonus - Awesome Contracts

See the [**Awesome (Ethereum) Contracts / Blockchain Services**](https://github.com/rubycocos/awesome-contracts) repo.
See the [**Awesome (Ethereum) Contracts / Blockchain Services @ Open Blockchains**](https://github.com/openblockchains/awesome-contracts) repo.
that is a cache of (ethereum) contract ABIs (application binary interfaces)
and open source code (if verified / available)
with auto-generated docs via abidoc & friends.
Expand Down
78 changes: 2 additions & 76 deletions abidoc/lib/abidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,8 @@

## our own code
require_relative 'abidoc/version' # note: let version always go first
require_relative 'abidoc/model'
require_relative 'abidoc/generate'



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 @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
85 changes: 85 additions & 0 deletions abidoc/lib/abidoc/generate.rb
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
67 changes: 67 additions & 0 deletions abidoc/lib/abidoc/model.rb
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
2 changes: 1 addition & 1 deletion abidoc/lib/abidoc/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ABIDoc

MAJOR = 0
MINOR = 1
PATCH = 0
PATCH = 1
VERSION = [MAJOR,MINOR,PATCH].join('.')

def self.version
Expand Down
1 change: 1 addition & 0 deletions abidoc/sandbox/test_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# to run use
# ruby -I ./lib sandbox/test_gen.rb

$LOAD_PATH.unshift( "../abiparser/lib" )
require 'abidoc'

punks_v1 = '0x6ba6f2207e343923ba692e5cae646fb0f566db8d'
Expand Down
12 changes: 0 additions & 12 deletions abiparser/lib/abiparser/constructor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ def sig
buf
end


def doc
buf = "constructor"
if @inputs.empty?
buf << "()"
else
buf2 = @inputs.map {|param| param.doc }
buf << "(#{buf2.join(', ')})"
end
buf
end

end # class Constructor
end # module ABI

Expand Down
19 changes: 0 additions & 19 deletions abiparser/lib/abiparser/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,6 @@ def sighash
end


def doc
## note: text with markdown formatting
buf = "function **#{@name}**"
if @inputs.empty?
buf << "()"
else
buf2 = @inputs.map {|param| param.doc }
buf << "(#{buf2.join(', ')})"
end
if @outputs.empty?
## do nothing
else
buf << " ⇒ "
buf2 = @outputs.map {|param| param.doc }
buf << "(#{buf2.join(', ')})"
end
buf
end


def types
## for debugging / analytics return all used types (input+output)
Expand Down
12 changes: 0 additions & 12 deletions abiparser/lib/abiparser/param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,5 @@ def sig
@sig
end


def doc
buf = ''
if @internal_type && @internal_type != sig
buf << "#{@internal_type} "
else
buf << "#{sig} "
end
buf << (@name ? @name : '_')
buf
end

end ## class Param
end ## module ABI

0 comments on commit 0ddd175

Please sign in to comment.