forked from onflow/fcl-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend-get-collection.js
31 lines (22 loc) · 919 Bytes
/
send-get-collection.js
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
import {invariant} from "@onflow/util-invariant"
import {GetCollectionByIDRequest, AccessAPI} from "@onflow/protobuf"
import {response} from "../response/response.js"
import {unary as defaultUnary} from "./unary"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
const hexBuffer = hex => Buffer.from(hex, "hex")
export async function sendGetCollection(ix, opts = {}) {
invariant(opts.node, `SDK Send Get Collection Error: opts.node must be defined.`)
const unary = opts.unary || defaultUnary
ix = await ix
const req = new GetCollectionByIDRequest()
req.setId(hexBuffer(ix.collection.id))
const res = await unary(opts.node, AccessAPI.GetCollectionByID, req)
const collection = res.getCollection()
const ret = response()
ret.tag = ix.tag
ret.collection = {
id: u8ToHex(collection.getId_asU8()),
transactionIds: (collection.getTransactionIdsList()).map(u8ToHex)
}
return ret
}