-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
984 lines (885 loc) · 27.1 KB
/
index.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
import {
init,
setWallet,
Greeter,
listAllocations,
createAllocation,
getAllocation,
getBalance,
getBalanceWasm,
bulkUpload,
download,
getFaucetToken,
sendTransaction,
listObjects,
share,
showLogs,
hideLogs,
copyObject,
moveObject,
deleteObject,
renameObject,
reloadAllocation,
freezeAllocation,
cancelAllocation,
updateAllocation,
createDir,
getFileStats,
downloadBlocks,
getUSDRate,
isWalletID,
getPublicEncryptionKey,
getLookupHash,
createAllocationWithBlobbers,
getAllocationBlobbers,
getBlobberIds,
createReadPool,
createWallet,
recoverWallet,
getAllocationFromAuthTicket,
getReadPoolInfo,
lockWritePool,
getBlobbers,
decodeAuthTicket,
initBridge,
burnZCN,
mintZCN,
getMintWZCNPayload,
} from "@zerochain/zus-sdk";
import { get, onClick, onClickGroup, setHtml, onChange, setValue } from "./dom";
import { startPlay, stopPlay } from "./player";
const getWallet = () => {
const clientID = get("clientId").value;
const publicKey = get("publicKey").value;
const privateKey = get("privateKey").value;
const mnemonic = get("mnemonic").value;
return {
clientID,
privateKey,
publicKey,
mnemonic,
};
};
const configJson = {
chainId: "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe",
signatureScheme: "bls0chain",
minConfirmation: 50,
minSubmit: 50,
confirmationChainLength: 3,
blockWorker: "https://dev.zus.network/dns",
zboxHost: "https://0box.dev.zus.network",
zboxAppType: "vult",
};
const config = [
configJson.chainId,
configJson.blockWorker,
configJson.signatureScheme,
configJson.minConfirmation,
configJson.minSubmit,
configJson.confirmationChainLength,
configJson.zboxHost,
configJson.zboxAppType,
];
window.downloadCallback = function (totalBytes, completedBytes, error) {
console.log(
"download: " + completedBytes + "/" + totalBytes + " err:" + error
);
};
const getAppendedFileName = (filename, postfix) => {
const isExtnExist = filename.lastIndexOf(".") > 0;
const newFileName = isExtnExist
? filename.substring(0, filename.lastIndexOf(".")) +
postfix +
filename.substring(filename.lastIndexOf("."), filename.length)
: filename + postfix;
console.log("getAppendedFileName", newFileName);
return newFileName;
};
const listAllocationsClick = async () => {
//Call listAllocations method
const allocations = await listAllocations();
console.log("allocations", allocations);
let allocationListHtml = "";
allocations.map((allocation, index) => {
allocationListHtml += `
<div key=${index}>
<input
type="radio"
name="selectedAllocation"
id="selectedAllocation"
value=${allocation.id}
/>
<label htmlFor=${allocation.id}>
Allocation: ${allocation.id}
</label>
<br></br>
</div>`;
});
setHtml("listAllocations", allocationListHtml);
if (allocations && allocations.length > 0) {
onClickGroup("selectedAllocation", selectAllocation);
}
};
const listFilesClick = async () => {
//Call listFiles method
const selectedAllocation = getSelectedAllocation();
console.log("listFilesClick selectedAllocation", selectedAllocation);
let fileListHtml = "";
try {
const list = (await listObjects(selectedAllocation, "/")) || [];
files = list;
console.log("file list", list);
if (list && list.length > 0) {
fileListHtml += `
<div>
<b>File List: /</b>
</div>
`;
}
list.map((file) => {
fileListHtml += `
<div>
<input
type="radio"
name="selectedFile"
id="selectedFile"
value=${file.path}
/>
<label htmlFor=${file.path}>
${file.path}
</label>
<br></br>
</div>`;
});
} catch (error) {
console.log("error:", error);
}
try {
const destList = (await listObjects(selectedAllocation, "/test")) || [];
console.log("file destList", destList);
if (destList && destList.length > 0) {
fileListHtml += `
<div>
<b>File List: /test</b>
</div>
`;
}
destList.map((file) => {
fileListHtml += `
<div>
<input
type="radio"
name="selectedFile"
id="selectedFile"
value=${file.path}
/>
<label htmlFor=${file.path}>
${file.path}
</label>
<br></br>
</div>`;
});
} catch (error) {
console.log("error:", error);
}
setHtml("listFiles", fileListHtml);
if (fileListHtml && fileListHtml.length > 0) {
onClickGroup("selectedFile", selectFile);
}
};
const getSelectedAllocation = () => {
const selectedAllocationElement = document.querySelector(
'input[name="selectedAllocation"]:checked'
);
const selectedAllocation = selectedAllocationElement?.value;
console.log("selected allocation", selectedAllocation);
return selectedAllocation;
};
const selectAllocation = () => {
getSelectedAllocation();
};
const handleUploadFiles = async (event) => {
console.log("handleUploadFiles", event.currentTarget.files);
//setFilesForUpload(event.currentTarget.files);
};
const getSelectedFile = () => {
const selectedFileElement = document.querySelector(
'input[name="selectedFile"]:checked'
);
const selectedFile = selectedFileElement?.value;
console.log("selected file", selectedFile);
return selectedFile;
};
const selectFile = () => {
getSelectedFile();
};
const handleUpdateMnemonic = async (event) => {
console.log("handleUpdateMnemonic", event.currentTarget.value);
setValue("mnemonic", event.currentTarget.value);
};
const getBlobberListForAllocation = async () => {
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + 30);
const referredBlobberURLs = [
"https://dev2.zus.network/blobber02",
"https://dev1.zus.network/blobber02",
],
dataShards = 2,
parityShards = 2,
size = 2 * 1073741824,
expiry = Math.floor(expiryDate.getTime() / 1000),
minReadPrice = 0,
maxReadPrice = 184467440737095516,
minWritePrice = 0,
maxWritePrice = 184467440737095516;
//Call getAllocationBlobbers method
const blobberList = await getAllocationBlobbers(
referredBlobberURLs,
dataShards,
parityShards,
size,
expiry,
minReadPrice,
maxReadPrice,
minWritePrice,
maxWritePrice
);
console.log("blobberList", blobberList);
return blobberList;
};
let files = [];
const bindEvents = () => {
console.log("bindEvents");
onClick("btnGreet", async () => {
console.log("calling Greet");
//Call Greeter method
const greetMessage = Greeter("john doe");
console.log("greetMessage", greetMessage);
setHtml("message", greetMessage);
});
onClick("btnInit", async () => {
console.log("calling init");
//Initialize SDK
await init(config);
});
onClick("btnSetWallet", async () => {
const { clientID, privateKey, publicKey, mnemonic } = getWallet();
await setWallet(clientID, privateKey, publicKey, mnemonic);
});
onClick("btnSendMeTokens", async () => {
await getFaucetToken();
});
onClick("btnSendTransaction", async () => {
console.log("calling sendTransaction");
const { clientID, privateKey, publicKey } = getWallet();
const fromWallet = {
id: clientID,
public_key: publicKey,
secretKey: privateKey,
};
const sendTo = get("sendTo").value;
const sendAmount = get("sendAmount").value;
await sendTransaction(fromWallet, sendTo, parseInt(sendAmount), "");
});
onClick("btnGetBalance", async () => {
const { clientID } = getWallet();
const wallet = await getBalance(clientID);
txtOutput.innerHTML = JSON.stringify(wallet, null, 2);
});
onClick("btnGetBalanceWasm", async () => {
const { clientID } = getWallet();
const wallet = await getBalanceWasm(clientID);
txtOutput.innerHTML = JSON.stringify(wallet, null, 2);
});
onClick("btnCreateWallet", async () => {
console.log("calling createWallet");
const wallet = await createWallet();
console.log("Wallet", wallet);
txtOutput.innerHTML = JSON.stringify(wallet, null, 2);
setValue("clientId", wallet.keys.walletId);
setValue("publicKey", wallet.keys.publicKey);
setValue("privateKey", wallet.keys.privateKey);
});
onClick("btnRecoverWallet", async () => {
console.log("calling recoverWallet");
const mnemonic = get("mnemonic").value;
const wallet = await recoverWallet(mnemonic);
console.log("Wallet", wallet);
txtOutput.innerHTML = JSON.stringify(wallet, null, 2);
setValue("clientId", wallet.keys.walletId);
setValue("publicKey", wallet.keys.publicKey);
setValue("privateKey", wallet.keys.privateKey);
});
onClick("btnListAllocations", listAllocationsClick);
onClick("btnCreateAllocation", async () => {
console.log("calling createAllocation");
const expiry = new Date();
expiry.setDate(expiry.getDate() + 30);
//datashards, parityshards int, size, expiry int64,minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string
const config = {
datashards: 2,
parityshards: 2,
size: 2 * 1073741824,
expiry: Math.floor(expiry.getTime() / 1000),
minReadPrice: 0,
maxReadPrice: 184467440737095516,
minWritePrice: 0,
maxWritePrice: 184467440737095516,
lock: 5000000000,
};
//Call createAllocation method
await createAllocation(config);
listAllocationsClick();
});
onClick("btnGetAllocation", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for get details");
return;
}
const allocation = await getAllocation(selectedAllocation);
console.log("allocation", allocation);
let allocationDetailHtml = `
<div>
Allocation: ${allocation.id}, Size: ${allocation.size}, Start Time: ${allocation.start_time}, Expiration Date: ${allocation.expiration_date}
</div>
<br></br>
</div>`;
setHtml("allocationDetails", allocationDetailHtml);
});
onClick("btnReloadAllocation", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for reload");
return;
}
const allocation = await reloadAllocation(selectedAllocation);
console.log("allocation", allocation);
let allocationDetailHtml = `
<div>
Allocation: ${allocation.id}, Name: ${allocation.name}, Size: ${allocation.size}, Start Time: ${allocation.start_time}, Expiration Date: ${allocation.expiration_date}
</div>
<br></br>
</div>`;
setHtml("allocationDetails", allocationDetailHtml);
});
onClick("btnFreezeAllocation", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for freeze");
return;
}
await freezeAllocation(selectedAllocation);
});
onClick("btnCancelAllocation", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for cancel");
return;
}
await cancelAllocation(selectedAllocation);
});
onClick("btnUpdateAllocation", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for update");
return;
}
console.log("updating allocation", selectedAllocation);
const allocationSize = get("allocationSize").value;
const expiry = new Date();
expiry.setDate(expiry.getDate() + 30);
//allocationId string,size, expiry int64,lock int64, isImmutable, updateTerms bool,addBlobberId, removeBlobberId string
const size = parseInt(allocationSize),
expiryVal = Math.floor(expiry.getTime() / 1000),
lock = 5000000000,
updateTerms = true,
addBlobberId = "",
removeBlobberId = "";
//Call updateAllocation method
await updateAllocation(
selectedAllocation,
size,
expiryVal,
lock,
updateTerms,
addBlobberId,
removeBlobberId
);
});
onChange("uploadFile", handleUploadFiles);
onClick("btnUpload", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for upload");
return;
}
const filesForUpload = get("uploadFile").files;
console.log("filesForUpload", filesForUpload);
if (!(filesForUpload && filesForUpload.length > 0)) {
alert("Please select the files for upload");
return;
}
console.log("uploading to allocation", selectedAllocation, filesForUpload);
if (filesForUpload && filesForUpload.length > 0) {
const objects = [];
const allocationId = selectedAllocation;
for (const file of filesForUpload) {
objects.push({
allocationId: allocationId,
remotePath: `/${file.name}`,
file: file,
// thumbnailBytes: await readBytes(file), //only for demo, don't upload original file as thumbnail in production
thumbnailBytes: "",
encrypt: false,
isUpdate: false,
isRepair: false,
numBlocks: 100,
callback: function (totalBytes, completedBytes, error) {
console.log(
file.name +
" " +
completedBytes +
"/" +
totalBytes +
" err:" +
error
);
},
});
}
const results = await bulkUpload(objects);
console.log("upload results", JSON.stringify(results));
}
});
onClick("btnDownload", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for download");
return;
}
const path = getSelectedFile();
if (path) {
const allocationId = selectedAllocation;
console.log("downloading ", path, " from ", allocationId);
//allocationID, remotePath, authTicket, lookupHash string, downloadThumbnailOnly bool, numBlocks int, callback
const file = await download(
allocationId,
path,
"",
"",
false,
10,
"downloadCallback"
);
console.log("downloaded file", file);
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = file.url;
a.download = file.fileName;
a.click();
window.URL.revokeObjectURL(file.url);
document.body.removeChild(a);
}
});
onClick("btnShare", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation for share");
return;
}
const path = getSelectedFile();
if (path) {
const allocationId = selectedAllocation;
console.log("sharing ", path, " from ", allocationId);
//allocationId, filePath, clientId, encryptionPublicKey string, expireAt int, revoke bool,availableAfter string
const authTicket = await share(allocationId, path, "", "", 0, false, 0);
console.log("authTicket", authTicket);
setValue("authTicket", authTicket);
}
});
onClick("btnDownloadShared", async () => {
const authTicket = get("authTicket").value;
if (authTicket) {
console.log("downloading using authTicket", authTicket);
//allocationID, remotePath, authTicket, lookupHash string, downloadThumbnailOnly bool, numBlocks int
const file = await download("", "", authTicket, "", false, 10);
console.log("downloaded file", file);
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = file.url;
a.download = file.fileName;
a.click();
window.URL.revokeObjectURL(file.url);
document.body.removeChild(a);
}
});
onClick("btnListFiles", listFilesClick);
onClick("btnCopy", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for copy");
return;
}
console.log("copy file", selectedAllocation, path);
//allocationId, path, destination
await copyObject(selectedAllocation, path, "/test");
console.log("copy completed");
});
onClick("btnMove", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for move");
return;
}
console.log("move file", selectedAllocation, path);
//allocationId, path, destination
await moveObject(selectedAllocation, path, "/test");
console.log("move completed");
});
onClick("btnDelete", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for delete");
return;
}
console.log("delete file", selectedAllocation, path);
//allocationId, path
await deleteObject(selectedAllocation, path);
console.log("delete completed");
});
onClick("btnRename", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for rename");
return;
}
console.log("rename file", selectedAllocation, path);
//allocationId, path, newName
await renameObject(
selectedAllocation,
path,
getAppendedFileName(path, "_new")
);
console.log("rename completed");
});
const player = get("player");
let isPlayerReady = false;
onClick("btnPlay", async () => {
if (isPlayerReady) {
if (player.paused) {
player.play();
}
} else {
const file = files.find((it) => it.path == getSelectedFile());
console.log("playing file", file);
const isLive = file.type == "d";
if (file) {
const allocationId = getSelectedAllocation();
startPlay({
allocationId,
videoElement: player,
remotePath: file?.path,
authTicket: "",
lookupHash: file?.lookup_hash,
mimeType: file?.mimetype,
isLive: isLive,
});
isPlayerReady = true;
}
}
});
onClick("btnPlayShared", async () => {
if (isPlayerReady) {
if (player.paused) {
player.play();
}
} else {
const authTicket = get("authTicket").value;
const isLive = false;
if (authTicket) {
const allocationId = getSelectedAllocation();
startPlay({
allocationId,
videoElement: player,
remotePath: "",
authTicket: authTicket,
lookupHash: "",
mimeType: "",
isLive: isLive,
});
isPlayerReady = true;
}
}
});
onClick("btnPause", async () => {
player.pause();
});
onClick("btnStop", async () => {
if (isPlayerReady) {
stopPlay({ videoElement: player });
isPlayerReady = false;
}
});
onClick("btnCreateDir", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const dirName = get("dirName").value;
console.log("Create Dir", selectedAllocation, dirName);
//allocationId, path
await createDir(selectedAllocation, "/" + dirName);
console.log("create Dir completed");
});
onClick("btnGetFileStats", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for stats");
return;
}
console.log("getting file stats", selectedAllocation, path);
const fileStats = await getFileStats(selectedAllocation, path);
console.log("file stats completed", fileStats);
});
onClick("btnDownloadBlocks", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for download blocks");
return;
}
console.log("download blocks", selectedAllocation, path);
//allocationID, remotePath, authTicket, lookupHash string, numBlocks int, startBlockNumber, endBlockNumber int64, callbackFuncName string
const output = await downloadBlocks(
selectedAllocation,
path,
"",
"",
10,
0,
10
);
console.log("downloaded blocks", output);
});
onClick("btnGetLookupHash", async () => {
const selectedAllocation = getSelectedAllocation();
if (!selectedAllocation) {
alert("Please select allocation");
return;
}
const path = getSelectedFile();
if (!path) {
alert("Please select the file for getLookupHash");
return;
}
console.log("getLookupHash file", selectedAllocation, path);
//allocationId, path
const hash = await getLookupHash(selectedAllocation, path);
console.log("getLookupHash completed", hash);
});
onClick("btnGetPublicEncryptKey", async () => {
const mnemonic = get("mnemonic").value;
console.log("getPublicEncryptionKey", mnemonic);
const key = await getPublicEncryptionKey(mnemonic);
console.log("getPublicEncryptionKey completed", key);
setHtml("encryptKey", key);
});
onChange("mnemonic", handleUpdateMnemonic);
onClick("btnGetPublicEncryptKey", async () => {
const mnemonic = get("mnemonic").value;
console.log("getPublicEncryptionKey", mnemonic);
const key = await getPublicEncryptionKey(mnemonic);
console.log("getPublicEncryptionKey completed", key);
setHtml("encryptKey", key);
});
onClick("btnGetUSDRate", async () => {
console.log("getUSDRate");
const rate = await getUSDRate("zcn");
console.log("getUSDRate completed", rate);
setHtml("utilsOutput", rate);
});
onClick("btnIsWalletID", async () => {
const clientId = get("clientId").value;
console.log("isWalletID", clientId);
const output = await isWalletID(clientId);
// const output = await isWalletID("test");
console.log("isWalletID completed", output);
setHtml("utilsOutput", output);
});
onClick("btnCreateAllocationWithBlobbers", async () => {
console.log("CreateAllocationWithBlobbers");
const preferredBlobbers = getBlobberListForAllocation();
const expiry = new Date();
expiry.setDate(expiry.getDate() + 30);
//datashards, parityshards int, size, expiry int64,minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string
const config = {
datashards: 2,
parityshards: 2,
size: 2 * 1073741824,
expiry: Math.floor(expiry.getTime() / 1000),
minReadPrice: 0,
maxReadPrice: 184467440737095516,
minWritePrice: 0,
maxWritePrice: 184467440737095516,
lock: 5000000000,
blobbers: preferredBlobbers,
};
//Call createAllocationWithBlobbers method
await createAllocationWithBlobbers(config);
listAllocationsClick();
});
onClick("btnGetAllocationBlobbers", async () => {
console.log("GetAllocationBlobbers");
await getBlobberListForAllocation();
});
onClick("btnGetBlobberIds", async () => {
console.log("GetBlobberIds");
//https://dev1.zus.network/sharder01/v1/screst/6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7/getblobbers
//const blobberUrls = [];
const blobberUrls = [
"https://dev2.zus.network/blobber02",
"https://dev1.zus.network/blobber02",
];
//Call getBlobberIds method
const blobberIds = await getBlobberIds(blobberUrls);
console.log("blobberIds", blobberIds);
});
onClick("btnCreateReadPool", async () => {
console.log("CreateReadPool");
//Call createReadPool method
const result = await createReadPool();
console.log("result", result);
});
onClick("btnGetAllocFromAuthTicket", async () => {
const authTicket = get("authTicket").value;
console.log("GetAllocFromAuthTicket", authTicket);
const allocation = await getAllocationFromAuthTicket(authTicket);
console.log("allocation", allocation);
});
onClick("btnGetReadPoolInfo", async () => {
const clientId = get("clientId").value;
console.log("GetReadPoolInfo", clientId);
const result = await getReadPoolInfo(clientId);
console.log("result", result);
});
onClick("btnLockWritePool", async () => {
const allocationId = getSelectedAllocation();
console.log("LockWritePool", allocationId);
//allocationId string, tokens string, fee string
const result = await lockWritePool(allocationId, 1000, 10);
console.log("result", result);
});
onClick("btnGetBlobbers", async () => {
console.log("GetBlobbers");
const result = await getBlobbers();
console.log("result", result);
});
onClick("btnDecodeAuthTicket", async () => {
const authTicket = get("authTicket").value;
console.log("DecodeAuthTicket", authTicket);
const result = await decodeAuthTicket(authTicket);
console.log("result", result);
});
onClick("btnInitBridge", async () => {
const ethereumAddress = "0x5B9eb7E72247c45F6c4B8424FB2002151c57c54d",
bridgeAddress = "0x2405e40161ea6da91AE0e95061e7A8462b4D5eEa",
authorizersAddress = "0xB132C20A02AD7C38d88805F0e3fFDdfb54224C58",
wzcnAddress = "0x10140fbca3a468A1c35F132D75659eF0EB5d95DB",
ethereumNodeURL =
"https://goerli.infura.io/v3/6141be73a15d47748af0dc14f53d57d7",
gasLimit = 300000,
value = 0,
consensusThreshold = 75.0;
console.log(
"initBridgeClick",
ethereumAddress,
bridgeAddress,
authorizersAddress,
wzcnAddress,
ethereumNodeURL,
gasLimit,
value,
consensusThreshold
);
//Call initBridge method
await initBridge(
ethereumAddress,
bridgeAddress,
authorizersAddress,
wzcnAddress,
ethereumNodeURL,
gasLimit,
value,
consensusThreshold
);
});
onClick("btnBurnZCN", async () => {
const amount = 1000;
console.log("burnZCNClick", amount);
const hash = await burnZCN(amount);
setValue("txHash", hash);
return hash;
});
onClick("btnGetMintWZCNPayload", async () => {
const burnTrxHash = get("txHash").value;
console.log("getMintWZCNPayloadClick", burnTrxHash);
const result = await getMintWZCNPayload(burnTrxHash);
return result;
});
onClick("btnMintZCN", async () => {
const burnTrxHash = get("txHash").value;
const timeout = 100;
console.log("mintZCNClick", burnTrxHash, timeout);
const hash = await mintZCN(burnTrxHash, timeout);
return hash;
});
const log = console.log;
const logs = get("logs");
onClick("btnShowLogs", async () => {
await showLogs();
console.log = (s) => {
log(s);
logs.value += s;
logs.scrollLeft = 0;
logs.scrollTop = logs.scrollHeight;
};
});
onClick("btnHideLogs", async () => {
await hideLogs();
console.log = log;
});
};
window.onload = bindEvents;