-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathcreateRollupPrepareTransaction.ts
More file actions
36 lines (29 loc) · 1.01 KB
/
createRollupPrepareTransaction.ts
File metadata and controls
36 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Transaction, decodeFunctionData } from 'viem';
import { rollupCreatorABI } from './contracts/RollupCreator';
import { CreateRollupFunctionInputs } from './types/createRollupTypes';
function createRollupDecodeFunctionData(data: `0x${string}`) {
return decodeFunctionData({
abi: rollupCreatorABI,
data,
});
}
export type CreateRollupTransaction = Transaction & {
getInputs(): CreateRollupFunctionInputs;
};
export function createRollupPrepareTransaction(tx: Transaction): CreateRollupTransaction {
return {
...tx,
getInputs: function () {
const { functionName, args } = createRollupDecodeFunctionData(tx.input);
if (functionName !== 'createRollup') {
throw new Error(`
[createRollupPrepareTransaction] expected function name to be "createRollup" but got "${functionName}"
`);
}
if (typeof args === 'undefined') {
throw new Error(`[createRollupPrepareTransaction] failed to decode function data`);
}
return args;
},
};
}