abidump 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Manifest.txt +6 -0
  4. data/README.md +284 -0
  5. data/Rakefile +38 -0
  6. data/bin/abidump +17 -0
  7. data/lib/abidump.rb +196 -0
  8. metadata +104 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4ffdb9017adf411045359acd07b66756f48f58339604ef43354e59b46430e27
4
+ data.tar.gz: 4b405724f017886a0fedb5662125358a068b916ae39b721abe476ed73e3b9c35
5
+ SHA512:
6
+ metadata.gz: 7624386685f09523f23dc64b53cdecde1e88dae0b7c2c7e2ace3d8cc75b92f720ca1e49f50960b011538f84711ccc5380237803909f1cc2a748e50cfefadc0c5
7
+ data.tar.gz: 9f76dad3a9f5d83ae5db4ab1ce935c719edcbc9f7e5132567760dfefc8202841dd27b97e3b430207b4aeed5c22ea396ccfa0d590715c84c381f686d77aef5b14
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2023-02-06
2
+
3
+ * Everything is new. First release
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ bin/abidump
6
+ lib/abidump.rb
data/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # abidump
2
+
3
+
4
+ abidump gem - command-line tool to dump / pretty print or (re)format application binary interfaces (abi) for Ethereum & Co.
5
+
6
+
7
+ * home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
8
+ * bugs :: [github.com/rubycocos/blockchain/issues](https://github.com/rubycocos/blockchain/issues)
9
+ * gem :: [rubygems.org/gems/abidump](https://rubygems.org/gems/abidump)
10
+ * rdoc :: [rubydoc.info/gems/abidump](http://rubydoc.info/gems/abidump)
11
+
12
+
13
+
14
+ ## New to the Solidity (Contract) Programming Language?
15
+
16
+ See [**Awesome Solidity @ Open Blockchains »**](https://github.com/openblockchains/awesome-solidity)
17
+
18
+
19
+
20
+
21
+ ## Usage
22
+
23
+
24
+ Let's try a dry run:
25
+
26
+ ```
27
+ $ abidump --help
28
+ ```
29
+
30
+ resulting in:
31
+
32
+ ```
33
+ ==> welcome to the abidump tool
34
+
35
+ Usage: abidump [options]
36
+ -j, --json use json format (default: false)
37
+ -y, --yaml use yaml format (default: false)
38
+ -h, --help Prints this help
39
+ ```
40
+
41
+
42
+ Let's pretty print (dump) the application binary interface (abi)
43
+ for punks v1 (anno 2017):
44
+
45
+ ```
46
+ $ abidump ./address/0x6ba6f2207e343923ba692e5cae646fb0f566db8d/abi.json
47
+ ```
48
+
49
+ resulting in:
50
+
51
+
52
+ ```
53
+ ==> summary:
54
+ 29 abi item(s):
55
+ 1 constructor
56
+ 6 events
57
+ Assign, Transfer, PunkTransfer, PunkOffered, PunkBought, PunkNoLongerForSale
58
+ 22 functions
59
+ name, reservePunksForOwner, punksOfferedForSale, totalSupply, decimals, withdraw, imageHash, nextPunkIndexToAssign, punkIndexToAddress, standard, balanceOf, buyPunk, transferPunk, symbol, numberOfPunksToReserve, numberOfPunksReserved, offerPunkForSaleToAddress, punksRemainingToAssign, offerPunkForSale, getPunk, pendingWithdrawals, punkNoLongerForSale
60
+
61
+ ==> constructor:
62
+ payable: true
63
+ inputs (0):
64
+ []
65
+
66
+ ==> event Assign:
67
+ anonymous: false
68
+ inputs (2):
69
+ - type: address
70
+ indexed: true
71
+ name: to
72
+ - type: uint256
73
+ indexed: false
74
+ name: punkIndex
75
+
76
+ ==> event Transfer:
77
+ anonymous: false
78
+ inputs (3):
79
+ - type: address
80
+ indexed: true
81
+ name: from
82
+ - type: address
83
+ indexed: true
84
+ name: to
85
+ - type: uint256
86
+ indexed: false
87
+ name: value
88
+
89
+ ==> event PunkTransfer:
90
+ anonymous: false
91
+ inputs (3):
92
+ - type: address
93
+ indexed: true
94
+ name: from
95
+ - type: address
96
+ indexed: true
97
+ name: to
98
+ - type: uint256
99
+ indexed: false
100
+ name: punkIndex
101
+
102
+ ...
103
+
104
+ ==> function name:
105
+ constant: true
106
+ payable: false
107
+ inputs (0):
108
+ []
109
+ outputs (1):
110
+ - type: string
111
+ name: _
112
+
113
+ ==> function reservePunksForOwner:
114
+ constant: false
115
+ payable: false
116
+ inputs (1):
117
+ - type: uint256
118
+ name: maxForThisRun
119
+ outputs (0):
120
+ []
121
+
122
+ ==> function punksOfferedForSale:
123
+ constant: true
124
+ payable: false
125
+ inputs (1):
126
+ - type: uint256
127
+ name: _
128
+ outputs (5):
129
+ - type: bool
130
+ name: isForSale
131
+ - type: uint256
132
+ name: punkIndex
133
+ - type: address
134
+ name: seller
135
+ - type: uint256
136
+ name: minValue
137
+ - type: address
138
+ name: onlySellTo
139
+
140
+ ...
141
+ ```
142
+
143
+
144
+ Let's try to dump (pretty print) the
145
+ application binary interface (abi)
146
+ for punk blocks (anno 2022):
147
+
148
+ ```
149
+ $ abidump ./address/0x58e90596c2065befd3060767736c829c18f3474c/abi.json
150
+ ```
151
+
152
+ resulting in:
153
+
154
+ ```
155
+ ==> summary:
156
+ 11 abi item(s):
157
+ 1 constructor
158
+ 1 event
159
+ NewBlock
160
+ 9 functions
161
+ blocks, getBlocks, index, nextId, registerBlock, svgFromIDs, svgFromKeys, svgFromNames, svgFromPunkID
162
+
163
+ ==> constructor:
164
+ stateMutability: nonpayable
165
+ inputs (0):
166
+ []
167
+
168
+ ==> event NewBlock:
169
+ anonymous: false
170
+ inputs (3):
171
+ - type: address
172
+ indexed: false
173
+ name: _
174
+ - type: uint256
175
+ indexed: false
176
+ name: _
177
+ - type: string
178
+ indexed: false
179
+ name: _
180
+
181
+ ==> function blocks:
182
+ stateMutability: view
183
+ inputs (1):
184
+ - type: bytes32
185
+ name: _
186
+ outputs (3):
187
+ - type: uint8 (enum PunkBlocks.Layer)
188
+ name: layer
189
+ - type: bytes
190
+ name: dataMale
191
+ - type: bytes
192
+ name: dataFemale
193
+
194
+ ==> function getBlocks:
195
+ stateMutability: view
196
+ inputs (2):
197
+ - type: uint256
198
+ name: _fromID
199
+ - type: uint256
200
+ name: _count
201
+ outputs (2):
202
+ - type: tuple[] (struct PunkBlocks.Block[])
203
+ name: _
204
+ components:
205
+ - type: uint8 (enum PunkBlocks.Layer)
206
+ name: layer
207
+ - type: bytes
208
+ name: dataMale
209
+ - type: bytes
210
+ name: dataFemale
211
+ - type: uint256
212
+ name: _
213
+
214
+ ==> function index:
215
+ stateMutability: view
216
+ inputs (1):
217
+ - type: uint256
218
+ name: _
219
+ outputs (1):
220
+ - type: bytes32
221
+ name: _
222
+
223
+ ==> function nextId:
224
+ stateMutability: view
225
+ inputs (0):
226
+ []
227
+ outputs (1):
228
+ - type: uint256
229
+ name: _
230
+
231
+ ==> function registerBlock:
232
+ stateMutability: nonpayable
233
+ inputs (4):
234
+ - type: bytes
235
+ name: _dataMale
236
+ - type: bytes
237
+ name: _dataFemale
238
+ - type: uint8
239
+ name: _layer
240
+ - type: string
241
+ name: _name
242
+ outputs (0):
243
+ []
244
+
245
+ ==> function svgFromIDs:
246
+ stateMutability: view
247
+ inputs (1):
248
+ - type: uint256[]
249
+ name: _ids
250
+ outputs (1):
251
+ - type: string
252
+ name: _
253
+
254
+ ...
255
+ ```
256
+
257
+
258
+ and so on.
259
+
260
+
261
+ Bonus - Using the `-j / --json` switch / flag
262
+ or `-y / --yaml` you can (re)export or (re)format
263
+ the application binary interface (abi)
264
+ to pretty printed json or yaml. Example.
265
+
266
+
267
+ ```
268
+ $ abidump --json ./address/0x58e90596c2065befd3060767736c829c18f3474c/abi.json
269
+ $ abidump --yaml ./address/0x58e90596c2065befd3060767736c829c18f3474c/abi.json
270
+ ```
271
+
272
+
273
+
274
+ ## License
275
+
276
+ The scripts are dedicated to the public domain.
277
+ Use it as you please with no restrictions whatsoever.
278
+
279
+
280
+ ## Questions? Comments?
281
+
282
+
283
+ Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
284
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'hoe'
2
+
3
+
4
+ ###
5
+ # hack/ quick fix for broken intuit_values - overwrite with dummy
6
+ class Hoe
7
+ def intuit_values( input ); end
8
+ end
9
+
10
+
11
+ Hoe.spec 'abidump' do
12
+
13
+ self.version = '0.1.0'
14
+
15
+ self.summary = "abidump gem - command-line tool to dump / pretty print or (re)format application binary interfaces (abi) for Ethereum & Co."
16
+ self.description = summary
17
+
18
+ self.urls = { home: 'https://github.com/rubycocos/blockchain' }
19
+
20
+ self.author = 'Gerald Bauer'
21
+ self.email = 'wwwmake@googlegroups.com'
22
+
23
+ # switch extension to .markdown for gihub formatting
24
+ self.readme_file = 'README.md'
25
+ self.history_file = 'CHANGELOG.md'
26
+
27
+ self.extra_deps = [
28
+ ['cocos'],
29
+ ]
30
+
31
+ self.licenses = ['Public Domain']
32
+
33
+ self.spec_extras = {
34
+ required_ruby_version: '>= 2.3'
35
+ }
36
+
37
+ end
38
+
data/bin/abidump ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###################
4
+ # == DEV TIPS:
5
+ #
6
+ # For local testing run like:
7
+ #
8
+ # ruby -Ilib bin/abidump
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/abidump
13
+ #
14
+
15
+ require 'abidump'
16
+
17
+ ABIDump::Tool.main
data/lib/abidump.rb ADDED
@@ -0,0 +1,196 @@
1
+ require 'cocos'
2
+ require 'optparse'
3
+
4
+
5
+
6
+ module ABIDump
7
+
8
+ class Tool
9
+
10
+ def self.main( args=ARGV )
11
+ puts "==> welcome to abidump tool with args:"
12
+ pp args
13
+
14
+ options = {
15
+ }
16
+
17
+ parser = OptionParser.new do |opts|
18
+
19
+ opts.on("-j", "--json", "use json format (default: false)") do |value|
20
+ options[ :json] = true
21
+ end
22
+
23
+ opts.on("-y", "--yaml", "use yaml format (default: false)") do |value|
24
+ options[ :yaml] = true
25
+ end
26
+
27
+ opts.on("-h", "--help", "Prints this help") do
28
+ puts opts
29
+ exit
30
+ end
31
+ end
32
+
33
+ parser.parse!( args )
34
+ puts "options:"
35
+ pp options
36
+
37
+ puts "args:"
38
+ pp args
39
+
40
+ if args.size < 1
41
+ puts "!! ERROR - no abi contract path found - use $ abidump <path>"
42
+ puts ""
43
+ exit
44
+ end
45
+
46
+ path = args[0]
47
+
48
+ ## read data
49
+ data = read_json( path )
50
+
51
+ if options[ :yaml ]
52
+ do_dump_yaml( data )
53
+ elsif options[ :json ]
54
+ do_dump_json( data )
55
+ else
56
+ do_dump( data )
57
+ end
58
+
59
+ puts "bye"
60
+ end
61
+
62
+
63
+
64
+
65
+ def self.do_dump_yaml( data )
66
+ buf = YAML.dump( data )
67
+ puts buf
68
+ end
69
+
70
+ def self.do_dump_json( data )
71
+ buf = JSON.pretty_generate( data )
72
+ puts buf
73
+ end
74
+
75
+ def self._norm_types( data )
76
+ ## hack: remove items and re-add to sort key order!!!
77
+ ##
78
+ ## clean-up / normalize type
79
+ ## if type && internalType is the same
80
+ ## than delete internalType for now - why? why not?
81
+ data.each do |h|
82
+ name = h.delete('name')
83
+ type = h.delete('type')
84
+ internal_type = h.delete('internalType')
85
+ indexed = h.delete('indexed')
86
+ components = h.delete('components')
87
+
88
+ unless h.empty?
89
+ puts "!! ERROR - found unknown props in abi inputs/outpus:"
90
+ pp h
91
+ exit 1
92
+ end
93
+
94
+ h['type'] = type if type
95
+ if type && internal_type && type != internal_type
96
+ h['type'] += " (#{internal_type})"
97
+ end
98
+
99
+ h['indexed'] = indexed unless indexed.nil? ## note: indexed is a true/false prop
100
+
101
+ ## note: change empty name e.g. '' to _ - why? why not?
102
+ if name
103
+ h['name'] = name.empty? ? "_" : name
104
+ end
105
+
106
+ if components
107
+ h['components'] = components
108
+ _norm_types( components)
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+ def self._dump( data, indent: 2 )
115
+ buf = YAML.dump( data )
116
+ buf = buf.sub( /^---\n?/, '' ) ## remove leading --- if present
117
+
118
+ # puts "---> debug:"
119
+ # pp buf
120
+ # puts "<---"
121
+
122
+ buf.each_line do |line|
123
+ print ' ' * indent
124
+ puts line
125
+ end
126
+ end
127
+
128
+
129
+ def self.do_dump( data )
130
+
131
+ ## calc summary stats
132
+ counter = {}
133
+ data.each do |h|
134
+ type = h['type']
135
+ stat = counter[ type ] ||= { count: 0, names: [] }
136
+ stat[:count] += 1
137
+
138
+ name = h['name']
139
+ stat[:names] << name if name
140
+ end
141
+
142
+
143
+ data.each do |h|
144
+ type = h.delete('type')
145
+ name = h.delete('name')
146
+ inputs = h.delete('inputs')
147
+ outputs = h.delete('outputs')
148
+
149
+ puts
150
+ print "==> #{type}"
151
+ print " #{name}" if name
152
+ puts ":"
153
+ _dump( h, indent: 6 )
154
+
155
+ if inputs
156
+ puts " inputs (#{inputs.size}):"
157
+ _norm_types( inputs )
158
+ _dump( inputs, indent: 6 )
159
+ end
160
+
161
+ if outputs
162
+ puts " outputs (#{outputs.size}):"
163
+ _norm_types( outputs )
164
+ _dump( outputs, indent: 6 )
165
+ end
166
+ end
167
+
168
+ ## always dump stats at the end - why? why not?
169
+ puts
170
+ puts "==> summary: "
171
+ puts " #{data.size} abi item(s):"
172
+ counter.each do |(type, h)|
173
+ count = h[:count]
174
+ print " #{count}"
175
+ print " #{type}"
176
+ print "s" if count > 1
177
+ print "\n"
178
+
179
+ names = h[:names]
180
+ if names.size > 0
181
+ print " "
182
+ print names.join( ', ' )
183
+ print "\n"
184
+ end
185
+ end
186
+ end
187
+ end # class Tool
188
+ end # module ABIDump
189
+
190
+
191
+
192
+
193
+ ##############
194
+ # add alternate spellings - why? why not?
195
+ AbiDump = ABIDump
196
+ Abidump = ABIDump
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abidump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocos
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '7'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: hoe
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.23'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.23'
61
+ description: abidump gem - command-line tool to dump / pretty print or (re)format
62
+ application binary interfaces (abi) for Ethereum & Co.
63
+ email: wwwmake@googlegroups.com
64
+ executables:
65
+ - abidump
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - CHANGELOG.md
69
+ - Manifest.txt
70
+ - README.md
71
+ files:
72
+ - CHANGELOG.md
73
+ - Manifest.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/abidump
77
+ - lib/abidump.rb
78
+ homepage: https://github.com/rubycocos/blockchain
79
+ licenses:
80
+ - Public Domain
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options:
84
+ - "--main"
85
+ - README.md
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '2.3'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.3.7
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: abidump gem - command-line tool to dump / pretty print or (re)format application
103
+ binary interfaces (abi) for Ethereum & Co.
104
+ test_files: []