//returns a Promise<string> containing the contract code id if successful
function upload_contract(bytes) {
const storeCode = new MsgStoreCode(wallet.key.accAddress, bytes);
return wallet.createAndSignTx({ msgs: [storeCode], })
.then(storeCodeTx => terra.tx.broadcast(storeCodeTx))
.then(storeCodeTxResult => {
if (isTxError(storeCodeTxResult)) {
return Promise.reject(`store code failed. code: ${storeCodeTxResult.code}, codespace: ${storeCodeTxResult.codespace}, raw_log: ${storeCodeTxResult.raw_log}`);
}
const {
store_code: { code_id },
} = storeCodeTxResult.logs[0].eventsByType;
return Promise.resolve(code_id[0]);
});
}