-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathteal_utils.js
86 lines (68 loc) · 1.82 KB
/
teal_utils.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
function sleep(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
async function getAppIndex(txn, net, ref) {
let data = undefined
let dataObj = undefined
let id = undefined
let url = ""
await sleep(15000)
if (ref.EnableDeveloperAPI) {
url = ref.indexer
}
else {
if (!net) {
url = "https://testnet-idx.algonode.cloud"
}
else {
url = "https://mainnet-idx.algonode.cloud"
}
}
data = await fetch(url + '/v2/transactions/' + txn)
dataObj = await data.json()
id = await dataObj.transaction["created-application-index"]
return id
}
function u8array(text) {
return Uint8Array.from(Array.from(text).map(letter => letter.charCodeAt(0)));
}
async function readGlobalState(net,index,ref) {
let url = ""
if (ref.EnableDeveloperAPI) {
url = ref.indexer
}
else {
if (!net) {
url = "https://testnet-idx.algonode.cloud"
}
else {
url = "https://mainnet-idx.algonode.cloud"
}
}
let appData = await fetch(url + '/v2/applications/' + index)
let appJSON = await appData.json()
return appJSON.application.params["global-state"]
}
async function getAsaIndex(txn, net, ref) {
let data = undefined
let dataObj = undefined
let id = undefined
let url = ""
await sleep(15000)
if (ref.EnableDeveloperAPI) {
url = ref.indexer
}
else {
if (!net) {
url = "https://testnet-idx.algonode.cloud"
}
else {
url = "https://mainnet-idx.algonode.cloud"
}
}
data = await fetch(url + '/v2/transactions/' + txn)
dataObj = await data.json()
id = await dataObj.transaction["created-asset-index"]
return id
}
export {getAppIndex, getAsaIndex, u8array, readGlobalState}