sequence-sdk 1.2.0 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7b66d906a04f01900203dc177533f0553b9a50c8
4
- data.tar.gz: 71e07a3fd57e6ef1139883bfa2028dc1ffe983af
2
+ SHA256:
3
+ metadata.gz: e09d4689bbc276d717124a3bc897d1a39fb8d2615f42e6ef5b034dd83baa2b9c
4
+ data.tar.gz: 2c045c5197ca3fadf832f94db50bdfd5d7644f403c1c6c02d048b01570c30033
5
5
  SHA512:
6
- metadata.gz: a8e2b3b1d2203f6dec039726340dcb4eb6e36b4625923ac1f861e8a00b1bcc972979dab084a6266b118e4ad5d6fcec47b12aa9c1339dd3413c52d6ef0b6fadd8
7
- data.tar.gz: 7ff33dc5a42c4be3e5552071095f458082ccdeaf3c5fda1765301e3c5cbf362b566b5b7a60f62fc57d2f8489bb876ad0935930a95da7983aac86f4b894e75075
6
+ metadata.gz: 787a26b9b6d8a199ba3a22e665a3ef670bcf35427c36b83289b0406a07db2aa494847b558f5800dd4941879d51aaba15d91289902e511314c7a782be2d3cf143
7
+ data.tar.gz: 9e54a051eff305522130abf1073720ce3b0dedf1e4def79d0a4435fddab759c9ac60429948ac4db486b253f1dd83c81bc3767fe07b8e5ffb6fb97b291030cb8b
data/README.md CHANGED
@@ -14,7 +14,7 @@ for the language's schedule for security and bug fixes.
14
14
  Add the following to your `Gemfile`:
15
15
 
16
16
  ```ruby
17
- gem 'sequence-sdk', '~> 1.2.0'
17
+ gem 'sequence-sdk', '~> 1.3.0'
18
18
  ```
19
19
 
20
20
  ### In your code
@@ -94,6 +94,7 @@ module Sequence
94
94
  # @option opts [Array<String|Integer>] filter_params
95
95
  # A list of values that will be interpolated into the filter expression.
96
96
  # @option opts [Integer>] page_size
97
+ # Deprecated. Use list.page(size: size) instead.
97
98
  # The number of items to return in the result set.
98
99
  # @return [Query]
99
100
  def query(opts = {})
@@ -106,6 +107,24 @@ module Sequence
106
107
  )
107
108
  Query.new(client, opts)
108
109
  end
110
+
111
+ # Filters accounts.
112
+ #
113
+ # @param [Hash] opts
114
+ # Options hash
115
+ # @option opts [String] filter
116
+ # A filter expression.
117
+ # @option opts [Array<String|Integer>] filter_params
118
+ # A list of values that will be interpolated into the filter expression.
119
+ # @return [Query]
120
+ def list(opts = {})
121
+ validate_inclusion_of!(
122
+ opts,
123
+ :filter,
124
+ :filter_params,
125
+ )
126
+ Query.new(client, opts)
127
+ end
109
128
  end
110
129
 
111
130
  class Query < Sequence::Query
@@ -45,8 +45,9 @@ module Sequence
45
45
  attrib :flavor_id
46
46
 
47
47
  # @!attribute [r] snapshot
48
- # A copy of the associated tags (flavor, source account, and destination
49
- # account) as they existed at the time of the transaction.
48
+ # A copy of the associated tags (flavor, source account, destination
49
+ # account, action, and token) as they existed at the time of the
50
+ # transaction.
50
51
  # @return [Hash]
51
52
  attrib :snapshot
52
53
 
@@ -6,6 +6,7 @@ module Sequence
6
6
  # A summation of contract amounts. Contracts are selected using a filter, and
7
7
  # their values are summed using the common values of one or more contract
8
8
  # fields.
9
+ # @deprecated Use {Token::ClientModule#sum} instead.
9
10
  class Balance < ResponseObject
10
11
  # @!attribute [r] amount
11
12
  # Summation of contract amounts.
@@ -7,6 +7,7 @@ require_relative './dev_utils'
7
7
  require_relative './flavor'
8
8
  require_relative './key'
9
9
  require_relative './stats'
10
+ require_relative './token'
10
11
  require_relative './transaction'
11
12
 
12
13
  module Sequence
@@ -76,6 +77,11 @@ module Sequence
76
77
  @keys ||= Key::ClientModule.new(self)
77
78
  end
78
79
 
80
+ # @return [Token::ClientModule]
81
+ def tokens
82
+ @tokens ||= Token::ClientModule.new(self)
83
+ end
84
+
79
85
  # @return [Transaction::ClientModule]
80
86
  def transactions
81
87
  @transactions ||= Transaction::ClientModule.new(self)
@@ -4,6 +4,7 @@ require_relative './query'
4
4
 
5
5
  module Sequence
6
6
  # An entry in the ledger that contains value that can be spent.
7
+ # @deprecated Use {Token::ClientModule#list} instead.
7
8
  class Contract < ResponseObject
8
9
  # @!attribute [r] id
9
10
  # A unique ID.
@@ -55,7 +55,6 @@ module Sequence
55
55
  if opts[:keys].nil? || opts[:keys].empty?
56
56
  raise ArgumentError, ':keys must be provided'
57
57
  end
58
- opts = { client_token: SecureRandom.uuid }.merge(opts)
59
58
  Flavor.new(client.session.request('create-flavor', opts))
60
59
  end
61
60
 
@@ -69,7 +68,7 @@ module Sequence
69
68
  # @return [void]
70
69
  def update_tags(opts = {})
71
70
  validate_inclusion_of!(opts, :id, :tags)
72
- if (opts[:id].nil? || opts[:id].empty?)
71
+ if opts[:id].nil? || opts[:id].empty?
73
72
  raise ArgumentError, ':id must be provided'
74
73
  end
75
74
  client.session.request('update-flavor-tags', opts)
@@ -88,8 +87,6 @@ module Sequence
88
87
  opts,
89
88
  :filter,
90
89
  :filter_params,
91
- :page_size,
92
- :after,
93
90
  )
94
91
  Query.new(client, opts)
95
92
  end
@@ -26,9 +26,9 @@ module Sequence
26
26
 
27
27
  attr_accessor :dis_macaroon
28
28
 
29
- def initialize(host, macaroon, opts = {})
29
+ def initialize(base_url, macaroon, opts = {})
30
30
  @mutex = Mutex.new
31
- @host = URI(host)
31
+ @base_url = URI(base_url)
32
32
  @macaroon = macaroon
33
33
  @dis_macaroon = nil
34
34
  @opts = opts
@@ -114,13 +114,7 @@ module Sequence
114
114
  end
115
115
 
116
116
  def setup_connection
117
- args = [@host.hostname, @host.port]
118
-
119
- # Override host+port for local development.
120
- env_addr = ENV['SEQADDR']
121
- if env_addr
122
- args = (env_addr.split(':') + [nil])[0...2]
123
- end
117
+ args = [@base_url.hostname, @base_url.port]
124
118
 
125
119
  # Proxy configuration
126
120
  if @opts.key?(:proxy_addr)
@@ -41,12 +41,20 @@ module Sequence
41
41
  # @option opts [Array<String>] ids
42
42
  # A list of ids of keys to retrieve.
43
43
  # @option opts [Integer>] page_size
44
+ # Deprecated. Use list.page(size: size) instead.
44
45
  # The number of items to return in the result set.
45
46
  # @return [Query]
46
47
  def query(opts = {})
47
48
  validate_inclusion_of!(opts, :aliases, :ids, :page_size, :after)
48
49
  Query.new(client, opts)
49
50
  end
51
+
52
+ # Lists all keys.
53
+ # Executes a query, returning an enumerable over individual keys.
54
+ # @return [Query]
55
+ def list
56
+ Query.new(client)
57
+ end
50
58
  end
51
59
 
52
60
  class Query < Sequence::Query
@@ -3,18 +3,26 @@ require_relative './response_object'
3
3
  module Sequence
4
4
  # @private
5
5
  class Page < ResponseObject
6
+ include ::Enumerable
7
+
6
8
  # @!attribute [r] items
7
9
  # List of items.
8
10
  # @return [Array]
9
11
  attrib :items
10
12
 
11
13
  # @!attribute [r] next
12
- # Query object to request next page of items
14
+ # Deprecated. Use {#cursor} instead.
15
+ # Query object to request next page of items.
13
16
  # @return [Hash]
14
17
  attrib :next
15
18
 
19
+ # @!attribute [r] cursor
20
+ # String encoding the query object to request the next page of items.
21
+ # @return [String]
22
+ attrib :cursor
23
+
16
24
  # @!attribute [r] last_page
17
- # Indicator of whether there are more pages to load
25
+ # Indicator of whether there are more pages to load.
18
26
  # @return [Boolean]
19
27
  attrib :last_page
20
28
 
@@ -22,5 +30,11 @@ module Sequence
22
30
  super(raw_attribs)
23
31
  @items = @items.map { |i| translate.call(i) }
24
32
  end
33
+
34
+ def each
35
+ @items.to_a.each do |item|
36
+ yield item
37
+ end
38
+ end
25
39
  end
26
40
  end
@@ -3,6 +3,7 @@ require_relative './page'
3
3
  module Sequence
4
4
  class Query
5
5
  include ::Enumerable
6
+ include Sequence::Validations
6
7
 
7
8
  # @private
8
9
  # @return [Client]
@@ -48,6 +49,15 @@ module Sequence
48
49
  PageQuery.new(client, query, method(:fetch), method(:translate))
49
50
  end
50
51
 
52
+ def page(opts = {})
53
+ validate_inclusion_of!(opts, :size, :cursor)
54
+ unless opts[:size].nil? || opts[:size].zero?
55
+ opts[:page_size] = opts.delete(:size)
56
+ end
57
+ @query = @query.merge(opts)
58
+ pages.page
59
+ end
60
+
51
61
  # @private
52
62
  class PageQuery
53
63
  include ::Enumerable
@@ -76,6 +86,10 @@ module Sequence
76
86
  end
77
87
  end
78
88
 
89
+ def page
90
+ Page.new(@fetch.call(@query), @translate)
91
+ end
92
+
79
93
  alias_method :all, :to_a
80
94
  end
81
95
  end
@@ -9,8 +9,6 @@ module Sequence
9
9
  class Session
10
10
  def initialize(opts)
11
11
  @opts = opts
12
- @host = @opts[:host] || 'https://api.seq.com'
13
- @session_host = @opts[:session_host] || 'https://session-api.seq.com'
14
12
  @ledger = @opts[:ledger_name] || raise(ArgumentError, "missing ledger_name")
15
13
  @macaroon = @opts[:credential] || raise(ArgumentError, "missing credential")
16
14
 
@@ -32,8 +30,9 @@ module Sequence
32
30
  end
33
31
  end
34
32
 
35
- @session_api = HttpWrapper.new(@session_host, nil)
36
- @ledger_api = HttpWrapper.new(@host, @macaroon, @opts)
33
+ addr = ENV['SEQADDR'] || 'api.seq.com'
34
+ @session_api = HttpWrapper.new('https://session-' + addr, nil)
35
+ @ledger_api = HttpWrapper.new('https://' + addr, @macaroon, @opts)
37
36
  end
38
37
 
39
38
  def dup
@@ -0,0 +1,134 @@
1
+ require_relative './client_module'
2
+ require_relative './response_object'
3
+ require_relative './query'
4
+
5
+ module Sequence
6
+ # More info: {https://dashboard.seq.com/docs/tokens}
7
+ module Token
8
+ class ClientModule < Sequence::ClientModule
9
+ # @param [Hash] opts
10
+ # Options hash.
11
+ # @option opts [String] filter
12
+ # A filter expression.
13
+ # @option opts [Array<String|Integer>] filter_params
14
+ # A list of values that will be interpolated into the filter expression.
15
+ # @return [Query]
16
+ def list(opts = {})
17
+ validate_inclusion_of!(
18
+ opts,
19
+ :filter,
20
+ :filter_params,
21
+ )
22
+ GroupQuery.new(client, opts)
23
+ end
24
+
25
+ # @param [Hash] opts
26
+ # Options hash.
27
+ # @option opts [String] filter
28
+ # A filter expression.
29
+ # @option opts [Array<String|Integer>] filter_params
30
+ # A list of values that will be interpolated into the filter expression.
31
+ # @option opts [Array<String>] group_by
32
+ # A list of token fields to be summed.
33
+ # @return [Query]
34
+ def sum(opts = {})
35
+ validate_inclusion_of!(
36
+ opts,
37
+ :filter,
38
+ :filter_params,
39
+ :group_by,
40
+ )
41
+ SumQuery.new(client, opts)
42
+ end
43
+ end
44
+
45
+ class GroupQuery < Sequence::Query
46
+ def fetch(query)
47
+ client.session.request('list-tokens', query)
48
+ end
49
+
50
+ def translate(raw)
51
+ Group.new(raw)
52
+ end
53
+ end
54
+
55
+ class Group < Sequence::ResponseObject
56
+ # @!attribute [r] amount
57
+ # The amount of tokens in the group.
58
+ # @return [Integer]
59
+ attrib :amount
60
+
61
+ # @!attribute [r] flavor_id
62
+ # The flavor of the tokens in the group.
63
+ # @return [String]
64
+ attrib :flavor_id
65
+
66
+ # @!attribute [r] flavor_tags
67
+ # The tags of the flavor of the tokens in the group.
68
+ # @return [Hash]
69
+ attrib :flavor_tags
70
+
71
+ # @!attribute [r] account_id
72
+ # The account containing the tokens.
73
+ # @return [String]
74
+ attrib :account_id
75
+
76
+ # @!attribute [r] account_tags
77
+ # The tags of the account containing the tokens.
78
+ # @return [Hash]
79
+ attrib :account_tags
80
+
81
+ # @!attribute [r] tags
82
+ # The tags of the tokens in the group.
83
+ # @return [Hash]
84
+ attrib :tags
85
+ end
86
+
87
+ class SumQuery < Sequence::Query
88
+ def fetch(query)
89
+ client.session.request('sum-tokens', query)
90
+ end
91
+
92
+ def translate(raw)
93
+ Sum.new(raw)
94
+ end
95
+ end
96
+
97
+ class Sum < Sequence::ResponseObject
98
+ # @!attribute [r] amount
99
+ # The amount of tokens in the group.
100
+ # @return [Integer]
101
+ attrib :amount
102
+
103
+ # @!attribute [r] flavor_id
104
+ # The flavor of the tokens in the group.
105
+ # Is nil unless included in `group_by` request parameter.
106
+ # @return [String]
107
+ attrib :flavor_id
108
+
109
+ # @!attribute [r] flavor_tags
110
+ # The tags of the flavor of the tokens in the group.
111
+ # Is nil unless included in `group_by` request parameter.
112
+ # @return [Hash]
113
+ attrib :flavor_tags
114
+
115
+ # @!attribute [r] account_id
116
+ # The account containing the tokens.
117
+ # Is nil unless included in `group_by` request parameter.
118
+ # @return [String]
119
+ attrib :account_id
120
+
121
+ # @!attribute [r] account_tags
122
+ # The tags of the account containing the tokens.
123
+ # Is nil unless included in `group_by` request parameter.
124
+ # @return [Hash]
125
+ attrib :account_tags
126
+
127
+ # @!attribute [r] tags
128
+ # The tags of the tokens in the group.
129
+ # Is nil unless included in `group_by` request parameter.
130
+ # @return [Hash]
131
+ attrib :tags
132
+ end
133
+ end
134
+ end
@@ -25,6 +25,12 @@ module Sequence
25
25
  # @return [Integer]
26
26
  attrib :sequence_number
27
27
 
28
+ # @!attribute [r] token_tags
29
+ # User specified, unstructured data embedded within a token
30
+ # (possibly null).
31
+ # @return [Hash]
32
+ attrib :token_tags
33
+
28
34
  # @!attribute [r] reference_data
29
35
  # User-specified key-value data embedded into the transaction.
30
36
  # @return [Hash]
@@ -76,11 +82,28 @@ module Sequence
76
82
  # A Unix timestamp in milliseconds of the most recent transaction
77
83
  # timestamp to include in the query results.
78
84
  # @option opts [Integer>] page_size
85
+ # Deprecated. Use list.page(size: size) instead.
79
86
  # The number of items to return in the result set.
80
87
  # @return [Query]
81
88
  def query(opts = {})
82
89
  Query.new(client, opts)
83
90
  end
91
+
92
+ # Executes a query, returning an enumerable over individual transactions.
93
+ # @param [Hash] opts Options hash
94
+ # @option opts [String] filter
95
+ # A filter expression.
96
+ # @option opts [Array<String|Integer>] filter_params
97
+ # A list of values that will be interpolated into the filter expression.
98
+ # @return [Query]
99
+ def list(opts = {})
100
+ validate_inclusion_of!(
101
+ opts,
102
+ :filter,
103
+ :filter_params,
104
+ )
105
+ Query.new(client, opts)
106
+ end
84
107
  end
85
108
 
86
109
  class Query < Sequence::Query
@@ -107,8 +130,9 @@ module Sequence
107
130
  attrib :flavor_id
108
131
 
109
132
  # @!attribute [r] snapshot
110
- # A copy of the associated tags (flavor, source account, and destination
111
- # account) as they existed at the time of the transaction.
133
+ # A copy of the associated tags (flavor, source account, destination
134
+ # account, action, and token) as they existed at the time of the
135
+ # transaction.
112
136
  # @return [Hash]
113
137
  attrib :snapshot
114
138
 
@@ -241,6 +265,8 @@ module Sequence
241
265
  # Deprecated. Use :destination_account_id instead.
242
266
  # Alias of the account receiving the asset units. You must specify a
243
267
  # destination account ID or alias.
268
+ # @option opts [Hash] :token_tags
269
+ # Tags to add to the receiving tokens.
244
270
  # @option opts [Hash] :reference_data
245
271
  # Reference data for the action.
246
272
  # @return [Builder]
@@ -253,6 +279,7 @@ module Sequence
253
279
  :asset_alias,
254
280
  :destination_account_id,
255
281
  :destination_account_alias,
282
+ :token_tags,
256
283
  :reference_data,
257
284
  )
258
285
  validate_either!(opts, :flavor_id, :asset_id, :asset_alias)
@@ -277,6 +304,10 @@ module Sequence
277
304
  # Deprecated. Use :flavor_id instead.
278
305
  # ID of the asset to be transferred. You must specify either an ID or an
279
306
  # alias.
307
+ # @option opts [String] filter
308
+ # Token filter string. See {https://dashboard.seq.com/docs/filters}.
309
+ # @option opts [Array<String|Integer>] filter_params
310
+ # A list of parameter values for filter string (if needed).
280
311
  # @option opts [String] :asset_alias
281
312
  # Deprecated. Use :flavor_id instead.
282
313
  # Asset alias of the asset to be transferred. You must specify either an
@@ -298,9 +329,12 @@ module Sequence
298
329
  # Deprecated. Use :destination_account_id instead.
299
330
  # Alias of the account receiving the asset units. You must specify a
300
331
  # destination account ID or alias.
332
+ # @option opts [Hash] :token_tags
333
+ # Tags to add to the receiving tokens.
301
334
  # @option opts [Hash] :reference_data
302
335
  # reference data for the action.
303
336
  # @option opts [Hash] :change_reference_data
337
+ # Deprecated. This happens automatically when using token tags.
304
338
  # reference data for the change contract.
305
339
  # @return [Builder]
306
340
  def transfer(opts = {})
@@ -308,6 +342,8 @@ module Sequence
308
342
  opts,
309
343
  :amount,
310
344
  :flavor_id,
345
+ :filter,
346
+ :filter_params,
311
347
  :asset_id,
312
348
  :asset_alias,
313
349
  :source_account_id,
@@ -315,6 +351,7 @@ module Sequence
315
351
  :source_contract_id,
316
352
  :destination_account_id,
317
353
  :destination_account_alias,
354
+ :token_tags,
318
355
  :reference_data,
319
356
  :change_reference_data,
320
357
  )
@@ -341,6 +378,10 @@ module Sequence
341
378
  # Amount of the flavor to be retired.
342
379
  # @option opts [String] :flavor_id
343
380
  # ID of the flavor to be retired.
381
+ # @option opts [String] filter
382
+ # Token filter string. See {https://dashboard.seq.com/docs/filters}.
383
+ # @option opts [Array<String|Integer>] filter_params
384
+ # A list of parameter values for filter string (if needed).
344
385
  # @option opts [String] :asset_id
345
386
  # Deprecated. Use :flavor_id instead.
346
387
  # ID of the asset to be retired. You must specify either an ID or an
@@ -362,6 +403,7 @@ module Sequence
362
403
  # @option opts [Hash] :reference_data
363
404
  # Reference data for the action.
364
405
  # @option opts [Hash] :change_reference_data
406
+ # Deprecated. This happens automatically when using token tags.
365
407
  # Reference data for the change contract.
366
408
  # @return [Builder]
367
409
  def retire(opts = {})
@@ -369,6 +411,8 @@ module Sequence
369
411
  opts,
370
412
  :amount,
371
413
  :flavor_id,
414
+ :filter,
415
+ :filter_params,
372
416
  :asset_id,
373
417
  :asset_alias,
374
418
  :source_account_id,
@@ -1,3 +1,3 @@
1
1
  module Sequence
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chain Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-16 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: SDK for Sequence
14
14
  email:
@@ -36,6 +36,7 @@ files:
36
36
  - lib/sequence/response_object.rb
37
37
  - lib/sequence/session.rb
38
38
  - lib/sequence/stats.rb
39
+ - lib/sequence/token.rb
39
40
  - lib/sequence/transaction.rb
40
41
  - lib/sequence/validations.rb
41
42
  - lib/sequence/version.rb
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  version: '0'
60
61
  requirements: []
61
62
  rubyforge_project:
62
- rubygems_version: 2.6.13
63
+ rubygems_version: 2.7.6
63
64
  signing_key:
64
65
  specification_version: 4
65
66
  summary: SDK for Sequence