/**
 * Parse solc compiler outputs: AST JSON and storage layout.
 */
/**
 * Parse solc --storage-layout output.
 */
export function parseStorageLayout(json, contractName) {
    const entries = [];
    if (!json || typeof json !== 'object')
        return { entries };
    const data = json;
    // solc outputs nested under contracts
    const contracts = data.contracts;
    if (!contracts)
        return { entries };
    for (const [, fileContracts] of Object.entries(contracts)) {
        for (const [name, contractData] of Object.entries(fileContracts)) {
            if (contractName && name !== contractName)
                continue;
            const cd = contractData;
            const layout = cd.storageLayout;
            if (!layout)
                continue;
            const storage = layout.storage;
            if (!Array.isArray(storage))
                continue;
            for (const item of storage) {
                const s = item;
                entries.push({
                    contract: name,
                    label: String(s.label ?? ''),
                    type: String(s.type ?? ''),
                    slot: Number(s.slot ?? 0),
                    offset: Number(s.offset ?? 0),
                    numberOfBytes: Number((layout.types?.[String(s.type)]
                        ?.numberOfBytes) ?? 0),
                });
            }
        }
    }
    return { entries };
}
//# sourceMappingURL=solc.js.map