6
6
7
7
require 'etherscan-lite'
8
8
require 'abidoc'
9
+ require 'solidity'
9
10
10
11
11
12
13
+ require_relative 'abibase/directory'
14
+
15
+
12
16
def format_code ( txt )
13
17
## {{ to {
14
18
## and }} to }
@@ -130,9 +134,13 @@ def self.main( args=ARGV )
130
134
puts "args:"
131
135
pp args
132
136
133
- command = args [ 0 ] || 'download '
137
+ command = args [ 0 ] || 'add '
134
138
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 )
136
144
do_download_abis
137
145
elsif [ 'code' ] . include? ( command )
138
146
do_download_code
@@ -148,6 +156,40 @@ def self.main( args=ARGV )
148
156
end
149
157
150
158
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
151
193
152
194
153
195
@@ -237,16 +279,73 @@ def self.do_download_code
237
279
end
238
280
end
239
281
282
+ def self . do_generate_docs
283
+ puts "==> generate docs..."
284
+
285
+ each_contract do |meta |
240
286
287
+ addr = meta . addr
288
+ ## add solidity contract outline
289
+ parser = Solidity ::Parser . read ( "./address/#{ addr } /contract.sol" )
241
290
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
243
329
puts "==> generate docs..."
244
330
245
331
paths = Dir . glob ( "./address/**/abi.json" )
246
332
## paths = paths[0..2]
247
333
paths . each do |path |
248
334
basename = File . basename ( File . dirname ( path ) )
249
335
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
+
250
349
abi = ABI . read ( path )
251
350
252
351
natspec = if File . exist? ( "./address/#{ basename } /contract.md" )
@@ -255,9 +354,10 @@ def self.do_generate_docs
255
354
nil
256
355
end
257
356
258
- buf = abi . generate_doc ( title : "Contract ABI - #{ basename } " ,
259
- natspec : natspec )
357
+ buf << abi . generate_doc ( title : "Contract ABI - #{ basename } " ,
358
+ natspec : natspec )
260
359
puts buf
360
+
261
361
write_text ( "./address/#{ basename } /README.md" , buf )
262
362
263
363
buf = abi . generate_interface ( name : '' ) # solidity interface declarations (source code)
0 commit comments