add private key option to migration script (#1811)

This commit is contained in:
Xianny 2019-05-13 16:32:37 -07:00 committed by GitHub
parent 54be45bedc
commit 8d9932fc42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
#!/usr/bin/env node
import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { PrivateKeyWalletSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { logUtils, providerUtils } from '@0x/utils';
import * as yargs from 'yargs';
@ -17,14 +17,24 @@ const args = yargs
type: 'string',
demandOption: true,
})
.option('pk', {
describe: 'Private key for the `from` address',
type: 'string',
})
.example(
'$0 --rpc-url http://localhost:8545 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631',
'$0 --rpc-url http://localhost:8545 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --pk 0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d',
'Full usage example',
).argv;
(async () => {
const rpcSubprovider = new RPCSubprovider(args['rpc-url']);
const provider = new Web3ProviderEngine();
if (args.pk !== undefined && args.pk !== '') {
const pkSubprovider = new PrivateKeyWalletSubprovider(args.pk as string);
provider.addProvider(pkSubprovider);
}
provider.addProvider(rpcSubprovider);
providerUtils.startProviderEngine(provider);
const normalizedFromAddress = (args.from as string).toLowerCase();