From cf5211197e8d4e8c942f6c74c38e38b9495bec22 Mon Sep 17 00:00:00 2001 From: Servio Date: Tue, 2 Jul 2024 15:49:23 -0400 Subject: [PATCH 1/7] self versioning was added --- .github/workflows/pipeline.yml | 22 +++++++++++++++++++++- .version | 1 - 2 files changed, 21 insertions(+), 2 deletions(-) delete mode 100644 .version diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 712aeef6..06366d32 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -53,7 +53,27 @@ jobs: toolchain: stable - name: Compile run: | - VERSION=$(cat .version) + ELYSD=./elysd + json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "${{vars.FS_CONTRACT_ADDRESS}}" '{ "version": {} }') + echo "Response json: $json" + VERSION=$(echo $json | jq -r ".data.version") + echo "Current version: $VERSION" + + # Extract the major, minor, and patch versions + version_parts=(${VERSION//./ }) + major=${version_parts[0]} + minor=${version_parts[1]} + patch=${version_parts[2]} + + # Increment the minor version + minor=$((minor + 1)) + + # Update the version string + VERSION="$major.$minor.$patch" + + # Print the updated version number + echo "New version number: $new_version" + sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/account-history-contract/Cargo.toml sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/trade-shield-contract/Cargo.toml sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/financial-snapshot-contract/Cargo.toml diff --git a/.version b/.version deleted file mode 100644 index be386c9e..00000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -0.33.0 From d72b3946c004e6e85301a34fa3b46f0d4d0b0b8d Mon Sep 17 00:00:00 2001 From: Servio Date: Tue, 2 Jul 2024 15:50:07 -0400 Subject: [PATCH 2/7] self versioning was added --- .github/workflows/pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 06366d32..064885a2 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -72,8 +72,8 @@ jobs: VERSION="$major.$minor.$patch" # Print the updated version number - echo "New version number: $new_version" - + echo "New version number: $VERSION" + sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/account-history-contract/Cargo.toml sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/trade-shield-contract/Cargo.toml sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/financial-snapshot-contract/Cargo.toml From 4cf05d1a2821a9b7f9fd24278f004302fb387074 Mon Sep 17 00:00:00 2001 From: Servio Date: Tue, 2 Jul 2024 16:58:21 -0400 Subject: [PATCH 3/7] self versioning was added --- .github/workflows/pipeline.yml | 233 +++++---------------------------- 1 file changed, 32 insertions(+), 201 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 75cff296..bd817f6a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -34,7 +34,7 @@ jobs: cargo test --verbose working-directory: . devnet: - needs: test + #needs: test name: deploy on devnet runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' @@ -53,30 +53,40 @@ jobs: toolchain: stable - name: Compile run: | - ELYSD=./elysd - json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "${{vars.FS_CONTRACT_ADDRESS}}" '{ "version": {} }') - echo "Response json: $json" - VERSION=$(echo $json | jq -r ".data.version") - echo "Current version: $VERSION" - - # Extract the major, minor, and patch versions - version_parts=(${VERSION//./ }) - major=${version_parts[0]} - minor=${version_parts[1]} - patch=${version_parts[2]} + getNewVersionBYContract(){ + + local contractAddress=$1 + + ELYSD=./elysd + local json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "$contractAddress" '{ "version": {} }') + local VERSION=$(echo $json | jq -r ".data.version") + + # Extract the major, minor, and patch versions + local version_parts=(${VERSION//./ }) + local major=${version_parts[0]} + local minor=${version_parts[1]} + local patch=${version_parts[2]} - # Increment the minor version - minor=$((minor + 1)) + # Increment the minor version + local minor=$((minor + 1)) - # Update the version string - VERSION="$major.$minor.$patch" + # Update the version string + VERSION="$major.$minor.$patch" - # Print the updated version number - echo "New version number: $VERSION" + echo $VERSION + } - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/account-history-contract/Cargo.toml - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/trade-shield-contract/Cargo.toml - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/financial-snapshot-contract/Cargo.toml + accountHistoryContractVersion=$(getNewVersionBYContract ${{vars.AH_CONTRACT_ADDRESS}}) + tradeShieldContractVersion=$(getNewVersionBYContract ${{vars.TS_CONTRACT_ADDRESS}}) + financialSnapshotContractVersion=$(getNewVersionBYContract ${{vars.FS_CONTRACT_ADDRESS}}) + + echo "new accountHistoryContractVersion: $accountHistoryContractVersion" + echo "new tradeShieldContractVersion: $tradeShieldContractVersion" + echo "new financialSnapshotContractVersion: $financialSnapshotContractVersion" + + sed -i "s/^version = .*/version = \"$accountHistoryContractVersion\"/" contracts/account-history-contract/Cargo.toml + sed -i "s/^version = .*/version = \"$tradeShieldContractVersion\"/" contracts/trade-shield-contract/Cargo.toml + sed -i "s/^version = .*/version = \"$financialSnapshotContractVersion\"/" contracts/financial-snapshot-contract/Cargo.toml cargo update docker run --rm -v "$(pwd)":/code \ @@ -236,183 +246,4 @@ jobs: printf "export NAME=%s\n" "$NAME" printf "export FS_CONTRACT_ADDRESS=%s\n" "$fs_contract_address" printf "export TS_CONTRACT_ADDRESS=%s\n" "$ts_contract_address" - printf "export AH_CONTRACT_ADDRESS=%s\n" "$ah_contract_address" - testnet: - needs: test - name: deploy on testnet - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/testnet' - environment: testnet - steps: - - uses: actions/checkout@v4 - - name: Downloading elys - run: | - URL=https://github.com/elys-network/elys/releases/download/v0.30.0/elysd-v0.30.0-linux-amd64 - wget $URL -O elysd - chmod +x elysd - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - - name: Compile - run: | - VERSION=${{ github.sha }} - echo "VERSION": $VERSION - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/account-history-contract/Cargo.toml - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/trade-shield-contract/Cargo.toml - sed -i "s/^version = .*/version = \"$VERSION\"/" contracts/financial-snapshot-contract/Cargo.toml - cargo update - - docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/workspace-optimizer:0.14.0 - - name: Deploy - run: | - # helper functions - extract_txhash() { awk -F 'txhash: ' '/txhash:/{print $2; exit}'; } - extract_code_id() { awk -F 'key: code_id|value: ' '/key: code_id/ { getline; gsub(/"/, "", $2); print $2; exit }'; } - extract_contract_address() { awk -F 'key: _contract_address|value: ' '/key: _contract_address/ { getline; gsub(/"/, "", $2); print $2; exit }'; } - extract_account_number() { awk -F 'account_number: ' '/account_number:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; } - extract_sequence() { awk -F 'sequence: ' '/sequence:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; } - - ELYSD=./elysd - - wait_for_tx() { - local txhash=$1 - # loop until query tx cli does not fail - while ! $ELYSD q tx $txhash --node "$NODE" &> /dev/null; do - echo "Waiting for the transaction $txhash to be included in a block..." - sleep 0.5 - done - } - - exit_if_tx_is_empty() { - local tx=$1 - if [[ -z "$tx" ]]; then - echo "Error: there is not a txhash" - exit 1 - fi - } - - # environment variables - NODE=${{vars.NODE}} - NAME=${{vars.NAME}} - - - # set elysd config - $ELYSD config keyring-backend test - $ELYSD config node $NODE - $ELYSD config chain-id ${{vars.CHAIN_ID}} - $ELYSD config broadcast-mode sync - - echo "${{ secrets.KEY_MNEMONIC }}" | elysd keys add $NAME --recover --keyring-backend test - - user_address=$(elysd keys show $NAME -a) - - # get account and sequence number - account_number=$($ELYSD q account $user_address --node $NODE | extract_account_number) - sequence=$($ELYSD q account $user_address --node $NODE | extract_sequence) - - echo "account_number: $account_number" - echo "sequence: $sequence" - - - # environment variables - OPTIONS="--from $NAME --gas auto --gas-adjustment 1.3 --fees 300000uelys -y --account-number $account_number -b async --log_level trace --trace" - - ##contracts - FS_CONTRACT_ADDRESS=${{vars.FS_CONTRACT_ADDRESS}} - TS_CONTRACT_ADDRESS=${{vars.TS_CONTRACT_ADDRESS}} - AH_CONTRACT_ADDRESS=${{vars.AH_CONTRACT_ADDRESS}} - - printf "FS_CONTRACT_ADDRESS=%s\n" "$FS_CONTRACT_ADDRESS" - printf "TS_CONTRACT_ADDRESS=%s\n" "$TS_CONTRACT_ADDRESS" - printf "AH_CONTRACT_ADDRESS=%s\n" "$AH_CONTRACT_ADDRESS" - - # store and init/migrate financial snapshot contract - txhash=$($ELYSD tx wasm store $OPTIONS --sequence $(($sequence + 1)) artifacts/financial_snapshot_contract.wasm | extract_txhash) - echo "fs store txhash: $txhash" - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id) - echo "fs code id: $codeid" - - if [ "$FS_CONTRACT_ADDRESS" != "empty" ]; then - txhash=$( $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 2)) $FS_CONTRACT_ADDRESS $codeid '{}' | extract_txhash) - echo "fs migrate txhash: $txhash" - else - txhash=$( $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 2)) --label "fs" --admin $NAME $codeid '{}' | extract_txhash) - echo "fs init txhash: $txhash" - fi - - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - export fs_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address) - echo "fs_contract_address: $fs_contract_address" - - # store and init/migrate trade shield contract - txhash=$($ELYSD tx wasm store $OPTIONS --sequence $(($sequence + 3)) artifacts/trade_shield_contract.wasm | extract_txhash) - echo "ts store txhash: $txhash" - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id) - echo "ts code id: $codeid" - - if [ "$TS_CONTRACT_ADDRESS" != "empty" ]; then - txhash=$($ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 4)) $TS_CONTRACT_ADDRESS $codeid '{ - "account_history_address": "'"$AH_CONTRACT_ADDRESS"'" - }' | extract_txhash) - echo "ts migrate txhash: $txhash" - else - # set localnet AH deterministic address as param - txhash=$($ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 4)) --label "ts" --admin $NAME $codeid '{ - "account_history_address": "elys17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs98tvuy" - }' | extract_txhash) - echo "ts init txhash: $txhash" - fi - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - export ts_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address) - echo "ts_contract_address: $ts_contract_address" - - # store and init/migrate account history contract - txhash=$($ELYSD tx wasm store artifacts/account_history_contract.wasm $OPTIONS --sequence $(($sequence + 5)) | extract_txhash) - - echo "ah store txhash: $txhash" - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - - codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id) - echo "ah code id: $codeid" - - if [ "$AH_CONTRACT_ADDRESS" != "empty" ]; then - txhash=$($ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 6)) $AH_CONTRACT_ADDRESS $codeid '{ - "trade_shield_address": "'"$TS_CONTRACT_ADDRESS"'", - "limit": 1 - }' | extract_txhash) - echo "ah migrate txhash: $txhash" - else - txhash=$($ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 6)) --label "ah" --admin $NAME $codeid '{ - "limit": 300, - "expiration": { - "at_time": "604800000000000" - }, - "trade_shield_address": "'"$ts_contract_address"'" - }' | extract_txhash) - echo "ah init txhash: $txhash" - fi - - exit_if_tx_is_empty $txhash - wait_for_tx $txhash - ah_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address) - echo "ah_contract_address: $ah_contract_address" - - # print environment variables to set - printf "\nset those environment variables to use the contracts:\n\n" - printf "export NODE=%s\n" "$NODE" - printf "export NAME=%s\n" "$NAME" - printf "export FS_CONTRACT_ADDRESS=%s\n" "$fs_contract_address" - printf "export TS_CONTRACT_ADDRESS=%s\n" "$ts_contract_address" - printf "export AH_CONTRACT_ADDRESS=%s\n" "$ah_contract_address" + printf "export AH_CONTRACT_ADDRESS=%s\n" "$ah_contract_address" \ No newline at end of file From 674708e69d7f44d18a79fa19a8b37a576e26a24c Mon Sep 17 00:00:00 2001 From: Servio Date: Thu, 4 Jul 2024 17:57:28 -0400 Subject: [PATCH 4/7] self versioning was added --- .gitignore | 4 +- Cargo.lock | 151 +++++++++--------- contracts/account-history-contract/Cargo.toml | 2 +- .../src/entry_point/migrate.rs | 16 +- .../financial-snapshot-contract/Cargo.toml | 1 + .../src/entry_point/migrate.rs | 18 ++- contracts/trade-shield-contract/Cargo.toml | 1 + .../src/entry_point/migrate.rs | 20 ++- 8 files changed, 128 insertions(+), 85 deletions(-) diff --git a/.gitignore b/.gitignore index 28d91a3a..25b4a564 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ yarn.lock # VSCode config .vscode/ -.DS_Store \ No newline at end of file +.DS_Store +/scripts/local_build.sh +contracts.local \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 8e398de6..91b85687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "elys-bindings", "elys-bindings-test", "schemars", + "semver", "serde", "serde_json", "thiserror", @@ -27,9 +28,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom", "once_cell", @@ -38,9 +39,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "autocfg" @@ -56,9 +57,9 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -92,9 +93,9 @@ dependencies = [ [[package]] name = "bnum" -version = "0.8.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" [[package]] name = "byteorder" @@ -104,9 +105,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cargo-husky" @@ -137,9 +138,9 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "cosmwasm-crypto" -version = "1.5.0" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8bb3c77c3b7ce472056968c745eb501c440fbc07be5004eba02782c35bfbbe3" +checksum = "dd50718a2b6830ce9eb5d465de5a018a12e71729d66b70807ce97e6dd14f931d" dependencies = [ "digest 0.10.7", "ecdsa", @@ -151,18 +152,18 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.5.0" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea73e9162e6efde00018d55ed0061e93a108b5d6ec4548b4f8ce3c706249687" +checksum = "242e98e7a231c122e08f300d9db3262d1007b51758a8732cd6210b3e9faa4f3a" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.5.0" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df41ea55f2946b6b43579659eec048cc2f66e8c8e2e3652fc5e5e476f673856" +checksum = "7879036156092ad1c22fe0d7316efc5a5eceec2bc3906462a2560215f2a2f929" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -173,9 +174,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.5.0" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43609e92ce1b9368aa951b334dd354a2d0dd4d484931a5f83ae10e12a26c8ba9" +checksum = "0bb57855fbfc83327f8445ae0d413b1a05ac0d68c396ab4d122b2abd7bb82cb6" dependencies = [ "proc-macro2", "quote", @@ -184,9 +185,9 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.5.0" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d6864742e3a7662d024b51a94ea81c9af21db6faea2f9a6d2232bb97c6e53e" +checksum = "78c1556156fdf892a55cced6115968b961eaaadd6f724a2c2cb7d1e168e32dd3" dependencies = [ "base64", "bech32", @@ -206,9 +207,9 @@ dependencies = [ [[package]] name = "cosmwasm-storage" -version = "1.5.0" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2b4ae72a03e8f56c85df59d172d51d2d7dc9cec6e2bc811e3fb60c588032a4" +checksum = "66de2ab9db04757bcedef2b5984fbe536903ada4a8a9766717a4a71197ef34f6" dependencies = [ "cosmwasm-std", "serde", @@ -216,9 +217,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -328,9 +329,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -370,9 +371,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" @@ -405,9 +406,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -482,6 +483,7 @@ dependencies = [ "elys-bindings", "elys-bindings-test", "schemars", + "semver", "serde", "thiserror", ] @@ -505,9 +507,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -560,15 +562,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "k256" -version = "0.13.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if", "ecdsa", @@ -580,9 +582,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "num-traits" @@ -601,9 +603,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "pkcs8" @@ -617,9 +619,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -649,9 +651,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -683,15 +685,15 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "schemars_derive", @@ -701,14 +703,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.68", ] [[package]] @@ -733,49 +735,49 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.68", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -834,9 +836,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -851,9 +853,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -862,22 +864,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.68", ] [[package]] @@ -895,6 +897,7 @@ dependencies = [ "elys-bindings", "elys-bindings-test", "schemars", + "semver", "serde", "serde_json", "thiserror", @@ -926,6 +929,6 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/contracts/account-history-contract/Cargo.toml b/contracts/account-history-contract/Cargo.toml index e23c93b1..405e9973 100644 --- a/contracts/account-history-contract/Cargo.toml +++ b/contracts/account-history-contract/Cargo.toml @@ -25,7 +25,7 @@ cw-utils = { version = "0.13", default-features = false } cw2 = { version = "1.0.1" } elys-bindings = { path = "../../bindings" } chrono = { version = "0.4.33", default-features = false, features = ["alloc"] } - +semver = "1.0" [dev-dependencies] trade_shield_contract = { path = "../trade-shield-contract" } diff --git a/contracts/account-history-contract/src/entry_point/migrate.rs b/contracts/account-history-contract/src/entry_point/migrate.rs index 8fd3eeaa..b4a0dfab 100644 --- a/contracts/account-history-contract/src/entry_point/migrate.rs +++ b/contracts/account-history-contract/src/entry_point/migrate.rs @@ -4,14 +4,13 @@ use cw_utils::Expiration; use elys_bindings::account_history::msg::MigrationMsg; // use elys_bindings::account_history::types::Metadata; use elys_bindings::{ElysMsg, /*ElysQuerier,*/ ElysQuery}; +use semver::Version; use crate::states::{ DELETE_EPOCH, DELETE_OLD_DATA_ENABLED, EXPIRATION, PARAMS_ADMIN, PROCESSED_ACCOUNT_PER_BLOCK, TRADE_SHIELD_ADDRESS, }; -use super::instantiate::{CONTRACT_NAME, CONTRACT_VERSION}; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate( deps: DepsMut, @@ -53,8 +52,17 @@ pub fn migrate( if ver.contract != CONTRACT_NAME { return Err(StdError::generic_err("Can only upgrade from same type").into()); } - if ver.version.as_str() >= CONTRACT_VERSION { - return Err(StdError::generic_err("Cannot upgrade from a newer version").into()); + let new_contract_version = Version::parse(CONTRACT_VERSION).unwrap(); + let actual_contract_version = Version::parse(ver.version.as_str()).unwrap(); + + if new_contract_version.le(&actual_contract_version) { + let err_version: String = format!( + "Error the version of account-history-contract {} has to be upper to {}", + new_contract_version.to_string(), + actual_contract_version.to_string() + ); + + return Err(StdError::generic_err(err_version).into()); } let admin = "elys16xffmfa6k45j340cx5zyp66lqvuw62a0neaa7w".to_string(); diff --git a/contracts/financial-snapshot-contract/Cargo.toml b/contracts/financial-snapshot-contract/Cargo.toml index 2a933ecc..bceaae0b 100644 --- a/contracts/financial-snapshot-contract/Cargo.toml +++ b/contracts/financial-snapshot-contract/Cargo.toml @@ -19,6 +19,7 @@ cw-utils = "0.13" cw2 = { version = "1.0.1" } anyhow = "1" elys-bindings = { path = "../../bindings" } +semver = "1.0" [dev-dependencies] cw-multi-test = "0.13.4" diff --git a/contracts/financial-snapshot-contract/src/entry_point/migrate.rs b/contracts/financial-snapshot-contract/src/entry_point/migrate.rs index 5c3342cf..4dc36dc7 100644 --- a/contracts/financial-snapshot-contract/src/entry_point/migrate.rs +++ b/contracts/financial-snapshot-contract/src/entry_point/migrate.rs @@ -1,12 +1,12 @@ -use cosmwasm_std::entry_point; use cosmwasm_std::Empty; +use cosmwasm_std::{entry_point, StdError}; use cw2::set_contract_version; use self::instantiate::{CONTRACT_NAME, CONTRACT_VERSION}; use super::*; use elys_bindings::*; - +use semver::Version; #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> StdResult> { // Uncomment after first migration @@ -19,6 +19,20 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> StdResult= CONTRACT_VERSION { - return Err(StdError::generic_err("Cannot upgrade from a newer version").into()); - } + let new_contract_version = Version::parse(CONTRACT_VERSION).unwrap(); + let actual_contract_version = Version::parse(ver.version.as_str()).unwrap(); + + if new_contract_version.le(&actual_contract_version) { + let err_version: String = format!( + "Error the version of trade-shield-contract {} has to be upper to {}", + new_contract_version.to_string(), + actual_contract_version.to_string() + ); + return Err(StdError::generic_err(err_version).into()); + } // set the new version set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; Ok(Response::new()) From a8dd3329b37420054f91969ceb67727c740c91fb Mon Sep 17 00:00:00 2001 From: Servio Date: Thu, 4 Jul 2024 18:00:13 -0400 Subject: [PATCH 5/7] self versioning was added --- contracts/account-history-contract/src/entry_point/migrate.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/account-history-contract/src/entry_point/migrate.rs b/contracts/account-history-contract/src/entry_point/migrate.rs index b4a0dfab..d4647925 100644 --- a/contracts/account-history-contract/src/entry_point/migrate.rs +++ b/contracts/account-history-contract/src/entry_point/migrate.rs @@ -3,14 +3,14 @@ use cw2::set_contract_version; use cw_utils::Expiration; use elys_bindings::account_history::msg::MigrationMsg; // use elys_bindings::account_history::types::Metadata; -use elys_bindings::{ElysMsg, /*ElysQuerier,*/ ElysQuery}; +use elys_bindings::{ElysMsg, ElysQuery}; use semver::Version; +use super::instantiate::{CONTRACT_NAME, CONTRACT_VERSION}; use crate::states::{ DELETE_EPOCH, DELETE_OLD_DATA_ENABLED, EXPIRATION, PARAMS_ADMIN, PROCESSED_ACCOUNT_PER_BLOCK, TRADE_SHIELD_ADDRESS, }; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate( deps: DepsMut, From d50380a37fb98fc83f27c1137e2e2768ecba5659 Mon Sep 17 00:00:00 2001 From: Servio Date: Thu, 4 Jul 2024 18:15:46 -0400 Subject: [PATCH 6/7] build test need test --- .github/workflows/pipeline.yml | 2 +- Cargo.lock | 6 +++--- contracts/account-history-contract/Cargo.toml | 2 +- contracts/financial-snapshot-contract/Cargo.toml | 2 +- contracts/trade-shield-contract/Cargo.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index bd817f6a..b16c57d3 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -34,7 +34,7 @@ jobs: cargo test --verbose working-directory: . devnet: - #needs: test + needs: test name: deploy on devnet runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' diff --git a/Cargo.lock b/Cargo.lock index 91b85687..960bf068 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "account-history-contract" -version = "0.0.0" +version = "0.2.20" dependencies = [ "account-history-contract", "anyhow", @@ -470,7 +470,7 @@ dependencies = [ [[package]] name = "financial_snapshot_contract" -version = "0.0.0" +version = "0.2.20" dependencies = [ "anyhow", "cargo-husky", @@ -884,7 +884,7 @@ dependencies = [ [[package]] name = "trade_shield_contract" -version = "0.0.0" +version = "0.2.20" dependencies = [ "anyhow", "cargo-husky", diff --git a/contracts/account-history-contract/Cargo.toml b/contracts/account-history-contract/Cargo.toml index 405e9973..2dad0954 100644 --- a/contracts/account-history-contract/Cargo.toml +++ b/contracts/account-history-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "account-history-contract" -version = "0.0.0" +version = "0.2.20" edition = "2021" [lib] diff --git a/contracts/financial-snapshot-contract/Cargo.toml b/contracts/financial-snapshot-contract/Cargo.toml index bceaae0b..e02d3cb4 100644 --- a/contracts/financial-snapshot-contract/Cargo.toml +++ b/contracts/financial-snapshot-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "financial_snapshot_contract" -version = "0.0.0" +version = "0.2.20" edition = "2021" publish = false license = "Apache-2.0" diff --git a/contracts/trade-shield-contract/Cargo.toml b/contracts/trade-shield-contract/Cargo.toml index 7eff214c..ead51de2 100644 --- a/contracts/trade-shield-contract/Cargo.toml +++ b/contracts/trade-shield-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trade_shield_contract" -version = "0.0.0" +version = "0.2.20" edition = "2021" [lib] From 6de80059fd240c757556a375679fefacb5ec37ae Mon Sep 17 00:00:00 2001 From: Servio Date: Thu, 4 Jul 2024 18:18:24 -0400 Subject: [PATCH 7/7] build test need test --- Cargo.lock | 6 +++--- contracts/account-history-contract/Cargo.toml | 2 +- contracts/financial-snapshot-contract/Cargo.toml | 2 +- contracts/trade-shield-contract/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 960bf068..91b85687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "account-history-contract" -version = "0.2.20" +version = "0.0.0" dependencies = [ "account-history-contract", "anyhow", @@ -470,7 +470,7 @@ dependencies = [ [[package]] name = "financial_snapshot_contract" -version = "0.2.20" +version = "0.0.0" dependencies = [ "anyhow", "cargo-husky", @@ -884,7 +884,7 @@ dependencies = [ [[package]] name = "trade_shield_contract" -version = "0.2.20" +version = "0.0.0" dependencies = [ "anyhow", "cargo-husky", diff --git a/contracts/account-history-contract/Cargo.toml b/contracts/account-history-contract/Cargo.toml index 2dad0954..405e9973 100644 --- a/contracts/account-history-contract/Cargo.toml +++ b/contracts/account-history-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "account-history-contract" -version = "0.2.20" +version = "0.0.0" edition = "2021" [lib] diff --git a/contracts/financial-snapshot-contract/Cargo.toml b/contracts/financial-snapshot-contract/Cargo.toml index e02d3cb4..bceaae0b 100644 --- a/contracts/financial-snapshot-contract/Cargo.toml +++ b/contracts/financial-snapshot-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "financial_snapshot_contract" -version = "0.2.20" +version = "0.0.0" edition = "2021" publish = false license = "Apache-2.0" diff --git a/contracts/trade-shield-contract/Cargo.toml b/contracts/trade-shield-contract/Cargo.toml index ead51de2..7eff214c 100644 --- a/contracts/trade-shield-contract/Cargo.toml +++ b/contracts/trade-shield-contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trade_shield_contract" -version = "0.2.20" +version = "0.0.0" edition = "2021" [lib]