-
Notifications
You must be signed in to change notification settings - Fork 37
/
migrate.ts
73 lines (64 loc) · 2.04 KB
/
migrate.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
import { Command } from '@oclif/command';
import { LCDClient } from '@terra-money/feather.js';
import { loadConfig, loadConnections, CONFIG_FILE_NAME as execPath } from '../../config';
import { migrate, storeCode } from '../../lib/deployment';
import { getSigner } from '../../lib/signer';
import * as flag from '../../lib/flag';
import runCommand from '../../lib/runCommand';
import defaultErrorCheck from '../../lib/defaultErrorCheck';
export default class ContractMigrate extends Command {
static description = 'Migrate the contract.';
static flags = {
'no-rebuild': flag.noRebuild,
'instance-id': flag.instanceId,
'code-id': flag.codeId,
...flag.tx,
...flag.terrainPaths,
};
static args = [{ name: 'contract', required: true }];
async run() {
const { args, flags } = this.parse(ContractMigrate);
// Command to be performed.
const command = async () => {
const connections = loadConnections(flags.prefix);
const config = loadConfig();
const conf = config(flags.network, args.contract);
const connection = connections(flags.network);
const lcd = new LCDClient({ [connection.chainID]: connection });
const signer = await getSigner({
network: flags.network,
signerId: flags.signer,
keysPath: flags['keys-path'],
lcd,
prefix: flags.prefix,
});
const codeId = await storeCode({
conf,
noRebuild: flags['no-rebuild'],
contract: args.contract,
signer,
network: flags.network,
refsPath: flags['refs-path'],
lcd,
prefix: flags.prefix,
});
migrate({
conf,
signer,
contract: args.contract,
codeId,
network: flags.network,
instanceId: flags['instance-id'],
refsPath: flags['refs-path'],
lcd,
prefix: flags.prefix,
});
};
// Attempt to execute command while backtracking through file tree.
await runCommand(
execPath,
command,
defaultErrorCheck(args.contract),
);
}
}