-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathupdateAdmin.ts
82 lines (68 loc) · 2.3 KB
/
updateAdmin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Command } from '@oclif/command';
import * as YAML from 'yaml';
import { LCDClient, MsgUpdateContractAdmin } from '@terra-money/feather.js';
import { cli } from 'cli-ux';
import { loadConnections, loadRefs, CONFIG_FILE_NAME as execPath } from '../../config';
import { getSigner } from '../../lib/signer';
import * as flag from '../../lib/flag';
import runCommand from '../../lib/runCommand';
import defaultErrorCheck from '../../lib/defaultErrorCheck';
export default class ContractUpdateAdmin extends Command {
static description = 'Update the admin of a contract.';
static flags = {
...flag.tx,
'instance-id': flag.instanceId,
...flag.terrainPaths,
};
static args = [
{ name: 'contract', required: true },
{ name: 'admin', required: true },
];
async run() {
const { args, flags } = this.parse(ContractUpdateAdmin);
// Command execution path.
// Command to be performed.
const command = async () => {
const connections = loadConnections(flags.prefix);
const refs = loadRefs(flags['refs-path']);
const { network } = flags;
const connection = connections(network);
const { chainID } = connection;
const lcd = new LCDClient({ [chainID]: connection });
const signer = await getSigner({
network: flags.network,
signerId: flags.signer,
keysPath: flags['keys-path'],
lcd,
prefix: flags.prefix,
});
const contractAddress = refs[network][chainID][args.contract].contractAddresses[flags['instance-id']];
cli.action.start(
`Updating contract admin to: ${args.admin}`,
);
const updateAdminTx = await signer.createAndSignTx({
chainID,
msgs: [
new MsgUpdateContractAdmin(
signer.key.accAddress(flags.prefix),
args.admin,
contractAddress,
),
],
});
const res = await lcd.tx.broadcast(updateAdminTx, chainID);
cli.action.stop();
if (res) {
cli.log(YAML.stringify(JSON.parse(res.raw_log)));
} else {
cli.error('Transaction not included in block before timeout.');
}
};
// Attempt to execute command while backtracking through file tree.
await runCommand(
execPath,
command,
defaultErrorCheck(args.contract),
);
}
}