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
Show file tree
Hide file tree
Changes from 4 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
37 changes: 37 additions & 0 deletions stellar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,40 @@ node stellar/gmp.js [source-chain] [message-id] [source-address] [payload]
# Example
node stellar/gmp.js execute avalanche '0x0bcbbfc9b006db6958f3fce75f11fdc306b45e8e43396211f414f40d2d6db7c5-0' 0xba76c6980428A0b10CFC5d8ccb61949677A61233 0x1234
```

## Pausable Contract Functionality

This script allows you to manage the pausable state of a Stellar contract. You can check if the contract is paused, pause the contract, or unpause the contract.

#### Usage

To use this script, run the following command with the appropriate options:

```bash
node stellar/pause.js --action <action> --address <contract-address>
```

#### Options

- `--action <action>`: The action to perform on the contract. Choices are `paused`, `pause`, and `unpause`. This option is mandatory.
- `--address <contract-address>`: The address of the contract to interact with. This option is mandatory.

#### Examples

Check if the contract is paused:

```bash
node stellar/pause.js --action paused --address CBC2TFJUF4PIZFZXRJJ3K47OBZW5BUJVWBELZDJGMNGNVVNA4A64D5FI
```

Pause the contract:

```bash
node stellar/pause.js --action pause --address CBC2TFJUF4PIZFZXRJJ3K47OBZW5BUJVWBELZDJGMNGNVVNA4A64D5FI
```

Unpause the contract:

```bash
node stellar/pause.js --action unpause --address CBC2TFJUF4PIZFZXRJJ3K47OBZW5BUJVWBELZDJGMNGNVVNA4A64D5FI
```
67 changes: 67 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,67 @@
const { Contract } = require('@stellar/stellar-sdk');
TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved
const { Command } = require('commander');
const { getWallet, broadcast, addBaseOptions } = require('./utils');
const { loadConfig, printInfo } = require('../evm/utils');
const { getChainConfig, addOptionsToCommands } = require('../common');
require('./cli-utils');

async function paused(contract) {
return contract.call('paused');
}

async function pause(contract) {
return contract.call('pause');
}

async function unpause(contract) {
return contract.call('unpause');
}

async function processCommand(processor, options, contractName) {
const config = loadConfig(options.env);
const chain = getChainConfig(config, options.chainName);
const wallet = await getWallet(chain, options);
const contract = new Contract(chain.contracts?.[contractName]?.address || options.address);

const operation = await processor(contract);

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

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

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

program.name('contract').description('Common contract operations');

program
.command('paused')
.description('Check if the contract is paused')
.argument('<contract-name>', 'contract name to deploy')
.action((contractName, options) => {
processCommand(paused, options, contractName);
});

program
.command('pause')
.description('Pause the contract')
.argument('<contract-name>', 'contract name to deploy')
.action((contractName, options) => {
processCommand(pause, options, contractName);
});

program
.command('unpause')
.description('Unpause the contract')
.argument('<contract-name>', 'contract name to deploy')
.action((contractName, options) => {
processCommand(unpause, options, contractName);
});

TanvirDeol marked this conversation as resolved.
Show resolved Hide resolved
addOptionsToCommands(program, addBaseOptions);

program.parse();
}