Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customized accessor to token whitelist #140

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 64 additions & 59 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,70 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3

- name: Install Docker Compose via Package Manager
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
shell: bash

- name: Verify Docker Compose Installation
run: docker-compose --version
shell: bash

- name: Start a private ethereum network
uses: ./.github/actions/geth
id: geth

- name: Sleep for 20 seconds
run: sleep 20s
shell: bash

- name: Get latest block from geth node
run: |
curl -X POST "http://127.0.0.1:8546" --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", true],"id":1}'
shell: bash

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install web3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install web3==5.31.3
shell: bash

- name: deploy erc20 USDC
run: .github/scripts/init_erc20.sh
shell: bash

- name: Get erc20 infos
run: python .github/scripts/contract_infos.py
shell: bash

- name: Populate transactions
run: python .github/scripts/populate_txns.py
shell: bash

- name: Start Rosetta Server
run: .github/scripts/setup.sh
shell: bash

- name: Run Check:construction test
run: .github/scripts/construction.sh
shell: bash

- name: Run Check:data test
run: .github/scripts/cli.sh
shell: bash
- uses: actions/checkout@v3

- name: Set up Python
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other changes are just auto-format except this Setup Python workflow. We need to downgrade to 3.9 to avoid the error when importing web3 library: ethereum/web3.py#2704 (comment)

uses: actions/setup-python@v3
with:
python-version: "3.9"

- name: Install Docker Compose via Package Manager
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
shell: bash

- name: Verify Docker Compose Installation
run: docker-compose --version
shell: bash

- name: Start a private ethereum network
uses: ./.github/actions/geth
id: geth

- name: Sleep for 20 seconds
run: sleep 20s
shell: bash

- name: Get latest block from geth node
run: |
curl -X POST "http://127.0.0.1:8546" --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", true],"id":1}'
shell: bash

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install web3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install web3==5.31.3
shell: bash

- name: deploy erc20 USDC
run: .github/scripts/init_erc20.sh
shell: bash

- name: Get erc20 infos
run: python .github/scripts/contract_infos.py
shell: bash

- name: Populate transactions
run: python .github/scripts/populate_txns.py
shell: bash

- name: Start Rosetta Server
run: .github/scripts/setup.sh
shell: bash

- name: Run Check:construction test
run: .github/scripts/construction.sh
shell: bash

- name: Run Check:data test
run: .github/scripts/cli.sh
shell: bash

Test:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ type RosettaConfig struct {

// ForwardHeaders is the list of headers to forward to and from the native node
ForwardHeaders []string

// Functor to access allowlisted tokens.
// This should be defined in rosetta-xxx implementation if needed
TokenWhitelistAccessor func() ([]Token, error)
}

type Token struct {
Expand Down
18 changes: 15 additions & 3 deletions services/block_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,21 @@ func (s *BlockAPIService) PopulateTransaction(
receiptLogs = tx.Receipt.Logs
}

filterTokens := s.client.GetRosettaConfig().FilterTokens
tokenWhiteList := s.client.GetRosettaConfig().TokenWhiteList
useTokenWhiteListMetadata := s.client.GetRosettaConfig().UseTokenWhiteListMetadata
rosettaConfig := s.client.GetRosettaConfig()
filterTokens := rosettaConfig.FilterTokens

if rosettaConfig.TokenWhitelistAccessor != nil {
whitelist, err := rosettaConfig.TokenWhitelistAccessor()
if err != nil {
return nil, fmt.Errorf("could not get token whitelist: %w", err)
}

rosettaConfig.TokenWhiteList = whitelist
}

tokenWhiteList := rosettaConfig.TokenWhiteList

useTokenWhiteListMetadata := rosettaConfig.UseTokenWhiteListMetadata
indexUnknownTokens := s.config.RosettaCfg.IndexUnknownTokens

// Compute tx operations via tx.Receipt logs for ERC20 transfer, mint and burn
Expand Down
Loading