@atomiqlabs/chain-evm 1.0.0-dev.36 → 1.0.0-dev.37
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/evm/chain/modules/EVMTransactions.d.ts +1 -1
- package/dist/evm/chain/modules/EVMTransactions.js +33 -19
- package/dist/evm/wallet/EVMSigner.d.ts +2 -1
- package/dist/evm/wallet/EVMSigner.js +2 -1
- package/package.json +1 -1
- package/src/evm/chain/modules/EVMTransactions.ts +26 -15
- package/src/evm/wallet/EVMSigner.ts +3 -1
|
@@ -54,7 +54,7 @@ export declare class EVMTransactions extends EVMModule<any> {
|
|
|
54
54
|
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
55
55
|
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
56
56
|
* are executed in order)
|
|
57
|
-
* @param onBeforePublish a callback called before every transaction is published
|
|
57
|
+
* @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
|
|
58
58
|
*/
|
|
59
59
|
sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
60
60
|
/**
|
|
@@ -99,45 +99,59 @@ class EVMTransactions extends EVMModule_1.EVMModule {
|
|
|
99
99
|
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
100
100
|
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
101
101
|
* are executed in order)
|
|
102
|
-
* @param onBeforePublish a callback called before every transaction is published
|
|
102
|
+
* @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
|
|
103
103
|
*/
|
|
104
104
|
async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
|
|
105
105
|
await this.prepareTransactions(signer, txs);
|
|
106
106
|
const signedTxs = [];
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
//Don't separate the signing process from the sending when using browser-based wallet
|
|
108
|
+
if (!signer.isBrowserWallet)
|
|
109
|
+
for (let i = 0; i < txs.length; i++) {
|
|
110
|
+
const tx = txs[i];
|
|
111
|
+
const signedTx = ethers_1.Transaction.from(await signer.account.signTransaction(tx));
|
|
112
|
+
signedTxs.push(signedTx);
|
|
113
|
+
this.logger.debug("sendAndConfirm(): transaction signed (" + (i + 1) + "/" + txs.length + "): " + signedTx);
|
|
114
|
+
}
|
|
115
115
|
this.logger.debug("sendAndConfirm(): sending transactions, count: " + txs.length +
|
|
116
116
|
" waitForConfirmation: " + waitForConfirmation + " parallel: " + parallel);
|
|
117
117
|
const txIds = [];
|
|
118
118
|
if (parallel) {
|
|
119
119
|
const promises = [];
|
|
120
120
|
for (let i = 0; i < signedTxs.length; i++) {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
let tx;
|
|
122
|
+
if (signer.isBrowserWallet) {
|
|
123
|
+
tx = await signer.account.sendTransaction(txs[i]);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const signedTx = signedTxs[i];
|
|
127
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
128
|
+
tx = signedTx;
|
|
129
|
+
}
|
|
123
130
|
if (waitForConfirmation)
|
|
124
|
-
promises.push(this.confirmTransaction(
|
|
125
|
-
txIds.push(
|
|
126
|
-
this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + signedTxs.length + "): " +
|
|
131
|
+
promises.push(this.confirmTransaction(tx, abortSignal));
|
|
132
|
+
txIds.push(tx.hash);
|
|
133
|
+
this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + signedTxs.length + "): " + tx.hash);
|
|
127
134
|
}
|
|
128
135
|
if (promises.length > 0)
|
|
129
136
|
await Promise.all(promises);
|
|
130
137
|
}
|
|
131
138
|
else {
|
|
132
139
|
for (let i = 0; i < signedTxs.length; i++) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
let tx;
|
|
141
|
+
if (signer.isBrowserWallet) {
|
|
142
|
+
tx = await signer.account.sendTransaction(txs[i]);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const signedTx = signedTxs[i];
|
|
146
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
147
|
+
tx = signedTx;
|
|
148
|
+
}
|
|
149
|
+
const confirmPromise = this.confirmTransaction(tx, abortSignal);
|
|
150
|
+
this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + txs.length + "): " + tx.hash);
|
|
137
151
|
//Don't await the last promise when !waitForConfirmation
|
|
138
152
|
if (i < txs.length - 1 || waitForConfirmation)
|
|
139
153
|
await confirmPromise;
|
|
140
|
-
txIds.push(
|
|
154
|
+
txIds.push(tx.hash);
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
this.logger.info("sendAndConfirm(): sent transactions, count: " + txs.length +
|
|
@@ -3,7 +3,8 @@ import { Signer } from "ethers";
|
|
|
3
3
|
export declare class EVMSigner implements AbstractSigner {
|
|
4
4
|
account: Signer;
|
|
5
5
|
readonly address: string;
|
|
6
|
-
|
|
6
|
+
readonly isBrowserWallet: boolean;
|
|
7
|
+
constructor(account: Signer, address: string, isBrowserWallet?: boolean);
|
|
7
8
|
getNonce(): Promise<number>;
|
|
8
9
|
getAddress(): string;
|
|
9
10
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EVMSigner = void 0;
|
|
4
4
|
class EVMSigner {
|
|
5
|
-
constructor(account, address) {
|
|
5
|
+
constructor(account, address, isBrowserWallet = false) {
|
|
6
6
|
this.account = account;
|
|
7
7
|
this.address = address;
|
|
8
|
+
this.isBrowserWallet = isBrowserWallet;
|
|
8
9
|
}
|
|
9
10
|
getNonce() {
|
|
10
11
|
return Promise.resolve(null);
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ export class EVMTransactions extends EVMModule<any> {
|
|
|
33
33
|
* @param abortSignal signal to abort waiting for tx confirmation
|
|
34
34
|
* @private
|
|
35
35
|
*/
|
|
36
|
-
private async confirmTransaction(tx:
|
|
36
|
+
private async confirmTransaction(tx: {nonce: number, from: string, hash: string}, abortSignal?: AbortSignal) {
|
|
37
37
|
let state = "pending";
|
|
38
38
|
while(state==="pending" || state==="not_found") {
|
|
39
39
|
await timeoutPromise(3000, abortSignal);
|
|
@@ -121,15 +121,14 @@ export class EVMTransactions extends EVMModule<any> {
|
|
|
121
121
|
* @param abortSignal abort signal to abort waiting for transaction confirmations
|
|
122
122
|
* @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
|
|
123
123
|
* are executed in order)
|
|
124
|
-
* @param onBeforePublish a callback called before every transaction is published
|
|
124
|
+
* @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
|
|
125
125
|
*/
|
|
126
126
|
public async sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]> {
|
|
127
127
|
await this.prepareTransactions(signer, txs);
|
|
128
128
|
const signedTxs: Transaction[] = [];
|
|
129
129
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
for(let i=0;i<txs.length;i++) {
|
|
130
|
+
//Don't separate the signing process from the sending when using browser-based wallet
|
|
131
|
+
if(!signer.isBrowserWallet) for(let i=0;i<txs.length;i++) {
|
|
133
132
|
const tx = txs[i];
|
|
134
133
|
const signedTx = Transaction.from(await signer.account.signTransaction(tx));
|
|
135
134
|
signedTxs.push(signedTx);
|
|
@@ -143,22 +142,34 @@ export class EVMTransactions extends EVMModule<any> {
|
|
|
143
142
|
if(parallel) {
|
|
144
143
|
const promises: Promise<void>[] = [];
|
|
145
144
|
for(let i=0;i<signedTxs.length;i++) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
let tx: {nonce: number, from: string, hash: string};
|
|
146
|
+
if(signer.isBrowserWallet) {
|
|
147
|
+
tx = await signer.account.sendTransaction(txs[i]);
|
|
148
|
+
} else {
|
|
149
|
+
const signedTx = signedTxs[i];
|
|
150
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
151
|
+
tx = signedTx;
|
|
152
|
+
}
|
|
153
|
+
if(waitForConfirmation) promises.push(this.confirmTransaction(tx, abortSignal));
|
|
154
|
+
txIds.push(tx.hash);
|
|
155
|
+
this.logger.debug("sendAndConfirm(): transaction sent ("+(i+1)+"/"+signedTxs.length+"): "+tx.hash);
|
|
151
156
|
}
|
|
152
157
|
if(promises.length>0) await Promise.all(promises);
|
|
153
158
|
} else {
|
|
154
159
|
for(let i=0;i<signedTxs.length;i++) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
let tx: {nonce: number, from: string, hash: string};
|
|
161
|
+
if(signer.isBrowserWallet) {
|
|
162
|
+
tx = await signer.account.sendTransaction(txs[i]);
|
|
163
|
+
} else {
|
|
164
|
+
const signedTx = signedTxs[i];
|
|
165
|
+
await this.sendSignedTransaction(signedTx, onBeforePublish);
|
|
166
|
+
tx = signedTx;
|
|
167
|
+
}
|
|
168
|
+
const confirmPromise = this.confirmTransaction(tx, abortSignal);
|
|
169
|
+
this.logger.debug("sendAndConfirm(): transaction sent ("+(i+1)+"/"+txs.length+"): "+tx.hash);
|
|
159
170
|
//Don't await the last promise when !waitForConfirmation
|
|
160
171
|
if(i<txs.length-1 || waitForConfirmation) await confirmPromise;
|
|
161
|
-
txIds.push(
|
|
172
|
+
txIds.push(tx.hash);
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
175
|
|
|
@@ -6,10 +6,12 @@ export class EVMSigner implements AbstractSigner {
|
|
|
6
6
|
|
|
7
7
|
account: Signer;
|
|
8
8
|
public readonly address: string;
|
|
9
|
+
public readonly isBrowserWallet: boolean;
|
|
9
10
|
|
|
10
|
-
constructor(account: Signer, address: string) {
|
|
11
|
+
constructor(account: Signer, address: string, isBrowserWallet: boolean = false) {
|
|
11
12
|
this.account = account;
|
|
12
13
|
this.address = address;
|
|
14
|
+
this.isBrowserWallet = isBrowserWallet;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
getNonce(): Promise<number> {
|