diff --git a/src/scripts/export/handlers/wasm.ts b/src/scripts/export/handlers/wasm.ts index 157263c0..936ab97c 100644 --- a/src/scripts/export/handlers/wasm.ts +++ b/src/scripts/export/handlers/wasm.ts @@ -43,6 +43,11 @@ export const wasm: HandlerMaker = async ({ }) => { const chainId = await cosmWasmClient.getChainId() + // Terra Classic uses different prefixes: + // https://github.com/classic-terra/wasmd/blob/v0.30.0-terra.3/x/wasm/types/keys.go#L31-L32 + const CONTRACT_KEY_PREFIX = chainId === 'columbus-5' ? 0x04 : 0x02 + const CONTRACT_STORE_PREFIX = chainId === 'columbus-5' ? 0x05 : 0x03 + // Get code ID for contract, cached in memory. const codeIdCache = new LRUCache({ max: 1000, @@ -101,16 +106,17 @@ export const wasm: HandlerMaker = async ({ } const match: Handler['match'] = (trace) => { - // ContractStorePrefix = 0x03 // wasm keys are formatted as: // ContractStorePrefix || contractAddressBytes || keyBytes - // ContractKeyPrefix = 0x02 // contract info keys are formatted as: // ContractKeyPrefix || contractAddressBytes const keyData = fromBase64(trace.key) - if (keyData[0] !== 0x02 && keyData[0] !== 0x03) { + if ( + keyData[0] !== CONTRACT_STORE_PREFIX && + keyData[0] !== CONTRACT_KEY_PREFIX + ) { return } @@ -133,13 +139,13 @@ export const wasm: HandlerMaker = async ({ const blockTimeUnixMs = BigInt(trace.blockTimeUnixMs).toString() // If contract key, save contract info. - if (trace.operation === 'write' && keyData[0] === 0x02) { + if (trace.operation === 'write' && keyData[0] === CONTRACT_KEY_PREFIX) { // Parse as protobuf to get code ID. const protobufContractInfo = fromBase64(trace.value) let contractInfo try { contractInfo = ContractInfo.decode(protobufContractInfo) - } catch { + } catch (err) { // If failed to decode, not contract info. return }