@dusk-network/app-core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +49 -3
- package/package.json +19 -2
- package/src/bridge.d.ts +20 -6
- package/src/bridge.js +32 -11
- package/src/duskevm-withdrawals.d.ts +535 -0
- package/src/duskevm-withdrawals.js +2429 -0
- package/src/history.d.ts +9 -2
- package/src/history.js +11 -4
package/src/history.d.ts
CHANGED
|
@@ -108,9 +108,15 @@ export type HistoryEntry = {
|
|
|
108
108
|
/**
|
|
109
109
|
* What left or reached the account, in lux, fees aside. A gas refund the
|
|
110
110
|
* transaction paid to another account than its sender is what left the
|
|
111
|
-
* sender, beside its fee, and what reached that account.
|
|
111
|
+
* sender, beside its fee, and what reached that account (`refund`).
|
|
112
112
|
*/
|
|
113
113
|
value: bigint;
|
|
114
|
+
/**
|
|
115
|
+
* Of `value`, the unspent gas the transaction paid to another account
|
|
116
|
+
* than its sender, in lux; left out when there's none. An entry an
|
|
117
|
+
* earlier version kept has none, whatever its value holds.
|
|
118
|
+
*/
|
|
119
|
+
refund?: bigint;
|
|
114
120
|
/** The memo as text, or as 0x hex when it isn't text; "" for none. */
|
|
115
121
|
memo: string;
|
|
116
122
|
/** Whether the account paid the fee. */
|
|
@@ -160,9 +166,10 @@ export type EntryDetails = {
|
|
|
160
166
|
* stores as JSON, with its details once read, and any fields the app keeps
|
|
161
167
|
* beside them (as its hook's facts).
|
|
162
168
|
*/
|
|
163
|
-
export type KeptEntry = Omit<HistoryEntry, "value"> &
|
|
169
|
+
export type KeptEntry = Omit<HistoryEntry, "value" | "refund"> &
|
|
164
170
|
Partial<EntryDetails> & {
|
|
165
171
|
value: string;
|
|
172
|
+
refund?: string;
|
|
166
173
|
[field: string]: unknown;
|
|
167
174
|
};
|
|
168
175
|
|
package/src/history.js
CHANGED
|
@@ -437,6 +437,8 @@ export function parseHistoryEntry(account, raw) {
|
|
|
437
437
|
|
|
438
438
|
let inValue = 0n;
|
|
439
439
|
let outValue = 0n;
|
|
440
|
+
// Of those, unspent gas paid to another account than its sender.
|
|
441
|
+
let refunded = 0n;
|
|
440
442
|
/** @type {bigint | null} */
|
|
441
443
|
let selfValue = null;
|
|
442
444
|
let payer = false;
|
|
@@ -493,9 +495,11 @@ export function parseHistoryEntry(account, raw) {
|
|
|
493
495
|
|
|
494
496
|
if (d.refund_info[0] === account) {
|
|
495
497
|
inValue += refund;
|
|
498
|
+
refunded += refund;
|
|
496
499
|
receivedFrom ??= d.sender;
|
|
497
500
|
} else if (d.sender === account) {
|
|
498
501
|
outValue += refund;
|
|
502
|
+
refunded += refund;
|
|
499
503
|
}
|
|
500
504
|
}
|
|
501
505
|
} else if (topic === "convert") {
|
|
@@ -570,7 +574,7 @@ export function parseHistoryEntry(account, raw) {
|
|
|
570
574
|
else counterparty = direction === "out" ? sentTo : receivedFrom;
|
|
571
575
|
}
|
|
572
576
|
|
|
573
|
-
return { blockHeight, counterparty: counterparty || null, direction, hash, kind, memo, payer, value };
|
|
577
|
+
return { blockHeight, counterparty: counterparty || null, direction, hash, kind, memo, payer, value, ...(refunded ? { refund: refunded } : {}) };
|
|
574
578
|
}
|
|
575
579
|
|
|
576
580
|
/**
|
|
@@ -589,9 +593,10 @@ export function historyEntry(row, { network = null, pools } = {}) {
|
|
|
589
593
|
const sozu = Boolean(
|
|
590
594
|
net && row.contractId && row.fnName && isSozuCall(net, { contractId: row.contractId, fnName: row.fnName }, { pools: pools ?? [] })
|
|
591
595
|
);
|
|
596
|
+
const { refund, ...fields } = row;
|
|
592
597
|
|
|
593
598
|
return {
|
|
594
|
-
...
|
|
599
|
+
...fields,
|
|
595
600
|
blockHash: row.blockHash,
|
|
596
601
|
blockHeight: row.blockHeight,
|
|
597
602
|
bridge: row.bridge,
|
|
@@ -615,6 +620,7 @@ export function historyEntry(row, { network = null, pools } = {}) {
|
|
|
615
620
|
success: row.success ?? null,
|
|
616
621
|
timestamp: row.timestamp ?? null,
|
|
617
622
|
value: u64(row.value),
|
|
623
|
+
...(refund === undefined ? {} : { refund: u64(refund) }),
|
|
618
624
|
};
|
|
619
625
|
}
|
|
620
626
|
|
|
@@ -629,7 +635,7 @@ export function historyEntry(row, { network = null, pools } = {}) {
|
|
|
629
635
|
function keptOf(entry) {
|
|
630
636
|
if (typeof entry?.value !== "bigint") return /** @type {KeptEntry} */ (entry);
|
|
631
637
|
|
|
632
|
-
const { route, sozu, ...rest } = /** @type {ReadEntry} */ (entry);
|
|
638
|
+
const { refund, route, sozu, ...rest } = /** @type {ReadEntry} */ (entry);
|
|
633
639
|
const { gasPrice, gasSpent } = rest;
|
|
634
640
|
|
|
635
641
|
return {
|
|
@@ -638,6 +644,7 @@ function keptOf(entry) {
|
|
|
638
644
|
success: rest.success ?? undefined,
|
|
639
645
|
timestamp: rest.detailsAt ? rest.timestamp : undefined,
|
|
640
646
|
value: rest.value.toString(),
|
|
647
|
+
...(refund === undefined ? {} : { refund: refund.toString() }),
|
|
641
648
|
};
|
|
642
649
|
}
|
|
643
650
|
|
|
@@ -977,7 +984,7 @@ export async function fetchTxNonce(archive, hash) {
|
|
|
977
984
|
* @param {HistoryEntry} entry
|
|
978
985
|
* @returns {KeptEntry}
|
|
979
986
|
*/
|
|
980
|
-
const toKept = (entry) => ({ ...entry, value: entry.value.toString() });
|
|
987
|
+
const toKept = ({ refund, ...entry }) => ({ ...entry, value: entry.value.toString(), ...(refund === undefined ? {} : { refund: refund.toString() }) });
|
|
981
988
|
|
|
982
989
|
/**
|
|
983
990
|
* @param {HistoryOptions} options
|