Skip to content

Commit

Permalink
added upgrade method to devnet and mainnet snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
newbreedofgeek committed Dec 13, 2023
1 parent 6579938 commit beebc90
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
20 changes: 19 additions & 1 deletion interaction/devnet.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEPLOY_TRANSACTION=$(mxpy data load --key=deployTransaction-devnet)
TOKEN="ITHEUM-fce905"
TOKEN_HEX="0x$(echo -n ${TOKEN} | xxd -p -u | tr -d '\n')"

# to deploy from last reprodubible build, we need to change
# to deploy from last reprodubible build, we need to change or vice versa
# --bytecode output/datanftmint.wasm \
# to
# --bytecode output-docker/datanftmint/datanftmint.wasm \
Expand All @@ -35,6 +35,24 @@ deploy(){
mxpy data store --key=deployTransaction-devnet --value=${TRANSACTION}
}

# any change to code or property requires a full upgrade
# always check if you are deploy via a reprodubible build and that the code hash is the same before and after upgrade (that is if you are only changing props and not code.. for code, the RB will be different)
# if only changing props, you can't just "append" new props. you have to add the old ones again and then add a new prop you need. i.e. it's not append, it's a whole reset
# for upgrade, --outfile deployOutput is not needed
# in below code example we added --metadata-payable to add PAYABLE to the prop of the SC and removed --metadata-not-readable to make it READABLE
upgrade(){
mxpy --verbose contract upgrade ${ADDRESS} \
--bytecode output-docker/datanftmint/datanftmint.wasm \
--metadata-payable-by-sc \
--metadata-payable \
--pem ${WALLET} \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--gas-limit 150000000 \
--recall-nonce \
--send || return
}

# if you interact without calling deploy(), then you need to 1st run this to restore the vars from data
restoreDeployData() {
TRANSACTION=$(mxpy data parse --file="./interaction/deploy-devnet.interaction.json" --expression="data['emittedTransactionHash']")
Expand Down
27 changes: 27 additions & 0 deletions interaction/mainnet.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ DEPLOY_TRANSACTION=$(mxpy data load --key=deployTransaction-mainnet)
TOKEN="ITHEUM-df6f26"
TOKEN_HEX="0x$(echo -n ${TOKEN} | xxd -p -u | tr -d '\n')"

# to deploy from last reprodubible build, we need to change or vice versa
# --bytecode output/datanftmint.wasm \
# to
# --bytecode output-docker/datanftmint/datanftmint.wasm
deployLedgerMainnet(){
mxpy --verbose contract deploy \
--bytecode output-docker/datanftmint/datanftmint.wasm \
Expand All @@ -29,10 +33,33 @@ deployLedgerMainnet(){
mxpy data store --key=deployTransaction-mainnet --value=${TRANSACTION}
}

# any change to code or property requires a full upgrade
# always check if you are deploy via a reprodubible build and that the code hash is the same before and after upgrade (that is if you are only changing props and not code.. for code, the RB will be different)
# if only changing props, you can't just "append" new props. you have to add the old ones again and then add a new prop you need. i.e. it's not append, it's a whole reset
# for upgrade, --outfile deployOutput is not needed
# in below code example we added --metadata-payable to add PAYABLE to the prop of the SC and removed --metadata-not-readable to make it READABLE
upgrade(){
mxpy --verbose contract upgrade ${ADDRESS} \
--bytecode output-docker/datanftmint/datanftmint.wasm \
--metadata-payable-by-sc \
--metadata-payable \
--proxy ${PROXY} \
--chain ${CHAIN_ID} \
--gas-limit 150000000 \
--recall-nonce \
--ledger \
--ledger-address-index 0 \
--send || return
}

# if you interact without calling deploy(), then you need to 1st run this to restore the vars from data
restoreDeployDataLedgerMainnet() {
TRANSACTION=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['contractAddress']")

# after we upgraded to mxpy 8.1.2, mxpy data parse seems to load the ADDRESS correctly but it breaks when used below with a weird "Bad address" error
# so, we just hardcode the ADDRESS here. Just make sure you use the "data['contractAddress'] from the latest deploy-devnet.interaction.json file
ADDRESS="erd1qqqqqqqqqqqqqpgqmuzgkurn657afd3r2aldqy2snsknwvrhc77q3lj8l6"
}

initializeContractMainnet(){
Expand Down

0 comments on commit beebc90

Please sign in to comment.