Skip to content

Commit 00b2afd

Browse files
committed
up
1 parent 8ab1135 commit 00b2afd

File tree

3 files changed

+189
-5
lines changed

3 files changed

+189
-5
lines changed

abibase/lib/abibase.rb

+105-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
require 'etherscan-lite'
88
require 'abidoc'
9+
require 'solidity'
910

1011

1112

13+
require_relative 'abibase/directory'
14+
15+
1216
def format_code( txt )
1317
## {{ to {
1418
## and }} to }
@@ -130,9 +134,13 @@ def self.main( args=ARGV )
130134
puts "args:"
131135
pp args
132136

133-
command = args[0] || 'download'
137+
command = args[0] || 'add'
134138

135-
if ['d', 'dl', 'download'].include?( command )
139+
if ['a', 'add'].include?( command )
140+
do_add
141+
elsif ['l', 'ls', 'list'].include?( command )
142+
do_list
143+
elsif ['d', 'dl', 'download'].include?( command )
136144
do_download_abis
137145
elsif ['code'].include?( command )
138146
do_download_code
@@ -148,6 +156,40 @@ def self.main( args=ARGV )
148156
end
149157

150158

159+
def self.do_add
160+
puts "==> add abis..."
161+
162+
recs = read_csv( "./contracts.csv" )
163+
puts " #{recs.size} record(s)"
164+
end
165+
166+
def self.do_list
167+
puts "==> list contracts..."
168+
169+
# recs = read_meta( "./address" )
170+
171+
each_contract do |meta|
172+
puts "==> #{meta.addr}"
173+
174+
print " name: "
175+
puts meta.name
176+
print " names (#{meta.names.size}): "
177+
puts meta.names.join(' | ' )
178+
179+
print " timestamp: "
180+
puts meta.timestamp
181+
182+
print " created: "
183+
puts meta.created
184+
185+
print " block: "
186+
puts meta.block
187+
print " txid: "
188+
puts meta.txid
189+
print " creator: "
190+
puts meta.creator
191+
end
192+
end
151193

152194

153195

@@ -237,16 +279,73 @@ def self.do_download_code
237279
end
238280
end
239281

282+
def self.do_generate_docs
283+
puts "==> generate docs..."
284+
285+
each_contract do |meta|
240286

287+
addr = meta.addr
288+
## add solidity contract outline
289+
parser = Solidity::Parser.read( "./address/#{addr}/contract.sol" )
241290

242-
def self.do_generate_docs
291+
buf = String.new( '' )
292+
buf << "Contract outline - [contract.sol](contract.sol):\n\n"
293+
buf << "```\n"
294+
buf << parser.outline
295+
buf << "```\n"
296+
buf << "\n\n"
297+
298+
## add some more metadata
299+
buf << "Created on Ethereum Mainnet:\n"
300+
buf << "- Block #{meta.block} @ #{meta.created} (#{meta.timestamp})\n"
301+
buf << "- Tx Id #{meta.txid}\n"
302+
buf << "- By #{meta.creator}\n"
303+
buf << "\n\n"
304+
305+
306+
abi = ABI.read( "./address/#{addr}/abi.json" )
307+
308+
natspec = if File.exist?( "./address/#{addr}/contract.md" )
309+
Natspec.read( "./address/#{addr}/contract.md" )
310+
else
311+
nil
312+
end
313+
314+
buf << abi.generate_doc( title: "#{meta.names.join(' | ')} - Contract ABI @ #{addr}",
315+
natspec: natspec )
316+
puts buf
317+
318+
write_text( "./address/#{addr}/README.md", buf )
319+
320+
buf = abi.generate_interface( name: '' ) # solidity interface declarations (source code)
321+
write_text( "./address/#{addr}/interface.sol", buf )
322+
end
323+
end
324+
325+
326+
327+
328+
def self.do_generate_docs_old
243329
puts "==> generate docs..."
244330

245331
paths = Dir.glob( "./address/**/abi.json" )
246332
## paths = paths[0..2]
247333
paths.each do |path|
248334
basename = File.basename( File.dirname( path ))
249335

336+
337+
## add solidity contract outline
338+
parser = Solidity::Parser.read( "./address/#{basename}/contract.sol" )
339+
340+
buf = String.new( '' )
341+
buf << "Contract outline:\n\n"
342+
buf << "```\n"
343+
buf << parser.outline
344+
buf << "```\n"
345+
buf << "(source: [contract.sol](contract.sol))\n"
346+
buf << "\n\n"
347+
348+
250349
abi = ABI.read( path )
251350

252351
natspec = if File.exist?( "./address/#{basename}/contract.md" )
@@ -255,9 +354,10 @@ def self.do_generate_docs
255354
nil
256355
end
257356

258-
buf = abi.generate_doc( title: "Contract ABI - #{basename}",
259-
natspec: natspec )
357+
buf << abi.generate_doc( title: "Contract ABI - #{basename}",
358+
natspec: natspec )
260359
puts buf
360+
261361
write_text( "./address/#{basename}/README.md", buf )
262362

263363
buf = abi.generate_interface( name: '' ) # solidity interface declarations (source code)

abibase/lib/abibase/directory.rb

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
###
3+
# read all contract metadata
4+
5+
6+
class Meta
7+
def initialize( data )
8+
@data = data
9+
## split and normalize names
10+
@names = (data['name'] || data['names'])
11+
.split( '|' )
12+
.map { |name| name.gsub(/[ \t]+/, ' ' ).strip }
13+
end
14+
15+
def name() @names[0]; end
16+
def names() @names; end
17+
18+
def timestamp() @data['timestamp']; end
19+
def created()
20+
## use timestamp for now and ignore created for now - why? why not?
21+
Time.at( @data['timestamp'] ).utc
22+
end
23+
24+
def address() @data['address']; end
25+
alias_method :addr, :address
26+
def txid() @data['txid']; end
27+
def creator() @data['creator']; end
28+
def block() @data['block']; end ## add blocknumber alias - why? why not?
29+
end # class Meta
30+
31+
32+
def each_contract( &block )
33+
recs = read_meta
34+
recs.each do |rec|
35+
block.call( Meta.new( rec ) )
36+
end
37+
end
38+
39+
40+
def read_meta( basedir='./address' )
41+
puts "==> read contract metadata..."
42+
43+
## collection all addresses
44+
recs = []
45+
paths = Dir.glob( "#{basedir}/**/contract.yml" )
46+
## paths = paths[0..2]
47+
paths.each do |path|
48+
data = read_yaml( path )
49+
50+
## auto-add basedir or such - why? why not?
51+
52+
## auto-add addr or dobule check - why? why not?
53+
## basename = File.basename( File.dirname( path ))
54+
55+
recs << data
56+
end
57+
58+
############
59+
## sort by block (reverse chronological)
60+
recs = recs.sort do |l,r|
61+
l['block'] <=> r['block']
62+
end
63+
64+
## pp recs
65+
## puts " #{recs.size} record(s)"
66+
67+
recs
68+
end

solidity/NOTES.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
# Notes About Solidity
22

33

4+
## Todos
5+
6+
fix moonbirds scan
7+
8+
```
9+
interface ITokenURIGenerator
10+
contract Moonbirds is ERC721ACommon, BaseTokenURI, FixedPriceSeller, SignerManager, ERC2981, AccessControlEnumerable
11+
contract) external onlyOwner
12+
contract; } /** @notice If renderingContract is set then returns its tokenURI(tokenId) return value, otherwise returns the standard baseTokenURI + tokenId. */ function tokenURI(uint256 tokenId) public view override returns (string memory)
13+
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata
14+
```
15+
416

517

618
## More
719

20+
Solidity by Example -
21+
22+
Solidity in x Minutes -
23+
824
Awesome Solidity - <https://github.com/bkrem/awesome-solidity>
925

0 commit comments

Comments
 (0)