-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueryChainGraph.js
95 lines (91 loc) · 2.77 KB
/
queryChainGraph.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
async function queryChainGraph(queryReq, chaingraphUrl){
const jsonObj = {
"operationName": null,
"variables": {},
"query": queryReq
};
const response = await fetch(chaingraphUrl, {
method: "POST",
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(jsonObj), // body data type must match "Content-Type" header
});
return await response.json();
}
export async function queryTotalSupplyFT(tokenId, chaingraphUrl){
const queryReqTotalSupply = `query {
transaction(
where: {
inputs: {
outpoint_transaction_hash: { _eq: "\\\\x${tokenId}" }
outpoint_index: { _eq: 0 }
}
}
) {
outputs(where: { token_category: { _eq: "\\\\x${tokenId}" } }) {
fungible_token_amount
}
}
}`;
return await queryChainGraph(queryReqTotalSupply, chaingraphUrl);
}
export async function queryActiveMinting(tokenId, chaingraphUrl){
const queryReqActiveMinting = `query {
output(
where: {
token_category: { _eq: "\\\\x${tokenId}" }
_and: { nonfungible_token_capability: { _eq: "minting" } }
_not: { spent_by: {} }
}
) {
locking_bytecode
}
}`;
return await queryChainGraph(queryReqActiveMinting, chaingraphUrl);
}
export async function querySupplyNFTs(tokenId, chaingraphUrl, offset =0){
const queryReqTotalSupply = `query {
output(
offset: ${offset}
where: {
token_category: {
_eq: "\\\\x${tokenId}"
}
_and: [
{ nonfungible_token_capability: { _eq: "none" } }
]
_not: { spent_by: {} }
}
) {
locking_bytecode
}
}`;
return await queryChainGraph(queryReqTotalSupply, chaingraphUrl);
}
export async function queryAuthHead(tokenId, chaingraphUrl){
const queryReqAuthHead = `query {
transaction(
where: {
hash: {
_eq: "\\\\x${tokenId}"
}
}
) {
hash
authchains {
authhead {
identity_output {
transaction_hash
}
}
}
}
}`;
return await queryChainGraph(queryReqAuthHead, chaingraphUrl);
}