class FlowClient::Client
Flow client
Attributes
address_aliases[RW]
Public Class Methods
new(node_address)
click to toggle source
# File lib/flow_client/client.rb, line 13 def initialize(node_address) @stub = Access::AccessAPI::Stub.new(node_address, :this_channel_is_insecure) @address_aliases = {} end
Public Instance Methods
execute_script(script, args = [])
click to toggle source
Scripts
# File lib/flow_client/client.rb, line 31 def execute_script(script, args = []) req = Access::ExecuteScriptAtLatestBlockRequest.new( script: FlowClient::Utils.substitute_address_aliases(script, @address_aliases), arguments: args ) res = @stub.execute_script_at_latest_block(req) parse_json(res.value) end
get_account(address)
click to toggle source
Accounts
# File lib/flow_client/client.rb, line 24 def get_account(address) req = Access::GetAccountAtLatestBlockRequest.new(address: to_bytes(address)) res = @stub.get_account_at_latest_block(req) res.account end
get_events(type, start_height, end_height)
click to toggle source
Events
# File lib/flow_client/client.rb, line 50 def get_events(type, start_height, end_height) 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: true)
click to toggle source
Blocks
# File lib/flow_client/client.rb, line 41 def get_latest_block(is_sealed: true) req = Access::GetLatestBlockRequest.new( is_sealed: is_sealed ) @stub.get_latest_block(req) end
get_transaction(transaction_id)
click to toggle source
# File lib/flow_client/client.rb, line 70 def get_transaction(transaction_id) req = Access::GetTransactionRequest.new( id: to_bytes(transaction_id) ) @stub.get_transaction(req) end
get_transaction_result(transaction_id)
click to toggle source
# File lib/flow_client/client.rb, line 77 def get_transaction_result(transaction_id) req = Access::GetTransactionRequest.new( id: to_bytes(transaction_id) ) @stub.get_transaction_result(req) end
ping()
click to toggle source
# File lib/flow_client/client.rb, line 18 def ping req = Access::PingRequest.new @stub.ping(req) end
send_transaction(transaction)
click to toggle source
Send a FlowClient::Transaction
transaction to the blockchain
# File lib/flow_client/client.rb, line 62 def send_transaction(transaction) transaction.address_aliases = @address_aliases req = Access::SendTransactionRequest.new( transaction: transaction.to_protobuf_message ) @stub.send_transaction(req) end
Private Instance Methods
parse_json(event_payload)
click to toggle source
# File lib/flow_client/client.rb, line 86 def parse_json(event_payload) JSON.parse(event_payload, object_class: OpenStruct) end
to_bytes(string)
click to toggle source
# File lib/flow_client/client.rb, line 90 def to_bytes(string) [string].pack("H*") end
to_string(bytes)
click to toggle source
# File lib/flow_client/client.rb, line 94 def to_string(bytes) bytes.unpack1("H*") end