Skip to content

Commit

Permalink
Merge branch 'main' into feat/cosmwasm-migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
eguajardo authored Jan 13, 2025
2 parents c3f6c18 + f752faf commit f770e39
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cosmwasm/update-code-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

require('dotenv').config();

const { printInfo, loadConfig, saveConfig } = require('../common');
const { prepareWallet, prepareClient, initContractConfig, getAmplifierContractConfig, fetchCodeIdFromContract } = require('./utils');

const { Command } = require('commander');
const { addAmplifierOptions } = require('./cli-utils');

const processCommand = async (options) => {
const { env } = options;
const config = loadConfig(env);

initContractConfig(config, options);

const wallet = await prepareWallet(options);
const client = await prepareClient(config, wallet);

const { contractConfig } = getAmplifierContractConfig(config, options);

printInfo('Old code id', contractConfig.codeId);

contractConfig.codeId = await fetchCodeIdFromContract(client, contractConfig);

printInfo('New code id', contractConfig.codeId);

saveConfig(config, env);
};

const programHandler = () => {
const program = new Command();

program.name('update-code-id').description('Update configured code id of contract with the one currently being used on-chain');

addAmplifierOptions(program, {
contractOptions: true,
});

program.action((options) => {
processCommand(options);
});

program.parse();
};

if (require.main === module) {
programHandler();
}
13 changes: 13 additions & 0 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ const fetchCodeIdFromCodeHash = async (client, contractBaseConfig) => {
return codeId;
};

const fetchCodeIdFromContract = async (client, contractConfig) => {
const { address } = contractConfig;

if (!address) {
throw new Error('Contract address not found in the config');
}

const { codeId } = await client.getContract(address);

return codeId;
};

const addDefaultInstantiateAddresses = async (client, config, options) => {
const { contractConfig } = getAmplifierContractConfig(config, options);

Expand Down Expand Up @@ -888,6 +900,7 @@ module.exports = {
instantiateContract,
migrateContract,
fetchCodeIdFromCodeHash,
fetchCodeIdFromContract,
addDefaultInstantiateAddresses,
getChainTruncationParams,
decodeProposalAttributes,
Expand Down

0 comments on commit f770e39

Please sign in to comment.