Class: Flow::Client
- Inherits:
-
Object
- Object
- Flow::Client
- Defined in:
- lib/flow/client.rb
Overview
The client class is used to access the Flow API
Constant Summary collapse
- NODES =
{ mainnet: "access.mainnet.nodes.onflow.org:9000", testnet: "access.devnet.nodes.onflow.org:9000", canarynet: "access.canary.nodes.onflow.org:9000" }.freeze
Instance Method Summary collapse
-
#execute_script(script, args = []) ⇒ OpenStruct
Execute a read-only Cadence script against the latest sealed execution state.
-
#get_account_at_block_height(address, block_height) ⇒ Flow::Entities::Account
Get an account by address at the given block height.
-
#get_account_at_latest_block(address) ⇒ Flow::Entities::Account
Get an account by address.
-
#get_block_by_height(height) ⇒ Flow::Entities::Block
Get a full block by height.
-
#get_block_by_id(id) ⇒ Flow::Entities::Block
Get a full block by ID.
-
#get_block_header_by_height(height) ⇒ Flow::Entities::BlockHeader
Get a block header by height.
-
#get_block_header_by_id(id) ⇒ Flow::Entities::BlockHeader
Get a block header by ID.
-
#get_collection_by_id(id) ⇒ Flow::Entities::Collection
Gets a collection by ID.
-
#get_events_for_block_ids(type, block_ids = []) ⇒ EventsResponse
Retrieve events for the specified block IDs and event type.
-
#get_events_for_height_range(type, start_height: 2, end_height: 3) ⇒ EventsResponse
Retrieve events emitted within the specified block range.
-
#get_latest_block(is_sealed: false) ⇒ Flow::Entities::Block
Get the full payload of the latest sealed or unsealed block.
-
#get_latest_block_header(is_sealed: false) ⇒ Flow::Entities::BlockHeader
Get the latest sealed or unsealed block header.
-
#get_latest_protocol_state_snapshot ⇒ Object
Retrieve the latest Protocol state snapshot serialized as a byte array.
-
#get_network_parameters ⇒ Hash
Retrieve the network parameters.
-
#get_transaction(id) ⇒ Flow::Entities::Transaction
Get a transaction by ID.
-
#get_transaction_result(id) ⇒ Flow::Access::TransactionResultResponse
Get the execution result of a transaction.
-
#initialize(node: :mainnet) ⇒ Client
constructor
A new instance of Client.
-
#ping ⇒ Flow::Access::PingResponse
Check if the Access API is ready and available.
Constructor Details
Instance Method Details
#execute_script(script, args = []) ⇒ OpenStruct
Execute a read-only Cadence script against the latest sealed execution state
241 242 243 244 245 246 247 248 249 |
# File 'lib/flow/client.rb', line 241 def execute_script(script, args = []) req = Access::ExecuteScriptAtLatestBlockRequest.new( script: script, arguments: args ) res = @stub.execute_script_at_latest_block(req) parse_json(res.value) end |
#get_account_at_block_height(address, block_height) ⇒ Flow::Entities::Account
Get an account by address at the given block height
219 220 221 222 223 224 225 226 227 |
# File 'lib/flow/client.rb', line 219 def get_account_at_block_height(address, block_height) req = Access::GetAccountAtBlockHeightRequest.new( address: to_bytes(address), block_height: block_height ) res = @stub.get_account_at_latest_block(req) res.account end |
#get_account_at_latest_block(address) ⇒ Flow::Entities::Account
Get an account by address
205 206 207 208 209 |
# File 'lib/flow/client.rb', line 205 def get_account_at_latest_block(address) req = Access::GetAccountAtLatestBlockRequest.new(address: to_bytes(address)) res = @stub.get_account_at_latest_block(req) res.account end |
#get_block_by_height(height) ⇒ Flow::Entities::Block
Get a full block by height
118 119 120 121 122 |
# File 'lib/flow/client.rb', line 118 def get_block_by_height(height) req = Access::GetBlockByHeightRequest.new(height: height) res = @stub.get_block_by_height(req) res.block end |
#get_block_by_id(id) ⇒ Flow::Entities::Block
The ID should be bytes
or it should be formatted automatically
Get a full block by ID
105 106 107 108 109 |
# File 'lib/flow/client.rb', line 105 def get_block_by_id(id) req = Access::GetBlockByIDRequest.new(id: id) res = @stub.get_block_by_id(req) res.block end |
#get_block_header_by_height(height) ⇒ Flow::Entities::BlockHeader
Get a block header by height
71 72 73 74 75 |
# File 'lib/flow/client.rb', line 71 def get_block_header_by_height(height) req = Access::GetBlockHeaderByHeightRequest.new(height: height) res = @stub.get_block_header_by_height(req) res.block end |
#get_block_header_by_id(id) ⇒ Flow::Entities::BlockHeader
The ID should be bytes
or it should be formatted automatically
Get a block header by ID
58 59 60 61 62 |
# File 'lib/flow/client.rb', line 58 def get_block_header_by_id(id) req = Access::GetBlockHeaderByIDRequest.new(id: id) res = @stub.get_block_header_by_id(req) res.block end |
#get_collection_by_id(id) ⇒ Flow::Entities::Collection
The ID should be bytes
or it should be formatted automatically
Gets a collection by ID
139 140 141 142 143 |
# File 'lib/flow/client.rb', line 139 def get_collection_by_id(id) req = Access::GetCollectionByIDRequest.new(id: id) res = @stub.get_collection_by_id(req) res.collection end |
#get_events_for_block_ids(type, block_ids = []) ⇒ EventsResponse
Scope the response further
Retrieve events for the specified block IDs and event type
288 289 290 291 292 293 294 295 |
# File 'lib/flow/client.rb', line 288 def get_events_for_block_ids(type, block_ids = []) req = Access::GetEventsForBlockIDsRequest.new( type: type, block_ids: block_ids ) @stub.get_events_for_block_ids(req) end |
#get_events_for_height_range(type, start_height: 2, end_height: 3) ⇒ EventsResponse
Scope the response further
Retrieve events emitted within the specified block range
268 269 270 271 272 273 274 275 276 |
# File 'lib/flow/client.rb', line 268 def get_events_for_height_range(type, start_height: 2, end_height: 3) req = Access::GetEventsForHeightRangeRequest.new( type: type, start_height: start_height, end_height: end_height ) @stub.get_events_for_height_range(req) end |
#get_latest_block(is_sealed: false) ⇒ Flow::Entities::Block
Get the full payload of the latest sealed or unsealed block
90 91 92 93 94 |
# File 'lib/flow/client.rb', line 90 def get_latest_block(is_sealed: false) req = Access::GetLatestBlockRequest.new(is_sealed: is_sealed) res = @stub.get_latest_block(req) res.block end |
#get_latest_block_header(is_sealed: false) ⇒ Flow::Entities::BlockHeader
Get the latest sealed or unsealed block header
43 44 45 46 47 |
# File 'lib/flow/client.rb', line 43 def get_latest_block_header(is_sealed: false) req = Access::GetLatestBlockHeaderRequest.new(is_sealed: is_sealed) res = @stub.get_latest_block_header(req) res.block end |
#get_latest_protocol_state_snapshot ⇒ Object
Fix. This currently fails with unimplemented_error
Retrieve the latest Protocol state snapshot serialized as a byte array.
It is used by Flow nodes joining the network to bootstrap a space-efficient local state
330 331 332 333 |
# File 'lib/flow/client.rb', line 330 def get_latest_protocol_state_snapshot req = Access::GetLatestProtocolStateSnapshotRequest.new @stub.get_latest_protocol_state_snapshot(req) end |
#get_network_parameters ⇒ Hash
Retrieve the network parameters
310 311 312 313 314 |
# File 'lib/flow/client.rb', line 310 def get_network_parameters req = Access::GetNetworkParametersRequest.new res = @stub.get_network_parameters(req) res.to_h end |
#get_transaction(id) ⇒ Flow::Entities::Transaction
The ID should be bytes
or it should be formatted automatically
Get a transaction by ID
172 173 174 175 176 |
# File 'lib/flow/client.rb', line 172 def get_transaction(id) req = Access::GetTransactionRequest.new(id: id) res = @stub.get_transaction(req) res.transaction end |
#get_transaction_result(id) ⇒ Flow::Access::TransactionResultResponse
The ID should be bytes
or it should be formatted automatically
We might want to change the return value here, TransactionReturnResponse has these available keys: status, status_code, error_message, events
Get the execution result of a transaction
189 190 191 192 |
# File 'lib/flow/client.rb', line 189 def get_transaction_result(id) req = Access::GetTransactionRequest.new(id: id) @stub.get_transaction_result(req) end |
#ping ⇒ Flow::Access::PingResponse
Check if the Access API is ready and available
26 27 28 |
# File 'lib/flow/client.rb', line 26 def ping @stub.ping(Access::PingRequest.new) end |