tealrb 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tealrb/contract.rb +19 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94ca888a944ccee0517d5e543498570af448a9eb3ea1ba74d3d3261ffc4b86f0
4
- data.tar.gz: 54ac7826a7af43fb82fa17cf010a2ce869511546067f7a151181b86d3445b0bf
3
+ metadata.gz: 2480b69400b8916b30ebd58c19b804190a6390780ad335006ac0364ea9d4ad4e
4
+ data.tar.gz: 6cf7f7f79217b1938f71bf07348923a7d31d3d83d76a4219f43e58bb1db2e3bc
5
5
  SHA512:
6
- metadata.gz: 4f986ae5a4e3c37460142951923c3908ec95b58d0d91f695a49a07f8e8eee062499d496b185e1f2eafec8ed2020ca9d83a4c8c50c97531a8a67e26057e7bb794
7
- data.tar.gz: c73f78d20f1c76ccc41e42450f713b14dc42049d8d44ee1498c59e38cda3e7699e4f1e655932f5b86c68d707d1a1abba7d59fc5c92244552236bb2a472a3d4c2
6
+ metadata.gz: c8220e4aadbdcbe9a992ada723431281665edda6a19c07771978b5a8b4ae9cf987a208ed69e9c96f4360a6a3ace9762dc930e4bab99574b2114effc0ffd1060e
7
+ data.tar.gz: 47790d4ee2171f4c2e95473f7c7cc6674d9634804c8c0dac2eeafff368df073166d9dfd371efc24026e1c94f4c333b1904af9fa4a959992116df7859dc314875
@@ -11,7 +11,8 @@ module TEALrb
11
11
  attr_reader :teal
12
12
 
13
13
  class << self
14
- attr_accessor :subroutines, :version, :teal_methods, :abi_method_hash, :abi_description, :debug
14
+ attr_accessor :subroutines, :version, :teal_methods, :abi_method_hash, :abi_description, :debug,
15
+ :disable_abi_routing
15
16
 
16
17
  private
17
18
 
@@ -22,6 +23,7 @@ module TEALrb
22
23
  klass.abi_description = ABI::ABIDescription.new
23
24
  klass.abi_method_hash = {}
24
25
  klass.debug = false
26
+ klass.disable_abi_routing = false
25
27
  super
26
28
  end
27
29
  end
@@ -164,14 +166,28 @@ module TEALrb
164
166
  nil
165
167
  end
166
168
 
167
- # transpiles #main
169
+ # transpiles #main and routes abi methods. To disable abi routing, set `@disable_abi_routing` to true in your
170
+ # Contract subclass
168
171
  def compile
169
172
  TEAL.instance << 'main:' if TEAL.instance.include? 'b main'
170
- eval_tealrb(rewrite(method(:main).source, method_rewriter: true), debug_context: 'main')
173
+ route_abi_methods unless self.class.disable_abi_routing
174
+ eval_tealrb(rewrite(method(:main).source, method_rewriter: true), debug_context: 'main') if respond_to? :main
171
175
  end
172
176
 
173
177
  private
174
178
 
179
+ def route_abi_methods
180
+ self.class.abi_description.methods.each do |meth|
181
+ signature = "#{meth[:name]}(#{meth[:args].map{ _1[:type]}.join(',')})#{meth[:returns][:type]}"
182
+ selector = OpenSSL::Digest.new('SHA512-256').hexdigest(signature)[..7]
183
+
184
+ IfBlock.new(AppArgs[0] == byte(selector)) do
185
+ callsub(meth[:name])
186
+ approve
187
+ end
188
+ end
189
+ end
190
+
175
191
  def generate_method_source(name, definition)
176
192
  new_source = rewrite(definition.source, method_rewriter: true)
177
193
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tealrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Polny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-28 00:00:00.000000000 Z
11
+ date: 2022-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source