abidoc 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/README.md +114 -0
- data/lib/abidoc/generate.rb +85 -0
- data/lib/abidoc/model.rb +67 -0
- data/lib/abidoc/version.rb +1 -1
- data/lib/abidoc.rb +3 -56
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f3e9a48dff69f7a1b40cfdb0576a6780c80a7e789969996a93987263769c8c
|
4
|
+
data.tar.gz: 934f1f64b48b26106b16511f775b7353356128cc6236a9e8cde97747ccb207d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cc8363ca326724f2afd6f950f2a4556f8fbff67682f05ddbf400ef5bd3a8cc160e498816483c0b2ffb5115dd3a86c9164009382b8dcb9e36409299623315dda
|
7
|
+
data.tar.gz: c72388140e2e625c264817fafab023a80b5ee4641fa70c1b6285e2149b3bcb1e23cba42593f04a2cdc4542bc8fc169a252964683e7546c3f1df92bf86f283f64
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -9,9 +9,123 @@ abidoc - application binary interface (abi) documentation generator for Ethereum
|
|
9
9
|
* rdoc :: [rubydoc.info/gems/abidoc](http://rubydoc.info/gems/abidoc)
|
10
10
|
|
11
11
|
|
12
|
+
|
12
13
|
## Usage
|
13
14
|
|
14
15
|
|
16
|
+
Let's try to generate the contract abi docs
|
17
|
+
for punks v1 (anno 2017):
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
require 'abidoc'
|
21
|
+
|
22
|
+
punks_v1 = '0x6ba6f2207e343923ba692e5cae646fb0f566db8d'
|
23
|
+
|
24
|
+
abi = ABI.read( "./abis/#{punks_v1}.json" )
|
25
|
+
buf = abi.generate_doc( title: 'Contract ABI for Punks V1' )
|
26
|
+
write_text( "./o/punks_v1.md", buf )
|
27
|
+
```
|
28
|
+
|
29
|
+
resulting in:
|
30
|
+
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
# Contract ABI for Punks V1
|
35
|
+
|
36
|
+
|
37
|
+
**Constructor**
|
38
|
+
|
39
|
+
- constructor()
|
40
|
+
|
41
|
+
**1 Payable Function(s)**
|
42
|
+
|
43
|
+
- function buyPunk(uint256 punkIndex) _payable_
|
44
|
+
|
45
|
+
**7 Transact Functions(s)**
|
46
|
+
|
47
|
+
- function reservePunksForOwner(uint256 maxForThisRun)
|
48
|
+
- function withdraw()
|
49
|
+
- function transferPunk(address to, uint256 punkIndex)
|
50
|
+
- function offerPunkForSaleToAddress(uint256 punkIndex, uint256 minSalePriceInWei, address toAddress)
|
51
|
+
- function offerPunkForSale(uint256 punkIndex, uint256 minSalePriceInWei)
|
52
|
+
- function getPunk(uint256 punkIndex)
|
53
|
+
- function punkNoLongerForSale(uint256 punkIndex)
|
54
|
+
|
55
|
+
**14 Query Functions(s)**
|
56
|
+
|
57
|
+
- function name() ⇒ (string _) _readonly_
|
58
|
+
- function punksOfferedForSale(uint256 _) ⇒ (bool isForSale, uint256 punkIndex, address seller, uint256 minValue, address onlySellTo) _readonly_
|
59
|
+
- function totalSupply() ⇒ (uint256 _) _readonly_
|
60
|
+
- function decimals() ⇒ (uint8 _) _readonly_
|
61
|
+
- function imageHash() ⇒ (string _) _readonly_
|
62
|
+
- function nextPunkIndexToAssign() ⇒ (uint256 _) _readonly_
|
63
|
+
- function punkIndexToAddress(uint256 _) ⇒ (address _) _readonly_
|
64
|
+
- function standard() ⇒ (string _) _readonly_
|
65
|
+
- function balanceOf(address _) ⇒ (uint256 _) _readonly_
|
66
|
+
- function symbol() ⇒ (string _) _readonly_
|
67
|
+
- function numberOfPunksToReserve() ⇒ (uint256 _) _readonly_
|
68
|
+
- function numberOfPunksReserved() ⇒ (uint256 _) _readonly_
|
69
|
+
- function punksRemainingToAssign() ⇒ (uint256 _) _readonly_
|
70
|
+
- function pendingWithdrawals(address _) ⇒ (uint256 _) _readonly_
|
71
|
+
|
72
|
+
---
|
73
|
+
|
74
|
+
|
75
|
+
Let's try to generate the contract abi docs
|
76
|
+
for punk blocks (anno 2022):
|
77
|
+
|
78
|
+
``` ruby
|
79
|
+
punk_blocks = '0x58e90596c2065befd3060767736c829c18f3474c'
|
80
|
+
|
81
|
+
abi = ABI.read( "./address/#{punk_blocks}.json" )
|
82
|
+
|
83
|
+
buf = abi.generate_doc( title: 'Contract ABI for Punk Blocks' )
|
84
|
+
write_text( "./punk_blocks.md", buf )
|
85
|
+
```
|
86
|
+
|
87
|
+
resulting in:
|
88
|
+
|
89
|
+
---
|
90
|
+
|
91
|
+
# Contract ABI for Punk Blocks
|
92
|
+
|
93
|
+
|
94
|
+
**Constructor**
|
95
|
+
|
96
|
+
- constructor()
|
97
|
+
|
98
|
+
**1 Transact Functions(s)**
|
99
|
+
|
100
|
+
- function registerBlock(bytes _dataMale, bytes _dataFemale, uint8 _layer, string _name)
|
101
|
+
|
102
|
+
**8 Query Functions(s)**
|
103
|
+
|
104
|
+
- function blocks(bytes32 _) ⇒ (uint8 layer, bytes dataMale, bytes dataFemale) _readonly_
|
105
|
+
- function getBlocks(uint256 _fromID, uint256 _count) ⇒ (tuple[] _, uint256 _) _readonly_
|
106
|
+
- function index(uint256 _) ⇒ (bytes32 _) _readonly_
|
107
|
+
- function nextId() ⇒ (uint256 _) _readonly_
|
108
|
+
- function svgFromIDs(uint256[] _ids) ⇒ (string _) _readonly_
|
109
|
+
- function svgFromKeys(bytes32[] _attributeKeys) ⇒ (string _) _readonly_
|
110
|
+
- function svgFromNames(string[] _attributeNames) ⇒ (string _) _readonly_
|
111
|
+
- function svgFromPunkID(uint256 _tokenID) ⇒ (string _) _readonly_
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
and so on.
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
## Bonus - Awesome Contracts
|
121
|
+
|
122
|
+
See the [**Awesome (Ethereum) Contracts / Blockchain Services @ Open Blockchains**](https://github.com/openblockchains/awesome-contracts) repo.
|
123
|
+
that is a cache of (ethereum) contract ABIs (application binary interfaces)
|
124
|
+
and open source code (if verified / available)
|
125
|
+
with auto-generated docs via abidoc & friends.
|
126
|
+
|
127
|
+
|
128
|
+
|
15
129
|
|
16
130
|
|
17
131
|
## License
|
@@ -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
|
data/lib/abidoc/model.rb
ADDED
@@ -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
|
data/lib/abidoc/version.rb
CHANGED
data/lib/abidoc.rb
CHANGED
@@ -1,64 +1,11 @@
|
|
1
1
|
require 'abiparser'
|
2
|
+
require 'natspec'
|
2
3
|
|
3
4
|
|
4
5
|
## our own code
|
5
6
|
require_relative 'abidoc/version' # note: let version always go first
|
7
|
+
require_relative 'abidoc/model'
|
8
|
+
require_relative 'abidoc/generate'
|
6
9
|
|
7
10
|
|
8
11
|
|
9
|
-
module ABI
|
10
|
-
class Contract
|
11
|
-
|
12
|
-
|
13
|
-
def generate_doc( title: 'Contract ABI' )
|
14
|
-
buf = ''
|
15
|
-
buf << "# #{title}\n\n"
|
16
|
-
|
17
|
-
if @ctor
|
18
|
-
buf << "\n"
|
19
|
-
buf << "**Constructor**\n\n"
|
20
|
-
buf << "- #{@ctor.doc}\n"
|
21
|
-
## buf << " - sig #{@ctor.sig} => 0x#{sig(@ctor.sig).hexdigest}\n"
|
22
|
-
end
|
23
|
-
|
24
|
-
if payable_functions.size > 0
|
25
|
-
buf << "\n"
|
26
|
-
buf << "**#{payable_functions.size} Payable Function(s)**\n\n"
|
27
|
-
payable_functions.each do |func|
|
28
|
-
buf << "- #{func.doc} _payable_\n"
|
29
|
-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
if transact_functions.size > 0
|
34
|
-
buf << "\n"
|
35
|
-
buf << "**#{transact_functions.size} Transact Functions(s)**\n\n"
|
36
|
-
transact_functions.each do |func|
|
37
|
-
buf << "- #{func.doc}\n"
|
38
|
-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
if query_functions.size > 0
|
43
|
-
buf << "\n"
|
44
|
-
buf << "**#{query_functions.size} Query Functions(s)**\n\n"
|
45
|
-
query_functions.each do |func|
|
46
|
-
buf << "- #{func.doc} _readonly_\n"
|
47
|
-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
if helper_functions.size > 0
|
52
|
-
buf << "\n"
|
53
|
-
buf << "**#{helper_functions.size} Helper Functions(s)**\n\n"
|
54
|
-
helper_functions.each do |func|
|
55
|
-
buf << "- #{func.doc}\n"
|
56
|
-
## buf << " - sig #{func.sig} => 0x#{sig(func.sig).hexdigest}\n"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
buf
|
61
|
-
end
|
62
|
-
|
63
|
-
end ## class Contract
|
64
|
-
end ## module ABI
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abiparser
|
@@ -73,6 +73,8 @@ files:
|
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
75
|
- lib/abidoc.rb
|
76
|
+
- lib/abidoc/generate.rb
|
77
|
+
- lib/abidoc/model.rb
|
76
78
|
- lib/abidoc/version.rb
|
77
79
|
homepage: https://github.com/rubycocos/blockchain
|
78
80
|
licenses:
|