Skip to content

Commit 0ddd175

Browse files
committed
up
1 parent 3984103 commit 0ddd175

File tree

10 files changed

+159
-121
lines changed

10 files changed

+159
-121
lines changed

abidoc/Manifest.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ Manifest.txt
33
README.md
44
Rakefile
55
lib/abidoc.rb
6+
lib/abidoc/generate.rb
7+
lib/abidoc/model.rb
68
lib/abidoc/version.rb

abidoc/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ and so on.
119119

120120
## Bonus - Awesome Contracts
121121

122-
See the [**Awesome (Ethereum) Contracts / Blockchain Services**](https://github.com/rubycocos/awesome-contracts) repo.
122+
See the [**Awesome (Ethereum) Contracts / Blockchain Services @ Open Blockchains**](https://github.com/openblockchains/awesome-contracts) repo.
123123
that is a cache of (ethereum) contract ABIs (application binary interfaces)
124124
and open source code (if verified / available)
125125
with auto-generated docs via abidoc & friends.

abidoc/lib/abidoc.rb

+2-76
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,8 @@
44

55
## our own code
66
require_relative 'abidoc/version' # note: let version always go first
7+
require_relative 'abidoc/model'
8+
require_relative 'abidoc/generate'
79

810

911

10-
module ABI
11-
class Contract
12-
13-
14-
def generate_doc( title: 'Contract ABI',
15-
natspec: nil )
16-
buf = ''
17-
buf << "# #{title}\n\n"
18-
19-
if natspec && natspec.head.size > 0
20-
natspec.head.each do |line|
21-
buf << (line.empty? ? "\n" : "#{line}\n")
22-
end
23-
end
24-
buf << "\n\n"
25-
26-
27-
28-
if @ctor
29-
buf << "\n"
30-
buf << "**Constructor**\n\n"
31-
buf << "- #{@ctor.doc}\n"
32-
## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n"
33-
end
34-
35-
if payable_functions.size > 0
36-
buf << "\n"
37-
buf << "**#{payable_functions.size} Payable Function(s)**\n\n"
38-
payable_functions.each do |func|
39-
buf << "- #{func.doc} _payable_\n"
40-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
41-
end
42-
end
43-
44-
if transact_functions.size > 0
45-
buf << "\n"
46-
buf << "**#{transact_functions.size} Transact Functions(s)**\n\n"
47-
transact_functions.each do |func|
48-
buf << "- #{func.doc}\n"
49-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
50-
end
51-
end
52-
53-
54-
if query_functions.size > 0
55-
buf << "\n"
56-
buf << "**#{query_functions.size} Query Functions(s)**\n\n"
57-
query_functions.each do |func|
58-
if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ])
59-
sect = natspec.storage[ func.name ] || natspec.functions[ func.name ]
60-
buf << "- #{sect[0]}"
61-
sect[1].each do |line|
62-
buf << (line.empty? ? " <br>" : " <br> #{line}")
63-
end
64-
buf << "\n"
65-
else
66-
buf << "- #{func.doc} _readonly_\n"
67-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
68-
end
69-
end
70-
end
71-
72-
if helper_functions.size > 0
73-
buf << "\n"
74-
buf << "**#{helper_functions.size} Helper Functions(s)**\n\n"
75-
helper_functions.each do |func|
76-
buf << "- #{func.doc}\n"
77-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
78-
end
79-
end
80-
81-
buf
82-
end
83-
84-
end ## class Contract
85-
end ## module ABI

abidoc/lib/abidoc/generate.rb

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module ABI
2+
class Contract
3+
4+
5+
def generate_doc( title: 'Contract ABI',
6+
natspec: nil )
7+
buf = ''
8+
buf << "# #{title}\n\n"
9+
10+
if natspec && natspec.head.size > 0
11+
natspec.head.each do |line|
12+
buf << (line.empty? ? "\n" : "#{line}\n")
13+
end
14+
end
15+
buf << "\n\n"
16+
17+
18+
if events.size > 0
19+
buf << "\n"
20+
buf << "**#{events.size} Event Log Type(s)**\n\n"
21+
events.each do |event|
22+
buf << "- #{event.doc}\n"
23+
end
24+
end
25+
26+
27+
28+
if @ctor
29+
buf << "\n"
30+
buf << "**Constructor**\n\n"
31+
buf << "- #{@ctor.doc}\n"
32+
## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n"
33+
end
34+
35+
if payable_functions.size > 0
36+
buf << "\n"
37+
buf << "**#{payable_functions.size} Payable Function(s)**\n\n"
38+
payable_functions.each do |func|
39+
buf << "- #{func.doc} _payable_\n"
40+
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
41+
end
42+
end
43+
44+
if transact_functions.size > 0
45+
buf << "\n"
46+
buf << "**#{transact_functions.size} Transact Functions(s)**\n\n"
47+
transact_functions.each do |func|
48+
buf << "- #{func.doc}\n"
49+
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
50+
end
51+
end
52+
53+
54+
if query_functions.size > 0
55+
buf << "\n"
56+
buf << "**#{query_functions.size} Query Functions(s)**\n\n"
57+
query_functions.each do |func|
58+
if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ])
59+
sect = natspec.storage[ func.name ] || natspec.functions[ func.name ]
60+
buf << "- #{sect[0]}"
61+
sect[1].each do |line|
62+
buf << (line.empty? ? " <br>" : " <br> #{line}")
63+
end
64+
buf << "\n"
65+
else
66+
buf << "- #{func.doc} _readonly_\n"
67+
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
68+
end
69+
end
70+
end
71+
72+
if helper_functions.size > 0
73+
buf << "\n"
74+
buf << "**#{helper_functions.size} Helper Functions(s)**\n\n"
75+
helper_functions.each do |func|
76+
buf << "- #{func.doc}\n"
77+
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
78+
end
79+
end
80+
81+
buf
82+
end
83+
84+
end ## class Contract
85+
end ## module ABI

abidoc/lib/abidoc/model.rb

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module ABI
2+
3+
class Param
4+
def doc
5+
buf = ''
6+
if @internal_type && @internal_type != sig
7+
buf << "#{@internal_type} "
8+
else
9+
buf << "#{sig} "
10+
end
11+
buf << (@name ? @name : '_')
12+
buf
13+
end
14+
end
15+
16+
17+
class Constructor
18+
def doc
19+
buf = "constructor"
20+
if @inputs.empty?
21+
buf << "()"
22+
else
23+
params = @inputs.map {|param| param.doc }
24+
buf << "(#{params.join(', ')})"
25+
end
26+
buf
27+
end
28+
end ## class Constructor
29+
30+
class Function
31+
def doc
32+
## note: text with markdown formatting
33+
buf = "function **#{@name}**"
34+
if @inputs.empty?
35+
buf << "()"
36+
else
37+
params = @inputs.map {|param| param.doc }
38+
buf << "(#{params.join(', ')})"
39+
end
40+
if @outputs.empty?
41+
## do nothing
42+
else
43+
buf << " ⇒ "
44+
params = @outputs.map {|param| param.doc }
45+
buf << "(#{params.join(', ')})"
46+
end
47+
buf
48+
end
49+
end ## class Function
50+
51+
52+
class Event
53+
def doc
54+
## note: text with markdown formatting
55+
buf = "event **#{@name}**"
56+
if @inputs.empty?
57+
buf << "()"
58+
else
59+
params = @inputs.map {|param| param.doc }
60+
buf << "(#{params.join(', ')})"
61+
end
62+
buf
63+
end
64+
end ## class Event
65+
66+
67+
end ## module ABI

abidoc/lib/abidoc/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module ABIDoc
33

44
MAJOR = 0
55
MINOR = 1
6-
PATCH = 0
6+
PATCH = 1
77
VERSION = [MAJOR,MINOR,PATCH].join('.')
88

99
def self.version

abidoc/sandbox/test_gen.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# to run use
33
# ruby -I ./lib sandbox/test_gen.rb
44

5+
$LOAD_PATH.unshift( "../abiparser/lib" )
56
require 'abidoc'
67

78
punks_v1 = '0x6ba6f2207e343923ba692e5cae646fb0f566db8d'

abiparser/lib/abiparser/constructor.rb

-12
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,6 @@ def sig
8383
buf
8484
end
8585

86-
87-
def doc
88-
buf = "constructor"
89-
if @inputs.empty?
90-
buf << "()"
91-
else
92-
buf2 = @inputs.map {|param| param.doc }
93-
buf << "(#{buf2.join(', ')})"
94-
end
95-
buf
96-
end
97-
9886
end # class Constructor
9987
end # module ABI
10088

abiparser/lib/abiparser/function.rb

-19
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,6 @@ def sighash
115115
end
116116

117117

118-
def doc
119-
## note: text with markdown formatting
120-
buf = "function **#{@name}**"
121-
if @inputs.empty?
122-
buf << "()"
123-
else
124-
buf2 = @inputs.map {|param| param.doc }
125-
buf << "(#{buf2.join(', ')})"
126-
end
127-
if @outputs.empty?
128-
## do nothing
129-
else
130-
buf << " ⇒ "
131-
buf2 = @outputs.map {|param| param.doc }
132-
buf << "(#{buf2.join(', ')})"
133-
end
134-
buf
135-
end
136-
137118

138119
def types
139120
## for debugging / analytics return all used types (input+output)

abiparser/lib/abiparser/param.rb

-12
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,5 @@ def sig
5555
@sig
5656
end
5757

58-
59-
def doc
60-
buf = ''
61-
if @internal_type && @internal_type != sig
62-
buf << "#{@internal_type} "
63-
else
64-
buf << "#{sig} "
65-
end
66-
buf << (@name ? @name : '_')
67-
buf
68-
end
69-
7058
end ## class Param
7159
end ## module ABI

0 commit comments

Comments
 (0)