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

feat: added public addresses with failover #365

Merged
merged 6 commits into from
Sep 17, 2024
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
2 changes: 1 addition & 1 deletion pkg/options/configs/testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mediator = ["0x7B49d6ee530B0A538D26E344f3B02E79ACa96De2"]
api_host = "https://api-testnet.lilypad.tech/"

[web3]
rpc_url = "wss://capable-tame-butterfly.arbitrum-sepolia.quiknode.pro/b866a1312df26e5763237e1aff0a300bd4501647"
rpc_url = "wss://arbitrum-sepolia-rpc.publicnode.com,wss://rpc.ankr.com/arbitrum_sepolia,wss://arbitrum-sepolia.drpc.org/,wss://testnet-rpc.etherspot.io/v1/421614,wss://endpoints.omniatech.io/v1/arbitrum/sepolia/public,wss://arb-sepolia.g.alchemy.com/v2/4PDb7czJf8E6z7ZjhXB0Z5fdU1XaQT0u"
chain_id = 421614
controller_address = "0x4a83270045FB4BCd1bdFe1bD6B00762A9D8bbF4E"
payments_address = "0xdE7CEa09A23e7Aa4980B95F69B8912F39A0e323A"
Expand Down
17 changes: 13 additions & 4 deletions pkg/web3/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,19 @@ func NewContractSDK(options Web3Options) (*Web3SDK, error) {
displayOpts.PrivateKey = "*********"
log.Debug().Msgf("NewContractSDK: %+v", displayOpts)

client, err := ethclient.Dial(options.RpcURL)
if err != nil {
return nil, err
rpcs := strings.Split(options.RpcURL, ",")
var client *ethclient.Client
var err error
for _, url := range rpcs {
client, err = ethclient.Dial(url)
Copy link
Contributor

Choose a reason for hiding this comment

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

using dial is useless for select available rpc. since arb not check cu when connect.

my sugesstion is to use module like index := address%len(rpcsClients). or a more simple way to use random select

if err != nil {
log.Error().Msgf("Failed to connect to %s: %v", url, err)
continue
} else {
break
}
}

privateKey, err := ParsePrivateKey(options.PrivateKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -229,7 +238,7 @@ func NewContractSDK(options Web3Options) (*Web3SDK, error) {
TransactOpts: transactOpts,
Contracts: contracts,
}
log.Debug().Msgf("Public Address: %s", web3SDK.GetAddress())
log.Info().Msgf("Public Address: %s", web3SDK.GetAddress())

return web3SDK, nil
}
Expand Down
Loading