@mysten-incubation/suipay-buyer 0.3.0-dev.22 → 0.3.0-dev.23
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/dist/index.js +48 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3747,13 +3747,18 @@ var GUARDED_DELEGATE_ARG_LAYOUT = {
|
|
|
3747
3747
|
recipient: null,
|
|
3748
3748
|
amount: 6,
|
|
3749
3749
|
paymentIdHash: 7,
|
|
3750
|
-
expiresAtMs: 9
|
|
3750
|
+
expiresAtMs: 9,
|
|
3751
|
+
// After clock (10): chain id, refund config, decide window, refund window.
|
|
3752
|
+
decideWindowMs: 13,
|
|
3753
|
+
refundWindowMs: 14
|
|
3751
3754
|
},
|
|
3752
3755
|
settle_any_recipient_to_refund_vault: {
|
|
3753
3756
|
recipient: 4,
|
|
3754
3757
|
amount: 5,
|
|
3755
3758
|
paymentIdHash: 6,
|
|
3756
|
-
expiresAtMs: 9
|
|
3759
|
+
expiresAtMs: 9,
|
|
3760
|
+
decideWindowMs: 13,
|
|
3761
|
+
refundWindowMs: 14
|
|
3757
3762
|
}
|
|
3758
3763
|
};
|
|
3759
3764
|
function pureBytesOf(data, arg) {
|
|
@@ -3833,11 +3838,48 @@ function recoverGuardedDelegateCalls(finalized) {
|
|
|
3833
3838
|
paymentIdHash: readPureVectorU8Hex(data, args[layout.paymentIdHash]),
|
|
3834
3839
|
amount: readPureU64(data, args[layout.amount]),
|
|
3835
3840
|
recipient: layout.recipient === null ? null : readPureAddress(data, args[layout.recipient]),
|
|
3836
|
-
expiresAtMs: readPureU64(data, args[layout.expiresAtMs])
|
|
3841
|
+
expiresAtMs: readPureU64(data, args[layout.expiresAtMs]),
|
|
3842
|
+
..."decideWindowMs" in layout ? {
|
|
3843
|
+
decideWindowMs: readPureU64(data, args[layout.decideWindowMs]),
|
|
3844
|
+
refundWindowMs: readPureU64(data, args[layout.refundWindowMs])
|
|
3845
|
+
} : {}
|
|
3837
3846
|
});
|
|
3838
3847
|
}
|
|
3839
3848
|
return calls;
|
|
3840
3849
|
}
|
|
3850
|
+
var VAULT_SETTLEMENT_TS_TIMEOUT_MS = 1e4;
|
|
3851
|
+
function withTimeout(work, ms, label) {
|
|
3852
|
+
return new Promise((resolve, reject2) => {
|
|
3853
|
+
const timer = setTimeout(() => reject2(new Error(`${label} timed out after ${ms}ms`)), ms);
|
|
3854
|
+
Promise.resolve(work).then((value) => {
|
|
3855
|
+
clearTimeout(timer);
|
|
3856
|
+
resolve(value);
|
|
3857
|
+
}, (err) => {
|
|
3858
|
+
clearTimeout(timer);
|
|
3859
|
+
reject2(err);
|
|
3860
|
+
});
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
async function readVaultSettlementMs(client, digest) {
|
|
3864
|
+
const ledger = client.ledgerService;
|
|
3865
|
+
if (!ledger?.getTransaction)
|
|
3866
|
+
return void 0;
|
|
3867
|
+
try {
|
|
3868
|
+
const call = await withTimeout(ledger.getTransaction({
|
|
3869
|
+
digest,
|
|
3870
|
+
readMask: { paths: ["timestamp"] }
|
|
3871
|
+
}), VAULT_SETTLEMENT_TS_TIMEOUT_MS, "vault settlement timestamp read");
|
|
3872
|
+
const ts = call.response.transaction?.timestamp;
|
|
3873
|
+
if (!ts || ts.seconds === void 0)
|
|
3874
|
+
return void 0;
|
|
3875
|
+
const seconds = Number(ts.seconds);
|
|
3876
|
+
if (!Number.isFinite(seconds))
|
|
3877
|
+
return void 0;
|
|
3878
|
+
return seconds * 1e3 + Math.floor((ts.nanos ?? 0) / 1e6);
|
|
3879
|
+
} catch {
|
|
3880
|
+
return void 0;
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3841
3883
|
function createSpendAccountSettledTxReader(options) {
|
|
3842
3884
|
const network = toGrpcNetwork(options.network);
|
|
3843
3885
|
const client = options.client ?? createFailoverGrpcClient({
|
|
@@ -3892,6 +3934,7 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
3892
3934
|
kind: e.eventType.split("::").pop() ?? e.eventType
|
|
3893
3935
|
}));
|
|
3894
3936
|
const guardedDelegateCalls = recoverGuardedDelegateCalls(finalized);
|
|
3937
|
+
const timestampMs = events.some((event) => event.kind === "VaultOpened") ? await readVaultSettlementMs(client, digest) : void 0;
|
|
3895
3938
|
return {
|
|
3896
3939
|
status: "success",
|
|
3897
3940
|
txDigest: digest,
|
|
@@ -3899,7 +3942,8 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
3899
3942
|
moveCalls,
|
|
3900
3943
|
objectIds,
|
|
3901
3944
|
events,
|
|
3902
|
-
guardedDelegateCalls
|
|
3945
|
+
guardedDelegateCalls,
|
|
3946
|
+
...timestampMs !== void 0 ? { timestampMs } : {}
|
|
3903
3947
|
};
|
|
3904
3948
|
}
|
|
3905
3949
|
};
|
package/package.json
CHANGED