| 52 | } |
| 53 | |
| 54 | export const buildAccountAlloc = (config: AllocConfig): [Address, GenesisAccountAlloc] => { |
| 55 | const { address, balance, nonce, code, storage } = schemaAllocConfig.parse(config) |
| 56 | let storageMap: Record<Bytes32, Bytes32> | undefined |
| 57 | if (storage != null) { |
| 58 | storageMap = {} as Record<Bytes32, Bytes32> |
| 59 | for (const [key, value] of storage ?? []) { |
| 60 | if (key in storageMap) { |
| 61 | throw new Error(`Duplicate storage key: ${key}`) |
| 62 | } |
| 63 | storageMap[key] = value |
| 64 | } |
| 65 | } |
| 66 | return [ |
| 67 | address, |
| 68 | { |
| 69 | balance: toHex(balance), |
| 70 | nonce: nonce === 0n ? undefined : toHex(nonce), |
| 71 | code, |
| 72 | storage: storageMap, |
| 73 | }, |
| 74 | ] |
| 75 | } |
| 76 | |
| 77 | export const buildImplContractAlloc = async ( |
| 78 | ctx: BuilderContext, |