terra: Also allow private key in deploy script
The mnemonic might no longer be available.
This commit is contained in:
parent
7da21a60b6
commit
ce20776f5d
|
@ -25,8 +25,8 @@ endif
|
|||
$(WASMS) artifacts/checksums.txt: $(SOURCE_FILES)
|
||||
DOCKER_BUILDKIT=1 docker build --target artifacts -o artifacts .
|
||||
|
||||
payer-$(NETWORK).json:
|
||||
$(error Missing private key in payer-$(NETWORK).json)
|
||||
payer-$(NETWORK):
|
||||
$(error Missing private key in payer-$(NETWORK))
|
||||
|
||||
.PHONY: deploy/bridge
|
||||
## Deploy core bridge
|
||||
|
@ -40,12 +40,12 @@ deploy/token_bridge: token_bridge-code-id-$(NETWORK).txt
|
|||
## Deploy NFT bridge
|
||||
deploy/nft_bridge: nft_bridge-code-id-$(NETWORK).txt
|
||||
|
||||
%-code-id-$(NETWORK).txt: check-network tools/node_modules payer-$(NETWORK).json artifacts
|
||||
%-code-id-$(NETWORK).txt: check-network tools/node_modules payer-$(NETWORK) artifacts
|
||||
@echo "Deploying artifacts/$($*_SOURCE).wasm on $(NETWORK)"
|
||||
@node tools/deploy_single.js \
|
||||
--network $(NETWORK) \
|
||||
--artifact artifacts/$($*_SOURCE).wasm \
|
||||
--mnemonic "$$(cat payer-$(NETWORK).json)" \
|
||||
--private-key "$$(cat payer-$(NETWORK))" \
|
||||
| grep -i "code id" | sed s/[^0-9]//g \
|
||||
> $@
|
||||
@echo "Deployed at code id $$(cat $@) (stored in $@)"
|
||||
|
@ -85,3 +85,4 @@ clean:
|
|||
rm -f artifacts/checksums.txt
|
||||
rm -rf tools/node_modules
|
||||
rm -rf test/node_modules
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { LCDClient, MnemonicKey } from "@terra-money/terra.js";
|
||||
import { LCDClient, MnemonicKey, RawKey } from "@terra-money/terra.js";
|
||||
import {
|
||||
MsgInstantiateContract,
|
||||
MsgStoreCode,
|
||||
|
@ -23,8 +23,8 @@ const argv = yargs(hideBin(process.argv))
|
|||
type: 'string',
|
||||
required: true
|
||||
})
|
||||
.option('mnemonic', {
|
||||
description: 'Mnemonic (private key)',
|
||||
.option('private-key', {
|
||||
description: 'Private key (hex or mnemonic)',
|
||||
type: 'string',
|
||||
required: true
|
||||
})
|
||||
|
@ -61,12 +61,18 @@ const gasPrices = await axios
|
|||
.get(TERRA_GAS_PRICES_URL)
|
||||
.then((result) => result.data);
|
||||
|
||||
const wallet = lcd.wallet(
|
||||
new MnemonicKey({
|
||||
mnemonic: argv.mnemonic
|
||||
})
|
||||
);
|
||||
|
||||
let wallet;
|
||||
// Try either a private key in hex form or a mnemonic
|
||||
try {
|
||||
wallet = lcd.wallet(
|
||||
new RawKey(new Uint8Array(Buffer.from(argv['private-key'], "hex")))
|
||||
);
|
||||
} catch {
|
||||
wallet = lcd.wallet(
|
||||
new MnemonicKey({
|
||||
mnemonic: argv['private-key']
|
||||
}))
|
||||
}
|
||||
await wallet.sequence();
|
||||
|
||||
/* Deploy artifacts */
|
||||
|
@ -101,10 +107,17 @@ const tx = await wallet.createAndSignTx({
|
|||
});
|
||||
|
||||
const rs = await lcd.tx.broadcast(tx);
|
||||
const ci = /"code_id","value":"([^"]+)/gm.exec(rs.raw_log)[1];
|
||||
codeId = parseInt(ci);
|
||||
try {
|
||||
|
||||
const ci = /"code_id","value":"([^"]+)/gm.exec(rs.raw_log)[1];
|
||||
codeId = parseInt(ci);
|
||||
|
||||
console.log("Code ID: ", codeId);
|
||||
} catch (e) {
|
||||
console.error("Couldn't parse logs: " + e);
|
||||
console.error(rs.raw_log);
|
||||
}
|
||||
|
||||
console.log("Code ID: ", codeId);
|
||||
|
||||
/* Instantiate contracts.
|
||||
*
|
||||
|
@ -159,3 +172,4 @@ async function instantiate(codeId, inst_msg) {
|
|||
function convert_terra_address_to_hex(human_addr) {
|
||||
return "0x" + toHex(zeroPad(Bech32.decode(human_addr).data, 32));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue