Skip to content

Commit 3de9f4b

Browse files
committed
Added actions to TransactionSimulator
1 parent deb0606 commit 3de9f4b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export class MinaTransactionSender {
175175
const waitInstruction: "sent" | "included" = waitOnStatus;
176176
const hash = await new Promise<TxSendResult<"sent" | "included">>(
177177
(resolve, reject) => {
178-
txStatus.on(waitInstruction, (result) => {
179-
log.info(`Tx ${result.hash} included`);
180-
resolve(result);
178+
txStatus.on(waitInstruction, (txSendResult) => {
179+
log.info(`Tx ${txSendResult.hash} included`);
180+
resolve(txSendResult);
181181
});
182182
txStatus.on("rejected", (error) => {
183183
reject(error);

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import {
1111
UInt32,
1212
Transaction,
1313
} from "o1js";
14-
import { ReturnType } from "@proto-kit/protocol";
14+
import {
15+
ACTIONS_EMPTY_HASH,
16+
MINA_EVENT_PREFIXES,
17+
ReturnType,
18+
} from "@proto-kit/protocol";
1519
import { match } from "ts-pattern";
1620
import { inject, injectable } from "tsyringe";
17-
import { noop } from "@proto-kit/common";
21+
import { hashWithPrefix, noop, range } from "@proto-kit/common";
1822

1923
import { distinctByPredicate } from "../../helpers/utils";
2024
import type { MinaBaseLayer } from "../../protocol/baselayer/MinaBaseLayer";
@@ -277,13 +281,32 @@ export class MinaTransactionSimulator {
277281
}).verificationKey = update.verificationKey.value;
278282
}
279283

284+
this.applyZkApp(account, au.body);
285+
}
286+
287+
private applyZkApp(
288+
account: Account,
289+
{ update, actions }: AccountUpdate["body"]
290+
) {
280291
if (account.zkapp !== undefined) {
281292
const { appState } = update;
282293
for (let i = 0; i < 8; i++) {
283294
if (appState[i].isSome.toBoolean()) {
284295
account.zkapp.appState[i] = appState[i].value;
285296
}
286297
}
298+
299+
if (actions.data.length > 0) {
300+
// We don't care about the correct historical array, so we just
301+
// populate the full array with the current value
302+
const previousActionState =
303+
account.zkapp.actionState.at(0) ?? ACTIONS_EMPTY_HASH;
304+
const newActionsHash = hashWithPrefix(
305+
MINA_EVENT_PREFIXES.sequenceEvents,
306+
[previousActionState, actions.hash]
307+
);
308+
account.zkapp.actionState = range(0, 5).map(() => newActionsHash);
309+
}
287310
}
288311
}
289312
}

0 commit comments

Comments
 (0)