-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflow.rb
More file actions
41 lines (33 loc) · 936 Bytes
/
Copy pathflow.rb
File metadata and controls
41 lines (33 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'flow/access/access_services_pb'
require 'flow/execution/execution_services_pb'
require 'json'
class Flow
def initialize(node_address)
@stub = Access::AccessAPI::Stub.new(node_address, :this_channel_is_insecure)
end
def ping
req = Access::PingRequest.new
res = @stub.ping(req)
res
end
def get_account(address)
req = Access::GetAccountAtLatestBlockRequest.new(address: to_bytes(address))
res = @stub.get_account_at_latest_block(req)
res.account
end
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
private
def parse_json(event_payload)
JSON.parse(event_payload, object_class: OpenStruct)
end
def to_bytes(string)
[string].pack('H*')
end
def to_string(bytes)
bytes.unpack('H*').first
end
end