abi2sol 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ae4954b393b297c829f3c6b04915ca618a70be4651d422e412aa0348a6f22f8
4
+ data.tar.gz: 69fce3be531ce078a95c1fd1d359817ff9291503ff9fd6a7cd40f4f67ec05135
5
+ SHA512:
6
+ metadata.gz: 6c157cc040f6bccf94c6d0fc90ad2d0a3dacbdcb9b0ea28f3fae406c66fdd065db9a774035bf52bef1a5488aca1258ce32302f37ff4bd0bcdbff07e0a188c964
7
+ data.tar.gz: d87ed5a52b9d59eac1540f7b6672086e868f2915fbc7f4fe8d1036fbd88dea75517181d87e80b15f79206243597b5cafc92e3ccc31c947159042a6e780a6e172
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2023-02-03
2
+
3
+ * Everything is new. First release
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ bin/abi2sol
6
+ lib/abi2sol.rb
7
+ lib/abi2sol/generate.rb
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # abi2sol
2
+
3
+
4
+ abi2sol gem - command-line tool for application binary interface (abi) to solidity (contract) source code generation 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/abi2sol](https://rubygems.org/gems/abi2sol)
10
+ * rdoc :: [rubydoc.info/gems/abi2sol](http://rubydoc.info/gems/abi2sol)
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
+ $ abi2sol --help
28
+ ```
29
+
30
+ resulting in:
31
+
32
+ ```
33
+ abiparser/0.1.2 on Ruby 3.1.1
34
+ ==> welcome to the abi2parse tool
35
+
36
+ Usage: abi2sol [options]
37
+ --name STRING name of contract interface (default: nil)
38
+ -h, --help Prints this help
39
+ ```
40
+
41
+
42
+ Let's try to generate the contract solidity source code
43
+ for punks v1 (anno 2017):
44
+
45
+ ```
46
+ $ abi2sol --name PunksV1 ./address/0x6ba6f2207e343923ba692e5cae646fb0f566db8d/abi.json
47
+ ```
48
+
49
+ resulting in:
50
+
51
+
52
+ ``` solidity
53
+ interface PunksV1 {
54
+ // 1 Payable Function(s)
55
+ function buyPunk(uint256 punkIndex) payable ;
56
+
57
+ // 7 Transact Functions(s)
58
+ function reservePunksForOwner(uint256 maxForThisRun);
59
+ function withdraw();
60
+ function transferPunk(address to, uint256 punkIndex);
61
+ function offerPunkForSaleToAddress(uint256 punkIndex, uint256 minSalePriceInWei, address toAddress);
62
+ function offerPunkForSale(uint256 punkIndex, uint256 minSalePriceInWei);
63
+ function getPunk(uint256 punkIndex);
64
+ function punkNoLongerForSale(uint256 punkIndex);
65
+
66
+ // 14 Query Functions(s)
67
+ function name() view returns (string _);
68
+ function punksOfferedForSale(uint256 _) view returns (bool isForSale, uint256 punkIndex, address seller, uint256 minValue, address onlySellTo);
69
+ function totalSupply() view returns (uint256 _);
70
+ function decimals() view returns (uint8 _);
71
+ function imageHash() view returns (string _);
72
+ function nextPunkIndexToAssign() view returns (uint256 _);
73
+ function punkIndexToAddress(uint256 _) view returns (address _);
74
+ function standard() view returns (string _);
75
+ function balanceOf(address _) view returns (uint256 _);
76
+ function symbol() view returns (string _);
77
+ function numberOfPunksToReserve() view returns (uint256 _);
78
+ function numberOfPunksReserved() view returns (uint256 _);
79
+ function punksRemainingToAssign() view returns (uint256 _);
80
+ function pendingWithdrawals(address _) view returns (uint256 _);
81
+ }
82
+ ```
83
+
84
+
85
+ Let's try to generate the contract solidity source code
86
+ for punk blocks (anno 2022):
87
+
88
+ ```
89
+ $ abi2sol --name PunkBlocks ./address/0x58e90596c2065befd3060767736c829c18f3474c/abi.json
90
+ ```
91
+
92
+ resulting in:
93
+
94
+ ``` solidity
95
+ interface PunkBlocks {
96
+ // 1 Transact Functions(s)
97
+ function registerBlock(bytes _dataMale, bytes _dataFemale, uint8 _layer, string _name);
98
+
99
+ // 8 Query Functions(s)
100
+ function blocks(bytes32 _) view returns (uint8 layer /* enum PunkBlocks.Layer */, bytes dataMale, bytes dataFemale);
101
+ function getBlocks(uint256 _fromID, uint256 _count) view returns ((uint8,bytes,bytes)[] _ /* struct PunkBlocks.Block[] */, uint256 _);
102
+ function index(uint256 _) view returns (bytes32 _);
103
+ function nextId() view returns (uint256 _);
104
+ function svgFromIDs(uint256[] _ids) view returns (string _);
105
+ function svgFromKeys(bytes32[] _attributeKeys) view returns (string _);
106
+ function svgFromNames(string[] _attributeNames) view returns (string _);
107
+ function svgFromPunkID(uint256 _tokenID) view returns (string _);
108
+ }
109
+
110
+ ```
111
+
112
+
113
+ and so on.
114
+
115
+
116
+
117
+ ## Bonus - Awesome Contracts
118
+
119
+ See the [**Awesome (Ethereum) Contracts / Blockchain Services @ Open Blockchains**](https://github.com/openblockchains/awesome-contracts) repo.
120
+ that is a cache of (ethereum) contract ABIs (application binary interfaces)
121
+ and open source code (if verified / available)
122
+ with auto-generated docs via abidoc & friends.
123
+
124
+
125
+
126
+ ## License
127
+
128
+ The scripts are dedicated to the public domain.
129
+ Use it as you please with no restrictions whatsoever.
130
+
131
+
132
+ ## Questions? Comments?
133
+
134
+
135
+ Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
136
+
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 'abi2sol' do
12
+
13
+ self.version = '0.1.0'
14
+
15
+ self.summary = "abi2sol gem - command-line tool for application binary interface (abi) to solidity (contract) source code generation 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
+ ['abiparser'],
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/abi2sol 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/abi2sol
9
+ #
10
+ # Set the executable bit in Linux. Example:
11
+ #
12
+ # % chmod a+x bin/abi2sol
13
+ #
14
+
15
+ require 'abi2sol'
16
+
17
+ Abi2Sol::Tool.main
@@ -0,0 +1,57 @@
1
+
2
+ module ABI
3
+ class Contract
4
+
5
+
6
+ def generate_interface( name: ) ## interface declarations
7
+ buf = ''
8
+ buf << "interface #{name} {"
9
+
10
+
11
+ # include constructor - why? why not?
12
+ #
13
+ # if @ctor
14
+ # buf << "\n"
15
+ # buf << "// Constructor\n"
16
+ # buf << "#{@ctor.decl}\n"
17
+ # end
18
+
19
+ if payable_functions.size > 0
20
+ buf << "\n"
21
+ buf << "// #{payable_functions.size} Payable Function(s)\n"
22
+ payable_functions.each do |func|
23
+ buf << "#{func.decl}\n"
24
+ end
25
+ end
26
+
27
+ if transact_functions.size > 0
28
+ buf << "\n"
29
+ buf << "// #{transact_functions.size} Transact Functions(s)\n"
30
+ transact_functions.each do |func|
31
+ buf << "#{func.decl}\n"
32
+ end
33
+ end
34
+
35
+ if query_functions.size > 0
36
+ buf << "\n"
37
+ buf << "// #{query_functions.size} Query Functions(s)\n"
38
+ query_functions.each do |func|
39
+ buf << "#{func.decl}\n"
40
+ end
41
+ end
42
+
43
+ if helper_functions.size > 0
44
+ buf << "\n"
45
+ buf << "// #{helper_functions.size} Helper Functions(s)\n\n"
46
+ helper_functions.each do |func|
47
+ buf << "#{func.decl}\n"
48
+ end
49
+ end
50
+
51
+ buf << "}\n"
52
+ buf
53
+ end
54
+
55
+
56
+ end ## class Contract
57
+ end ## module ABI
data/lib/abi2sol.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'abiparser'
2
+ require 'optparse'
3
+
4
+
5
+
6
+ ## our own code
7
+ require_relative 'abi2sol/generate'
8
+
9
+
10
+
11
+ module Abi2Sol
12
+ class Tool
13
+
14
+ def self.main( args=ARGV )
15
+ puts "==> welcome to abi2parse tool with args:"
16
+ pp args
17
+
18
+ options = {
19
+ }
20
+
21
+ parser = OptionParser.new do |opts|
22
+
23
+ opts.on("--name STRING",
24
+ "name of contract interface (default: nil)") do |str|
25
+ options[ :name] = str
26
+ end
27
+
28
+ opts.on("-h", "--help", "Prints this help") do
29
+ puts opts
30
+ exit
31
+ end
32
+ end
33
+
34
+ parser.parse!( args )
35
+ puts "options:"
36
+ pp options
37
+
38
+ puts "args:"
39
+ pp args
40
+
41
+ if args.size < 1
42
+ puts "!! ERROR - no contract found - use <contract>"
43
+ puts ""
44
+ exit
45
+ end
46
+
47
+ path = args[0]
48
+
49
+ do_generate( path, name: options[:name] )
50
+
51
+ puts "bye"
52
+ end
53
+
54
+
55
+
56
+ def self.do_generate( path, name: )
57
+ abi = ABI.read( path )
58
+ ## pp abi
59
+
60
+ puts "==> generate contract interface from abi in (#{path})..."
61
+
62
+ buf = abi.generate_interface( name: name )
63
+ puts buf
64
+ ## write_text( "./tmp/punks_v1.sol", buf )
65
+ end
66
+
67
+
68
+ end # class Tool
69
+ end # module Abi2Sol
70
+
71
+
72
+
73
+ ######
74
+ # add convience alternate spelling / names
75
+ Abi2sol = Abi2Sol
76
+ Abi2solidity = Abi2Sol
77
+ Abi2Solidity = Abi2Sol
78
+
79
+ AbiToSol = Abi2Sol
80
+ AbiToSolidity = Abi2Sol
81
+
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abi2sol
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-03 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: 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: abi2sol gem - command-line tool for application binary interface (abi)
62
+ to solidity (contract) source code generation for Ethereum & Co.
63
+ email: wwwmake@googlegroups.com
64
+ executables:
65
+ - abi2sol
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/abi2sol
77
+ - lib/abi2sol.rb
78
+ - lib/abi2sol/generate.rb
79
+ homepage: https://github.com/rubycocos/blockchain
80
+ licenses:
81
+ - Public Domain
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options:
85
+ - "--main"
86
+ - README.md
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '2.3'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.3.7
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: abi2sol gem - command-line tool for application binary interface (abi) to
104
+ solidity (contract) source code generation for Ethereum & Co.
105
+ test_files: []