Skip to content

Conversation

@snissn
Copy link
Contributor

@snissn snissn commented Feb 11, 2025

Title:
Refactor Config Handling & Add Multichain Support

closes #11

Description:
This PR introduces a dedicated config package to improve configuration management and adds support for multiple source blockchains. The refactor makes it easier to integrate different blockchain networks (e.g., Ethereum, Polygon, Avalanche) with Filecoin.

Key Changes:

  • Config Refactor:

    • Moved configuration logic to config/config.go for better modularity.
    • Updated .gitignore to properly exclude config/xchain_key.json.
    • Restructured config.json to support multiple source chains under "sources", with a "destination" section for Filecoin.
  • CLI Enhancements:

    • Added a --chain argument to specify the source blockchain.
    • Updated all commands (daemon, offer, dealStatus) to load chain-specific settings dynamically.
  • Code Improvements:

    • Removed hardcoded Config struct from xchain.go and replaced it with config.Config.
    • Updated NewAggregator and other relevant functions to use config.SourceChainConfig.
    • Fixed logging issue in processDealStatus by using %v instead of %s for structured data.
  • Testing & Dependencies:

    • Updated xchain_test.go to use the new config structure and test chain selection.
    • Updated go.mod to include github.com/stretchr/testify and github.com/filecoin-project/go-cbor-util for improved testing and CBOR support.

Why This Matters:

  • Enables seamless integration of multiple chains without modifying core logic.
  • Enhances code organization & maintainability by separating config management.
  • Provides better error handling & logging for deal processing.
  • Improves testability with structured config loading.

- Introduced a dedicated `config` package (`config/config.go`) to manage configuration.
- Updated `.gitignore` to properly exclude `config/xchain_key.json`.
- Refactored `config.json` structure to support multiple source chains (e.g., Ethereum, Polygon, Avalanche).
- Updated CLI to require a `--chain` argument to specify the source blockchain.
- Modified `xchain.go` to dynamically load source chain configuration based on `--chain`.
- Updated `NewAggregator` and other functions to use `config.SourceChainConfig`.
- Fixed logging issue in `processDealStatus` by using `%v` instead of `%s` for structured data.
- Removed old hardcoded `Config` struct from `xchain.go` and replaced it with the `config` package.
- Updated tests (`xchain_test.go`) to use the new config structure and support multiple chains.
- Updated `go.mod` to include `github.com/stretchr/testify` and `github.com/filecoin-project/go-cbor-util` for improved testing and CBOR support.

This refactor improves modularity, allowing seamless integration of multiple blockchains.
@snissn snissn self-assigned this Feb 11, 2025
@longfeiWan9
Copy link
Contributor

I only have one comment above. The rest looks great. @snissn

@longfeiWan9 longfeiWan9 merged commit ee84f45 into main Feb 13, 2025
1 check passed
@longfeiWan9 longfeiWan9 deleted the mikers/multichain-config branch February 13, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance Multi-Chain Support & Improve RPC/API Error Clarity

3 participants