Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stellar): added pause and unpause functionality #538

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions stellar/pause.js
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { Contract } = require('@stellar/stellar-sdk');
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved
const { Command, Option } = require('commander');
const { getWallet, broadcast, addBaseOptions } = require('./utils');
const { loadConfig, printInfo } = require('../evm/utils');
const { getChainConfig } = require('../common');
require('./cli-utils');

async function processCommand(options, _, chain) {
const wallet = await getWallet(chain, options);

const contract = new Contract(options.address || chain.contracts?.pausable_contract?.address);
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved

let operation;

switch (options.action) {
case 'paused': {
operation = contract.call('paused');
break;
}

case 'pause': {
operation = contract.call('pause');
break;
}

case 'unpause': {
operation = contract.call('unpause');
break;
}

default: {
throw new Error(`Unknown action: ${options.action}`);
}
}

const returnValue = await broadcast(operation, wallet, chain, `${options.action} performed`, options);

if (returnValue.value()) {
printInfo('Return value', returnValue.value());
}
}

if (require.main === module) {
const program = new Command();

program.name('pausable').description('Pausable contract management');
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved

addBaseOptions(program, { address: true });
program.addOption(
new Option('--action <action>', 'pausable contract action').choices(['paused', 'pause', 'unpause']).makeOptionMandatory(true),
);
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved

TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved
program.action((options) => {
const config = loadConfig(options.env);
processCommand(options, config, getChainConfig(config, options.chainName));
});

program.parse();
}