abi2ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad8b991ef9ac6969aa4a618e3f978c8ff9d04572b8e35479614d995f15fe5392
4
+ data.tar.gz: ab052e6d53d8338ae96d5cb25bb61a8ce10fecf9f43e40955a6cdd0b0e1c1152
5
+ SHA512:
6
+ metadata.gz: d03c419be9aaea423eff8686363bedbf70df1b526035c041bcdbbec53161166bd4d206c5f86c444cacd3f83b48ffd9334a09ec0ad3c8f65c53619997bbb20869
7
+ data.tar.gz: 363441a86ddcfcacf9954bd614108127b518da06b68b420190a3fb1360279875f0e67d0d65e3195ac66804515b9ce6d59d7fb3e7d226a1793eaceb08fec45ce8
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2023-02-09
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
+ lib/abi2ruby.rb
6
+ lib/abi2ruby/generate.rb
data/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # Application Binary Interface (ABI) Contract Generator
2
+
3
+ abi2ruby - generate ready-to-use (blockchain) contract services / function calls for ethereum & co. via application binary inferfaces (abis)
4
+
5
+
6
+ * home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
7
+ * bugs :: [github.com/rubycocos/blockchain/issues](https://github.com/rubycocos/blockchain/issues)
8
+ * gem :: [rubygems.org/gems/abi2ruby](https://rubygems.org/gems/abi2ruby)
9
+ * rdoc :: [rubydoc.info/gems/abi2ruby](http://rubydoc.info/gems/abi2ruby)
10
+
11
+
12
+
13
+ ## Usage
14
+
15
+ Let's try to generate the contract "wrapper" code in ruby
16
+ from the application binary interface (abi) in json
17
+ for punk blocks (anno 2020) - plus let's add the optional "natspec" comments:
18
+
19
+ ``` ruby
20
+ require 'abi2ruby'
21
+
22
+ punk_blocks = '0x58e90596c2065befd3060767736c829c18f3474c'
23
+
24
+ abi = ABI.read( "./abis/#{punk_blocks}.json" )
25
+ natspec = Natspec.read( "./abis/#{punk_blocks}.md" )
26
+
27
+ buf = abi.generate_code( name: 'PunkBlocks',
28
+ address: punk_blocks,
29
+ natspec: natspec )
30
+ write_text( "./punk_blocks.rb", buf )
31
+ ```
32
+
33
+ resulting in:
34
+
35
+
36
+ ---
37
+
38
+ ``` ruby
39
+ #########################
40
+ # PunkBlocks contract / (blockchain) services / function calls
41
+ # auto-generated via abi2ruby (see https://rubygems.org/gems/abi2ruby) on 2023-01-13 15:31:38 UTC
42
+ # - 8 query functions(s)
43
+ #
44
+ #
45
+ # - Author: tycoon.eth, thanks to @geraldb & @samwilsn on Github for inspiration!
46
+ # - Version: v0.0.2
47
+ # - Pragma: solidity ^0.8.17
48
+ #
49
+ #
50
+ # ███████████ █████
51
+ # ░░███░░░░░███ ░░███
52
+ # ░███ ░███ █████ ████ ████████ ░███ █████
53
+ # ░██████████ ░░███ ░███ ░░███░░███ ░███░░███
54
+ # ░███░░░░░░ ░███ ░███ ░███ ░███ ░██████░
55
+ # ░███ ░███ ░███ ░███ ░███ ░███░░███
56
+ # █████ ░░████████ ████ █████ ████ █████
57
+ # ░░░░░ ░░░░░░░░ ░░░░ ░░░░░ ░░░░ ░░░░░
58
+ #
59
+ #
60
+ #
61
+ # ███████████ ████ █████
62
+ # ░░███░░░░░███░░███ ░░███
63
+ # ░███ ░███ ░███ ██████ ██████ ░███ █████ █████
64
+ # ░██████████ ░███ ███░░███ ███░░███ ░███░░███ ███░░
65
+ # ░███░░░░░███ ░███ ░███ ░███░███ ░░░ ░██████░ ░░█████
66
+ # ░███ ░███ ░███ ░███ ░███░███ ███ ░███░░███ ░░░░███
67
+ # ███████████ █████░░██████ ░░██████ ████ █████ ██████
68
+ # ░░░░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░░
69
+ #
70
+ # A Registry of 24x24 png images
71
+ #
72
+ # This contract:
73
+ #
74
+ # 1. Stores all the classic traits of the CryptoPunks in
75
+ # individual png files, 100% on-chain. These are then used as
76
+ # blocks to construct CryptoPunk images. Outputted as SVGs.
77
+ #
78
+ # 2. Any of the 10,000 "classic" CryptoPunks can be generated
79
+ # by supplying desired arguments to a function, such as
80
+ # the id of a punk, or a list of the traits.
81
+ #
82
+ # 3. An unlimited number of new punk images can be generated from
83
+ # the existing classic set of traits, or even from new traits!
84
+ #
85
+ # 4. New traits (blocks) can be added to the contract by
86
+ # registering them with the `registerBlock` function.
87
+ #
88
+ # Further documentation:
89
+ # https://github.com/0xTycoon/punk-blocks
90
+ #
91
+ #
92
+ #
93
+ # **Data Structures**
94
+ #
95
+ # Layer is in the order of rendering
96
+ #
97
+ # enum Layer {
98
+ # Base, // 0 Base is the face. Determines if m or f version will be used...
99
+ # Cheeks, // 1 (Rosy Cheeks)
100
+ # Blemish, // 2 (Mole, Spots)
101
+ # Hair, // 3 (Purple Hair, Shaved Head, Pigtails, ...)
102
+ # Beard, // 4 (Big Beard, Front Beard, Goat, ...)
103
+ # Eyes, // 5 (Clown Eyes Green, Green Eye Shadow, ...)
104
+ # Eyewear, // 6 (VR, 3D Glass, Eye Mask, Regular Shades, Welding Glasses, ...)
105
+ # Nose, // 7 (Clown Nose)
106
+ # Mouth, // 8 (Hot Lipstick, Smile, Buck Teeth, ...)
107
+ # MouthProp, // 9 (Medical Mask, Cigarette, ...)
108
+ # Earring, // 10 (Earring)
109
+ # Headgear, // 11 (Beanie, Fedora, Hoodie, Police Cap, Tiara, Headband, ...)
110
+ # Neck // 12 (Choker, Silver Chain, Gold Chain)
111
+ # }
112
+ #
113
+ # struct Block {
114
+ # Layer layer; // 13 possible layers
115
+ # bytes dataMale; // male version of this attribute
116
+ # bytes dataFemale;// female version of this attribute
117
+ # }
118
+ #
119
+ #
120
+ # **Events**
121
+ #
122
+ # event NewBlock(address, uint256, string)
123
+
124
+
125
+ class PunkBlocks < Ethlite::Contract
126
+
127
+ address "0x58e90596c2065befd3060767736c829c18f3474c"
128
+
129
+ # storage - mapping(bytes32 => Block) public blocks
130
+ #
131
+ # stores punk attributes as a png
132
+ sig "blocks", inputs: ["bytes32"], outputs: ["uint8","bytes","bytes"]
133
+ def blocks(arg0)
134
+ do_call("blocks", arg0)
135
+ end
136
+
137
+ # function getBlocks
138
+ #
139
+ # getBlocks returns a sequential list of blocks in a single call
140
+ # @param _fromID is which id to begin from
141
+ # @param _count how many items to retrieve.
142
+ # @return Block[] list of blocks, uint256 next id
143
+ sig "getBlocks", inputs: ["uint256","uint256"], outputs: ["(uint8,bytes,bytes)[]","uint256"]
144
+ def getBlocks(_fromID, _count)
145
+ do_call("getBlocks", _fromID, _count)
146
+ end
147
+
148
+ # storage - mapping(uint256 => bytes32) public index
149
+ #
150
+ # index of each block by its sequence
151
+ sig "index", inputs: ["uint256"], outputs: ["bytes32"]
152
+ def index(arg0)
153
+ do_call("index", arg0)
154
+ end
155
+
156
+ # storage - uint256 public nextId
157
+ #
158
+ # next id to use when adding a block
159
+ sig "nextId", outputs: ["uint256"]
160
+ def nextId()
161
+ do_call("nextId")
162
+ end
163
+
164
+ # function svgFromIDs
165
+ #
166
+ # svgFromIDs returns the svg data as a string
167
+ # e.g. [9,55,99]
168
+ # One of the elements must be must be a layer 0 block.
169
+ # This element decides what version of image to use for the higher layers
170
+ # (dataMale or dataFemale)
171
+ # @param _ids uint256 ids of an attribute, by it's index of creation
172
+ sig "svgFromIDs", inputs: ["uint256[]"], outputs: ["string"]
173
+ def svgFromIDs(_ids)
174
+ do_call("svgFromIDs", _ids)
175
+ end
176
+
177
+ # function svgFromKeys
178
+ #
179
+ # svgFromKeys returns the svg data as a string
180
+ # @param _attributeKeys a list of attribute names that have been hashed,
181
+ # eg keccak256("Male 1"), keccak256("Goat")
182
+ # must have at least 1 layer 0 attribute (eg. keccak256("Male 1")) which
183
+ # decides what version of image to use for the higher layers
184
+ # (dataMale or dataFemale)
185
+ # e.g. ["0x9039da071f773e85254cbd0f99efa70230c4c11d63fce84323db9eca8e8ef283",
186
+ # "0xd5de5c20969a9e22f93842ca4d65bac0c0387225cee45a944a14f03f9221fd4a"]
187
+ sig "svgFromKeys", inputs: ["bytes32[]"], outputs: ["string"]
188
+ def svgFromKeys(_attributeKeys)
189
+ do_call("svgFromKeys", _attributeKeys)
190
+ end
191
+
192
+ # function svgFromNames
193
+ #
194
+ # svgFromNames returns the svg data as a string
195
+ # @param _attributeNames a list of attribute names, eg "Male 1", "Goat"
196
+ # must have at least 1 layer 0 attribute (eg. Male, Female, Alien, Ape, Zombie)
197
+ # e.g. ["Male 1","Goat"]
198
+ # Where "Male 1" is a layer 0 attribute, that decides what version of
199
+ # image to use for the higher
200
+ # layers (dataMale or dataFemale)
201
+ sig "svgFromNames", inputs: ["string[]"], outputs: ["string"]
202
+ def svgFromNames(_attributeNames)
203
+ do_call("svgFromNames", _attributeNames)
204
+ end
205
+
206
+ # function svgFromPunkID
207
+ #
208
+ # svgFromPunkID returns the svg data as a string given a punk id
209
+ # @param _tokenID uint256 IDs a punk id, 0-9999
210
+ sig "svgFromPunkID", inputs: ["uint256"], outputs: ["string"]
211
+ def svgFromPunkID(_tokenID)
212
+ do_call("svgFromPunkID", _tokenID)
213
+ end
214
+
215
+ end ## class PunkBlocks
216
+ ```
217
+
218
+
219
+ That's it for now.
220
+
221
+
222
+ Tip: For some pre-packaged ready-to-use "out-of-the-gem" contracts,
223
+ see [**ethlite-contracts »**](https://github.com/rubycocos/blockchain/tree/master/ethlite-contracts)
224
+
225
+
226
+
227
+
228
+
229
+
230
+ ## License
231
+
232
+ The scripts are dedicated to the public domain.
233
+ Use it as you please with no restrictions whatsoever.
234
+
235
+
236
+ ## Questions? Comments?
237
+
238
+
239
+ Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
240
+
241
+
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 'abi2ruby' do
12
+
13
+ self.version = '0.1.0'
14
+ self.summary = "abi2ruby - generate ready-to-use (blockchain) contract services / function calls for ethereum & co. via application binary inferfaces (abis)"
15
+ self.description = summary
16
+
17
+ self.urls = { home: 'https://github.com/rubycocos/blockchain' }
18
+
19
+ self.author = 'Gerald Bauer'
20
+ self.email = 'wwwmake@googlegroups.com'
21
+
22
+ # switch extension to .markdown for gihub formatting
23
+ self.readme_file = 'README.md'
24
+ self.history_file = 'CHANGELOG.md'
25
+
26
+ self.extra_deps = [
27
+ ['abiparser'],
28
+ ['natspec'],
29
+ ]
30
+
31
+ self.licenses = ['Public Domain']
32
+
33
+ self.spec_extras = {
34
+ required_ruby_version: '>= 2.3'
35
+ }
36
+
37
+ end
38
+
@@ -0,0 +1,128 @@
1
+
2
+ module ABI
3
+ class Contract
4
+
5
+
6
+ def _generate_func( func )
7
+ buf = String.new
8
+
9
+ buf << "def #{func.name}("
10
+
11
+ func.inputs.each_with_index do |param,i|
12
+ buf << ", " if i > 0
13
+ if param.name
14
+ buf << "#{param.name}"
15
+ else
16
+ buf << "arg#{i}"
17
+ end
18
+ end
19
+
20
+ buf << ")\n"
21
+
22
+ buf << " do_call("
23
+ buf << %Q{"#{func.name}"}
24
+
25
+ func.inputs.each_with_index do |param,i|
26
+ buf << ", "
27
+ if param.name
28
+ buf << "#{param.name}"
29
+ else
30
+ buf << "arg#{i}"
31
+ end
32
+ end
33
+
34
+ buf << ")\n"
35
+ buf << "end\n"
36
+
37
+ ## note: quick hack - for rdoc/yard doc generation
38
+ ## move sig method below method
39
+ buf << %Q{sig "#{func.name}"}
40
+
41
+ if func.inputs.size > 0
42
+ quoted_types = func.inputs.map {|param| %Q{"#{param.sig}"} }
43
+ buf << ", inputs: [#{quoted_types.join(',')}]"
44
+ end
45
+
46
+ if func.outputs.size > 0
47
+ quoted_types = func.outputs.map {|param| %Q{"#{param.sig}"} }
48
+ buf << ", outputs: [#{quoted_types.join(',')}]"
49
+ end
50
+ buf
51
+ end
52
+
53
+ def generate_code( name: 'Contract',
54
+ address: nil,
55
+ natspec: nil )
56
+ buf = ''
57
+ ## buf << "#########################\n"
58
+ buf << "# #{name} contract / (blockchain) services / function calls\n"
59
+ buf << "#\n"
60
+ buf << "# auto-generated via abi2ruby (see https://rubygems.org/gems/abi2ruby) on #{Time.now.utc}\n"
61
+ buf << "# - #{query_functions.size} query functions(s)\n"
62
+ buf << "# - #{helper_functions.size} helper functions(s)\n"
63
+
64
+ if natspec && natspec.head.size > 0
65
+ buf << "#\n#\n"
66
+ natspec.head.each do |line|
67
+ buf << (line.empty? ? "#\n" : "# #{line}\n")
68
+ end
69
+ end
70
+ buf << "\n\n"
71
+
72
+
73
+
74
+ buf << "class #{name} < Ethlite::Contract\n\n"
75
+
76
+ if address
77
+ buf << " address "
78
+ buf << %Q{"#{address}"}
79
+ buf << "\n"
80
+ end
81
+
82
+
83
+ if query_functions.size > 0
84
+ buf << "\n"
85
+ query_functions.each do |func|
86
+
87
+ if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ])
88
+ sect = natspec.storage[ func.name ] || natspec.functions[ func.name ]
89
+ buf << "# #{sect[0]}\n#\n"
90
+ sect[1].each do |line|
91
+ buf << (line.empty? ? "#\n" : "# #{line}\n")
92
+ end
93
+ else
94
+ buf << "# #{func.doc} _readonly_\n"
95
+ end
96
+
97
+ buf << _generate_func( func )
98
+ buf << "\n\n"
99
+ end
100
+ end
101
+
102
+
103
+ if helper_functions.size > 0
104
+ buf << "\n"
105
+ helper_functions.each do |func|
106
+
107
+ if natspec && (natspec.storage[ func.name] || natspec.functions[ func.name ])
108
+ sect = natspec.storage[ func.name ] || natspec.functions[ func.name ]
109
+ buf << "# #{sect[0]}\n#\n"
110
+ sect[1].each do |line|
111
+ buf << (line.empty? ? "#\n" : "# #{line}\n")
112
+ end
113
+ else
114
+ buf << "# #{func.doc} _readonly_\n"
115
+ end
116
+
117
+ buf << _generate_func( func )
118
+ buf << "\n\n"
119
+ end
120
+ end
121
+
122
+ buf << "end ## class #{name}\n"
123
+ buf << "\n"
124
+ buf
125
+ end
126
+
127
+ end ## class Contract
128
+ end ## module ABI
data/lib/abi2ruby.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'abiparser'
2
+ require 'natspec'
3
+
4
+
5
+ ## our own code
6
+ ## require_relative 'abi2ruby/version' # note: let version always go first
7
+
8
+ require_relative 'abi2ruby/generate'
9
+
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abi2ruby
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-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: abiparser
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: natspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: hoe
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.23'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.23'
75
+ description: abi2ruby - generate ready-to-use (blockchain) contract services / function
76
+ calls for ethereum & co. via application binary inferfaces (abis)
77
+ email: wwwmake@googlegroups.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files:
81
+ - CHANGELOG.md
82
+ - Manifest.txt
83
+ - README.md
84
+ files:
85
+ - CHANGELOG.md
86
+ - Manifest.txt
87
+ - README.md
88
+ - Rakefile
89
+ - lib/abi2ruby.rb
90
+ - lib/abi2ruby/generate.rb
91
+ homepage: https://github.com/rubycocos/blockchain
92
+ licenses:
93
+ - Public Domain
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options:
97
+ - "--main"
98
+ - README.md
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '2.3'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.3.7
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: abi2ruby - generate ready-to-use (blockchain) contract services / function
116
+ calls for ethereum & co. via application binary inferfaces (abis)
117
+ test_files: []