tealrb 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tealrb/abi.rb +1 -1
- data/lib/tealrb/account.rb +78 -0
- data/lib/tealrb/algod.rb +19 -0
- data/lib/tealrb/app.rb +132 -0
- data/lib/tealrb/app_args.rb +10 -0
- data/lib/tealrb/asset.rb +106 -0
- data/lib/tealrb/box.rb +17 -0
- data/lib/tealrb/byte_opcodes.rb +13 -0
- data/lib/tealrb/contract.rb +332 -121
- data/lib/tealrb/enums.rb +45 -0
- data/lib/tealrb/global.rb +94 -0
- data/lib/tealrb/group_txn.rb +42 -0
- data/lib/tealrb/if_block.rb +17 -24
- data/lib/tealrb/inner_txn.rb +95 -0
- data/lib/tealrb/local.rb +27 -0
- data/lib/tealrb/logs.rb +10 -0
- data/lib/tealrb/maybe_ops.rb +96 -0
- data/lib/tealrb/opcode_type.rb +31 -0
- data/lib/tealrb/opcodes.rb +541 -260
- data/lib/tealrb/rewriters.rb +71 -66
- data/lib/tealrb/scratch.rb +5 -4
- data/lib/tealrb/this_txn.rb +13 -0
- data/lib/tealrb/txn_fields.rb +333 -0
- data/lib/tealrb.rb +47 -18
- metadata +47 -3
- data/lib/tealrb/opcode_modules.rb +0 -904
data/lib/tealrb/enums.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
module Enums
|
5
|
+
class TxnType
|
6
|
+
def initialize(contract)
|
7
|
+
@contract = contract
|
8
|
+
end
|
9
|
+
|
10
|
+
def unknown
|
11
|
+
txn_type_int 'unknown'
|
12
|
+
end
|
13
|
+
|
14
|
+
def pay
|
15
|
+
txn_type_int 'pay'
|
16
|
+
end
|
17
|
+
|
18
|
+
def key_registration
|
19
|
+
txn_type_int 'keyreg'
|
20
|
+
end
|
21
|
+
|
22
|
+
def asset_config
|
23
|
+
txn_type_int 'acfg'
|
24
|
+
end
|
25
|
+
|
26
|
+
def asset_transfer
|
27
|
+
txn_type_int 'axfer'
|
28
|
+
end
|
29
|
+
|
30
|
+
def asset_freeze
|
31
|
+
txn_type_int 'afrz'
|
32
|
+
end
|
33
|
+
|
34
|
+
def application_call
|
35
|
+
txn_type_int 'appl'
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def txn_type_int(type)
|
41
|
+
@contract.teal << "int #{type}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
class Global
|
5
|
+
def initialize(contract)
|
6
|
+
@contract = contract
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](_key)
|
10
|
+
@contract.app_global_get
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(_key, _value)
|
14
|
+
@contract.app_global_put
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [uint64] microalgos (v1)
|
18
|
+
def min_txn_fee(*args)
|
19
|
+
@contract.global_opcode('MinTxnFee', *args)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [uint64] microalgos (v1)
|
23
|
+
def min_balance(*args)
|
24
|
+
@contract.global_opcode('MinBalance', *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [uint64] rounds (v1)
|
28
|
+
def max_txn_life(*args)
|
29
|
+
@contract.global_opcode('MaxTxnLife', *args)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [[]byte] 32 byte address of all zero bytes (v1)
|
33
|
+
def zero_address(*args)
|
34
|
+
@contract.global_opcode('ZeroAddress', *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [uint64] Number of transactions in this atomic transaction group. At least 1 (v1)
|
38
|
+
def group_size(*args)
|
39
|
+
@contract.global_opcode('GroupSize', *args)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [uint64] Maximum supported version (v2)
|
43
|
+
def logic_sig_version(*args)
|
44
|
+
@contract.global_opcode('LogicSigVersion', *args)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [uint64] Current round number. Application mode only. (v2)
|
48
|
+
def round(*args)
|
49
|
+
@contract.global_opcode('Round', *args)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [uint64] Last confirmed block UNIX timestamp. Fails if negative. Application mode only. (v2)
|
53
|
+
def latest_timestamp(*args)
|
54
|
+
@contract.global_opcode('LatestTimestamp', *args)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [uint64] ID of current application executing. Application mode only. (v2)
|
58
|
+
def current_application_id(*args)
|
59
|
+
@contract.global_opcode('CurrentApplicationID', *args)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [[]byte] Address of the creator of the current application. Application mode only. (v3)
|
63
|
+
def creator_address(*args)
|
64
|
+
@contract.global_opcode('CreatorAddress', *args)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Account] Address that the current application controls. Application mode only. (v5)
|
68
|
+
def current_application_address(*args)
|
69
|
+
@contract.account @contract.global_opcode('CurrentApplicationAddress', *args)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [[]byte] ID of the transaction group. 32 zero bytes if the transaction is not part of a group. (v5)
|
73
|
+
def group_id(*args)
|
74
|
+
@contract.global_opcode('GroupID', *args)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [uint64] The remaining cost that can be spent by opcodes in this program. (v6)
|
78
|
+
def opcode_budget(*args)
|
79
|
+
@contract.global_opcode('OpcodeBudget', *args)
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Application] The application ID of the application that called this application.
|
83
|
+
# 0 if this application is at the top-level. Application mode only. (v6)
|
84
|
+
def caller_application_id(*args)
|
85
|
+
@contract.app @contract.global_opcode('CallerApplicationID', *args)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [[]byte] The application address of the application that called this application.
|
89
|
+
# ZeroAddress if this application is at the top-level. Application mode only. (v6)
|
90
|
+
def caller_application_address(*args)
|
91
|
+
@contract.global_opcode('CallerApplicationAddress', *args)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
class GroupTxn < OpcodeType
|
5
|
+
include TxnFields
|
6
|
+
|
7
|
+
def txnfield_opcode(field, *_args)
|
8
|
+
@contract.gtxns field
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](index)
|
12
|
+
if index.is_a? Integer
|
13
|
+
Gtxn.new(@contract, index)
|
14
|
+
else
|
15
|
+
self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Gtxn < GroupTxn
|
21
|
+
def initialize(contract, index)
|
22
|
+
@index = index
|
23
|
+
super(contract)
|
24
|
+
end
|
25
|
+
|
26
|
+
def txnfield_opcode(field, *_args)
|
27
|
+
@contract.gtxn @index, field
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Pay < GroupTxn; end
|
32
|
+
|
33
|
+
class Keyreg < GroupTxn; end
|
34
|
+
|
35
|
+
class Keyreg < GroupTxn; end
|
36
|
+
|
37
|
+
class Axfer < GroupTxn; end
|
38
|
+
|
39
|
+
class Afrz < GroupTxn; end
|
40
|
+
|
41
|
+
class Appl < GroupTxn; end
|
42
|
+
end
|
data/lib/tealrb/if_block.rb
CHANGED
@@ -1,43 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module TEALrb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@id = 0
|
10
|
-
|
11
|
-
def initialize(_cond, &blk)
|
12
|
-
self.class.id ||= 0
|
4
|
+
module IfMethods
|
5
|
+
def teal_if(_cond, &blk)
|
6
|
+
@if_count ||= -1
|
7
|
+
@if_count += 1
|
13
8
|
@else_count = 0
|
14
|
-
@
|
15
|
-
@end_label = "if#{@id}_end:"
|
9
|
+
@end_label = "if#{@if_count}_end:"
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
TEAL.instance << "bz if#{@id}_else0"
|
11
|
+
@teal << "bz if#{@if_count}_else0"
|
20
12
|
blk.call
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
@teal << "b if#{@if_count}_end"
|
14
|
+
@teal << "if#{@if_count}_else0:"
|
15
|
+
@teal << @end_label
|
16
|
+
self
|
24
17
|
end
|
25
18
|
|
26
19
|
def elsif(_cond, &blk)
|
27
20
|
@else_count += 1
|
28
|
-
|
29
|
-
|
21
|
+
@teal.delete @end_label
|
22
|
+
@teal << "bz if#{@if_count}_else#{@else_count}"
|
30
23
|
blk.call
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
@teal << "b if#{@if_count}_end"
|
25
|
+
@teal << "if#{@if_count}_else#{@else_count}:"
|
26
|
+
@teal << @end_label
|
34
27
|
self
|
35
28
|
end
|
36
29
|
|
37
30
|
def else(&blk)
|
38
|
-
|
31
|
+
@teal.delete @end_label
|
39
32
|
blk.call
|
40
|
-
|
33
|
+
@teal << @end_label
|
41
34
|
end
|
42
35
|
end
|
43
36
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
class InnerTxn
|
5
|
+
def initialize(contract)
|
6
|
+
@contract = contract
|
7
|
+
end
|
8
|
+
|
9
|
+
def begin
|
10
|
+
@contract.itxn_begin
|
11
|
+
end
|
12
|
+
|
13
|
+
def submit
|
14
|
+
@contract.itxn_submit
|
15
|
+
end
|
16
|
+
|
17
|
+
def next
|
18
|
+
@contract.itxn_next
|
19
|
+
end
|
20
|
+
|
21
|
+
# @!method tx_id=(value)
|
22
|
+
# @!method application_id=(value)
|
23
|
+
# @!method on_completion=(value)
|
24
|
+
# @!method application_args=(value)
|
25
|
+
# @!method num_app_args=(value)
|
26
|
+
# @!method accounts=(value)
|
27
|
+
# @!method num_accounts=(value)
|
28
|
+
# @!method approval_program=(value)
|
29
|
+
# @!method clear_state_program=(value)
|
30
|
+
# @!method rekey_to=(value)
|
31
|
+
# @!method config_asset=(value)
|
32
|
+
# @!method config_asset_total=(value)
|
33
|
+
# @!method receiver=(value)
|
34
|
+
# @!method config_asset_decimals=(value)
|
35
|
+
# @!method config_asset_default_frozen=(value)
|
36
|
+
# @!method config_asset_unit_name=(value)
|
37
|
+
# @!method config_asset_name=(value)
|
38
|
+
# @!method config_asset_url=(value)
|
39
|
+
# @!method config_asset_metadata_hash=(value)
|
40
|
+
# @!method config_asset_reserve=(value)
|
41
|
+
# @!method config_asset_freeze=(value)
|
42
|
+
# @!method config_asset_manager=(value)
|
43
|
+
# @!method config_asset_clawback=(value)
|
44
|
+
# @!method freeze_asset=(value)
|
45
|
+
# @!method freeze_asset_account=(value)
|
46
|
+
# @!method freeze_asset_frozen=(value)
|
47
|
+
# @!method assets=(value)
|
48
|
+
# @!method num_assets=(value)
|
49
|
+
# @!method applications=(value)
|
50
|
+
# @!method num_applications=(value)
|
51
|
+
# @!method global_num_uint=(value)
|
52
|
+
# @!method global_num_byte_slice=(value)
|
53
|
+
# @!method local_num_uint=(value)
|
54
|
+
# @!method local_num_byte_slice=(value)
|
55
|
+
# @!method extra_program_pages=(value)
|
56
|
+
# @!method nonparticipation=(value)
|
57
|
+
# @!method logs=(value)
|
58
|
+
# @!method num_logs=(value)
|
59
|
+
# @!method created_asset_id=(value)
|
60
|
+
# @!method created_application_id=(value)
|
61
|
+
# @!method last_log=(value)
|
62
|
+
# @!method state_proof_pk=(value)
|
63
|
+
# @!method type=(value)
|
64
|
+
# @!method amount=(value)
|
65
|
+
# @!method sender=(value)
|
66
|
+
# @!method note=(value)
|
67
|
+
# @!method fee=(value)
|
68
|
+
# @!method first_valid=(value)
|
69
|
+
# @!method first_valid_time=(value)
|
70
|
+
# @!method last_valid=(value)
|
71
|
+
# @!method lease=(value)
|
72
|
+
# @!method close_remainder_to=(value)
|
73
|
+
# @!method vote_pk=(value)
|
74
|
+
# @!method selection_pk=(value)
|
75
|
+
# @!method vote_first=(value)
|
76
|
+
# @!method vote_last=(value)
|
77
|
+
# @!method vote_key_dilution=(value)
|
78
|
+
# @!method type_enum=(value)
|
79
|
+
# @!method xfer_asset=(value)
|
80
|
+
# @!method asset_amount=(value)
|
81
|
+
# @!method asset_sender=(value)
|
82
|
+
# @!method asset_receiver=(value)
|
83
|
+
# @!method asset_close_to=(value)
|
84
|
+
# @!method group_index=(value)
|
85
|
+
TxnFields.instance_methods.each do |m|
|
86
|
+
define_method("#{m}=") do |value|
|
87
|
+
if m == :application_id
|
88
|
+
@contract.itxn_field 'ApplicationID'
|
89
|
+
else
|
90
|
+
@contract.itxn_field m.to_s.split('_').collect(&:capitalize).join, value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/tealrb/local.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
class LocalAccount
|
5
|
+
def initialize(contract)
|
6
|
+
@contract = contract
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](_key)
|
10
|
+
@contract.app_local_get
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(_key, _value)
|
14
|
+
@contract.app_local_put
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Local
|
19
|
+
def initialize(contract)
|
20
|
+
@contract = contract
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](_account)
|
24
|
+
LocalAccount.new @contract
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/tealrb/logs.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
4
|
+
|
5
|
+
module TEALrb
|
6
|
+
module MaybeOps
|
7
|
+
def asset_holding_value(field, account_index = nil, asset_id = nil)
|
8
|
+
asset_holding_get field
|
9
|
+
swap
|
10
|
+
pop
|
11
|
+
end
|
12
|
+
|
13
|
+
def asset_holding_exists?(field, account_index = nil, asset_id = nil)
|
14
|
+
asset_holding_get field
|
15
|
+
pop
|
16
|
+
end
|
17
|
+
|
18
|
+
def app_param_exists?(field, app_id = nil)
|
19
|
+
app_params_get field
|
20
|
+
swap
|
21
|
+
pop
|
22
|
+
end
|
23
|
+
|
24
|
+
def app_param_value(field, app_id = nil)
|
25
|
+
app_params_get field
|
26
|
+
pop
|
27
|
+
end
|
28
|
+
|
29
|
+
def asset_param_exists?(field, asset_id = nil)
|
30
|
+
asset_params_get field
|
31
|
+
swap
|
32
|
+
pop
|
33
|
+
end
|
34
|
+
|
35
|
+
def asset_param_value(field, asset_id = nil)
|
36
|
+
asset_params_get field
|
37
|
+
pop
|
38
|
+
end
|
39
|
+
|
40
|
+
def acct_has_balance?(asset_id = nil)
|
41
|
+
acct_params_get 'AcctBalance'
|
42
|
+
swap
|
43
|
+
pop
|
44
|
+
end
|
45
|
+
|
46
|
+
def acct_param_value(field, asset_id = nil)
|
47
|
+
acct_params_get field
|
48
|
+
pop
|
49
|
+
end
|
50
|
+
|
51
|
+
def app_local_ex_exists?(account = nil, applicaiton = nil, key = nil)
|
52
|
+
app_local_get_ex
|
53
|
+
swap
|
54
|
+
pop
|
55
|
+
end
|
56
|
+
|
57
|
+
def app_local_ex_value(account = nil, applicaiton = nil, key = nil)
|
58
|
+
app_local_get_ex
|
59
|
+
pop
|
60
|
+
end
|
61
|
+
|
62
|
+
def app_global_ex_exists?(account = nil, applicaiton = nil, key = nil)
|
63
|
+
app_global_get_ex
|
64
|
+
swap
|
65
|
+
pop
|
66
|
+
end
|
67
|
+
|
68
|
+
def app_global_ex_value(account = nil, applicaiton = nil, key = nil)
|
69
|
+
app_global_get_ex
|
70
|
+
pop
|
71
|
+
end
|
72
|
+
|
73
|
+
def box_value(name = nil)
|
74
|
+
box_get
|
75
|
+
pop
|
76
|
+
end
|
77
|
+
|
78
|
+
def box_exists?(name = nil)
|
79
|
+
box_get
|
80
|
+
swap
|
81
|
+
pop
|
82
|
+
end
|
83
|
+
|
84
|
+
def box_len_value(name = nil)
|
85
|
+
box_len
|
86
|
+
pop
|
87
|
+
end
|
88
|
+
|
89
|
+
def box_len_exists?(name = nil)
|
90
|
+
box_len
|
91
|
+
swap
|
92
|
+
pop
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TEALrb
|
4
|
+
class OpcodeType
|
5
|
+
TEALrb::Opcodes::BINARY_OPCODE_METHOD_MAPPING.each do |meth, opcode|
|
6
|
+
define_method(meth) do |other|
|
7
|
+
@contract.send(opcode, self, other)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
TEALrb::Opcodes::UNARY_OPCODE_METHOD_MAPPING.each do |meth, opcode|
|
12
|
+
define_method(meth) do
|
13
|
+
@contract.send(opcode, self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(contract)
|
18
|
+
@contract = contract
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](index)
|
22
|
+
if index.is_a?(Integer)
|
23
|
+
@contract.txna @field, index
|
24
|
+
else
|
25
|
+
@contract.txnas @field
|
26
|
+
end
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|