sequence-sdk 1.5.2 → 2.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,28 +9,27 @@ module Sequence
9
9
  # @private
10
10
  class Stats < ResponseObject
11
11
  # @!attribute [r] flavor_count
12
- # The number of flavors in the ledger.
12
+ # The number of flavors in the ledger.
13
13
  # @return [Integer]
14
14
  attrib :flavor_count
15
15
 
16
- # @!attribute [r] asset_count
17
- # Deprecated. Use {#flavor_count} instead.
18
- # The number of assets in the ledger.
19
- # @return [Integer]
20
- attrib :asset_count
21
-
22
16
  # @!attribute [r] account_count
23
- # The number of accounts in the ledger.
17
+ # The number of accounts in the ledger.
24
18
  # @return [Integer]
25
19
  attrib :account_count
26
20
 
27
21
  # @!attribute [r] tx_count
28
- # The number of transactions in the ledger.
22
+ # The number of transactions in the ledger.
29
23
  # @return [Integer]
30
24
  attrib :tx_count
31
25
 
26
+ # @!attribute [r] ledger_type
27
+ # The ledger type. Value can be 'dev' or 'prod'.
28
+ # @return [Integer]
29
+ attrib :ledger_type
30
+
32
31
  class ClientModule < Sequence::ClientModule
33
- # Gets stats from the ledger.
32
+ # Get stats from the ledger.
34
33
  # @return [Stats]
35
34
  def get
36
35
  Stats.new(client.session.request('stats'))
@@ -8,39 +8,40 @@ module Sequence
8
8
  # More info: {https://dashboard.seq.com/docs/tokens}
9
9
  module Token
10
10
  class ClientModule < Sequence::ClientModule
11
- # @param [Hash] opts
12
- # Options hash.
13
- # @option opts [String] filter
11
+ # Execute a query, returning an enumerable over tokens.
12
+ # @param filter [String]
14
13
  # A filter expression.
15
- # @option opts [Array<String|Integer>] filter_params
14
+ # @param filter_params [Array<String|Integer>]
16
15
  # A list of values that will be interpolated into the filter expression.
17
16
  # @return [Query]
18
- def list(opts = {})
19
- validate_inclusion_of!(
20
- opts,
21
- :filter,
22
- :filter_params,
23
- )
24
- GroupQuery.new(client, opts)
17
+ # @example List all tokens after a certain time
18
+ # ledger.tokens.list(
19
+ # filter: 'timestamp > $1',
20
+ # filter_params: ['1985-10-26T01:21:00Z']
21
+ # ).each do |token|
22
+ # puts 'amount: ' + token.amount
23
+ # puts 'flavor_id: ' + token.flavor_id
24
+ # puts 'account_id: ' + token.account_id
25
+ # end
26
+ def list(filter: nil, filter_params: nil)
27
+ GroupQuery.new(client, filter: filter, filter_params: filter_params)
25
28
  end
26
29
 
27
- # @param [Hash] opts
28
- # Options hash.
29
- # @option opts [String] filter
30
+ # Execute a query, returning an enumerable over sums of tokens.
31
+ # @param filter [String]
30
32
  # A filter expression.
31
- # @option opts [Array<String|Integer>] filter_params
33
+ # @param filter_params [Array<String|Integer>]
32
34
  # A list of values that will be interpolated into the filter expression.
33
- # @option opts [Array<String>] group_by
35
+ # @param group_by [Array<String>]
34
36
  # A list of token fields to be summed.
35
37
  # @return [Query]
36
- def sum(opts = {})
37
- validate_inclusion_of!(
38
- opts,
39
- :filter,
40
- :filter_params,
41
- :group_by,
38
+ def sum(filter: nil, filter_params: nil, group_by: nil)
39
+ SumQuery.new(
40
+ client,
41
+ filter: filter,
42
+ filter_params: filter_params,
43
+ group_by: group_by,
42
44
  )
43
- SumQuery.new(client, opts)
44
45
  end
45
46
  end
46
47
 
@@ -5,7 +5,6 @@ require 'securerandom'
5
5
  require_relative './client_module'
6
6
  require_relative './query'
7
7
  require_relative './response_object'
8
- require_relative './validations'
9
8
 
10
9
  module Sequence
11
10
  # A transaction is an atomic update to the state of the ledger. Transactions
@@ -27,25 +26,13 @@ module Sequence
27
26
  # @return [Integer]
28
27
  attrib :sequence_number
29
28
 
30
- # @!attribute [r] reference_data
31
- # Deprecated. Use {Sequence::Action#tags} instead.
32
- # User-specified key-value data embedded into the transaction.
33
- # @return [Hash]
34
- attrib :reference_data
35
-
36
29
  # @!attribute [r] actions
37
30
  # List of actions taken by the transaction.
38
31
  # @return [Array<Action>]
39
32
  attrib(:actions) { |raw| raw.map { |v| Action.new(v) } }
40
33
 
41
- # @!attribute [r] contracts
42
- # Deprecated. Use {Token::ClientModule#list} instead.
43
- # List of contracts created by the transaction.
44
- # @return [Array<Contract>]
45
- attrib(:contracts) { |raw| raw.map { |v| Contract.new(v) } }
46
-
47
34
  class ClientModule < Sequence::ClientModule
48
- # Builds, signs, and submits a transaction.
35
+ # Build, sign, and submit a transaction.
49
36
  # @param [Builder] builder
50
37
  # Builder object with actions defined. If provided, overrides block
51
38
  # parameter.
@@ -62,41 +49,14 @@ module Sequence
62
49
  )
63
50
  end
64
51
 
65
- # @deprecated Use list instead.
66
- # Executes a query, returning an enumerable over individual transactions.
67
- # @param [Hash] opts Options hash
68
- # @option opts [String] filter
69
- # A filter expression.
70
- # @option opts [Array<String|Integer>] filter_params
71
- # A list of values that will be interpolated into the filter expression.
72
- # @option opts [Integer] start_time
73
- # A Unix timestamp in milliseconds of the earliest transaction timestamp
74
- # to include in the query results.
75
- # @option opts [Integer] end_time
76
- # A Unix timestamp in milliseconds of the most recent transaction
77
- # timestamp to include in the query results.
78
- # @option opts [Integer>] page_size
79
- # Deprecated. Use list.page(size: size) instead.
80
- # The number of items to return in the result set.
81
- # @return [Query]
82
- def query(opts = {})
83
- Query.new(client, opts)
84
- end
85
-
86
- # Executes a query, returning an enumerable over individual transactions.
87
- # @param [Hash] opts Options hash
88
- # @option opts [String] filter
52
+ # Execute a query, returning an enumerable over individual transactions.
53
+ # @param filter [String]
89
54
  # A filter expression.
90
- # @option opts [Array<String|Integer>] filter_params
55
+ # @param filter_params [Array<String|Integer>]
91
56
  # A list of values that will be interpolated into the filter expression.
92
57
  # @return [Query]
93
- def list(opts = {})
94
- validate_inclusion_of!(
95
- opts,
96
- :filter,
97
- :filter_params,
98
- )
99
- Query.new(client, opts)
58
+ def list(filter: nil, filter_params: nil)
59
+ Query.new(client, filter: filter, filter_params: filter_params)
100
60
  end
101
61
  end
102
62
 
@@ -112,11 +72,6 @@ module Sequence
112
72
 
113
73
  # A configuration object for creating and submitting transactions.
114
74
  class Builder
115
- include Sequence::Validations
116
-
117
- # @deprecated Use {Sequence::Action#tags} instead.
118
- attr_accessor :reference_data
119
-
120
75
  def initialize(&block)
121
76
  yield(self) if block
122
77
  end
@@ -126,17 +81,14 @@ module Sequence
126
81
  end
127
82
 
128
83
  def to_h
129
- {
130
- actions: actions,
131
- reference_data: reference_data,
132
- }
84
+ { actions: actions }
133
85
  end
134
86
 
135
87
  def to_json(opts = nil)
136
88
  to_h.to_json(opts)
137
89
  end
138
90
 
139
- # Adds an action to a transaction builder.
91
+ # Add an action to a transaction builder.
140
92
  # @param [Hash] opts
141
93
  # Action parameters.
142
94
  # @return [Builder]
@@ -148,205 +100,107 @@ module Sequence
148
100
  self
149
101
  end
150
102
 
151
- # Issues new tokens to a destination account.
152
- #
153
- # @param [Hash] opts
154
- # Options hash
155
- # @option opts [Integer] :amount
103
+ # Issue new tokens to a destination account.
104
+ # @param amount [Integer]
156
105
  # Amount of the flavor to be issued.
157
- # @option opts [String] :flavor_id
106
+ # @param flavor_id [String]
158
107
  # ID of the flavor to be issued.
159
- # @option opts [String] :asset_id
160
- # Deprecated. Use :flavor_id instead.
161
- # ID of the asset to be issued. You must specify either an ID or an
162
- # alias.
163
- # @option opts [String] :asset_alias
164
- # Deprecated. Use :flavor_id instead.
165
- # Asset alias of the asset to be issued. You must specify either an ID
166
- # or an alias.
167
- # @option opts [String] :destination_account_id
168
- # ID of the account receiving the flavor units. You must specify a
169
- # destination account ID or alias.
170
- # @option opts [String] :destination_account_alias
171
- # Deprecated. Use :destination_account_id instead.
172
- # Alias of the account receiving the asset units. You must specify a
173
- # destination account ID or alias.
174
- # @option opts [Hash] :token_tags
108
+ # @param destination_account_id [String]
109
+ # ID of the account receiving the flavor units.
110
+ # @param token_tags [Hash]
175
111
  # Tags to add to the receiving tokens.
176
- # @option opts [Hash] :action_tags
112
+ # @param action_tags [Hash]
177
113
  # Tags to add to the action.
178
- # @option opts [Hash] :reference_data
179
- # Deprecated. Use :token_tags or :action_tags instead.
180
- # Reference data for the action.
181
114
  # @return [Builder]
182
- def issue(opts = {})
183
- validate_inclusion_of!(
184
- opts,
185
- :amount,
186
- :flavor_id,
187
- :asset_id,
188
- :asset_alias,
189
- :destination_account_id,
190
- :destination_account_alias,
191
- :token_tags,
192
- :action_tags,
193
- :reference_data,
194
- )
195
- validate_either!(opts, :flavor_id, :asset_id, :asset_alias)
196
- validate_either!(
197
- opts,
198
- :destination_account_id,
199
- :destination_account_alias,
115
+ def issue(
116
+ amount:,
117
+ flavor_id:,
118
+ destination_account_id:,
119
+ token_tags: {},
120
+ action_tags: {}
121
+ )
122
+ add_action(
123
+ type: :issue,
124
+ amount: amount,
125
+ flavor_id: flavor_id,
126
+ destination_account_id: destination_account_id,
127
+ token_tags: token_tags,
128
+ action_tags: action_tags,
200
129
  )
201
- add_action(opts.merge(type: :issue))
202
130
  end
203
131
 
204
- # Moves tokens from a source (an account or contract) to a
205
- # destination account.
206
- #
207
- # @param [Hash] opts
208
- # Options hash
209
- # @option opts [Integer] :amount
132
+ # Move tokens from a source account to a destination account.
133
+ # @param amount [Integer]
210
134
  # Amount of the flavor to be transferred.
211
- # @option opts [String] :flavor_id
135
+ # @param flavor_id [String]
212
136
  # ID of the flavor to be transferred.
213
- # @option opts [String] :asset_id
214
- # Deprecated. Use :flavor_id instead.
215
- # ID of the asset to be transferred. You must specify either an ID or an
216
- # alias.
217
- # @option opts [String] filter
137
+ # @param source_account_id [String]
138
+ # ID of the account serving as the source of flavor units.
139
+ # @param destination_account_id [String]
140
+ # ID of the account receiving the flavor units.
141
+ # @param filter [String]
218
142
  # Token filter string. See {https://dashboard.seq.com/docs/filters}.
219
- # @option opts [Array<String|Integer>] filter_params
143
+ # @param filter_params [Array<String|Integer>]
220
144
  # A list of parameter values for filter string (if needed).
221
- # @option opts [String] :asset_alias
222
- # Deprecated. Use :flavor_id instead.
223
- # Asset alias of the asset to be transferred. You must specify either an
224
- # ID or an alias.
225
- # @option opts [String] :source_account_id
226
- # ID of the account serving as the source of flavor units. You must
227
- # specify a source account ID, account alias, or contract ID.
228
- # @option opts [String] :source_account_alias
229
- # Deprecated. Use :source_account_id instead.
230
- # Alias of the account serving as the source of asset units You must
231
- # specify a source account ID, account alias, or contract ID.
232
- # @option opts [String] :source_contract_id
233
- # ID of the contract serving as the source of flavor units. You must
234
- # specify a source account ID, account alias, or contract ID.
235
- # @option opts [String] :destination_account_id
236
- # ID of the account receiving the flavor units. You must specify a
237
- # destination account ID or alias.
238
- # @option opts [String] :destination_account_alias
239
- # Deprecated. Use :destination_account_id instead.
240
- # Alias of the account receiving the asset units. You must specify a
241
- # destination account ID or alias.
242
- # @option opts [Hash] :token_tags
145
+ # @param token_tags [Hash]
243
146
  # Tags to add to the receiving tokens.
244
- # @option opts [Hash] :action_tags
147
+ # @param action_tags [Hash]
245
148
  # Tags to add to the action.
246
- # @option opts [Hash] :reference_data
247
- # Deprecated. Use :token_tags or :action_tags instead.
248
- # reference data for the action.
249
- # @option opts [Hash] :change_reference_data
250
- # Deprecated. This happens automatically when using token tags.
251
- # reference data for the change contract.
252
149
  # @return [Builder]
253
- def transfer(opts = {})
254
- validate_inclusion_of!(
255
- opts,
256
- :amount,
257
- :flavor_id,
258
- :filter,
259
- :filter_params,
260
- :asset_id,
261
- :asset_alias,
262
- :source_account_id,
263
- :source_account_alias,
264
- :source_contract_id,
265
- :destination_account_id,
266
- :destination_account_alias,
267
- :token_tags,
268
- :action_tags,
269
- :reference_data,
270
- :change_reference_data,
271
- )
272
- validate_either!(opts, :flavor_id, :asset_id, :asset_alias)
273
- validate_either!(
274
- opts,
275
- :source_account_id,
276
- :source_account_alias,
277
- :source_contract_id,
150
+ def transfer(
151
+ amount:,
152
+ flavor_id:,
153
+ source_account_id:,
154
+ destination_account_id:,
155
+ filter: nil,
156
+ filter_params: nil,
157
+ token_tags: {},
158
+ action_tags: {}
159
+ )
160
+ add_action(
161
+ type: :transfer,
162
+ amount: amount,
163
+ flavor_id: flavor_id,
164
+ source_account_id: source_account_id,
165
+ destination_account_id: destination_account_id,
166
+ filter: filter,
167
+ filter_params: filter_params,
168
+ token_tags: token_tags,
169
+ action_tags: action_tags,
278
170
  )
279
- validate_either!(
280
- opts,
281
- :destination_account_id,
282
- :destination_account_alias,
283
- )
284
- add_action(opts.merge(type: :transfer))
285
171
  end
286
172
 
287
- # Takes tokens from a source (an account or contract) and
288
- # retires them.
289
- #
290
- # @param [Hash] opts Options hash
291
- # @option opts [Integer] :amount
173
+ # Take tokens from a source account and retire them.
174
+ # @param amount [Integer]
292
175
  # Amount of the flavor to be retired.
293
- # @option opts [String] :flavor_id
176
+ # @param flavor_id [String]
294
177
  # ID of the flavor to be retired.
295
- # @option opts [String] filter
178
+ # @param source_account_id [String]
179
+ # ID of the account serving as the source of flavor units.
180
+ # @param filter [String]
296
181
  # Token filter string. See {https://dashboard.seq.com/docs/filters}.
297
- # @option opts [Array<String|Integer>] filter_params
182
+ # @param filter_params [Array<String|Integer>]
298
183
  # A list of parameter values for filter string (if needed).
299
- # @option opts [String] :asset_id
300
- # Deprecated. Use :flavor_id instead.
301
- # ID of the asset to be retired. You must specify either an ID or an
302
- # alias.
303
- # @option opts [String] :asset_alias
304
- # Deprecated. Use :flavor_id instead.
305
- # Asset alias of the asset to be retired. You must specify either an ID
306
- # or an alias.
307
- # @option opts [String] :source_account_id
308
- # ID of the account serving as the source of flavor units. You must
309
- # specify a source account ID, account alias, or contract ID.
310
- # @option opts [String] :source_account_alias
311
- # Deprecated. Use :source_account_id instead.
312
- # Alias of the account serving as the source of asset units You must
313
- # specify a source account ID, account alias, or contract ID.
314
- # @option opts [String] :source_contract_id
315
- # ID of the contract serving as the source of flavor units. You must
316
- # specify a source account ID, account alias, or contract ID.
317
- # @option opts [Hash] :action_tags
184
+ # @param action_tags [Hash]
318
185
  # Tags to add to the action.
319
- # @option opts [Hash] :reference_data
320
- # Deprecated. Use :token_tags or :action_tags instead.
321
- # Reference data for the action.
322
- # @option opts [Hash] :change_reference_data
323
- # Deprecated. This happens automatically when using token tags.
324
- # Reference data for the change contract.
325
186
  # @return [Builder]
326
- def retire(opts = {})
327
- validate_inclusion_of!(
328
- opts,
329
- :amount,
330
- :flavor_id,
331
- :filter,
332
- :filter_params,
333
- :asset_id,
334
- :asset_alias,
335
- :source_account_id,
336
- :source_account_alias,
337
- :source_contract_id,
338
- :action_tags,
339
- :reference_data,
340
- :change_reference_data,
341
- )
342
- validate_either!(opts, :flavor_id, :asset_id, :asset_alias)
343
- validate_either!(
344
- opts,
345
- :source_account_id,
346
- :source_account_alias,
347
- :source_contract_id,
187
+ def retire(
188
+ amount:,
189
+ flavor_id:,
190
+ source_account_id:,
191
+ filter: nil,
192
+ filter_params: nil,
193
+ action_tags: {}
194
+ )
195
+ add_action(
196
+ type: :retire,
197
+ amount: amount,
198
+ flavor_id: flavor_id,
199
+ source_account_id: source_account_id,
200
+ filter: filter,
201
+ filter_params: filter_params,
202
+ action_tags: action_tags,
348
203
  )
349
- add_action(opts.merge(type: :retire))
350
204
  end
351
205
  end
352
206
  end