From ad08773daac75319e9c8b7954d145610498537d7 Mon Sep 17 00:00:00 2001 From: 0xjazper <0xjazper@gmail.com> Date: Wed, 29 May 2024 16:28:12 +0800 Subject: [PATCH] change to bash script --- .github/scripts/update-token-list.py | 59 ------------------------ .github/workflows/update-token-list.yml | 35 --------------- chains/81457/token-list.json | 9 +++- update_lish.sh | 60 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 95 deletions(-) delete mode 100755 .github/scripts/update-token-list.py delete mode 100644 .github/workflows/update-token-list.yml create mode 100755 update_lish.sh diff --git a/.github/scripts/update-token-list.py b/.github/scripts/update-token-list.py deleted file mode 100755 index 83f65a5..0000000 --- a/.github/scripts/update-token-list.py +++ /dev/null @@ -1,59 +0,0 @@ -import json -import os - -CHAINS_PATH = "chains" -TOKEN_LIST_FILENAME = "token-list.json" - -def process_chain(chain_dir): - assets_path = os.path.join(chain_dir, 'assets') - token_list_path = os.path.join(chain_dir, TOKEN_LIST_FILENAME) - - print(f"Processing chain directory: {chain_dir}") - - # Initialize token list array - token_list = [] - - # Iterate over each subdirectory in the assets directory - for dir_name in os.listdir(assets_path): - dir_path = os.path.join(assets_path, dir_name) - if os.path.isdir(dir_path): - token_info_path = os.path.join(dir_path, 'token-info.json') - token_logo_path = os.path.join(dir_path, 'token-logo.svg') - - if os.path.isfile(token_info_path) and os.path.isfile(token_logo_path): - with open(token_info_path, 'r') as f: - token_info = json.load(f) - - # Append token_info to token_list - token_list.append(token_info) - else: - print(f"token-info.json or token-logo.svg not found in {dir_path}") - - # Read existing token list if it exists - if os.path.isfile(token_list_path): - with open(token_list_path, 'r') as f: - existing_token_list = json.load(f) - else: - existing_token_list = [] - - # Sort token list by tokenAddress - token_list = sorted(token_list, key=lambda x: x['tokenAddress']) - - # Check if the new token list is different from the existing one - if token_list != existing_token_list: - # Write updated token list to token-list.json - with open(token_list_path, 'w') as f: - json.dump(token_list, f, indent=2) - print(f"Written updated token list to {token_list_path}") - else: - print(f"No changes detected in {token_list_path}, skipping write.") - -# Iterate over each subdirectory in the chains directory -for chain_dir in os.listdir(CHAINS_PATH): - chain_dir_path = os.path.join(CHAINS_PATH, chain_dir) - if os.path.isdir(chain_dir_path): - process_chain(chain_dir_path) - else: - print(f"No directories found in {CHAINS_PATH}") - -print("All token lists updated.") diff --git a/.github/workflows/update-token-list.yml b/.github/workflows/update-token-list.yml deleted file mode 100644 index 256d150..0000000 --- a/.github/workflows/update-token-list.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Update Token List on PR Merge - -on: - pull_request: - types: [opened] - -jobs: - update-token-list: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Update token-list.json - run: python .github/scripts/update-token-list.py - - - name: Commit and push changes - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git add chains/**/token-list.json - if git diff-index --quiet HEAD; then - echo "No changes to commit" - else - git commit -m 'Update token-list.json files' - git push origin HEAD:${{ github.ref }} - fi diff --git a/chains/81457/token-list.json b/chains/81457/token-list.json index 678ce58..c698ed3 100644 --- a/chains/81457/token-list.json +++ b/chains/81457/token-list.json @@ -405,6 +405,13 @@ "tokenDecimals": 18, "tokenCategory": "Stablecoin" }, + { + "tokenAddress": "0xdc60c24de182b07cb3f3a9269f120d8c15c4b381", + "tokenName": "Digital Art Movement", + "tokenSymbol": "DAM", + "tokenDecimals": 18, + "tokenCategory": "DeFi" + }, { "tokenAddress": "0xe4796ccb6bb5de2290c417ac337f2b66ca2e770e", "tokenName": "Staked FRAX", @@ -440,4 +447,4 @@ "tokenDecimals": 18, "tokenCategory": "Other" } -] \ No newline at end of file +] diff --git a/update_lish.sh b/update_lish.sh new file mode 100755 index 0000000..770327e --- /dev/null +++ b/update_lish.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +CHAINS_PATH="chains" +TOKEN_LIST_FILENAME="token-list.json" + +process_chain() { + local chain_dir=$1 + local assets_path="$chain_dir/assets" + local token_list_path="$chain_dir/$TOKEN_LIST_FILENAME" + + echo "Processing chain directory: $chain_dir" + + # Initialize token list array + local token_list="[]" + + # Iterate over each subdirectory in the assets directory + for dir_name in "$assets_path"/*; do + if [ -d "$dir_name" ]; then + local token_info_path="$dir_name/token-info.json" + local token_logo_path="$dir_name/token-logo.svg" + + if [ -f "$token_info_path" ] && [ -f "$token_logo_path" ]; then + local token_info=$(cat "$token_info_path") + token_list=$(echo "$token_list" | jq --argjson token_info "$token_info" '. + [$token_info]') + else + echo "token-info.json or token-logo.svg not found in $dir_name" + fi + fi + done + + # Read existing token list if it exists + if [ -f "$token_list_path" ]; then + local existing_token_list=$(cat "$token_list_path") + else + local existing_token_list="[]" + fi + + # Sort token list by tokenAddress + token_list=$(echo "$token_list" | jq 'sort_by(.tokenAddress)') + + # Check if the new token list is different from the existing one + if [ "$token_list" != "$existing_token_list" ]; then + # Write updated token list to token-list.json + echo "$token_list" | jq '.' > "$token_list_path" + echo "Written updated token list to $token_list_path" + else + echo "No changes detected in $token_list_path, skipping write." + fi +} + +# Iterate over each subdirectory in the chains directory +for chain_dir in "$CHAINS_PATH"/*; do + if [ -d "$chain_dir" ]; then + process_chain "$chain_dir" + else + echo "No directories found in $CHAINS_PATH" + fi +done + +echo "All token lists updated."