flow_client 0.2.3-arm64-darwin-21

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +37 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +26 -0
  6. data/CHANGELOG.md +24 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +114 -0
  10. data/Guardfile +79 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +747 -0
  13. data/Rakefile +12 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/docker-compose.yml +12 -0
  17. data/flow.json +21 -0
  18. data/flow_client.gemspec +44 -0
  19. data/lib/cadence/contracts/NonFungibleToken.cdc +144 -0
  20. data/lib/cadence/templates/add-account-key.cdc +16 -0
  21. data/lib/cadence/templates/add-contract.cdc +5 -0
  22. data/lib/cadence/templates/create-account.cdc +21 -0
  23. data/lib/cadence/templates/remove-contract.cdc +5 -0
  24. data/lib/cadence/templates/update-contract.cdc +5 -0
  25. data/lib/flow/access/access_pb.rb +168 -0
  26. data/lib/flow/access/access_services_pb.rb +96 -0
  27. data/lib/flow/entities/account_pb.rb +30 -0
  28. data/lib/flow/entities/block_header_pb.rb +20 -0
  29. data/lib/flow/entities/block_pb.rb +25 -0
  30. data/lib/flow/entities/block_seal_pb.rb +19 -0
  31. data/lib/flow/entities/collection_pb.rb +23 -0
  32. data/lib/flow/entities/event_pb.rb +20 -0
  33. data/lib/flow/entities/transaction_pb.rb +47 -0
  34. data/lib/flow/execution/execution_pb.rb +65 -0
  35. data/lib/flow/execution/execution_services_pb.rb +43 -0
  36. data/lib/flow/legacy/access/access_pb.rb +157 -0
  37. data/lib/flow/legacy/access/access_services_pb.rb +89 -0
  38. data/lib/flow/legacy/entities/account_pb.rb +28 -0
  39. data/lib/flow/legacy/entities/block_header_pb.rb +20 -0
  40. data/lib/flow/legacy/entities/block_pb.rb +25 -0
  41. data/lib/flow/legacy/entities/block_seal_pb.rb +19 -0
  42. data/lib/flow/legacy/entities/collection_pb.rb +22 -0
  43. data/lib/flow/legacy/entities/event_pb.rb +20 -0
  44. data/lib/flow/legacy/entities/transaction_pb.rb +45 -0
  45. data/lib/flow/legacy/execution/execution_pb.rb +65 -0
  46. data/lib/flow/legacy/execution/execution_services_pb.rb +42 -0
  47. data/lib/flow_client/account.rb +31 -0
  48. data/lib/flow_client/block.rb +81 -0
  49. data/lib/flow_client/cadence_type.rb +185 -0
  50. data/lib/flow_client/client.rb +387 -0
  51. data/lib/flow_client/collection.rb +35 -0
  52. data/lib/flow_client/crypto.rb +62 -0
  53. data/lib/flow_client/event.rb +52 -0
  54. data/lib/flow_client/proposal_key.rb +23 -0
  55. data/lib/flow_client/signature.rb +23 -0
  56. data/lib/flow_client/signer.rb +22 -0
  57. data/lib/flow_client/transaction.rb +190 -0
  58. data/lib/flow_client/utils.rb +67 -0
  59. data/lib/flow_client/version.rb +5 -0
  60. data/lib/flow_client.rb +22 -0
  61. data/logo.svg +121 -0
  62. data/logo@2x.png +0 -0
  63. data/template.md +748 -0
  64. metadata +192 -0
@@ -0,0 +1,65 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: flow/legacy/execution/execution.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'flow/legacy/entities/account_pb'
7
+ require 'flow/legacy/entities/event_pb'
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_file("flow/legacy/execution/execution.proto", :syntax => :proto3) do
10
+ add_message "execution.PingRequest" do
11
+ end
12
+ add_message "execution.PingResponse" do
13
+ end
14
+ add_message "execution.GetAccountAtBlockIDRequest" do
15
+ optional :block_id, :bytes, 1
16
+ optional :address, :bytes, 2
17
+ end
18
+ add_message "execution.GetAccountAtBlockIDResponse" do
19
+ optional :account, :message, 1, "entities.Account"
20
+ end
21
+ add_message "execution.ExecuteScriptAtBlockIDRequest" do
22
+ optional :block_id, :bytes, 1
23
+ optional :script, :bytes, 2
24
+ repeated :arguments, :bytes, 3
25
+ end
26
+ add_message "execution.ExecuteScriptAtBlockIDResponse" do
27
+ optional :value, :bytes, 1
28
+ end
29
+ add_message "execution.GetEventsForBlockIDsResponse" do
30
+ repeated :results, :message, 1, "execution.GetEventsForBlockIDsResponse.Result"
31
+ end
32
+ add_message "execution.GetEventsForBlockIDsResponse.Result" do
33
+ optional :block_id, :bytes, 1
34
+ optional :block_height, :uint64, 2
35
+ repeated :events, :message, 3, "entities.Event"
36
+ end
37
+ add_message "execution.GetEventsForBlockIDsRequest" do
38
+ optional :type, :string, 1
39
+ repeated :block_ids, :bytes, 2
40
+ end
41
+ add_message "execution.GetTransactionResultRequest" do
42
+ optional :block_id, :bytes, 1
43
+ optional :transaction_id, :bytes, 2
44
+ end
45
+ add_message "execution.GetTransactionResultResponse" do
46
+ optional :status_code, :uint32, 1
47
+ optional :error_message, :string, 2
48
+ repeated :events, :message, 3, "entities.Event"
49
+ end
50
+ end
51
+ end
52
+
53
+ module Execution
54
+ PingRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.PingRequest").msgclass
55
+ PingResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.PingResponse").msgclass
56
+ GetAccountAtBlockIDRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetAccountAtBlockIDRequest").msgclass
57
+ GetAccountAtBlockIDResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetAccountAtBlockIDResponse").msgclass
58
+ ExecuteScriptAtBlockIDRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.ExecuteScriptAtBlockIDRequest").msgclass
59
+ ExecuteScriptAtBlockIDResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.ExecuteScriptAtBlockIDResponse").msgclass
60
+ GetEventsForBlockIDsResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetEventsForBlockIDsResponse").msgclass
61
+ GetEventsForBlockIDsResponse::Result = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetEventsForBlockIDsResponse.Result").msgclass
62
+ GetEventsForBlockIDsRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetEventsForBlockIDsRequest").msgclass
63
+ GetTransactionResultRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetTransactionResultRequest").msgclass
64
+ GetTransactionResultResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("execution.GetTransactionResultResponse").msgclass
65
+ end
@@ -0,0 +1,42 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: flow/legacy/execution/execution.proto for package 'execution'
3
+
4
+ require 'grpc'
5
+ require 'flow/legacy/execution/execution_pb'
6
+
7
+ module Execution
8
+ module ExecutionAPI
9
+ # ExecutionAPI is the API provided by the execution nodes.
10
+ class Service
11
+
12
+ include ::GRPC::GenericService
13
+
14
+ self.marshal_class_method = :encode
15
+ self.unmarshal_class_method = :decode
16
+ self.service_name = 'execution.ExecutionAPI'
17
+
18
+ # Ping is used to check if the access node is alive and healthy.
19
+ rpc :Ping, ::Execution::PingRequest, ::Execution::PingResponse
20
+ # Accounts
21
+ #
22
+ # GetAccountAtBlockID gets an account by address at the given block ID
23
+ rpc :GetAccountAtBlockID, ::Execution::GetAccountAtBlockIDRequest, ::Execution::GetAccountAtBlockIDResponse
24
+ # Scripts
25
+ #
26
+ # ExecuteScriptAtBlockID executes a ready-only Cadence script against the
27
+ # execution state at the block with the given ID.
28
+ rpc :ExecuteScriptAtBlockID, ::Execution::ExecuteScriptAtBlockIDRequest, ::Execution::ExecuteScriptAtBlockIDResponse
29
+ # Events
30
+ #
31
+ # GetEventsForBlockIDs retrieves events for all the specified block IDs that
32
+ # have the given type
33
+ rpc :GetEventsForBlockIDs, ::Execution::GetEventsForBlockIDsRequest, ::Execution::GetEventsForBlockIDsResponse
34
+ # Transaction
35
+ #
36
+ # GetTransactionResult gets the result of a transaction.
37
+ rpc :GetTransactionResult, ::Execution::GetTransactionResultRequest, ::Execution::GetTransactionResultResponse
38
+ end
39
+
40
+ Stub = Service.rpc_stub_class
41
+ end
42
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlowClient
4
+ class AccountKey
5
+ attr_accessor :public_key,
6
+ :index, :sequence_number,
7
+ :sign_algo, :hash_algo,
8
+ :weight, :revoked
9
+
10
+ def initialize(public_key: nil, index: nil, sequence_number: nil, weight: 1000, revoked: false, hash_algo: FlowClient::Crypto::HashAlgos::SHA3_256)
11
+ @public_key = public_key
12
+ @index = index
13
+ @sequence_number = sequence_number
14
+ @weight = weight
15
+ @revoked = revoked
16
+ @hash_algo = hash_algo
17
+ end
18
+ end
19
+
20
+ class Account
21
+ attr_accessor :address, :balance, :keys, :contracts
22
+
23
+ def initialize(address: nil, balance: nil, keys: [], contracts: {})
24
+ @keys = keys
25
+ @address = address
26
+ @balance = balance
27
+ @contracts = contracts
28
+ @contracts = {}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlowClient
4
+ # Represents a block
5
+ class Block
6
+ attr_accessor :id,
7
+ :parent_id,
8
+ :height,
9
+ :timestamp,
10
+ :collection_guarantees,
11
+ :block_seals,
12
+ :signatures
13
+
14
+ def initialize
15
+ @id = nil
16
+ @parent_id = nil
17
+ @height = nil
18
+ @timestamp = nil
19
+ @collection_guarantees = []
20
+ @block_seals = []
21
+ @signatures = []
22
+ end
23
+
24
+ def self.parse_grpc_block_response(block_response)
25
+ block = Block.new
26
+ block.id = block_response.block.id.unpack1("H*")
27
+ block.parent_id = block_response.block.parent_id.unpack1("H*")
28
+ block.height = block_response.block.height
29
+ block.timestamp = FlowClient::Utils.parse_protobuf_timestamp(block_response.block.timestamp)
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
36
+ block.signatures = block_response.block.signatures.to_a.map { |sig| sig.unpack1("H*") }
37
+ block
38
+ end
39
+ end
40
+
41
+ # Represents a block seal
42
+ class BlockSeal
43
+ attr_accessor :block_id,
44
+ :execution_receipt_id,
45
+ :execution_receipt_signatures,
46
+ :result_approval_signatures
47
+
48
+ def initialize
49
+ @block_id = nil
50
+ @execution_receipt_id = nil
51
+ @execution_receipt_signatures = []
52
+ @result_approval_signatures = []
53
+ end
54
+
55
+ def self.parse_grpc_type(grpc_type)
56
+ block_seal = BlockSeal.new
57
+ block_seal.block_id = grpc_type.block_id.unpack1("H*")
58
+ block_seal.execution_receipt_id = grpc_type.execution_receipt_id.unpack1("H*")
59
+ block_seal.execution_receipt_signatures = grpc_type.execution_receipt_signatures.to_a.map do |sig|
60
+ sig.unpack1("H*")
61
+ end
62
+ block_seal.result_approval_signatures = grpc_type.result_approval_signatures.to_a.map { |sig| sig.unpack1("H*") }
63
+ block_seal
64
+ end
65
+ end
66
+
67
+ # Represents a block header
68
+ class BlockHeader
69
+ attr_accessor :id, :parent_id, :height, :timestamp
70
+
71
+ def initialize; end
72
+
73
+ def self.parse_grpc_type(grpc_type)
74
+ header = BlockHeader.new
75
+ header.id = grpc_type.id.unpack1("H*")
76
+ header.height = grpc_type.height
77
+ header.timestamp = FlowClient::Utils.parse_protobuf_timestamp(grpc_type.timestamp)
78
+ header
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module FlowClient
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
15
+ def self.String(value)
16
+ OpenStruct.new(type: "String", value: value.to_s)
17
+ end
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
28
+ def self.Optional(value = nil)
29
+ OpenStruct.new(type: "Optional", value: value)
30
+ end
31
+
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
39
+ OpenStruct.new(type: "Void")
40
+ end
41
+
42
+ def self.Bool(bool)
43
+ OpenStruct.new(type: "Bool", value: bool.to_s.downcase == "true")
44
+ end
45
+
46
+ def self.Address(address)
47
+ OpenStruct.new(type: "Address", value: address.to_s)
48
+ end
49
+
50
+ def self.Int(value)
51
+ OpenStruct.new(type: "Int", value: value.to_s)
52
+ end
53
+
54
+ def self.UInt(value)
55
+ OpenStruct.new(type: "UInt", value: value.to_s)
56
+ end
57
+
58
+ def self.Int8(value)
59
+ OpenStruct.new(type: "Int8", value: value.to_s)
60
+ end
61
+
62
+ def self.UInt8(value)
63
+ OpenStruct.new(type: "UInt8", value: value.to_s)
64
+ end
65
+
66
+ def self.Int16(value)
67
+ OpenStruct.new(type: "Int16", value: value.to_s)
68
+ end
69
+
70
+ def self.UInt16(value)
71
+ OpenStruct.new(type: "UInt16", value: value.to_s)
72
+ end
73
+
74
+ def self.Int32(value)
75
+ OpenStruct.new(type: "Int32", value: value.to_s)
76
+ end
77
+
78
+ def self.UInt32(value)
79
+ OpenStruct.new(type: "UInt32", value: value.to_s)
80
+ end
81
+
82
+ def self.Int64(value)
83
+ OpenStruct.new(type: "Int64", value: value.to_s)
84
+ end
85
+
86
+ def self.UInt64(value)
87
+ OpenStruct.new(type: "UInt64", value: value.to_s)
88
+ end
89
+
90
+ def self.Int128(value)
91
+ OpenStruct.new(type: "Int128", value: value.to_s)
92
+ end
93
+
94
+ def self.UInt128(value)
95
+ OpenStruct.new(type: "UInt128", value: value.to_s)
96
+ end
97
+
98
+ def self.Int256(value)
99
+ OpenStruct.new(type: "Int256", value: value.to_s)
100
+ end
101
+
102
+ def self.UInt256(value)
103
+ OpenStruct.new(type: "UInt256", value: value.to_s)
104
+ end
105
+
106
+ def self.Word8(value)
107
+ OpenStruct.new(type: "Word8", value: value.to_s)
108
+ end
109
+
110
+ def self.Word16(value)
111
+ OpenStruct.new(type: "Word16", value: value.to_s)
112
+ end
113
+
114
+ def self.Word32(value)
115
+ OpenStruct.new(type: "Word32", value: value.to_s)
116
+ end
117
+
118
+ def self.Word64(value)
119
+ OpenStruct.new(type: "Word64", value: value.to_s)
120
+ end
121
+
122
+ def self.Fix64(value)
123
+ OpenStruct.new(type: "Fix64", value: value.to_s)
124
+ end
125
+
126
+ def self.UFix64(value)
127
+ OpenStruct.new(type: "UFix64", value: value.to_s)
128
+ end
129
+
130
+ def self.Array(values)
131
+ OpenStruct.new(type: "Array", value: values)
132
+ end
133
+
134
+ def self.Dictionary(values)
135
+ OpenStruct.new(type: "Dictionary", value: values)
136
+ end
137
+
138
+ def self.DictionaryValue(key, value)
139
+ OpenStruct.new(key: key, value: value)
140
+ end
141
+
142
+ def self.Path(domain, identifier)
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
146
+
147
+ OpenStruct.new(
148
+ type: "Path",
149
+ value: OpenStruct.new(domain: domain, identifier: identifier)
150
+ )
151
+ end
152
+
153
+ def self.Type(type_value)
154
+ OpenStruct.new(type: "Type", value: OpenStruct.new(staticType: type_value.to_s))
155
+ end
156
+
157
+ def self.Capability(path, address, borrow_type)
158
+ OpenStruct.new(
159
+ type: "Capability",
160
+ value: OpenStruct.new(
161
+ path: path.to_s,
162
+ address: address.to_s,
163
+ borrowType: borrow_type.to_s
164
+ )
165
+ )
166
+ end
167
+
168
+ def self.Composite(type, value)
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
+
174
+ OpenStruct.new(type: type.to_s.capitalize, value: value)
175
+ end
176
+
177
+ def self.CompositeValue(id, fields)
178
+ OpenStruct.new(id: id, fields: fields)
179
+ end
180
+
181
+ def self.Field(name, value)
182
+ OpenStruct.new(name: name, value: value)
183
+ end
184
+ end
185
+ end