Skip to content

Commit

Permalink
Support customized accessor to token whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
shiatcb committed Jan 15, 2025
1 parent 6367671 commit 4a7712b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 62 deletions.
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
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

0 comments on commit 4a7712b

Please sign in to comment.