flow_client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +107 -0
- data/README.md +1 -1
- data/bin/console +0 -0
- data/lib/flow_client/account.rb +1 -0
- data/lib/flow_client/block.rb +14 -8
- data/lib/flow_client/cadence_type.rb +35 -15
- data/lib/flow_client/client.rb +13 -1
- data/lib/flow_client/collection.rb +3 -1
- data/lib/flow_client/crypto.rb +2 -2
- data/lib/flow_client/event.rb +5 -3
- data/lib/flow_client/proposal_key.rb +3 -1
- data/lib/flow_client/signature.rb +3 -1
- data/lib/flow_client/transaction.rb +2 -4
- data/lib/flow_client/utils.rb +0 -11
- data/lib/flow_client/version.rb +1 -1
- data/lib/flow_client.rb +1 -1
- data/template.md +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af7d7f1ba7669936797c908286ae084ca35d28ce1403767c7e670516391c744
|
4
|
+
data.tar.gz: 9ece3c471fb71a3bd5fadaac858e72681ee5db0e9259cc6871c4c413e56b2f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ba90c30234850aea96ef88fa41592429634a475fce24d931396a17b1214fa6c9e4080e04d754cb7429629e007dff51a6ecf6a94346ccea0ddae02d7af8ddfc
|
7
|
+
data.tar.gz: 5b3a241597f592be576678ac36e6c2196bb9efca62442c2ba27dd8fb185db70028d30e6185845a122fa7276f43bac21195db3388308413927faad6b7032ebd7b
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flow_client (0.2.2)
|
5
|
+
grpc
|
6
|
+
grpc-tools
|
7
|
+
json
|
8
|
+
openssl
|
9
|
+
rlp
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
ast (2.4.2)
|
15
|
+
coderay (1.1.3)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
ffi (1.15.4)
|
18
|
+
formatador (0.3.0)
|
19
|
+
google-protobuf (3.19.1-x86_64-darwin)
|
20
|
+
googleapis-common-protos-types (1.3.0)
|
21
|
+
google-protobuf (~> 3.14)
|
22
|
+
grpc (1.41.0-universal-darwin)
|
23
|
+
google-protobuf (~> 3.17)
|
24
|
+
googleapis-common-protos-types (~> 1.0)
|
25
|
+
grpc-tools (1.41.0)
|
26
|
+
guard (2.18.0)
|
27
|
+
formatador (>= 0.2.4)
|
28
|
+
listen (>= 2.7, < 4.0)
|
29
|
+
lumberjack (>= 1.0.12, < 2.0)
|
30
|
+
nenv (~> 0.1)
|
31
|
+
notiffany (~> 0.0)
|
32
|
+
pry (>= 0.13.0)
|
33
|
+
shellany (~> 0.0)
|
34
|
+
thor (>= 0.18.1)
|
35
|
+
guard-compat (1.2.1)
|
36
|
+
guard-rspec (4.7.3)
|
37
|
+
guard (~> 2.1)
|
38
|
+
guard-compat (~> 1.1)
|
39
|
+
rspec (>= 2.99.0, < 4.0)
|
40
|
+
ipaddr (1.2.3)
|
41
|
+
json (2.6.1)
|
42
|
+
listen (3.7.0)
|
43
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
44
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
45
|
+
lumberjack (1.2.8)
|
46
|
+
method_source (1.0.0)
|
47
|
+
nenv (0.3.0)
|
48
|
+
notiffany (0.1.3)
|
49
|
+
nenv (~> 0.1)
|
50
|
+
shellany (~> 0.0)
|
51
|
+
openssl (2.2.1)
|
52
|
+
ipaddr
|
53
|
+
parallel (1.21.0)
|
54
|
+
parser (3.0.2.0)
|
55
|
+
ast (~> 2.4.1)
|
56
|
+
pry (0.14.1)
|
57
|
+
coderay (~> 1.1)
|
58
|
+
method_source (~> 1.0)
|
59
|
+
rainbow (3.0.0)
|
60
|
+
rake (13.0.6)
|
61
|
+
rb-fsevent (0.11.0)
|
62
|
+
rb-inotify (0.10.1)
|
63
|
+
ffi (~> 1.0)
|
64
|
+
regexp_parser (2.1.1)
|
65
|
+
rexml (3.2.5)
|
66
|
+
rlp (0.7.3)
|
67
|
+
rspec (3.10.0)
|
68
|
+
rspec-core (~> 3.10.0)
|
69
|
+
rspec-expectations (~> 3.10.0)
|
70
|
+
rspec-mocks (~> 3.10.0)
|
71
|
+
rspec-core (3.10.1)
|
72
|
+
rspec-support (~> 3.10.0)
|
73
|
+
rspec-expectations (3.10.1)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.10.0)
|
76
|
+
rspec-mocks (3.10.2)
|
77
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
+
rspec-support (~> 3.10.0)
|
79
|
+
rspec-support (3.10.3)
|
80
|
+
rubocop (1.22.3)
|
81
|
+
parallel (~> 1.10)
|
82
|
+
parser (>= 3.0.0.0)
|
83
|
+
rainbow (>= 2.2.2, < 4.0)
|
84
|
+
regexp_parser (>= 1.8, < 3.0)
|
85
|
+
rexml
|
86
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
87
|
+
ruby-progressbar (~> 1.7)
|
88
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
89
|
+
rubocop-ast (1.13.0)
|
90
|
+
parser (>= 3.0.1.1)
|
91
|
+
ruby-progressbar (1.11.0)
|
92
|
+
shellany (0.0.1)
|
93
|
+
thor (1.1.0)
|
94
|
+
unicode-display_width (2.1.0)
|
95
|
+
|
96
|
+
PLATFORMS
|
97
|
+
x86_64-darwin-20
|
98
|
+
|
99
|
+
DEPENDENCIES
|
100
|
+
flow_client!
|
101
|
+
guard-rspec (~> 4.7)
|
102
|
+
rake (~> 13.0)
|
103
|
+
rspec (~> 3.0)
|
104
|
+
rubocop (~> 1.22)
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
2.2.26
|
data/README.md
CHANGED
@@ -669,7 +669,7 @@ After a transaction has been [built](#build-transactions) and [signed](#sign-tra
|
|
669
669
|
```ruby
|
670
670
|
tx_res = client.send_transaction(@transaction)
|
671
671
|
client.wait_for_transaction(tx_res.id) do |response|
|
672
|
-
|
672
|
+
# use response here
|
673
673
|
end
|
674
674
|
```
|
675
675
|
|
data/bin/console
CHANGED
File without changes
|
data/lib/flow_client/account.rb
CHANGED
data/lib/flow_client/block.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module FlowClient
|
3
4
|
# Represents a block
|
4
5
|
class Block
|
5
6
|
attr_accessor :id,
|
@@ -9,7 +10,7 @@ module FlowClient
|
|
9
10
|
:collection_guarantees,
|
10
11
|
:block_seals,
|
11
12
|
:signatures
|
12
|
-
|
13
|
+
|
13
14
|
def initialize
|
14
15
|
@id = nil
|
15
16
|
@parent_id = nil
|
@@ -26,8 +27,12 @@ module FlowClient
|
|
26
27
|
block.parent_id = block_response.block.parent_id.unpack1("H*")
|
27
28
|
block.height = block_response.block.height
|
28
29
|
block.timestamp = FlowClient::Utils.parse_protobuf_timestamp(block_response.block.timestamp)
|
29
|
-
block.collection_guarantees = block_response.block.collection_guarantees.to_a.map
|
30
|
-
|
30
|
+
block.collection_guarantees = block_response.block.collection_guarantees.to_a.map do |cg|
|
31
|
+
FlowClient::CollectionGuarantee.parse_grpc_type(cg)
|
32
|
+
end
|
33
|
+
block.block_seals = block_response.block.block_seals.to_a.map do |seal|
|
34
|
+
FlowClient::BlockSeal.parse_grpc_type(seal)
|
35
|
+
end
|
31
36
|
block.signatures = block_response.block.signatures.to_a.map { |sig| sig.unpack1("H*") }
|
32
37
|
block
|
33
38
|
end
|
@@ -51,7 +56,9 @@ module FlowClient
|
|
51
56
|
block_seal = BlockSeal.new
|
52
57
|
block_seal.block_id = grpc_type.block_id.unpack1("H*")
|
53
58
|
block_seal.execution_receipt_id = grpc_type.execution_receipt_id.unpack1("H*")
|
54
|
-
block_seal.execution_receipt_signatures = grpc_type.execution_receipt_signatures.to_a.map
|
59
|
+
block_seal.execution_receipt_signatures = grpc_type.execution_receipt_signatures.to_a.map do |sig|
|
60
|
+
sig.unpack1("H*")
|
61
|
+
end
|
55
62
|
block_seal.result_approval_signatures = grpc_type.result_approval_signatures.to_a.map { |sig| sig.unpack1("H*") }
|
56
63
|
block_seal
|
57
64
|
end
|
@@ -61,8 +68,7 @@ module FlowClient
|
|
61
68
|
class BlockHeader
|
62
69
|
attr_accessor :id, :parent_id, :height, :timestamp
|
63
70
|
|
64
|
-
def initialize
|
65
|
-
end
|
71
|
+
def initialize; end
|
66
72
|
|
67
73
|
def self.parse_grpc_type(grpc_type)
|
68
74
|
header = BlockHeader.new
|
@@ -72,4 +78,4 @@ module FlowClient
|
|
72
78
|
header
|
73
79
|
end
|
74
80
|
end
|
75
|
-
end
|
81
|
+
end
|
@@ -1,16 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "ostruct"
|
2
4
|
|
3
5
|
module FlowClient
|
4
6
|
module CadenceType
|
7
|
+
# Returns an OpenStruct representing a Cadence String type
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# @arg = FlowClient::CadenceType.String("Hello world!")
|
11
|
+
#
|
12
|
+
# @param [String] the string value
|
13
|
+
#
|
14
|
+
# @returns [OpenStruct] the Cadence String struct
|
5
15
|
def self.String(value)
|
6
16
|
OpenStruct.new(type: "String", value: value.to_s)
|
7
17
|
end
|
8
18
|
|
19
|
+
# Returns an OpenStruct representing a Cadence Optional type
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# @arg = FlowClient::CadenceType.Optional("Hello world!")
|
23
|
+
# @arg = FlowClient::CadenceType.Optional()
|
24
|
+
#
|
25
|
+
# @param [String] the string value
|
26
|
+
#
|
27
|
+
# @returns [OpenStruct] the Cadence Optional struct
|
9
28
|
def self.Optional(value = nil)
|
10
29
|
OpenStruct.new(type: "Optional", value: value)
|
11
30
|
end
|
12
31
|
|
13
|
-
|
32
|
+
# Returns an OpenStruct representing a Cadence Void type
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# @arg = FlowClient::CadenceType.Void()
|
36
|
+
#
|
37
|
+
# @returns [OpenStruct] the Cadence Void struct
|
38
|
+
def self.Void
|
14
39
|
OpenStruct.new(type: "Void")
|
15
40
|
end
|
16
41
|
|
@@ -62,14 +87,6 @@ module FlowClient
|
|
62
87
|
OpenStruct.new(type: "UInt64", value: value.to_s)
|
63
88
|
end
|
64
89
|
|
65
|
-
def self.Int64(value)
|
66
|
-
OpenStruct.new(type: "Int64", value: value.to_s)
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.UInt64(value)
|
70
|
-
OpenStruct.new(type: "UInt64", value: value.to_s)
|
71
|
-
end
|
72
|
-
|
73
90
|
def self.Int128(value)
|
74
91
|
OpenStruct.new(type: "Int128", value: value.to_s)
|
75
92
|
end
|
@@ -123,9 +140,9 @@ module FlowClient
|
|
123
140
|
end
|
124
141
|
|
125
142
|
def self.Path(domain, identifier)
|
126
|
-
|
127
|
-
"Domain can only be one of storage, private or public"
|
128
|
-
|
143
|
+
unless %w[storage private public].include? domain.to_s.downcase
|
144
|
+
raise raise ArgumentError, "Domain can only be one of storage, private or public"
|
145
|
+
end
|
129
146
|
|
130
147
|
OpenStruct.new(
|
131
148
|
type: "Path",
|
@@ -149,8 +166,11 @@ module FlowClient
|
|
149
166
|
end
|
150
167
|
|
151
168
|
def self.Composite(type, value)
|
152
|
-
valid_types = [
|
153
|
-
|
169
|
+
valid_types = %i[struct resource event contract enum]
|
170
|
+
unless valid_types.include? type
|
171
|
+
raise ArgumentError, "incorrect type, expected :struct, :resource, :event, :contract or :enum"
|
172
|
+
end
|
173
|
+
|
154
174
|
OpenStruct.new(type: type.to_s.capitalize, value: value)
|
155
175
|
end
|
156
176
|
|
@@ -162,4 +182,4 @@ module FlowClient
|
|
162
182
|
OpenStruct.new(name: name, value: value)
|
163
183
|
end
|
164
184
|
end
|
165
|
-
end
|
185
|
+
end
|
data/lib/flow_client/client.rb
CHANGED
@@ -31,6 +31,8 @@ module FlowClient
|
|
31
31
|
# Returns an account for the address specified at the latest
|
32
32
|
# block.
|
33
33
|
#
|
34
|
+
# @param [String] the address string value
|
35
|
+
#
|
34
36
|
# @return [FlowClient::Account] the account
|
35
37
|
def get_account(address)
|
36
38
|
req = Access::GetAccountAtLatestBlockRequest.new(address: to_bytes(address))
|
@@ -252,6 +254,8 @@ module FlowClient
|
|
252
254
|
|
253
255
|
# Returns the latest with height
|
254
256
|
#
|
257
|
+
# @param [Integer] block height
|
258
|
+
#
|
255
259
|
# @return [FlowClient::Block] the block
|
256
260
|
def get_block_by_height(height)
|
257
261
|
req = Access::GetBlockByHeightRequest.new(
|
@@ -265,6 +269,8 @@ module FlowClient
|
|
265
269
|
|
266
270
|
# Returns the collection with id
|
267
271
|
#
|
272
|
+
# @param [String] collection id
|
273
|
+
#
|
268
274
|
# @return [FlowClient::Collection] the collection
|
269
275
|
def get_collection_by_id(id)
|
270
276
|
req = Access::GetCollectionByIDRequest.new(
|
@@ -276,7 +282,13 @@ module FlowClient
|
|
276
282
|
|
277
283
|
# :section: Events
|
278
284
|
|
279
|
-
# Returns events of the given type between the start and end block heights
|
285
|
+
# Returns events of the given type between the start and end block heights
|
286
|
+
#
|
287
|
+
# @param [String] event name
|
288
|
+
# @param [Integer] start block height
|
289
|
+
# @param [Integer] end block height
|
290
|
+
#
|
291
|
+
# @return [FlowClient::EventsResult] the events response
|
280
292
|
def get_events(type, start_height, end_height)
|
281
293
|
req = Access::GetEventsForHeightRangeRequest.new(
|
282
294
|
type: type,
|
data/lib/flow_client/crypto.rb
CHANGED
@@ -19,7 +19,7 @@ module FlowClient
|
|
19
19
|
def self.sign(data, private_key_hex, hash_algo = HashAlgos::SHA3_256)
|
20
20
|
ssl_key = FlowClient::Crypto.key_from_hex_keys(private_key_hex)
|
21
21
|
# TODO: Fix this so that both hashing algos will work
|
22
|
-
asn = ssl_key.dsa_sign_asn1(OpenSSL::Digest.digest(
|
22
|
+
asn = ssl_key.dsa_sign_asn1(OpenSSL::Digest.digest(hash_algo, data))
|
23
23
|
r, s = OpenSSL::ASN1.decode(asn).value
|
24
24
|
combined_bytes = Utils.left_pad_bytes([r.value.to_s(16)].pack("H*").unpack("C*"), 32) +
|
25
25
|
Utils.left_pad_bytes([s.value.to_s(16)].pack("H*").unpack("C*"), 32)
|
@@ -46,7 +46,7 @@ module FlowClient
|
|
46
46
|
# Crypto::Curves::SECP256K1
|
47
47
|
#
|
48
48
|
# The 04 prefix indicating that the public key is uncompressed is stripped.
|
49
|
-
# https://datatracker.ietf.org/doc/html/rfc5480
|
49
|
+
# @see https://datatracker.ietf.org/doc/html/rfc5480
|
50
50
|
#
|
51
51
|
# Usage example:
|
52
52
|
# private_key, public_key = FlowClient::Crypto.generate_key_pair(FlowClient::Crypto::Curves::P256)
|
data/lib/flow_client/event.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FlowClient
|
2
4
|
class EventsResult
|
3
5
|
attr_accessor :block_id,
|
@@ -9,7 +11,7 @@ module FlowClient
|
|
9
11
|
@block_id = nil
|
10
12
|
@block_height = nil
|
11
13
|
@events = nil
|
12
|
-
@block_timestamp= nil
|
14
|
+
@block_timestamp = nil
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.parse_grpc_type(type)
|
@@ -28,7 +30,7 @@ module FlowClient
|
|
28
30
|
:transaction_index,
|
29
31
|
:event_index,
|
30
32
|
:payload
|
31
|
-
|
33
|
+
|
32
34
|
def initialize
|
33
35
|
@type = nil
|
34
36
|
@transaction_id = nil
|
@@ -47,4 +49,4 @@ module FlowClient
|
|
47
49
|
event
|
48
50
|
end
|
49
51
|
end
|
50
|
-
end
|
52
|
+
end
|
@@ -16,8 +16,6 @@ module FlowClient
|
|
16
16
|
:payer_address,
|
17
17
|
:authorizer_addresses,
|
18
18
|
:address_aliases,
|
19
|
-
:envelope_signatures,
|
20
|
-
:payload_signatures,
|
21
19
|
:proposal_key
|
22
20
|
|
23
21
|
attr_reader :envelope_signatures, :payload_signatures
|
@@ -36,7 +34,7 @@ module FlowClient
|
|
36
34
|
|
37
35
|
def arguments=(arguments)
|
38
36
|
arguments.to_a.each do |arg|
|
39
|
-
processed_arg = arg.
|
37
|
+
processed_arg = arg.instance_of?(OpenStruct) ? Utils.openstruct_to_json(arg) : arg
|
40
38
|
@arguments << processed_arg
|
41
39
|
end
|
42
40
|
end
|
@@ -189,4 +187,4 @@ module FlowClient
|
|
189
187
|
response
|
190
188
|
end
|
191
189
|
end
|
192
|
-
end
|
190
|
+
end
|
data/lib/flow_client/utils.rb
CHANGED
@@ -47,18 +47,7 @@ module FlowClient
|
|
47
47
|
|
48
48
|
def self.openstruct_to_json(struct)
|
49
49
|
struct.deep_to_h.to_json
|
50
|
-
# struct.each_pair.map do |key, value|
|
51
|
-
# [
|
52
|
-
# key,
|
53
|
-
# case value
|
54
|
-
# when OpenStruct then value.deep_to_h
|
55
|
-
# when Array then value.map {|el| el.class == OpenStruct ? el.deep_to_h : el}
|
56
|
-
# else value
|
57
|
-
# end
|
58
|
-
# ]
|
59
|
-
# end.to_h.to_json
|
60
50
|
end
|
61
|
-
|
62
51
|
end
|
63
52
|
end
|
64
53
|
|
data/lib/flow_client/version.rb
CHANGED
data/lib/flow_client.rb
CHANGED
data/template.md
CHANGED
@@ -669,7 +669,7 @@ After a transaction has been [built](#build-transactions) and [signed](#sign-tra
|
|
669
669
|
```ruby
|
670
670
|
tx_res = client.send_transaction(@transaction)
|
671
671
|
client.wait_for_transaction(tx_res.id) do |response|
|
672
|
-
|
672
|
+
# use response here
|
673
673
|
end
|
674
674
|
```
|
675
675
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nico du Plessis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- CHANGELOG.md
|
95
95
|
- CODE_OF_CONDUCT.md
|
96
96
|
- Gemfile
|
97
|
+
- Gemfile.lock
|
97
98
|
- Guardfile
|
98
99
|
- LICENSE.txt
|
99
100
|
- README.md
|
@@ -155,7 +156,7 @@ metadata:
|
|
155
156
|
homepage_uri: https://github.com/glucode/flow_client
|
156
157
|
source_code_uri: https://github.com/glucode/flow_client
|
157
158
|
changelog_uri: https://github.com/glucode/flow_client
|
158
|
-
post_install_message:
|
159
|
+
post_install_message:
|
159
160
|
rdoc_options: []
|
160
161
|
require_paths:
|
161
162
|
- lib
|
@@ -170,8 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
171
|
- !ruby/object:Gem::Version
|
171
172
|
version: '0'
|
172
173
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
174
|
-
signing_key:
|
174
|
+
rubygems_version: 3.2.15
|
175
|
+
signing_key:
|
175
176
|
specification_version: 4
|
176
177
|
summary: A Ruby client for the Flow blockchain
|
177
178
|
test_files: []
|