-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_TransactionsAndEventsForAddress.ts
107 lines (89 loc) · 3.81 KB
/
02_TransactionsAndEventsForAddress.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
import {Checkpoint, CheckpointPage, getFullnodeUrl, SuiClient} from "@mysten/sui.js/client";
const provider = new SuiClient({
url: getFullnodeUrl("testnet"),
});
/**
* Get latest 100 checkpoints in descending order and print Transaction Digests for each one of them
*/
provider.getCheckpoints({descendingOrder: true})
.then(function (checkpointPage: CheckpointPage) {
checkpointPage.data.forEach(checkpoint => {
console.log("---------------------------------------------------------------")
console.log(" ----------- Transactions for Checkpoint: ", checkpoint.sequenceNumber, " -------- ")
console.log("---------------------------------------------------------------")
checkpoint.transactions.forEach(tx => {
console.log(tx);
})
console.log("***************************************************************")
})
});
/**
* Get Checkpoint 1994010 and print details
*/
provider.getCheckpoint({id: "1994010"})
.then(function (checkpoint: Checkpoint) {
console.log("Checkpoint Sequence Num ", checkpoint.sequenceNumber);
console.log("Checkpoint timestampMs ", checkpoint.timestampMs);
console.log("Checkpoint # of Transactions ", checkpoint.transactions.length);
});
provider.getTransactionBlock({
digest:'HyWEk1GCEVVSgSG2GiNgigeY7TQsDs2WGQbAE5f5JGQz',
options: {
showInput: false,
showEffects: true,
showEvents: false,
showObjectChanges: false,
showBalanceChanges: false
}
}).then(block => {
console.log(block.effects);
}).catch(err => {
console.log("Error while fetching transaction block: ");
});
provider.multiGetTransactionBlocks({
digests:
[
"1WuC2hJs2kkBpe4Rk7jDyefZLZBJDJF5EwM2Kew7sVB",
"9psfk16gp3aX4nLGy8Err5PpvLmdaVwovL4SueqCBEW5",
"9xzjuoob2qsrh9kFMoHn8vbpiojesqZ3Wv3wkJ6Tz1Nv",
"3MzDkyZya7BRvtxkeM8NhtPGgJLX122gxHVNpc4Cxvkq",
"B1mAvKT9ADQpqrFHgmN8vrb5cakQfoYtdU2WyWzW5yYZ",
"AgPRUDrrJrAGUEj63H6NTq7DsjhB7EBxeGwEJynRzt8E",
"2W87VEbK3aLASNmmpQrmRN6FF6TkBojCgqTmjzsuWMGE",
"7mhDpg9zJSsq7KXHsnqWwCrBfbHpXTRFkGXHRPpcztHJ",
"4CWyteng664d5rLT2fJGv9k5k3vCFvSDDRpYPVfBHXg2",
],
options: {
showInput: false,
showEffects: true,
showEvents: false,
showObjectChanges: false,
showBalanceChanges: true
}
}).then(block => {
let totalCompCost = 0;
let totalStorageCost = 0;
let totalStorageRebate = 0;
let totalNonRefundableFee = 0;
for(let i=0; i<block.length; i++){
const b = block[i];
totalCompCost += parseInt(b.effects.gasUsed.computationCost);
totalStorageRebate += parseInt(b.effects.gasUsed.storageRebate);
totalStorageCost += parseInt(b.effects.gasUsed.storageCost);
totalNonRefundableFee += parseInt(b.effects.gasUsed.nonRefundableStorageFee);
}
console.log("Total TXs = ", block.length);
console.log("-----------------------------------------------")
console.log("Total Computation Cost: \t", totalCompCost);
console.log("Total Storage Rebate: \t", totalStorageRebate);
console.log("Total Storage Cost: \t", totalStorageCost);
console.log("Total Non Refundable Fee: \t", totalNonRefundableFee);
const base = 1000000000;
console.log("-----------------------------------------------")
console.log("IN SUI")
console.log("-----------------------------------------------")
console.log("Total Computation Cost: \t", totalCompCost/base);
console.log("Total Storage Rebate: \t", totalStorageRebate /base );
console.log("Total Storage Cost: \t", totalStorageCost/base);
console.log("Total Non Refundable Fee: \t", totalNonRefundableFee/base);
})