Skip to content

Commit deb0606

Browse files
committed
Added tx hashes to TransactionSender
1 parent 76b88db commit deb0606

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

packages/sequencer/src/settlement/SettlementModule.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,15 @@ export class SettlementModule
206206

207207
this.utils.signTransaction(tx, [feepayer], this.getContractKeys());
208208

209-
await this.transactionSender.proveAndSendTransaction(tx, "included");
209+
const { hash: transactionHash } =
210+
await this.transactionSender.proveAndSendTransaction(tx, "included");
210211

211212
log.info("Settlement transaction send queued");
212213

213214
const settlement = {
214215
batches: [batch.height],
215216
promisedMessagesHash: latestSequenceStateHash.toString(),
217+
transactionHash,
216218
};
217219

218220
await this.settlementStorage.pushSettlement(settlement);

packages/sequencer/src/settlement/transactions/MinaTransactionSender.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface TxEvents extends EventsRecord {
2525
rejected: [any];
2626
}
2727

28+
export type TxSendResult<Input extends "sent" | "included" | "none"> =
29+
Input extends "none" ? void : { hash: string };
30+
2831
@injectable()
2932
export class MinaTransactionSender {
3033
private txStatusEmitters: Record<string, EventEmitter<TxEvents>> = {};
@@ -113,10 +116,12 @@ export class MinaTransactionSender {
113116
return eventEmitter;
114117
}
115118

116-
public async proveAndSendTransaction(
119+
public async proveAndSendTransaction<
120+
Wait extends "sent" | "included" | "none",
121+
>(
117122
transaction: Transaction<false, true>,
118-
waitOnStatus: "sent" | "included" | "none" = "none"
119-
) {
123+
waitOnStatus: Wait
124+
): Promise<TxSendResult<Wait>> {
120125
const { publicKey, nonce } = transaction.transaction.feePayer.body;
121126

122127
log.debug(
@@ -167,16 +172,24 @@ export class MinaTransactionSender {
167172
const txStatus = await this.sendOrQueue(result.transaction);
168173

169174
if (waitOnStatus !== "none") {
170-
await new Promise<void>((resolve, reject) => {
171-
txStatus.on(waitOnStatus, () => {
172-
log.info("Tx included");
173-
resolve();
174-
});
175-
txStatus.on("rejected", (error) => {
176-
reject(error);
177-
});
178-
});
175+
const waitInstruction: "sent" | "included" = waitOnStatus;
176+
const hash = await new Promise<TxSendResult<"sent" | "included">>(
177+
(resolve, reject) => {
178+
txStatus.on(waitInstruction, (result) => {
179+
log.info(`Tx ${result.hash} included`);
180+
resolve(result);
181+
});
182+
txStatus.on("rejected", (error) => {
183+
reject(error);
184+
});
185+
}
186+
);
187+
188+
// Yeah that's not super clean, but couldn't figure out a better way tbh
189+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
190+
return hash as TxSendResult<Wait>;
179191
}
180-
return txStatus;
192+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
193+
return undefined as TxSendResult<Wait>;
181194
}
182195
}

0 commit comments

Comments
 (0)