zkcloudworker 0.23.3 → 0.23.5
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/node/index.cjs +31 -18
- package/dist/node/mina/transactions/send.d.ts +1 -0
- package/dist/node/mina/transactions/send.js +33 -18
- package/dist/node/mina/transactions/send.js.map +1 -1
- package/dist/web/mina/transactions/send.d.ts +1 -0
- package/dist/web/mina/transactions/send.js +33 -18
- package/dist/web/mina/transactions/send.js.map +1 -1
- package/package.json +1 -1
- package/src/mina/transactions/send.ts +47 -25
package/dist/node/index.cjs
CHANGED
@@ -2418,7 +2418,7 @@ var TinyContract = class extends import_o1js9.SmartContract {
|
|
2418
2418
|
// dist/node/mina/transactions/send.js
|
2419
2419
|
var import_o1js10 = require("o1js");
|
2420
2420
|
async function sendTx(params) {
|
2421
|
-
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId } = params;
|
2421
|
+
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, delay = chain === "zeko" ? 5e3 : 3e4 } = params;
|
2422
2422
|
const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
|
2423
2423
|
const auCount = [];
|
2424
2424
|
let proofAuthorizationCount = 0;
|
@@ -2447,19 +2447,25 @@ async function sendTx(params) {
|
|
2447
2447
|
try {
|
2448
2448
|
let txSent;
|
2449
2449
|
let sent = false;
|
2450
|
-
|
2450
|
+
let retry = 0;
|
2451
|
+
while (!sent && retry < 10) {
|
2451
2452
|
txSent = await tx.safeSend();
|
2452
|
-
if (txSent.status
|
2453
|
+
if (txSent.status === "pending") {
|
2453
2454
|
sent = true;
|
2454
2455
|
if (verbose)
|
2455
2456
|
console.log(`${description ?? ""} tx sent: hash: ${txSent.hash} status: ${txSent.status}`);
|
2456
2457
|
} else if (chain === "zeko") {
|
2457
|
-
|
2458
|
-
|
2459
|
-
|
2458
|
+
retry++;
|
2459
|
+
if (verbose) {
|
2460
|
+
console.log("Retrying Zeko tx, retry: ", retry);
|
2461
|
+
}
|
2462
|
+
await sleep(3e4);
|
2460
2463
|
} else {
|
2464
|
+
retry++;
|
2461
2465
|
console.error(`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}`, txSent.errors);
|
2462
|
-
|
2466
|
+
if (verbose)
|
2467
|
+
console.log(`Retrying ${chain} tx, retry:`, retry);
|
2468
|
+
await sleep(6e4);
|
2463
2469
|
}
|
2464
2470
|
}
|
2465
2471
|
if (txSent === void 0)
|
@@ -2471,11 +2477,9 @@ async function sendTx(params) {
|
|
2471
2477
|
if (verbose)
|
2472
2478
|
console.log(`Waiting for tx inclusion...`);
|
2473
2479
|
let txIncluded = await txSent.safeWait();
|
2474
|
-
if (txIncluded.status
|
2475
|
-
|
2476
|
-
|
2477
|
-
else
|
2478
|
-
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
2480
|
+
if (txIncluded.status !== "included") {
|
2481
|
+
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}, errors: ${String(txIncluded.errors ?? "")}`);
|
2482
|
+
}
|
2479
2483
|
if (chain !== "local") {
|
2480
2484
|
const { publicKey, nonce } = tx.transaction.feePayer.body;
|
2481
2485
|
const started = Date.now();
|
@@ -2486,20 +2490,29 @@ async function sendTx(params) {
|
|
2486
2490
|
})).account?.nonce;
|
2487
2491
|
if (newNonce && Number(newNonce.toBigint()) > Number(nonce.toBigint())) {
|
2488
2492
|
const txIncluded2 = await txSent.safeWait();
|
2489
|
-
if (txIncluded2.status === "included")
|
2493
|
+
if (txIncluded2.status === "included") {
|
2494
|
+
if (verbose)
|
2495
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded2.hash} status: ${txIncluded2.status}`);
|
2496
|
+
if (delay > 0)
|
2497
|
+
await sleep(delay);
|
2490
2498
|
return txIncluded2;
|
2491
|
-
else if (txIncluded2.status === "rejected") {
|
2492
|
-
await sleep(
|
2499
|
+
} else if (txIncluded2.status === "rejected") {
|
2500
|
+
await sleep(3e4);
|
2493
2501
|
const txIncluded3 = await txSent.safeWait();
|
2494
|
-
if (txIncluded3.status === "included")
|
2502
|
+
if (txIncluded3.status === "included") {
|
2503
|
+
if (verbose)
|
2504
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded3.hash} status: ${txIncluded3.status}`);
|
2505
|
+
if (delay > 0)
|
2506
|
+
await sleep(delay);
|
2495
2507
|
return txIncluded3;
|
2496
|
-
|
2508
|
+
}
|
2509
|
+
console.error(`tx failed: ${chain} tx rejected: hash: ${txIncluded3.hash} status: ${txIncluded3.status} errors: ${txIncluded3.errors}`);
|
2497
2510
|
return txIncluded3;
|
2498
2511
|
}
|
2499
2512
|
}
|
2500
2513
|
if (verbose)
|
2501
2514
|
console.log(`Waiting for ${chain} to update state for ${Math.floor((Date.now() - started) / 1e3)} sec...`);
|
2502
|
-
await sleep(
|
2515
|
+
await sleep(3e4);
|
2503
2516
|
}
|
2504
2517
|
console.error(`${chain} do not reflect nonce update for tx ${txIncluded.hash} with status ${txIncluded.status}`);
|
2505
2518
|
}
|
@@ -18,6 +18,7 @@ export declare function sendTx(params: {
|
|
18
18
|
verbose?: boolean;
|
19
19
|
wait?: boolean;
|
20
20
|
chain?: blockchain;
|
21
|
+
delay?: number;
|
21
22
|
}): Promise<Mina.IncludedTransaction | Mina.PendingTransaction | Mina.RejectedTransaction | undefined>;
|
22
23
|
export declare function getTxStatusFast(params: {
|
23
24
|
hash: string;
|
@@ -15,7 +15,7 @@ import { getCurrentNetwork } from "../utils/mina.js";
|
|
15
15
|
* `Mina.RejectedTransaction`, or `undefined` if there was an error during the process.
|
16
16
|
*/
|
17
17
|
export async function sendTx(params) {
|
18
|
-
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, } = params;
|
18
|
+
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, delay = chain === "zeko" ? 5000 : 30000, } = params;
|
19
19
|
// flatten accountUpdates
|
20
20
|
const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
|
21
21
|
const auCount = [];
|
@@ -48,21 +48,27 @@ export async function sendTx(params) {
|
|
48
48
|
try {
|
49
49
|
let txSent;
|
50
50
|
let sent = false;
|
51
|
-
|
51
|
+
let retry = 0;
|
52
|
+
while (!sent && retry < 10) {
|
52
53
|
txSent = await tx.safeSend();
|
53
|
-
if (txSent.status
|
54
|
+
if (txSent.status === "pending") {
|
54
55
|
sent = true;
|
55
56
|
if (verbose)
|
56
57
|
console.log(`${description ?? ""} tx sent: hash: ${txSent.hash} status: ${txSent.status}`);
|
57
58
|
}
|
58
59
|
else if (chain === "zeko") {
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
retry++;
|
61
|
+
if (verbose) {
|
62
|
+
console.log("Retrying Zeko tx, retry: ", retry);
|
63
|
+
}
|
64
|
+
await sleep(30000);
|
62
65
|
}
|
63
66
|
else {
|
67
|
+
retry++;
|
64
68
|
console.error(`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}`, txSent.errors);
|
65
|
-
|
69
|
+
if (verbose)
|
70
|
+
console.log(`Retrying ${chain} tx, retry:`, retry);
|
71
|
+
await sleep(60000);
|
66
72
|
}
|
67
73
|
}
|
68
74
|
if (txSent === undefined)
|
@@ -74,11 +80,9 @@ export async function sendTx(params) {
|
|
74
80
|
if (verbose)
|
75
81
|
console.log(`Waiting for tx inclusion...`);
|
76
82
|
let txIncluded = await txSent.safeWait();
|
77
|
-
if (txIncluded.status
|
78
|
-
|
79
|
-
|
80
|
-
else
|
81
|
-
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
83
|
+
if (txIncluded.status !== "included") {
|
84
|
+
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}, errors: ${String(txIncluded.errors ?? "")}`);
|
85
|
+
}
|
82
86
|
if (chain !== "local") {
|
83
87
|
// we still wait for the tx to be included in the block by checking the nonce
|
84
88
|
// even in the case of tx NOT included
|
@@ -93,21 +97,32 @@ export async function sendTx(params) {
|
|
93
97
|
if (newNonce &&
|
94
98
|
Number(newNonce.toBigint()) > Number(nonce.toBigint())) {
|
95
99
|
const txIncluded = await txSent.safeWait();
|
96
|
-
if (txIncluded.status === "included")
|
100
|
+
if (txIncluded.status === "included") {
|
101
|
+
if (verbose)
|
102
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
103
|
+
if (delay > 0)
|
104
|
+
await sleep(delay);
|
97
105
|
return txIncluded;
|
106
|
+
}
|
98
107
|
else if (txIncluded.status === "rejected") {
|
99
|
-
// We never should see this error as the nonce is updated
|
100
|
-
|
108
|
+
// We never should see this error as the nonce is updated (except when tx failed due to a preconditions),
|
109
|
+
// so we retry to check if the tx is included
|
110
|
+
await sleep(30000);
|
101
111
|
const txIncluded = await txSent.safeWait();
|
102
|
-
if (txIncluded.status === "included")
|
112
|
+
if (txIncluded.status === "included") {
|
113
|
+
if (verbose)
|
114
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
115
|
+
if (delay > 0)
|
116
|
+
await sleep(delay);
|
103
117
|
return txIncluded;
|
104
|
-
|
118
|
+
}
|
119
|
+
console.error(`tx failed: ${chain} tx rejected: hash: ${txIncluded.hash} status: ${txIncluded.status} errors: ${txIncluded.errors}`);
|
105
120
|
return txIncluded;
|
106
121
|
}
|
107
122
|
}
|
108
123
|
if (verbose)
|
109
124
|
console.log(`Waiting for ${chain} to update state for ${Math.floor((Date.now() - started) / 1000)} sec...`);
|
110
|
-
await sleep(
|
125
|
+
await sleep(30000);
|
111
126
|
}
|
112
127
|
// finally, if the tx is still not included, show an error
|
113
128
|
console.error(`${chain} do not reflect nonce update for tx ${txIncluded.hash} with status ${txIncluded.status}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../../src/mina/transactions/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAG7C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,
|
1
|
+
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../../src/mina/transactions/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAG7C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAO5B;IAMC,MAAM,EACJ,EAAE,EACF,WAAW,GAAG,EAAE,EAChB,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,IAAI,EACX,KAAK,GAAG,iBAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,EAC3C,KAAK,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GACxC,GAAG,MAAM,CAAC;IACX,yBAAyB;IACzB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,cAAc,CAAC;IAC9D,MAAM,OAAO,GAIP,EAAE,CAAC;IACT,IAAI,uBAAuB,GAAG,CAAC,CAAC;IAChC,0EAA0E;IAC1E,KAAK,MAAM,EAAE,IAAI,cAAc,EAAE,CAAC;QAChC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,iBA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K,uCAAuC,UAAU,CAAC,IAAI,gBAAgB,UAAU,CAAC,MAAM,EAAE,CAClG,CAAC;YACJ,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;;YAAM,OAAO,MAAM,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,KAAK,MAAM;YAAE,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAGrC;IACC,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,iBAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC;IACrE,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM;QACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAEzC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,QAAQ,EAAE,OAAO,IAAI,KAAK;SACnC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CACX,uDAAuD,EACvD,IAAI,EACJ,KAAK,CACN,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,sBAAsB,EAAE,CAAC;IAC7E,CAAC;AACH,CAAC"}
|
@@ -18,6 +18,7 @@ export declare function sendTx(params: {
|
|
18
18
|
verbose?: boolean;
|
19
19
|
wait?: boolean;
|
20
20
|
chain?: blockchain;
|
21
|
+
delay?: number;
|
21
22
|
}): Promise<Mina.IncludedTransaction | Mina.PendingTransaction | Mina.RejectedTransaction | undefined>;
|
22
23
|
export declare function getTxStatusFast(params: {
|
23
24
|
hash: string;
|
@@ -15,7 +15,7 @@ import { getCurrentNetwork } from "../utils/mina.js";
|
|
15
15
|
* `Mina.RejectedTransaction`, or `undefined` if there was an error during the process.
|
16
16
|
*/
|
17
17
|
export async function sendTx(params) {
|
18
|
-
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, } = params;
|
18
|
+
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, delay = chain === "zeko" ? 5000 : 30000, } = params;
|
19
19
|
// flatten accountUpdates
|
20
20
|
const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
|
21
21
|
const auCount = [];
|
@@ -48,21 +48,27 @@ export async function sendTx(params) {
|
|
48
48
|
try {
|
49
49
|
let txSent;
|
50
50
|
let sent = false;
|
51
|
-
|
51
|
+
let retry = 0;
|
52
|
+
while (!sent && retry < 10) {
|
52
53
|
txSent = await tx.safeSend();
|
53
|
-
if (txSent.status
|
54
|
+
if (txSent.status === "pending") {
|
54
55
|
sent = true;
|
55
56
|
if (verbose)
|
56
57
|
console.log(`${description ?? ""} tx sent: hash: ${txSent.hash} status: ${txSent.status}`);
|
57
58
|
}
|
58
59
|
else if (chain === "zeko") {
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
retry++;
|
61
|
+
if (verbose) {
|
62
|
+
console.log("Retrying Zeko tx, retry: ", retry);
|
63
|
+
}
|
64
|
+
await sleep(30000);
|
62
65
|
}
|
63
66
|
else {
|
67
|
+
retry++;
|
64
68
|
console.error(`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}`, txSent.errors);
|
65
|
-
|
69
|
+
if (verbose)
|
70
|
+
console.log(`Retrying ${chain} tx, retry:`, retry);
|
71
|
+
await sleep(60000);
|
66
72
|
}
|
67
73
|
}
|
68
74
|
if (txSent === undefined)
|
@@ -74,11 +80,9 @@ export async function sendTx(params) {
|
|
74
80
|
if (verbose)
|
75
81
|
console.log(`Waiting for tx inclusion...`);
|
76
82
|
let txIncluded = await txSent.safeWait();
|
77
|
-
if (txIncluded.status
|
78
|
-
|
79
|
-
|
80
|
-
else
|
81
|
-
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
83
|
+
if (txIncluded.status !== "included") {
|
84
|
+
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}, errors: ${String(txIncluded.errors ?? "")}`);
|
85
|
+
}
|
82
86
|
if (chain !== "local") {
|
83
87
|
// we still wait for the tx to be included in the block by checking the nonce
|
84
88
|
// even in the case of tx NOT included
|
@@ -93,21 +97,32 @@ export async function sendTx(params) {
|
|
93
97
|
if (newNonce &&
|
94
98
|
Number(newNonce.toBigint()) > Number(nonce.toBigint())) {
|
95
99
|
const txIncluded = await txSent.safeWait();
|
96
|
-
if (txIncluded.status === "included")
|
100
|
+
if (txIncluded.status === "included") {
|
101
|
+
if (verbose)
|
102
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
103
|
+
if (delay > 0)
|
104
|
+
await sleep(delay);
|
97
105
|
return txIncluded;
|
106
|
+
}
|
98
107
|
else if (txIncluded.status === "rejected") {
|
99
|
-
// We never should see this error as the nonce is updated
|
100
|
-
|
108
|
+
// We never should see this error as the nonce is updated (except when tx failed due to a preconditions),
|
109
|
+
// so we retry to check if the tx is included
|
110
|
+
await sleep(30000);
|
101
111
|
const txIncluded = await txSent.safeWait();
|
102
|
-
if (txIncluded.status === "included")
|
112
|
+
if (txIncluded.status === "included") {
|
113
|
+
if (verbose)
|
114
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
115
|
+
if (delay > 0)
|
116
|
+
await sleep(delay);
|
103
117
|
return txIncluded;
|
104
|
-
|
118
|
+
}
|
119
|
+
console.error(`tx failed: ${chain} tx rejected: hash: ${txIncluded.hash} status: ${txIncluded.status} errors: ${txIncluded.errors}`);
|
105
120
|
return txIncluded;
|
106
121
|
}
|
107
122
|
}
|
108
123
|
if (verbose)
|
109
124
|
console.log(`Waiting for ${chain} to update state for ${Math.floor((Date.now() - started) / 1000)} sec...`);
|
110
|
-
await sleep(
|
125
|
+
await sleep(30000);
|
111
126
|
}
|
112
127
|
// finally, if the tx is still not included, show an error
|
113
128
|
console.error(`${chain} do not reflect nonce update for tx ${txIncluded.hash} with status ${txIncluded.status}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../../src/mina/transactions/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAG7C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,
|
1
|
+
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../../src/mina/transactions/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AAG7C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAO5B;IAMC,MAAM,EACJ,EAAE,EACF,WAAW,GAAG,EAAE,EAChB,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,IAAI,EACX,KAAK,GAAG,iBAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,EAC3C,KAAK,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GACxC,GAAG,MAAM,CAAC;IACX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IAAI,sBAAsB,EAAE,CAAC;IAC7E,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
@@ -23,6 +23,7 @@ export async function sendTx(params: {
|
|
23
23
|
verbose?: boolean;
|
24
24
|
wait?: boolean;
|
25
25
|
chain?: blockchain;
|
26
|
+
delay?: number;
|
26
27
|
}): Promise<
|
27
28
|
| Mina.IncludedTransaction
|
28
29
|
| Mina.PendingTransaction
|
@@ -35,6 +36,7 @@ export async function sendTx(params: {
|
|
35
36
|
verbose = true,
|
36
37
|
wait = true,
|
37
38
|
chain = getCurrentNetwork().network.chainId,
|
39
|
+
delay = chain === "zeko" ? 5000 : 30000,
|
38
40
|
} = params;
|
39
41
|
// flatten accountUpdates
|
40
42
|
const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
|
@@ -79,9 +81,10 @@ export async function sendTx(params: {
|
|
79
81
|
try {
|
80
82
|
let txSent;
|
81
83
|
let sent = false;
|
82
|
-
|
84
|
+
let retry = 0;
|
85
|
+
while (!sent && retry < 10) {
|
83
86
|
txSent = await tx.safeSend();
|
84
|
-
if (txSent.status
|
87
|
+
if (txSent.status === "pending") {
|
85
88
|
sent = true;
|
86
89
|
if (verbose)
|
87
90
|
console.log(
|
@@ -90,14 +93,19 @@ export async function sendTx(params: {
|
|
90
93
|
}`
|
91
94
|
);
|
92
95
|
} else if (chain === "zeko") {
|
93
|
-
|
94
|
-
|
96
|
+
retry++;
|
97
|
+
if (verbose) {
|
98
|
+
console.log("Retrying Zeko tx, retry: ", retry);
|
99
|
+
}
|
100
|
+
await sleep(30000);
|
95
101
|
} else {
|
102
|
+
retry++;
|
96
103
|
console.error(
|
97
104
|
`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}`,
|
98
105
|
txSent.errors
|
99
106
|
);
|
100
|
-
|
107
|
+
if (verbose) console.log(`Retrying ${chain} tx, retry:`, retry);
|
108
|
+
await sleep(60000);
|
101
109
|
}
|
102
110
|
}
|
103
111
|
if (txSent === undefined) throw new Error("txSent is undefined");
|
@@ -112,19 +120,15 @@ export async function sendTx(params: {
|
|
112
120
|
if (txSent.status === "pending" && wait !== false && chain !== "zeko") {
|
113
121
|
if (verbose) console.log(`Waiting for tx inclusion...`);
|
114
122
|
let txIncluded = await txSent.safeWait();
|
115
|
-
if (txIncluded.status
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
)
|
122
|
-
|
123
|
-
|
124
|
-
`${description ?? ""} tx NOT included into block: hash: ${
|
125
|
-
txIncluded.hash
|
126
|
-
} status: ${txIncluded.status}`
|
127
|
-
);
|
123
|
+
if (txIncluded.status !== "included") {
|
124
|
+
console.error(
|
125
|
+
`${description ?? ""} tx NOT included into block: hash: ${
|
126
|
+
txIncluded.hash
|
127
|
+
} status: ${txIncluded.status}, errors: ${String(
|
128
|
+
txIncluded.errors ?? ""
|
129
|
+
)}`
|
130
|
+
);
|
131
|
+
}
|
128
132
|
if (chain !== "local") {
|
129
133
|
// we still wait for the tx to be included in the block by checking the nonce
|
130
134
|
// even in the case of tx NOT included
|
@@ -143,14 +147,32 @@ export async function sendTx(params: {
|
|
143
147
|
Number(newNonce.toBigint()) > Number(nonce.toBigint())
|
144
148
|
) {
|
145
149
|
const txIncluded = await txSent.safeWait();
|
146
|
-
if (txIncluded.status === "included")
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
+
if (txIncluded.status === "included") {
|
151
|
+
if (verbose)
|
152
|
+
console.log(
|
153
|
+
`${description ?? ""} tx included into block: hash: ${
|
154
|
+
txIncluded.hash
|
155
|
+
} status: ${txIncluded.status}`
|
156
|
+
);
|
157
|
+
if (delay > 0) await sleep(delay);
|
158
|
+
return txIncluded;
|
159
|
+
} else if (txIncluded.status === "rejected") {
|
160
|
+
// We never should see this error as the nonce is updated (except when tx failed due to a preconditions),
|
161
|
+
// so we retry to check if the tx is included
|
162
|
+
await sleep(30000);
|
150
163
|
const txIncluded = await txSent.safeWait();
|
151
|
-
if (txIncluded.status === "included")
|
164
|
+
if (txIncluded.status === "included") {
|
165
|
+
if (verbose)
|
166
|
+
console.log(
|
167
|
+
`${description ?? ""} tx included into block: hash: ${
|
168
|
+
txIncluded.hash
|
169
|
+
} status: ${txIncluded.status}`
|
170
|
+
);
|
171
|
+
if (delay > 0) await sleep(delay);
|
172
|
+
return txIncluded;
|
173
|
+
}
|
152
174
|
console.error(
|
153
|
-
`
|
175
|
+
`tx failed: ${chain} tx rejected: hash: ${txIncluded.hash} status: ${txIncluded.status} errors: ${txIncluded.errors}`
|
154
176
|
);
|
155
177
|
return txIncluded;
|
156
178
|
}
|
@@ -161,7 +183,7 @@ export async function sendTx(params: {
|
|
161
183
|
(Date.now() - started) / 1000
|
162
184
|
)} sec...`
|
163
185
|
);
|
164
|
-
await sleep(
|
186
|
+
await sleep(30000);
|
165
187
|
}
|
166
188
|
// finally, if the tx is still not included, show an error
|
167
189
|
console.error(
|