ton_sdk_client 1.7.1

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.
@@ -0,0 +1,257 @@
1
+ module TonSdk
2
+ module Processing
3
+
4
+ #
5
+ # types
6
+ #
7
+
8
+ class ParamsOfSendMessage
9
+ attr_reader :message, :abi, :send_events
10
+
11
+ def initialize(message:, abi: nil, send_events:)
12
+ @message = message
13
+ @abi = abi
14
+ @send_events = send_events
15
+ end
16
+
17
+ def to_h
18
+ {
19
+ message: @message,
20
+ abi: @abi.nil? ? nil : @abi.to_h,
21
+ send_events: @send_events
22
+ }
23
+ end
24
+ end
25
+
26
+ class ResultOfSendMessage
27
+ attr_reader :shard_block_id
28
+
29
+ def initialize(a)
30
+ @shard_block_id = a
31
+ end
32
+
33
+ def to_h
34
+ {
35
+ shard_block_id: @shard_block_id
36
+ }
37
+ end
38
+ end
39
+
40
+ class ParamsOfWaitForTransaction
41
+ attr_reader :abi, :message, :shard_block_id, :send_events
42
+
43
+ def initialize(abi: nil, message:, shard_block_id:, send_events:)
44
+ @abi = abi
45
+ @message = message
46
+ @shard_block_id = shard_block_id
47
+ @send_events = send_events
48
+ end
49
+
50
+ def to_h
51
+ {
52
+ abi: @abi.nil? ? nil : @abi.to_h,
53
+ message: @message,
54
+ shard_block_id: @shard_block_id,
55
+ send_events: @send_events
56
+ }
57
+ end
58
+ end
59
+
60
+ class ResultOfProcessMessage
61
+ attr_reader :transaction, :out_messages, :decoded, :fees
62
+
63
+ def initialize(transaction:, out_messages:, decoded: nil, fees:)
64
+ @transaction = transaction
65
+ @out_messages = out_messages
66
+ @decoded = decoded
67
+ @fees = fees
68
+ end
69
+
70
+ def to_h
71
+ {
72
+ transaction: @transaction,
73
+ out_messages: @out_messages,
74
+ decoded: @decoded,
75
+ fees: @fees
76
+ }
77
+ end
78
+ end
79
+
80
+ class ProcessingEvent
81
+ TYPES = [
82
+ :will_fetch_first_block,
83
+ :fetch_first_block_failed,
84
+ :will_send,
85
+ :did_send,
86
+ :send_failed,
87
+ :will_fetch_next_block,
88
+ :fetch_next_block_failed,
89
+ :message_expired
90
+ ]
91
+
92
+ attr_reader :type_, :error, :shard_block_id, :message_id, :message
93
+
94
+ def initialize(type_:, error: nil, shard_block_id: nil, message_id: nil, message: nil)
95
+ unless TYPES.include?(type_)
96
+ raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
97
+ end
98
+ @type_ = type_
99
+ @error = error
100
+ @shard_block_id = shard_block_id
101
+ @message_id = message_id
102
+ @message = message
103
+ end
104
+
105
+ def to_h
106
+ h1 = {
107
+ type: @type
108
+ }
109
+
110
+ h2 = case @type_
111
+ when :will_fetch_first_block
112
+ { }
113
+ when :fetch_first_block_failed
114
+ {
115
+ error: @error
116
+ }
117
+ when :will_send, :did_send, :will_fetch_next_block
118
+ {
119
+ shard_block_id: @shard_block_id,
120
+ message_id: @message_id,
121
+ message: @message
122
+ }
123
+ when :send_failed, :fetch_next_block_failed
124
+ {
125
+ shard_block_id: @shard_block_id,
126
+ message_id: @message_id,
127
+ message: @message,
128
+ error: @error
129
+ }
130
+ when :message_expired
131
+ {
132
+ message_id: @message_id,
133
+ message: @message,
134
+ error: @error
135
+ }
136
+ else
137
+ raise ArgumentError.new("unsupported type: #{@type_}")
138
+ end
139
+
140
+ h1.merge(h2)
141
+ end
142
+ end
143
+
144
+ class DecodedOutput
145
+ attr_reader :out_messages, :output
146
+
147
+ def initialize(out_messages:, output: nil)
148
+ @out_messages = out_messages
149
+ @output = output
150
+ end
151
+
152
+ def to_h
153
+ {
154
+ out_messages: @out_messages,
155
+ output: @output
156
+ }
157
+ end
158
+ end
159
+
160
+ class ParamsOfProcessMessage
161
+ attr_reader :message_encode_params, :send_events
162
+
163
+ def initialize(message_encode_params:, send_events:)
164
+ @message_encode_params = message_encode_params
165
+ @send_events = send_events
166
+ end
167
+
168
+ def to_h
169
+ {
170
+ message_encode_params: @message_encode_params.to_h,
171
+ send_events: @send_events
172
+ }
173
+ end
174
+ end
175
+
176
+
177
+ #
178
+ # functions
179
+ #
180
+
181
+ def self.send_message(ctx, params, client_callback = nil)
182
+ if (params.send_events == true) && client_callback.nil?
183
+ raise ArgumentError.new("with `send_events` set to true, `client_callback` may not be nil")
184
+ end
185
+
186
+ Interop::request_to_native_lib(
187
+ ctx,
188
+ "processing.send_message",
189
+ params.to_h.to_json,
190
+ client_callback: client_callback,
191
+ is_single_thread_only: false
192
+ ) do |resp|
193
+ if resp.success?
194
+ yield NativeLibResponsetResult.new(
195
+ result: ResultOfSendMessage.new(resp.result["shard_block_id"])
196
+ )
197
+ else
198
+ yield resp
199
+ end
200
+ end
201
+ end
202
+
203
+ def self.wait_for_transaction(ctx, params, client_callback = nil)
204
+ if (params.send_events == true) && client_callback.nil?
205
+ raise ArgumentError.new("with `send_events` set to true, `client_callback` may not be nil")
206
+ end
207
+
208
+ Interop::request_to_native_lib(
209
+ ctx,
210
+ "processing.wait_for_transaction",
211
+ params.to_h.to_json,
212
+ client_callback: client_callback,
213
+ is_single_thread_only: false
214
+ ) do |resp|
215
+ if resp.success?
216
+ yield NativeLibResponsetResult.new(
217
+ result: ResultOfProcessMessage.new(
218
+ transaction: resp.result["transaction"],
219
+ out_messages: resp.result["out_messages"],
220
+ decoded: resp.result["decoded"],
221
+ fees: resp.result["fees"]
222
+ )
223
+ )
224
+ else
225
+ yield resp
226
+ end
227
+ end
228
+ end
229
+
230
+ def self.process_message(ctx, params, client_callback = nil)
231
+ if (params.send_events == true) && client_callback.nil?
232
+ raise ArgumentError.new("with `send_events` set to true `client_callback` may not be nil")
233
+ end
234
+
235
+ Interop::request_to_native_lib(
236
+ ctx,
237
+ "processing.process_message",
238
+ params.to_h.to_json,
239
+ client_callback: client_callback,
240
+ is_single_thread_only: false
241
+ ) do |resp|
242
+ if resp.success?
243
+ yield NativeLibResponsetResult.new(
244
+ result: ResultOfProcessMessage.new(
245
+ transaction: resp.result["transaction"],
246
+ out_messages: resp.result["out_messages"],
247
+ decoded: resp.result["decoded"],
248
+ fees: resp.result["fees"]
249
+ )
250
+ )
251
+ else
252
+ yield resp
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,264 @@
1
+ module TonSdk
2
+ module Tvm
3
+
4
+ #
5
+ # types
6
+ #
7
+
8
+ class ExecutionOptions
9
+ attr_reader :blockchain_config, :block_time, :block_lt, :transaction_lt
10
+
11
+ def initialize(blockchain_config: nil, block_time: nil, block_lt: nil, transaction_lt: nil)
12
+ @blockchain_config = blockchain_config
13
+ @block_time = block_time
14
+ @block_lt = block_lt
15
+ @transaction_lt = transaction_lt
16
+ end
17
+ end
18
+
19
+ class AccountForExecutor
20
+ TYPES = [:none, :uninit, :account]
21
+ attr_reader :type_, :boc, :unlimited_balance
22
+
23
+ def new_with_type_none
24
+ @type_ = :none
25
+ end
26
+
27
+ def new_with_type_uninit
28
+ @type_ = :uninit
29
+ end
30
+
31
+ def new_with_type_account(boc:, unlimited_balance: nil)
32
+ @type_ = :account
33
+ @boc = boc
34
+ @unlimited_balance = unlimited_balance
35
+ end
36
+
37
+ def to_h
38
+ h1 = case @type_
39
+ when :none, :uninit
40
+ {
41
+ type: Helper.sym_to_capitalized_case_str(@type_),
42
+ }
43
+ when :account
44
+ {
45
+ type: Helper.sym_to_capitalized_case_str(@type_),
46
+ boc: @boc,
47
+ unlimited_balance: @unlimited_balance
48
+ }
49
+ end
50
+ end
51
+ end
52
+
53
+ class ParamsOfRunExecutor
54
+ attr_reader :message, :account, :execution_options, :abi, :skip_transaction_check,
55
+ :boc_cache, :return_updated_account
56
+
57
+ def initialize(
58
+ message:,
59
+ account:,
60
+ execution_options: nil,
61
+ abi: nil,
62
+ skip_transaction_check: nil,
63
+ boc_cache: nil,
64
+ return_updated_account: nil
65
+ )
66
+ @message = message
67
+ @account = account
68
+ @execution_options = execution_options
69
+ @abi = abi
70
+ @skip_transaction_check = skip_transaction_check
71
+ @boc_cache = boc_cache
72
+ @return_updated_account = return_updated_account
73
+ end
74
+
75
+ def to_h
76
+ abi_val = @abi.nil? ? nil : @abi.to_h
77
+ exe_opt_val = @execution_options.nil? ? nil : @execution_options.to_h
78
+ boc_cache_val = @boc_cache.nil? ? nil : @boc_cache.to_h
79
+
80
+ {
81
+ message: @message,
82
+ account: @account.to_h,
83
+ execution_options: exe_opt_val,
84
+ abi: abi_val,
85
+ skip_transaction_check: @skip_transaction_check,
86
+ boc_cache: boc_cache_val,
87
+ return_updated_account: @return_updated_account
88
+ }
89
+ end
90
+ end
91
+
92
+ class ResultOfRunExecutor
93
+ attr_reader :transaction, :out_messages, :decoded, :account, :fees
94
+
95
+ def initialize(transaction:, out_messages:, decoded: nil, account:, fees:)
96
+ @transaction = transaction
97
+ @out_messages = out_messages
98
+ @decoded = decoded
99
+ @account = account
100
+ @fees = fees
101
+ end
102
+ end
103
+
104
+ class ParamsOfRunTvm
105
+ attr_reader :message, :account, :execution_options, :abi,
106
+ :boc_cache, :return_updated_account
107
+
108
+ def initialize(message:, account:, execution_options: nil, abi: nil, boc_cache: nil, return_updated_account: nil)
109
+ @message = message
110
+ @account = account
111
+ @execution_options = execution_options
112
+ @abi = abi
113
+ @boc_cache = boc_cache
114
+ @return_updated_account = return_updated_account
115
+ end
116
+
117
+ def to_h
118
+ abi_val = @abi.nil? ? nil : @abi.to_h
119
+ exe_opt_val = @execution_options.nil? ? nil : @execution_options.to_h
120
+ boc_cache_val = @boc_cache.nil? ? nil : @boc_cache.to_h
121
+
122
+ {
123
+ message: @message,
124
+ account: @account,
125
+ execution_options: exe_opt_val,
126
+ abi: abi_val,
127
+ boc_cache: boc_cache_val,
128
+ return_updated_account: @return_updated_account
129
+ }
130
+ end
131
+ end
132
+
133
+ class ResultOfRunTvm
134
+ attr_reader :out_messages, :decoded, :account
135
+
136
+ def initialize(out_messages:, decoded: nil, account:)
137
+ @out_messages = out_messages
138
+ @decoded = decoded
139
+ @account = account
140
+ end
141
+ end
142
+
143
+ class ParamsOfRunGet
144
+ attr_reader :account, :function_name, :input, :execution_options
145
+
146
+ def initialize(account:, function_name:, input: nil, execution_options: nil)
147
+ @account = account
148
+ @function_name = function_name
149
+ @input = input
150
+ @execution_options = execution_options
151
+ end
152
+
153
+ def to_h
154
+ exe_opt_val = @execution_options.nil? ? nil : @execution_options.to_h
155
+
156
+ {
157
+ account: @account,
158
+ function_name: @function_name,
159
+ input: @input,
160
+ execution_options: exe_opt_val
161
+ }
162
+ end
163
+ end
164
+
165
+ class ResultOfRunGet
166
+ attr_reader :output
167
+
168
+ def initialize(a)
169
+ @output = a
170
+ end
171
+ end
172
+
173
+ class TransactionFees
174
+ attr_reader :in_msg_fwd_fee, :storage_fee, :gas_fee, :out_msgs_fwd_fee,
175
+ :total_account_fees
176
+
177
+ def initialize(in_msg_fwd_fee:, storage_fee: , gas_fee:, out_msgs_fwd_fee:,
178
+ total_account_fees:, total_output:
179
+ )
180
+ @in_msg_fwd_fee = in_msg_fwd_fee
181
+ @storage_fee = storage_fee
182
+ @gas_fee = gas_fee
183
+ @out_msgs_fwd_fee = out_msgs_fwd_fee
184
+ @total_account_fees = total_account_fees
185
+ @total_output = total_output
186
+ end
187
+
188
+ def to_h
189
+ {
190
+ in_msg_fwd_fee: @in_msg_fwd_fee,
191
+ storage_fee: @storage_fee,
192
+ gas_fee: @gas_fee,
193
+ out_msgs_fwd_fee: @out_msgs_fwd_fee,
194
+ total_account_fees: @total_account_fees,
195
+ total_output: @total_output
196
+ }
197
+ end
198
+ end
199
+
200
+ def self.run_executor(ctx, params)
201
+ pr_json = params.to_h.to_json
202
+ Interop::request_to_native_lib(
203
+ ctx,
204
+ "tvm.run_executor",
205
+ pr_json,
206
+ is_single_thread_only: false
207
+ ) do |resp|
208
+ if resp.success?
209
+ yield NativeLibResponsetResult.new(
210
+ result: ResultOfRunExecutor.new(
211
+ transaction: resp.result["transaction"],
212
+ out_messages: resp.result["out_messages"],
213
+ decoded: resp.result["decoded"],
214
+ account: resp.result["account"],
215
+ fees: resp.result["fees"]
216
+ )
217
+ )
218
+ else
219
+ yield resp
220
+ end
221
+ end
222
+ end
223
+
224
+ def self.run_tvm(ctx, params)
225
+ pr_json = params.to_h.to_json
226
+ Interop::request_to_native_lib(
227
+ ctx,
228
+ "tvm.run_tvm",
229
+ pr_json,
230
+ is_single_thread_only: false
231
+ ) do |resp|
232
+ if resp.success?
233
+ yield NativeLibResponsetResult.new(
234
+ result: ResultOfRunTvm.new(
235
+ out_messages: resp.result["out_messages"],
236
+ decoded: resp.result["decoded"],
237
+ account: resp.result["account"]
238
+ )
239
+ )
240
+ else
241
+ yield resp
242
+ end
243
+ end
244
+ end
245
+
246
+ def self.run_get(ctx, params)
247
+ pr_json = params.to_h.to_json
248
+ Interop::request_to_native_lib(
249
+ ctx,
250
+ "tvm.run_get",
251
+ pr_json,
252
+ is_single_thread_only: false
253
+ ) do |resp|
254
+ if resp.success?
255
+ yield NativeLibResponsetResult.new(
256
+ result: ResultOfRunGet.new(resp.result["output"])
257
+ )
258
+ else
259
+ yield resp
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end