This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·252 lines (236 loc) · 6.1 KB
/
index.ts
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env ts-node
export {};
const { Tezos } = require('@taquito/taquito');
const fs = require("fs");
const bob_address = 'tz1bDCu64RmcpWahdn9bWrDMi6cu7mXZynHm';
const { email, password, mnemonic, secret } =
JSON.parse(
fs.readFileSync(require('os').homedir() + '/Downloads/' + bob_address + '.json').toString()
);
Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/carthagenet' });
Tezos.importKey(email, password, mnemonic.join(" "), secret);
// JSON for the admin-lambda contract
const admin_lambda_json = '[{"prim":"parameter",' +
'"args":[{"prim":"lambda","args":[{"prim":"address"},' +
'{"prim":"pair","args":[{"prim":"list","args":[{"prim":"operation"}]},{"prim":"address"}]}]}]},' +
'{"prim":"storage","args":[{"prim":"address"}]},{"prim":"code","args":[[{"prim":"DUP"},{"prim":"CDR"},' +
'{"prim":"DIP","args":[[{"prim":"CAR"}]]},{"prim":"DUP"},{"prim":"SENDER"},{"prim":"COMPARE"},{"prim":"EQ"},' +
'{"prim":"IF","args":[[{"prim":"EXEC"}],[{"prim":"FAILWITH"}]]}]]}]';
// Check whether a contract is the admin-lambda contract
const is_admin_lambda_contract = contract => {
return admin_lambda_json === JSON.stringify(contract.script.code)
};
// The lambda JSON to update the admin of an admin-lambda contract
const update_admin_lambda = new_admin_address => {
return [
{
"prim": "DROP"
},
{
"prim": "PUSH",
"args": [
{
"prim": "address"
},
{
"string": new_admin_address
}
]
},
{
"prim": "NIL",
"args": [
{
"prim": "operation"
}
]
},
{
"prim": "PAIR"
}
]
};
// The lambda JSON to update the FA2 operator of an admin-lambda contract
const update_operators_lambda = (admin_lambda_address, fa2_address, new_operator_address) => {
return [
{
"prim": "PUSH",
"args": [
{
"prim": "address"
},
{
"string": "" + fa2_address + "%update_operators"
}
]
},
{
"prim": "CONTRACT",
"args": [
{
"prim": "list",
"args": [
{
"prim": "or",
"args": [
{
"prim": "pair",
"args": [
{
"prim": "address"
},
{
"prim": "address"
}
]
},
{
"prim": "pair",
"args": [
{
"prim": "address"
},
{
"prim": "address"
}
]
}
]
}
]
}
]
},
[
{
"prim": "IF_NONE",
"args": [
[
[
{
"prim": "UNIT"
},
{
"prim": "FAILWITH"
}
]
],
[]
]
}
],
{
"prim": "PUSH",
"args": [
{
"prim": "mutez"
},
{
"int": "0"
}
]
},
{
"prim": "PUSH",
"args": [
{
"prim": "list",
"args": [
{
"prim": "or",
"args": [
{
"prim": "pair",
"args": [
{
"prim": "address"
},
{
"prim": "address"
}
]
},
{
"prim": "pair",
"args": [
{
"prim": "address"
},
{
"prim": "address"
}
]
}
]
}
]
},
[
{
"prim": "Left",
"args": [
{
"prim": "Pair",
"args": [
{
"string": admin_lambda_address
},
{
"string": new_operator_address
}
]
}
]
}
]
]
},
{
"prim": "TRANSFER_TOKENS"
},
{
"prim": "DIP",
"args": [
[
{
"prim": "NIL",
"args": [
{
"prim": "operation"
}
]
}
]
]
},
{
"prim": "CONS"
},
{
"prim": "PAIR"
}
]
};
const admin_lambda_examples = async () => {
console.log('inside: admin_lambda_examples');
const admin_lambda_address = 'KT1GESj71qmXfFHQZgA3kbK3bPaxiyuhXbcE';
const admin_lambda_contract = await Tezos.contract.at(admin_lambda_address);
// Check whether bob is actually the admin
const storage = await admin_lambda_contract.storage();
console.log('bob is admin:', storage === bob_address);
// Check whether it's actually the admin-lambda contract
console.log('is_admin_lambda_contract:', is_admin_lambda_contract(admin_lambda_contract));
// Update the admin_lambda_contract's admin to bob_address
const update_admin_op = await admin_lambda_contract.methods.main(update_admin_lambda(bob_address)).send();
await update_admin_op.confirmation().then(() => console.log('update_admin_op.hash:', update_admin_op.hash));
// Update the admin_lambda_contract's operator on the
// fa2_address contract to fred_address:
const fred_address = 'tz1RwoEdg4efDQHarsw6aKtMUYvg278Gv1ir';
const fa2_address = 'KT1TUb1czajTExzPiSqaPBzDSYf85VqZ5PzT';
const update_operator_op = await admin_lambda_contract.methods.main(
update_operators_lambda(admin_lambda_address, fa2_address, fred_address)
).send();
await update_operator_op.confirmation().then(() => console.log('update_operator_op.hash:', update_operator_op.hash));
console.log('ending: admin_lambda_examples');
};
admin_lambda_examples();