chain-sdk 1.0.4 → 1.1.0
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 +4 -4
- data/README.md +2 -4
- data/lib/chain/access_token.rb +7 -4
- data/lib/chain/account.rb +33 -6
- data/lib/chain/asset.rb +13 -6
- data/lib/chain/balance.rb +7 -3
- data/lib/chain/batch_response.rb +8 -0
- data/lib/chain/config.rb +12 -3
- data/lib/chain/control_program.rb +1 -0
- data/lib/chain/hsm_signer.rb +7 -0
- data/lib/chain/mock_hsm.rb +7 -4
- data/lib/chain/receiver.rb +15 -0
- data/lib/chain/response_object.rb +39 -4
- data/lib/chain/transaction.rb +63 -27
- data/lib/chain/transaction_feed.rb +10 -4
- data/lib/chain/unspent_output.rb +10 -4
- data/lib/chain/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f23f819a849083b45080882adef93353e12d3b
|
4
|
+
data.tar.gz: e88714cdcf76f624b38965d69edb32349aabce1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16129701fb041747f5605831493653076ba29155c1879ebd0a504ea66b98db03053cacc5c8d62603aae60f7dd39756c6521c182c3124c19634a4ec4e9265a6ba
|
7
|
+
data.tar.gz: 4cff47a5f44808ae2592904e6b8a7d2a41032a92bf2a53ef7ec4e28123b889831175a926794d936d4d4c20250e44a3f3b740f2bd2bfa319f51ac2e3a2c71262f
|
data/README.md
CHANGED
@@ -4,14 +4,12 @@
|
|
4
4
|
|
5
5
|
### Get the gem
|
6
6
|
|
7
|
-
The Ruby SDK is available [via Rubygems](https://rubygems.org/gems/chain-sdk). Make sure to use the most recent version whose major and minor components (`major.minor.x`) match your version of Chain Core.
|
8
|
-
|
9
|
-
Ruby 2.0 or greater is required. We strongly recommend upgrading to Ruby 2.1 or greater, as [Ruby 2.0 has reached end-of-life](https://www.ruby-lang.org/en/downloads/branches/) and will no longer receive security updates and bugfixes.
|
7
|
+
The Ruby SDK is available [via Rubygems](https://rubygems.org/gems/chain-sdk). Make sure to use the most recent version whose major and minor components (`major.minor.x`) match your version of Chain Core. Ruby 2.1 or greater is required.
|
10
8
|
|
11
9
|
For most applications, you can simply add the following to your `Gemfile`:
|
12
10
|
|
13
11
|
```
|
14
|
-
gem 'chain-sdk', '~> 1.0
|
12
|
+
gem 'chain-sdk', '~> 1.1.0', require: 'chain'
|
15
13
|
```
|
16
14
|
|
17
15
|
### In your code
|
data/lib/chain/access_token.rb
CHANGED
@@ -23,22 +23,25 @@ module Chain
|
|
23
23
|
# @!attribute [r] created_at
|
24
24
|
# Timestamp of token creation.
|
25
25
|
# @return [Time]
|
26
|
-
attrib
|
26
|
+
attrib :created_at, rfc3339_time: true
|
27
27
|
|
28
28
|
class ClientModule < Chain::ClientModule
|
29
29
|
|
30
30
|
# Create client/network access token.
|
31
31
|
# @param [Hash] opts
|
32
|
-
# @option
|
32
|
+
# @option opts [String] :type Type specifiying the type of access token to be created.
|
33
33
|
# You must specify either 'client' or 'network'.
|
34
|
-
# @option
|
34
|
+
# @option opts [String] :id ID specifying the ID of newly created access token.
|
35
35
|
# You must specify a unique ID for access token.
|
36
36
|
# @return [AccessToken]
|
37
37
|
def create(opts = {})
|
38
38
|
AccessToken.new(client.conn.request('create-access-token', opts))
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
41
|
+
# Get all access tokens sorted by descending creation time,
|
42
|
+
# optionally filtered by type.
|
43
|
+
# @param [Hash] opts Filtering information
|
44
|
+
# @option opts [String] :type Type of access tokens to return; either 'client' or 'network'.
|
42
45
|
# @return [Query]
|
43
46
|
def query(opts = {})
|
44
47
|
Query.new(client, opts)
|
data/lib/chain/account.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative './client_module'
|
|
2
2
|
require_relative './control_program'
|
3
3
|
require_relative './errors'
|
4
4
|
require_relative './query'
|
5
|
+
require_relative './receiver'
|
5
6
|
require_relative './response_object'
|
6
7
|
|
7
8
|
module Chain
|
@@ -34,20 +35,25 @@ module Chain
|
|
34
35
|
attrib :tags
|
35
36
|
|
36
37
|
class ClientModule < Chain::ClientModule
|
37
|
-
# @param [Hash] opts
|
38
|
+
# @param [Hash] opts Options hash specifiying account creation details.
|
39
|
+
# @option opts [String] alias User specified, unique identifier.
|
40
|
+
# @option opts [Array<String>] root_xpubs The list of keys used to create control programs under the account.
|
41
|
+
# @option opts [Integer] quorum The number of keys required to sign transactions for the account.
|
42
|
+
# @option opts [Hash] tags User-specified tag structure for the account.
|
38
43
|
# @return [Account]
|
39
44
|
def create(opts)
|
40
45
|
opts = {client_token: SecureRandom.uuid}.merge(opts)
|
41
46
|
client.conn.singleton_batch_request('create-account', [opts]) { |item| Account.new(item) }
|
42
47
|
end
|
43
48
|
|
44
|
-
# @param [Array<Hash>] opts
|
45
|
-
# @return [
|
49
|
+
# @param [Array<Hash>] opts An array of options hashes. See {#create} for a description of the hash structure.
|
50
|
+
# @return [BatchResponse<Account>]
|
46
51
|
def create_batch(opts)
|
47
52
|
opts = opts.map { |i| {client_token: SecureRandom.uuid}.merge(i) }
|
48
53
|
client.conn.batch_request('create-account', opts) { |item| Account.new(item) }
|
49
54
|
end
|
50
55
|
|
56
|
+
# @deprecated (as of version 1.1) Use {#create_receiver} instead.
|
51
57
|
# @param [Hash] opts
|
52
58
|
# @return [ControlProgram]
|
53
59
|
def create_control_program(opts = {})
|
@@ -63,10 +69,31 @@ module Chain
|
|
63
69
|
) { |item| ControlProgram.new(item) }
|
64
70
|
end
|
65
71
|
|
66
|
-
#
|
72
|
+
# Creates a new receiver under the specified account.
|
73
|
+
#
|
74
|
+
# @param opts [Hash] Options hash
|
75
|
+
# @option opts [String] :account_alias Unique alias for an account. Either account_alias or account_id is required.
|
76
|
+
# @option opts [String] :account_id Unique ID for an account. Either account_alias or account_id is required.
|
77
|
+
# @option opts [String] :expires_at An RFC3339 timestamp indicating when the receiver will expire. Defaults to 30 days in the future.
|
78
|
+
# @return [Receiver]
|
79
|
+
def create_receiver(opts)
|
80
|
+
client.conn.singleton_batch_request('create-account-receiver', [opts]) { |item| Receiver.new(item) }
|
81
|
+
end
|
82
|
+
|
83
|
+
# Creates new receivers under the specified accounts.
|
84
|
+
#
|
85
|
+
# @param opts_list [Array<Hash>] Array of options hashes. See {#create_receiver} for a description of the hash structure.
|
86
|
+
# @return [BatchResponse<Receiver>]
|
87
|
+
def create_receiver_batch(opts_list)
|
88
|
+
client.conn.batch_request('create-account-receiver', opts_list) { |item| Receiver.new(item) }
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param [Hash] opts Filtering information
|
92
|
+
# @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
|
93
|
+
# @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
|
67
94
|
# @return [Query]
|
68
|
-
def query(
|
69
|
-
Query.new(client,
|
95
|
+
def query(opts = {})
|
96
|
+
Query.new(client, opts)
|
70
97
|
end
|
71
98
|
end
|
72
99
|
|
data/lib/chain/asset.rb
CHANGED
@@ -51,24 +51,31 @@ module Chain
|
|
51
51
|
attrib :is_local
|
52
52
|
|
53
53
|
class ClientModule < Chain::ClientModule
|
54
|
-
# @param [Hash] opts
|
54
|
+
# @param [Hash] opts Options hash specifiying asset creation details.
|
55
|
+
# @option opts [String] alias User specified, unique identifier.
|
56
|
+
# @option opts [Array<String>] root_xpubs The list of keys used to create the issuance program for the asset.
|
57
|
+
# @option opts [Integer] quorum The number of keys required to issue units of the asset.
|
58
|
+
# @option opts [Hash] tags User-specified, arbitrary/unstructured data local to the asset's originating core.
|
59
|
+
# @option opts [Hash] definition User-specified, arbitrary/unstructured data visible across blockchain networks.
|
55
60
|
# @return [Asset]
|
56
61
|
def create(opts)
|
57
62
|
opts = {client_token: SecureRandom.uuid}.merge(opts)
|
58
63
|
client.conn.singleton_batch_request('create-asset', [opts]) { |item| Asset.new(item) }
|
59
64
|
end
|
60
65
|
|
61
|
-
# @param [Hash] opts
|
62
|
-
# @return [
|
66
|
+
# @param [Array<Hash>] opts An array of options hashes. See {#create} for a description of the hash structure.
|
67
|
+
# @return [BatchResponse<Asset>]
|
63
68
|
def create_batch(opts)
|
64
69
|
opts = opts.map { |i| {client_token: SecureRandom.uuid}.merge(i) }
|
65
70
|
client.conn.batch_request('create-asset', opts) { |item| Asset.new(item) }
|
66
71
|
end
|
67
72
|
|
68
|
-
# @param [Hash]
|
73
|
+
# @param [Hash] opts Filtering information
|
74
|
+
# @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
|
75
|
+
# @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
|
69
76
|
# @return [Query]
|
70
|
-
def query(
|
71
|
-
Query.new(client,
|
77
|
+
def query(opts = {})
|
78
|
+
Query.new(client, opts)
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
data/lib/chain/balance.rb
CHANGED
@@ -16,10 +16,14 @@ module Chain
|
|
16
16
|
attrib :sum_by
|
17
17
|
|
18
18
|
class ClientModule < Chain::ClientModule
|
19
|
-
# @param [Hash]
|
19
|
+
# @param [Hash] opts Filtering information
|
20
|
+
# @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
|
21
|
+
# @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
|
22
|
+
# @option opts [Array<String>] sum_by List of unspent output attributes to sum by.
|
23
|
+
# @option opts [Integer] timestamp A millisecond Unix timestamp. By using this parameter, you can perform queries that reflect the state of the blockchain at different points in time.
|
20
24
|
# @return [Query]
|
21
|
-
def query(
|
22
|
-
Query.new(client,
|
25
|
+
def query(opts = {})
|
26
|
+
Query.new(client, opts)
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
data/lib/chain/batch_response.rb
CHANGED
data/lib/chain/config.rb
CHANGED
@@ -33,7 +33,7 @@ module Chain
|
|
33
33
|
|
34
34
|
# @!attribute [r] configured_at
|
35
35
|
# @return [Time]
|
36
|
-
attrib
|
36
|
+
attrib :configured_at, rfc3339_time: true
|
37
37
|
|
38
38
|
# @!attribute [r] is_signer
|
39
39
|
# @return [Boolean]
|
@@ -43,7 +43,7 @@ module Chain
|
|
43
43
|
# @return [Boolean]
|
44
44
|
attrib :is_generator
|
45
45
|
|
46
|
-
# @!attribute [r]
|
46
|
+
# @!attribute [r] generator_url
|
47
47
|
# @return [String]
|
48
48
|
attrib :generator_url
|
49
49
|
|
@@ -65,7 +65,7 @@ module Chain
|
|
65
65
|
|
66
66
|
# @!attribute [r] generator_block_height_fetched_at
|
67
67
|
# @return [Time]
|
68
|
-
attrib
|
68
|
+
attrib :generator_block_height_fetched_at, rfc3339_time: true
|
69
69
|
|
70
70
|
# @!attribute [r] is_production
|
71
71
|
# @return [Boolean]
|
@@ -105,16 +105,25 @@ module Chain
|
|
105
105
|
end
|
106
106
|
|
107
107
|
class ClientModule < Chain::ClientModule
|
108
|
+
# Reset specified Chain Core.
|
109
|
+
# @param [Boolean] everything If `true`, all objects including access tokens and MockHSM keys will be deleted. If `false`, then access tokens and MockHSM keys will be preserved.
|
108
110
|
# @return [void]
|
109
111
|
def reset(everything: false)
|
110
112
|
client.conn.request('reset', {everything: everything})
|
111
113
|
end
|
112
114
|
|
115
|
+
# Configure specified Chain Core.
|
116
|
+
# @param [Hash] opts Options for configuring Chain Core.
|
117
|
+
# @option opts [Boolean] is_generator Whether the local core will be a block generator for the blockchain; i.e., you are starting a new blockchain on the local core. `false` if you are connecting to a pre-existing blockchain.
|
118
|
+
# @option opts [String] generator_url A URL for the block generator. Required if `isGenerator` is false.
|
119
|
+
# @option opts [String] generator_access_token A network access token provided by administrators of the block generator. Required if `isGenerator` is false.
|
120
|
+
# @option opts [String] blockchain_id The unique ID of the generator's blockchain. Required if `isGenerator` is false.
|
113
121
|
# @return [void]
|
114
122
|
def configure(opts)
|
115
123
|
client.conn.request('configure', opts)
|
116
124
|
end
|
117
125
|
|
126
|
+
# Get info on specified Chain Core.
|
118
127
|
# @return [Info]
|
119
128
|
def info
|
120
129
|
Info.new(client.conn.request('info'))
|
data/lib/chain/hsm_signer.rb
CHANGED
@@ -10,6 +10,9 @@ module Chain
|
|
10
10
|
@xpubs_by_signer = {}
|
11
11
|
end
|
12
12
|
|
13
|
+
# Add a new key/signer pair to the HSM signer.
|
14
|
+
# @param [MockHsm::Key || String] xpub_or_key An object with an xpub key, or an xpub as a string.
|
15
|
+
# @param [Connection] signer_conn Authenticated connection to a specific HSM instance.
|
13
16
|
def add_key(xpub_or_key, signer_conn)
|
14
17
|
xpub = xpub_or_key.is_a?(MockHSM::Key) ? xpub_or_key.xpub : xpub_or_key
|
15
18
|
@xpubs_by_signer[signer_conn] ||= []
|
@@ -17,6 +20,8 @@ module Chain
|
|
17
20
|
@xpubs_by_signer[signer_conn].uniq!
|
18
21
|
end
|
19
22
|
|
23
|
+
# Sign a single transaction
|
24
|
+
# @param [Hash] tx_template A single transaction template.
|
20
25
|
def sign(tx_template)
|
21
26
|
return tx_template if @xpubs_by_signer.empty?
|
22
27
|
|
@@ -31,6 +36,8 @@ module Chain
|
|
31
36
|
tx_template
|
32
37
|
end
|
33
38
|
|
39
|
+
# Sign a batch of transactions
|
40
|
+
# @param [Array<Hash>] tx_templates Array of transaction templates.
|
34
41
|
def sign_batch(tx_templates)
|
35
42
|
if @xpubs_by_signer.empty?
|
36
43
|
# Treat all templates as if signed successfully.
|
data/lib/chain/mock_hsm.rb
CHANGED
@@ -12,6 +12,7 @@ module Chain
|
|
12
12
|
@keys_module ||= Key::ClientModule.new(client)
|
13
13
|
end
|
14
14
|
|
15
|
+
# MockHSM signer connection.
|
15
16
|
# @return [Connection]
|
16
17
|
def signer_conn
|
17
18
|
return @signer_conn if @signer_conn
|
@@ -37,16 +38,18 @@ module Chain
|
|
37
38
|
class ClientModule < Chain::ClientModule
|
38
39
|
|
39
40
|
# Creates a key object.
|
40
|
-
# @param [Hash] opts
|
41
|
+
# @param [Hash] opts Parameters for MockHSM key creation.
|
42
|
+
# @option opts [String] alias User specified, unique identifier.
|
41
43
|
# @return [Key]
|
42
44
|
def create(opts = {})
|
43
45
|
Key.new(client.conn.request('mockhsm/create-key', opts))
|
44
46
|
end
|
45
47
|
|
46
|
-
# @param [Hash]
|
48
|
+
# @param [Hash] opts Filtering information
|
49
|
+
# @option opts [Array<String>] aliases Optional list of requested aliases, max 200.
|
47
50
|
# @return [Query]
|
48
|
-
def query(
|
49
|
-
Query.new(client,
|
51
|
+
def query(opts = {})
|
52
|
+
Query.new(client, opts)
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './response_object'
|
2
|
+
|
3
|
+
module Chain
|
4
|
+
class Receiver < ResponseObject
|
5
|
+
# @!attribute [r] control_program
|
6
|
+
# The underlying control program that will be used in transactions paying to this receiver.
|
7
|
+
# @return [String]
|
8
|
+
attrib :control_program
|
9
|
+
|
10
|
+
# @!attribute [r] expires_at
|
11
|
+
# A timestamp indicating when the receiver will expire.
|
12
|
+
# @return [Time]
|
13
|
+
attrib :expires_at, rfc3339_time: true
|
14
|
+
end
|
15
|
+
end
|
@@ -18,7 +18,12 @@ module Chain
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_json(opts = nil)
|
21
|
-
to_h.
|
21
|
+
h = to_h.reduce({}) do |memo, (k, v)|
|
22
|
+
memo[k] = self.class.detranslate(k, v)
|
23
|
+
memo
|
24
|
+
end
|
25
|
+
|
26
|
+
h.to_json
|
22
27
|
end
|
23
28
|
|
24
29
|
def [](attrib_name)
|
@@ -41,8 +46,9 @@ module Chain
|
|
41
46
|
end
|
42
47
|
|
43
48
|
# @!visibility private
|
44
|
-
def self.attrib(attrib_name, &translate)
|
45
|
-
|
49
|
+
def self.attrib(attrib_name, opts = {}, &translate)
|
50
|
+
opts[:translate] = translate
|
51
|
+
attrib_opts[attrib_name.to_sym] = opts
|
46
52
|
attr_accessor attrib_name
|
47
53
|
end
|
48
54
|
|
@@ -55,6 +61,8 @@ module Chain
|
|
55
61
|
def self.translate(attrib_name, raw_value)
|
56
62
|
attrib_name = attrib_name.to_sym
|
57
63
|
opts = attrib_opts[attrib_name]
|
64
|
+
|
65
|
+
return Time.parse(raw_value) if opts[:rfc3339_time]
|
58
66
|
return raw_value if opts[:translate].nil?
|
59
67
|
|
60
68
|
begin
|
@@ -64,18 +72,45 @@ module Chain
|
|
64
72
|
end
|
65
73
|
end
|
66
74
|
|
75
|
+
# @!visibility private
|
76
|
+
def self.detranslate(attrib_name, raw_value)
|
77
|
+
opts = attrib_opts.fetch(attrib_name, {})
|
78
|
+
|
79
|
+
if opts[:rfc3339_time]
|
80
|
+
begin
|
81
|
+
return raw_value.to_datetime.rfc3339
|
82
|
+
rescue => e
|
83
|
+
raise DetranslateError.new(attrib_name, raw_value, e)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
raw_value
|
88
|
+
end
|
89
|
+
|
67
90
|
class TranslateError < StandardError
|
68
91
|
attr_reader :attrib_name
|
69
92
|
attr_reader :raw_value
|
70
93
|
attr_reader :source
|
71
94
|
|
72
95
|
def initialize(attrib_name, raw_value, source)
|
73
|
-
super "
|
96
|
+
super "Error translating attrib #{attrib_name}: #{source}"
|
74
97
|
@attrib_name = attrib_name
|
75
98
|
@raw_value = raw_value
|
76
99
|
@source = source
|
77
100
|
end
|
78
101
|
end
|
79
102
|
|
103
|
+
class DetranslateError < StandardError
|
104
|
+
attr_reader :attrib_name
|
105
|
+
attr_reader :raw_value
|
106
|
+
attr_reader :source
|
107
|
+
|
108
|
+
def initialize(attrib_name, raw_value, source)
|
109
|
+
super "Error de-translating attrib #{attrib_name}: #{source}"
|
110
|
+
@attrib_name = attrib_name
|
111
|
+
@raw_value = raw_value
|
112
|
+
@source = source
|
113
|
+
end
|
114
|
+
end
|
80
115
|
end
|
81
116
|
end
|
data/lib/chain/transaction.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'time'
|
3
2
|
|
4
3
|
require_relative './client_module'
|
5
4
|
require_relative './query'
|
@@ -16,7 +15,7 @@ module Chain
|
|
16
15
|
# @!attribute [r] timestamp
|
17
16
|
# Time of transaction.
|
18
17
|
# @return [Time]
|
19
|
-
attrib
|
18
|
+
attrib :timestamp, rfc3339_time: true
|
20
19
|
|
21
20
|
# @!attribute [r] block_id
|
22
21
|
# Unique identifier, or block hash, of the block containing a transaction.
|
@@ -54,9 +53,10 @@ module Chain
|
|
54
53
|
attrib(:outputs) { |raw| raw.map { |v| Output.new(v) } }
|
55
54
|
|
56
55
|
class ClientModule < Chain::ClientModule
|
57
|
-
#
|
58
|
-
# @
|
59
|
-
# @
|
56
|
+
# Build an unsigned transaction from a set of actions.
|
57
|
+
# @param [Builder] builder Builder object with actions defined. If provided, overrides block parameter.
|
58
|
+
# @yield Block defining transaction actions. A {Builder} object is passed as the only parameter.
|
59
|
+
# @return [Template] Unsigned transaction template, or error.
|
60
60
|
def build(builder = nil, &block)
|
61
61
|
if builder.nil?
|
62
62
|
builder = Builder.new(&block)
|
@@ -68,8 +68,9 @@ module Chain
|
|
68
68
|
) { |item| Template.new(item) }
|
69
69
|
end
|
70
70
|
|
71
|
-
#
|
72
|
-
# @
|
71
|
+
# Build multiple unsigned transactions from multiple sets of actions.
|
72
|
+
# @param [Array<Builder>] builders Multiple builder objects with actions defined.
|
73
|
+
# @return [BatchResponse<Template>] Batch of unsigned transaction templates, or errors.
|
73
74
|
def build_batch(builders)
|
74
75
|
client.conn.batch_request(
|
75
76
|
'build-transaction',
|
@@ -77,7 +78,8 @@ module Chain
|
|
77
78
|
) { |item| Template.new(item) }
|
78
79
|
end
|
79
80
|
|
80
|
-
#
|
81
|
+
# Submit a signed transaction to the blockchain.
|
82
|
+
# @param [Template] template Signed transaction template.
|
81
83
|
# @return [SubmitResponse]
|
82
84
|
def submit(template)
|
83
85
|
client.conn.singleton_batch_request(
|
@@ -86,8 +88,9 @@ module Chain
|
|
86
88
|
) { |item| SubmitResponse.new(item) }
|
87
89
|
end
|
88
90
|
|
89
|
-
#
|
90
|
-
# @
|
91
|
+
# Submit multiple signed transactions to the blockchain.
|
92
|
+
# @param [Array<Template>] templates Array of signed transaction templates.
|
93
|
+
# @return [BatchResponse<SubmitResponse>]
|
91
94
|
def submit_batch(templates)
|
92
95
|
client.conn.batch_request(
|
93
96
|
'submit-transaction',
|
@@ -95,10 +98,16 @@ module Chain
|
|
95
98
|
) { |item| SubmitResponse.new(item) }
|
96
99
|
end
|
97
100
|
|
98
|
-
#
|
101
|
+
# List all transactions, optionally filtered
|
102
|
+
# @param [Hash] opts Filtering information
|
103
|
+
# @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
|
104
|
+
# @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
|
105
|
+
# @option opts [Integer] start_time A Unix timestamp in milliseconds. When specified, only transactions with a block time greater than the start time will be returned.
|
106
|
+
# @option opts [Integer] end_time A Unix timestamp in milliseconds. When specified, only transactions with a block time less than the start time will be returned.
|
107
|
+
# @option opts [Integer] timeout A time in milliseconds after which a server timeout should occur. Defaults to 1000 (1 second).
|
99
108
|
# @return [Query]
|
100
|
-
def query(
|
101
|
-
Query.new(client,
|
109
|
+
def query(opts = {})
|
110
|
+
Query.new(client, opts)
|
102
111
|
end
|
103
112
|
end
|
104
113
|
|
@@ -150,6 +159,12 @@ module Chain
|
|
150
159
|
# @return [Integer]
|
151
160
|
attrib :amount
|
152
161
|
|
162
|
+
# @!attribute [r] spent_output_id
|
163
|
+
# The id of the output consumed by this input. ID is nil if this is an issuance input.
|
164
|
+
# @return [String]
|
165
|
+
attrib :spent_output_id
|
166
|
+
|
167
|
+
# @deprecated (as of version 1.1) Use {#spent_output_id} instead.
|
153
168
|
# @!attribute [r] spent_output
|
154
169
|
# The output consumed by this input.
|
155
170
|
# @return [SpentOutput]
|
@@ -172,6 +187,7 @@ module Chain
|
|
172
187
|
# @return [String]
|
173
188
|
attrib :account_tags
|
174
189
|
|
190
|
+
# @deprecated (as of version 1.1) Do not use this field.
|
175
191
|
# @!attribute [r] input_witness
|
176
192
|
# @return [String]
|
177
193
|
attrib :input_witness
|
@@ -182,6 +198,7 @@ module Chain
|
|
182
198
|
# @return [String]
|
183
199
|
attrib :issuance_program
|
184
200
|
|
201
|
+
# @deprecated (as of version 1.1) Do not use this field.
|
185
202
|
# @!attribute [r] control_program
|
186
203
|
# @return [String]
|
187
204
|
attrib :control_program
|
@@ -197,6 +214,7 @@ module Chain
|
|
197
214
|
# @return [Boolean]
|
198
215
|
attrib :is_local
|
199
216
|
|
217
|
+
# @deprecated (as of version 1.1)
|
200
218
|
class SpentOutput < ResponseObject
|
201
219
|
# @!attribute [r] transaction_id
|
202
220
|
# Unique transaction identifier.
|
@@ -211,6 +229,11 @@ module Chain
|
|
211
229
|
end
|
212
230
|
|
213
231
|
class Output < ResponseObject
|
232
|
+
# @!attribute [r] id
|
233
|
+
# The id of the output.
|
234
|
+
# @return [String]
|
235
|
+
attrib :id
|
236
|
+
|
214
237
|
# @!attribute [r] type
|
215
238
|
# The type of the output.
|
216
239
|
#
|
@@ -340,7 +363,7 @@ module Chain
|
|
340
363
|
to_h.to_json(opts)
|
341
364
|
end
|
342
365
|
|
343
|
-
# Add an action to the
|
366
|
+
# Add an action to the transaction builder
|
344
367
|
# @param [Hash] params Action parameters containing a type field and the
|
345
368
|
# required parameters for that type
|
346
369
|
# @return [Builder]
|
@@ -366,7 +389,7 @@ module Chain
|
|
366
389
|
|
367
390
|
# Add an issuance action.
|
368
391
|
# @param [Hash] params Action parameters
|
369
|
-
# @option params [String] :asset_id Asset ID
|
392
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be issued.
|
370
393
|
# You must specify either an ID or an alias.
|
371
394
|
# @option params [String] :asset_alias Asset alias specifying the asset to be issued.
|
372
395
|
# You must specify either an ID or an alias.
|
@@ -378,11 +401,11 @@ module Chain
|
|
378
401
|
|
379
402
|
# Add a spend action taken on a particular account.
|
380
403
|
# @param [Hash] params Action parameters
|
381
|
-
# @option params [String] :asset_id Asset ID
|
404
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be spent.
|
382
405
|
# You must specify either an ID or an alias.
|
383
406
|
# @option params [String] :asset_alias Asset alias specifying the asset to be spent.
|
384
407
|
# You must specify either an ID or an alias.
|
385
|
-
# @option params [String] :account_id Account ID
|
408
|
+
# @option params [String] :account_id Account ID specifying the account spending the asset.
|
386
409
|
# You must specify either an ID or an alias.
|
387
410
|
# @option params [String] :account_alias Account alias specifying the account spending the asset.
|
388
411
|
# You must specify either an ID or an alias.
|
@@ -394,8 +417,9 @@ module Chain
|
|
394
417
|
|
395
418
|
# Add a spend action taken on a particular unspent output.
|
396
419
|
# @param [Hash] params Action parameters
|
397
|
-
# @option params [String] :
|
398
|
-
# @option params [
|
420
|
+
# @option params [String] :output_id Output ID specifying the transaction output to spend.
|
421
|
+
# @option params [String] :transaction_id DEPRECATED (as of version 1.1) Transaction ID specifying the transaction to select an output from.
|
422
|
+
# @option params [Integer] :position DEPRECATED (as of version 1.1) Position of the output within the transaction to be spent.
|
399
423
|
# @return [Builder]
|
400
424
|
def spend_account_unspent_output(params)
|
401
425
|
add_action(params.merge(type: :spend_account_unspent_output))
|
@@ -403,11 +427,11 @@ module Chain
|
|
403
427
|
|
404
428
|
# Add a control action taken on a particular account.
|
405
429
|
# @param [Hash] params Action parameters
|
406
|
-
# @option params [String] :asset_id Asset ID
|
430
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be controlled.
|
407
431
|
# You must specify either an ID or an alias.
|
408
432
|
# @option params [String] :asset_alias Asset alias specifying the asset to be controlled.
|
409
433
|
# You must specify either an ID or an alias.
|
410
|
-
# @option params [String] :account_id Account ID
|
434
|
+
# @option params [String] :account_id Account ID specifying the account controlling the asset.
|
411
435
|
# You must specify either an ID or an alias.
|
412
436
|
# @option params [String] :account_alias Account alias specifying the account controlling the asset.
|
413
437
|
# You must specify either an ID or an alias.
|
@@ -417,9 +441,24 @@ module Chain
|
|
417
441
|
add_action(params.merge(type: :control_account))
|
418
442
|
end
|
419
443
|
|
444
|
+
# Sends assets to the specified receiver.
|
445
|
+
#
|
446
|
+
# @param [Hash] params Action parameters
|
447
|
+
# @option params [Receiver] :control_program the receiver object.
|
448
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be controlled.
|
449
|
+
# You must specify either an ID or an alias.
|
450
|
+
# @option params [String] :asset_alias Asset alias specifying the asset to be controlled.
|
451
|
+
# You must specify either an ID or an alias.
|
452
|
+
# @option params [Integer] :amount amount of the asset to be controlled.
|
453
|
+
# @return [Builder]
|
454
|
+
def control_with_receiver(params)
|
455
|
+
add_action(params.merge(type: :control_receiver))
|
456
|
+
end
|
457
|
+
|
458
|
+
# @deprecated (as of version 1.1) Use {#control_with_receiver} instead.
|
420
459
|
# Add a control action taken on a control program.
|
421
460
|
# @param [Hash] params Action parameters
|
422
|
-
# @option params [String] :asset_id Asset ID
|
461
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be controlled.
|
423
462
|
# You must specify either an ID or an alias.
|
424
463
|
# @option params [String] :asset_alias Asset alias specifying the asset to be controlled.
|
425
464
|
# You must specify either an ID or an alias.
|
@@ -432,17 +471,14 @@ module Chain
|
|
432
471
|
|
433
472
|
# Add a retire action.
|
434
473
|
# @param [Hash] params Action parameters
|
435
|
-
# @option params [String] :asset_id Asset ID
|
474
|
+
# @option params [String] :asset_id Asset ID specifying the asset to be retired.
|
436
475
|
# You must specify either an ID or an alias.
|
437
476
|
# @option params [String] :asset_alias Asset alias specifying the asset to be retired.
|
438
477
|
# You must specify either an ID or an alias.
|
439
478
|
# @option params [Integer] :amount Amount of the asset to be retired.
|
440
479
|
# @return [Builder]
|
441
480
|
def retire(params)
|
442
|
-
add_action(params.merge(
|
443
|
-
type: :control_program,
|
444
|
-
control_program: '6a'
|
445
|
-
))
|
481
|
+
add_action(params.merge(type: :retire))
|
446
482
|
end
|
447
483
|
end
|
448
484
|
|
@@ -82,15 +82,20 @@ module Chain
|
|
82
82
|
|
83
83
|
class ClientModule < Chain::ClientModule
|
84
84
|
|
85
|
-
# @param [Hash] opts
|
86
|
-
# @
|
85
|
+
# @param [Hash] opts Parameters for creating a Transaction Feed.
|
86
|
+
# @option opts [String] alias A unique alias for the transaction feed.
|
87
|
+
# @option opts [String] filter A valid filter string for the `/list-transactions` endpoint. The transaction feed will be composed of future transactions that match the filter.
|
88
|
+
# @return [TransactionFeed] Newly created transaction feed
|
87
89
|
def create(opts)
|
88
90
|
opts = {client_token: SecureRandom.uuid()}.merge(opts)
|
89
91
|
TransactionFeed.new(client.conn.request('create-transaction-feed', opts), client.conn)
|
90
92
|
end
|
91
93
|
|
92
|
-
#
|
93
|
-
# @
|
94
|
+
# Get single transaction feed given an id/alias.
|
95
|
+
# @param [Hash] opts Parameters to get single Transaction Feed.
|
96
|
+
# @option opts [String] id The unique ID of a transaction feed. Either `id` or `alias` is required.
|
97
|
+
# @option opts [String] alias The unique alias of a transaction feed. Either `id` or `alias` is required.
|
98
|
+
# @return [TransactionFeed] Requested transaction feed object
|
94
99
|
def get(opts)
|
95
100
|
TransactionFeed.new(client.conn.request('get-transaction-feed', opts), client.conn)
|
96
101
|
end
|
@@ -104,6 +109,7 @@ module Chain
|
|
104
109
|
nil
|
105
110
|
end
|
106
111
|
|
112
|
+
# List all transaction feeds
|
107
113
|
# @return [Query]
|
108
114
|
def query
|
109
115
|
Query.new(client)
|
data/lib/chain/unspent_output.rb
CHANGED
@@ -4,6 +4,9 @@ require_relative './query'
|
|
4
4
|
|
5
5
|
module Chain
|
6
6
|
class UnspentOutput < ResponseObject
|
7
|
+
# @!attribute [r] id
|
8
|
+
# @return [String]
|
9
|
+
attrib :id
|
7
10
|
|
8
11
|
# @!attribute [r] type
|
9
12
|
# @return [String]
|
@@ -70,10 +73,13 @@ module Chain
|
|
70
73
|
attrib :is_local
|
71
74
|
|
72
75
|
class ClientModule < Chain::ClientModule
|
73
|
-
# @param [Hash]
|
74
|
-
# @
|
75
|
-
|
76
|
-
|
76
|
+
# @param [Hash] opts Filtering information
|
77
|
+
# @option opts [String] filter Filter string, see {https://chain.com/docs/core/build-applications/queries}.
|
78
|
+
# @option opts [Array<String|Integer>] filter_params Parameter values for filter string (if needed).
|
79
|
+
# @option opts [Integer] timestamp A millisecond Unix timestamp. By using this parameter, you can perform queries that reflect the state of the blockchain at different points in time.
|
80
|
+
# @return [Query]
|
81
|
+
def query(opts = {})
|
82
|
+
Query.new(client, opts)
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
data/lib/chain/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chain-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chain Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/chain/hsm_signer.rb
|
103
103
|
- lib/chain/mock_hsm.rb
|
104
104
|
- lib/chain/query.rb
|
105
|
+
- lib/chain/receiver.rb
|
105
106
|
- lib/chain/response_object.rb
|
106
107
|
- lib/chain/transaction.rb
|
107
108
|
- lib/chain/transaction_feed.rb
|
@@ -119,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
120
|
requirements:
|
120
121
|
- - "~>"
|
121
122
|
- !ruby/object:Gem::Version
|
122
|
-
version: '2.
|
123
|
+
version: '2.1'
|
123
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
125
|
requirements:
|
125
126
|
- - ">="
|