sequence-sdk 1.5.2 → 2.pre.rc.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.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/lib/sequence/account.rb +31 -104
- data/lib/sequence/action.rb +15 -80
- data/lib/sequence/client.rb +24 -34
- data/lib/sequence/client_module.rb +0 -4
- data/lib/sequence/errors.rb +0 -4
- data/lib/sequence/feed.rb +28 -31
- data/lib/sequence/flavor.rb +29 -55
- data/lib/sequence/http_wrapper.rb +10 -13
- data/lib/sequence/key.rb +6 -36
- data/lib/sequence/page.rb +0 -6
- data/lib/sequence/query.rb +7 -20
- data/lib/sequence/session.rb +6 -45
- data/lib/sequence/stats.rb +9 -10
- data/lib/sequence/token.rb +24 -23
- data/lib/sequence/transaction.rb +84 -230
- data/lib/sequence/version.rb +1 -1
- metadata +131 -11
- data/lib/sequence/asset.rb +0 -119
- data/lib/sequence/balance.rb +0 -59
- data/lib/sequence/contract.rb +0 -104
- data/lib/sequence/validations.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa8125eb52fe8dbf7b905442ded7cae137c144161723ec224fffde4640dee208
|
4
|
+
data.tar.gz: 283e350688c0bea9a07c375ae6502743f0ceb50442a2a9398bc2673604c67736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3209b59c2b9e36a8c8e9e19926a923c23080cb31d46bed62425e2d4bde804b1924889caa3c4c8d0242e91c2d7622bd129ef44be388f6bbf8633a195b465737
|
7
|
+
data.tar.gz: c1d1a73d56753146d5c78788743d553cd0c74975d133bad62ea8586787b5fc3d87efddd47a78a7feb53bece656643eb4b3d069f18fff2f8c3c5af4316bf0df16
|
data/README.md
CHANGED
@@ -7,14 +7,14 @@
|
|
7
7
|
The Ruby SDK is available
|
8
8
|
[via Rubygems](https://rubygems.org/gems/sequence-sdk).
|
9
9
|
|
10
|
-
Ruby >= 2.
|
10
|
+
Ruby >= 2.3 is required. See
|
11
11
|
[Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/)
|
12
12
|
for the language's schedule for security and bug fixes.
|
13
13
|
|
14
14
|
Add the following to your `Gemfile`:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'sequence-sdk', '~> 1
|
17
|
+
gem 'sequence-sdk', '~> 2-rc.1'
|
18
18
|
```
|
19
19
|
|
20
20
|
### In your code
|
data/lib/sequence/account.rb
CHANGED
@@ -6,32 +6,20 @@ require_relative './query'
|
|
6
6
|
require_relative './response_object'
|
7
7
|
|
8
8
|
module Sequence
|
9
|
-
#
|
9
|
+
# An account is an object in Sequence that tracks ownership of tokens on a
|
10
|
+
# blockchain by creating and tracking control programs.
|
10
11
|
class Account < ResponseObject
|
11
12
|
# @!attribute [r] id
|
12
|
-
# Unique
|
13
|
+
# Unique identifier of the account.
|
13
14
|
# @return [String]
|
14
15
|
attrib :id
|
15
16
|
|
16
|
-
# @!attribute [r] alias
|
17
|
-
# Deprecated. Use {#id} instead.
|
18
|
-
# Unique, user-specified identifier.
|
19
|
-
# @return [String]
|
20
|
-
attrib :alias
|
21
|
-
|
22
17
|
# @!attribute [r] key_ids
|
23
18
|
# The set of key IDs used for signing transactions that spend from the
|
24
19
|
# account.
|
25
20
|
# @return [Array<String>]
|
26
21
|
attrib(:key_ids)
|
27
22
|
|
28
|
-
# @!attribute [r] keys
|
29
|
-
# Deprecated. Use {#key_ids} instead.
|
30
|
-
# The set of keys used for signing transactions that spend from the
|
31
|
-
# account.
|
32
|
-
# @return [Array<Key>]
|
33
|
-
attrib(:keys) { |raw| raw.map { |k| Key.new(k) } }
|
34
|
-
|
35
23
|
# @!attribute [r] quorum
|
36
24
|
# The number of keys required to sign transactions that spend from the
|
37
25
|
# account.
|
@@ -43,115 +31,54 @@ module Sequence
|
|
43
31
|
# @return [Hash]
|
44
32
|
attrib :tags
|
45
33
|
|
46
|
-
# @deprecated Use {#key_ids} instead.
|
47
34
|
class Key < ResponseObject
|
48
35
|
attrib :id
|
49
|
-
attrib :alias
|
50
36
|
end
|
51
37
|
|
52
38
|
class ClientModule < Sequence::ClientModule
|
53
|
-
#
|
54
|
-
# @param [
|
55
|
-
# Options hash
|
56
|
-
# @option opts [String] id
|
57
|
-
# Unique, user-specified identifier.
|
58
|
-
# @option opts [String] alias
|
59
|
-
# Deprecated. Use :id instead.
|
60
|
-
# Unique, user-specified identifier.
|
61
|
-
# @option opts [Array<String>] key_ids
|
39
|
+
# Create a new account in the ledger.
|
40
|
+
# @param key_ids [Array<String>]
|
62
41
|
# The key IDs used for signing transactions that spend from the account.
|
63
|
-
# @
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# key can be either a key object, or a hash containing either an `id` or
|
67
|
-
# `alias` field.
|
68
|
-
# @option opts [Integer] quorum
|
42
|
+
# @param id [String]
|
43
|
+
# Unique identifier. Auto-generated if not specified.
|
44
|
+
# @param quorum [Integer]
|
69
45
|
# The number of keys required to sign transactions that spend from the
|
70
46
|
# account. Defaults to the number of keys provided.
|
71
|
-
# @
|
47
|
+
# @param tags [Hash]
|
72
48
|
# User-specified key-value data describing the account.
|
73
49
|
# @return [Account]
|
74
|
-
def create(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
50
|
+
def create(key_ids:, id: nil, quorum: nil, tags: nil)
|
51
|
+
raise ArgumentError, ':key_ids cannot be empty' if key_ids == []
|
52
|
+
Account.new(
|
53
|
+
client.session.request(
|
54
|
+
'create-account',
|
55
|
+
id: id,
|
56
|
+
key_ids: key_ids,
|
57
|
+
quorum: quorum,
|
58
|
+
tags: tags,
|
59
|
+
),
|
83
60
|
)
|
84
|
-
if (opts[:key_ids].nil? || opts[:key_ids].empty?) &&
|
85
|
-
(opts[:keys].nil? || opts[:keys].empty?)
|
86
|
-
raise(
|
87
|
-
ArgumentError,
|
88
|
-
':key_ids or :keys (but not both) must be provided',
|
89
|
-
)
|
90
|
-
end
|
91
|
-
Account.new(client.session.request('create-account', opts))
|
92
61
|
end
|
93
62
|
|
94
|
-
#
|
95
|
-
# @param [
|
96
|
-
#
|
97
|
-
# @
|
98
|
-
# The ID of the account. Either an ID or alias should be provided, but
|
99
|
-
# not both.
|
100
|
-
# @option opts [String] alias
|
101
|
-
# Deprecated. Use :id instead.
|
102
|
-
# The alias of the account. Either an ID or alias should be provided,
|
103
|
-
# but not both.
|
104
|
-
# @option opts [Hash] tags
|
63
|
+
# Update an account's tags.
|
64
|
+
# @param id [String]
|
65
|
+
# The ID of the account.
|
66
|
+
# @param tags [Hash]
|
105
67
|
# A new set of tags, which will replace the existing tags.
|
106
68
|
# @return [void]
|
107
|
-
def update_tags(
|
108
|
-
|
109
|
-
|
110
|
-
(opts[:alias].nil? || opts[:alias].empty?)
|
111
|
-
raise ArgumentError, ':id or :alias (but not both) must be provided'
|
112
|
-
end
|
113
|
-
client.session.request('update-account-tags', opts)
|
69
|
+
def update_tags(id:, tags: nil)
|
70
|
+
raise ArgumentError, ':id cannot be blank' if id == ''
|
71
|
+
client.session.request('update-account-tags', id: id, tags: tags)
|
114
72
|
end
|
115
73
|
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# @param [Hash] opts
|
119
|
-
# Options hash
|
120
|
-
# @option opts [String] filter
|
74
|
+
# Filter accounts.
|
75
|
+
# @param filter [String]
|
121
76
|
# A filter expression.
|
122
|
-
# @
|
77
|
+
# @param filter_params [Array<String|Integer>]
|
123
78
|
# A list of values that will be interpolated into the filter expression.
|
124
|
-
# @option opts [Integer>] page_size
|
125
|
-
# Deprecated. Use list.page(size: size) instead.
|
126
|
-
# The number of items to return in the result set.
|
127
79
|
# @return [Query]
|
128
|
-
def
|
129
|
-
|
130
|
-
opts,
|
131
|
-
:filter,
|
132
|
-
:filter_params,
|
133
|
-
:page_size,
|
134
|
-
:after,
|
135
|
-
)
|
136
|
-
Query.new(client, opts)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Filters accounts.
|
140
|
-
#
|
141
|
-
# @param [Hash] opts
|
142
|
-
# Options hash
|
143
|
-
# @option opts [String] filter
|
144
|
-
# A filter expression.
|
145
|
-
# @option opts [Array<String|Integer>] filter_params
|
146
|
-
# A list of values that will be interpolated into the filter expression.
|
147
|
-
# @return [Query]
|
148
|
-
def list(opts = {})
|
149
|
-
validate_inclusion_of!(
|
150
|
-
opts,
|
151
|
-
:filter,
|
152
|
-
:filter_params,
|
153
|
-
)
|
154
|
-
Query.new(client, opts)
|
80
|
+
def list(filter: nil, filter_params: nil)
|
81
|
+
Query.new(client, filter: filter, filter_params: filter_params)
|
155
82
|
end
|
156
83
|
end
|
157
84
|
|
data/lib/sequence/action.rb
CHANGED
@@ -53,79 +53,27 @@ module Sequence
|
|
53
53
|
# @return [Hash]
|
54
54
|
attrib :snapshot, snapshot: true
|
55
55
|
|
56
|
-
# @!attribute [r] asset_id
|
57
|
-
# Deprecated. Use {#flavor_id} instead.
|
58
|
-
# The ID of the asset held by the action.
|
59
|
-
# @return [String]
|
60
|
-
attrib :asset_id
|
61
|
-
|
62
|
-
# @!attribute [r] asset_alias
|
63
|
-
# Deprecated. Use {#flavor_id} instead.
|
64
|
-
# The alias of the asset held by the action.
|
65
|
-
# @return [String]
|
66
|
-
attrib :asset_alias
|
67
|
-
|
68
|
-
# @!attribute [r] asset_tags
|
69
|
-
# Deprecated. Use {#snapshot} instead.
|
70
|
-
# The tags of the asset held by the action.
|
71
|
-
# @return [Hash]
|
72
|
-
attrib :asset_tags
|
73
|
-
|
74
56
|
# @!attribute [r] source_account_id
|
75
57
|
# The ID of the source account executing the action.
|
76
58
|
# @return [String]
|
77
59
|
attrib :source_account_id
|
78
60
|
|
79
|
-
# @!attribute [r] source_account_alias
|
80
|
-
# Deprecated. Use {#source_account_id} instead.
|
81
|
-
# The alias of the source account executing the action.
|
82
|
-
# @return [String]
|
83
|
-
attrib :source_account_alias
|
84
|
-
|
85
|
-
# @!attribute [r] source_account_tags
|
86
|
-
# Deprecated. Use {#snapshot} instead.
|
87
|
-
# The tags of the source account executing the action.
|
88
|
-
# @return [Hash]
|
89
|
-
attrib :source_account_tags
|
90
|
-
|
91
61
|
# @!attribute [r] destination_account_id
|
92
62
|
# The ID of the destination account affected by the action.
|
93
63
|
# @return [String]
|
94
64
|
attrib :destination_account_id
|
95
65
|
|
96
|
-
# @!attribute [r] destination_account_alias
|
97
|
-
# Deprecated. Use {#destination_account_id} instead.
|
98
|
-
# The alias of the destination account affected by the action.
|
99
|
-
# @return [String]
|
100
|
-
attrib :destination_account_alias
|
101
|
-
|
102
|
-
# @!attribute [r] destination_account_tags
|
103
|
-
# Deprecated. Use {#snapshot} instead.
|
104
|
-
# The tags of the destination account affected by the action.
|
105
|
-
# @return [Hash]
|
106
|
-
attrib :destination_account_tags
|
107
|
-
|
108
66
|
# @!attribute [r] tags
|
109
67
|
# User-specified key-value data embedded in the action.
|
110
68
|
# @return [Hash]
|
111
69
|
attrib :tags
|
112
70
|
|
113
|
-
# @!attribute [r] reference_data
|
114
|
-
# Deprecated. Use {#tags} instead.
|
115
|
-
# User-specified key-value data embedded in the action.
|
116
|
-
# @return [Hash]
|
117
|
-
attrib :reference_data
|
118
|
-
|
119
71
|
class ClientModule < Sequence::ClientModule
|
120
|
-
#
|
121
|
-
# @param [
|
122
|
-
# Options hash
|
123
|
-
# @option opts [String] filter
|
72
|
+
# Execute a query, returning an enumerable over individual actions.
|
73
|
+
# @param filter [String]
|
124
74
|
# A filter expression.
|
125
|
-
# @
|
75
|
+
# @param filter_params [Array<String|Integer>]
|
126
76
|
# A list of values that will be interpolated into the filter expression.
|
127
|
-
# @option opts [Integer>] page_size
|
128
|
-
# The number of items to return in the result set.
|
129
77
|
# @return [Query]
|
130
78
|
# @example List all actions after a certain time
|
131
79
|
# ledger.actions.list(
|
@@ -135,38 +83,25 @@ module Sequence
|
|
135
83
|
# puts 'timestamp: ' + action.timestamp
|
136
84
|
# puts 'amount: ' + action.amount
|
137
85
|
# end
|
138
|
-
def list(
|
139
|
-
|
140
|
-
opts,
|
141
|
-
:filter,
|
142
|
-
:filter_params,
|
143
|
-
:page_size,
|
144
|
-
:after,
|
145
|
-
)
|
146
|
-
ListQuery.new(client, opts)
|
86
|
+
def list(filter: nil, filter_params: nil)
|
87
|
+
ListQuery.new(client, filter: filter, filter_params: filter_params)
|
147
88
|
end
|
148
89
|
|
149
|
-
#
|
150
|
-
# @param [
|
151
|
-
# Options hash
|
152
|
-
# @option opts [String] filter
|
90
|
+
# Execute a query, returning an enumerable over sums of actions.
|
91
|
+
# @param filter [String]
|
153
92
|
# A filter expression.
|
154
|
-
# @
|
93
|
+
# @param filter_params [Array<String|Integer>]
|
155
94
|
# A list of values that will be interpolated into the filter expression.
|
156
|
-
# @
|
95
|
+
# @param group_by [Array<String>]
|
157
96
|
# A list of fields along which action values will be summed.
|
158
|
-
# @option opts [Integer>] page_size
|
159
|
-
# The number of items to return in the result set.
|
160
97
|
# @return [Query]
|
161
|
-
def sum(
|
162
|
-
|
163
|
-
|
164
|
-
:filter,
|
165
|
-
:filter_params,
|
166
|
-
:group_by,
|
167
|
-
:page_size,
|
98
|
+
def sum(filter: nil, filter_params: nil, group_by: nil)
|
99
|
+
SumQuery.new(
|
100
|
+
client,
|
101
|
+
filter: filter,
|
102
|
+
filter_params: filter_params,
|
103
|
+
group_by: group_by,
|
168
104
|
)
|
169
|
-
SumQuery.new(client, opts)
|
170
105
|
end
|
171
106
|
end
|
172
107
|
|
data/lib/sequence/client.rb
CHANGED
@@ -2,12 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative './account'
|
4
4
|
require_relative './action'
|
5
|
-
require_relative './asset'
|
6
|
-
require_relative './balance'
|
7
|
-
require_relative './contract'
|
8
5
|
require_relative './dev_utils'
|
9
6
|
require_relative './feed'
|
10
7
|
require_relative './flavor'
|
8
|
+
require_relative './http_wrapper'
|
11
9
|
require_relative './key'
|
12
10
|
require_relative './stats'
|
13
11
|
require_relative './token'
|
@@ -15,28 +13,29 @@ require_relative './transaction'
|
|
15
13
|
|
16
14
|
module Sequence
|
17
15
|
class Client
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# @
|
16
|
+
# Set up a Sequence client.
|
17
|
+
# This is the entry point for all other Sequence interaction.
|
18
|
+
# @param ledger_name [String]
|
21
19
|
# Ledger name.
|
22
|
-
# @
|
23
|
-
# Deprecated. Use :ledger_name instead.
|
24
|
-
# Ledger name.
|
25
|
-
# @option opts [String] credential
|
20
|
+
# @param credential [String]
|
26
21
|
# API credential secret.
|
27
22
|
# @return [Query]
|
28
|
-
def initialize(
|
29
|
-
if
|
30
|
-
raise ArgumentError, ':ledger_name
|
23
|
+
def initialize(ledger_name:, credential:)
|
24
|
+
if ledger_name.nil? || ledger_name == ''
|
25
|
+
raise ArgumentError, ':ledger_name cannot be blank'
|
31
26
|
end
|
32
|
-
if
|
33
|
-
raise ArgumentError, ':credential
|
27
|
+
if credential.nil? || credential == ''
|
28
|
+
raise ArgumentError, ':credential cannot be blank'
|
34
29
|
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
addr = ENV['SEQADDR'] || 'api.seq.com'
|
32
|
+
api = HttpWrapper.new('https://' + addr, credential)
|
33
|
+
@opts = {
|
34
|
+
addr: addr,
|
35
|
+
credential: credential,
|
36
|
+
ledger_name: ledger_name,
|
37
|
+
team_name: team_name(api),
|
38
|
+
}
|
40
39
|
end
|
41
40
|
|
42
41
|
# @private
|
@@ -55,11 +54,6 @@ module Sequence
|
|
55
54
|
@accounts ||= Account::ClientModule.new(self)
|
56
55
|
end
|
57
56
|
|
58
|
-
# @return [Asset::ClientModule]
|
59
|
-
def assets
|
60
|
-
@assets ||= Asset::ClientModule.new(self)
|
61
|
-
end
|
62
|
-
|
63
57
|
# @return [Flavor::ClientModule]
|
64
58
|
def flavors
|
65
59
|
@flavors ||= Flavor::ClientModule.new(self)
|
@@ -70,11 +64,6 @@ module Sequence
|
|
70
64
|
@actions ||= Action::ClientModule.new(self)
|
71
65
|
end
|
72
66
|
|
73
|
-
# @return [Balance::ClientModule]
|
74
|
-
def balances
|
75
|
-
@balances ||= Balance::ClientModule.new(self)
|
76
|
-
end
|
77
|
-
|
78
67
|
# @return [Key::ClientModule]
|
79
68
|
def keys
|
80
69
|
@keys ||= Key::ClientModule.new(self)
|
@@ -95,11 +84,6 @@ module Sequence
|
|
95
84
|
@feeds ||= Feed::ClientModule.new(self)
|
96
85
|
end
|
97
86
|
|
98
|
-
# @return [Contract::ClientModule]
|
99
|
-
def contracts
|
100
|
-
@contracts ||= Contract::ClientModule.new(self)
|
101
|
-
end
|
102
|
-
|
103
87
|
# @private
|
104
88
|
# @return [Stats::ClientModule]
|
105
89
|
def stats
|
@@ -110,5 +94,11 @@ module Sequence
|
|
110
94
|
def dev_utils
|
111
95
|
@dev_utils ||= DevUtils::ClientModule.new(self)
|
112
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def team_name(api)
|
101
|
+
api.post(SecureRandom.hex(10), '/hello', {})[:parsed_body]['team_name']
|
102
|
+
end
|
113
103
|
end
|
114
104
|
end
|