Skip to content

Commit

Permalink
backend: add Goerli ETH testnet network
Browse files Browse the repository at this point in the history
ETH merge happened recently, and Ropsten and Rinkeby testnets will soon
be deprecated from Etherscan. This add support for the new Goerli testnet.
  • Loading branch information
Beerosagos committed Oct 5, 2022
1 parent 6dcc046 commit ff44918
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,5 @@ Get Litecoin Testnet coins here: https://tltc.bitaps.com/
Get Ethereum Rinkeby coins here: http://rinkeby-faucet.com/

Get Ethereum Ropsten coins here: https://faucet.ropsten.be/

Get Ethereum Goerli coins here: https://goerlifaucet.com/
21 changes: 11 additions & 10 deletions backend/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ const accountsHardLimit = 5
func sortAccounts(accounts []*config.Account) {
compareCoin := func(coin1, coin2 coinpkg.Code) int {
order := map[coinpkg.Code]int{
coinpkg.CodeBTC: 0,
coinpkg.CodeTBTC: 1,
coinpkg.CodeLTC: 2,
coinpkg.CodeTLTC: 3,
coinpkg.CodeETH: 4,
coinpkg.CodeTETH: 5,
coinpkg.CodeRETH: 6,
coinpkg.CodeBTC: 0,
coinpkg.CodeTBTC: 1,
coinpkg.CodeLTC: 2,
coinpkg.CodeTLTC: 3,
coinpkg.CodeETH: 4,
coinpkg.CodeTETH: 5,
coinpkg.CodeRETH: 6,
coinpkg.CodeGOETH: 7,
}
order1, ok1 := order[coin1]
order2, ok2 := order[coin2]
Expand Down Expand Up @@ -116,7 +117,7 @@ func (backend *Backend) SupportedCoins(keystore keystore.Keystore) []coinpkg.Cod
allCoins := []coinpkg.Code{
coinpkg.CodeBTC, coinpkg.CodeTBTC, coinpkg.CodeRBTC,
coinpkg.CodeLTC, coinpkg.CodeTLTC,
coinpkg.CodeETH, coinpkg.CodeTETH, coinpkg.CodeRETH,
coinpkg.CodeETH, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH,
}
var availableCoins []coinpkg.Code
for _, coinCode := range allCoins {
Expand Down Expand Up @@ -221,7 +222,7 @@ func (backend *Backend) createAndPersistAccountConfig(
},
accountsConfig,
)
case coinpkg.CodeETH, coinpkg.CodeRETH, coinpkg.CodeTETH:
case coinpkg.CodeETH, coinpkg.CodeRETH, coinpkg.CodeTETH, coinpkg.CodeGOETH:
bip44Coin := "1'"
if coinCode == coinpkg.CodeETH {
bip44Coin = "60'"
Expand Down Expand Up @@ -672,7 +673,7 @@ func (backend *Backend) persistDefaultAccountConfigs(keystore keystore.Keystore,
}
}
} else {
for _, coinCode := range []coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH} {
for _, coinCode := range []coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH} {
if backend.config.AppConfig().Backend.DeprecatedCoinActive(coinCode) {
if _, err := backend.createAndPersistAccountConfig(coinCode, 0, "", keystore, nil, accountsConfig); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion backend/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestSupportedCoins(t *testing.T) {
b := newBackend(t, testnetEnabled, regtestDisabled)
defer b.Close()
require.Equal(t,
[]coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH},
[]coinpkg.Code{coinpkg.CodeTBTC, coinpkg.CodeTLTC, coinpkg.CodeTETH, coinpkg.CodeRETH, coinpkg.CodeGOETH},
b.SupportedCoins(&keystoremock.KeystoreMock{
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
Expand Down
7 changes: 7 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var fixedURLWhitelist = []string{
"https://etherscan.io/tx/",
"https://rinkeby.etherscan.io/tx/",
"https://ropsten.etherscan.io/tx/",
"https://goerli.etherscan.io/tx/",
// Moonpay onramp
"https://www.moonpay.com/",
"https://support.moonpay.com/",
Expand Down Expand Up @@ -380,6 +381,12 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
"https://ropsten.etherscan.io/tx/",
etherScan,
nil)
case code == coinpkg.CodeGOETH:
etherScan := etherscan.NewEtherScan("https://api-goerli.etherscan.io/api", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "Ethereum Goerli", "GOETH", "GOETH", params.GoerliChainConfig,
"https://goerli.etherscan.io/tx/",
etherScan,
nil)
case code == coinpkg.CodeERC20TEST:
etherScan := etherscan.NewEtherScan("https://api-ropsten.etherscan.io/api", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "ERC20 TEST", "TEST", "TETH", params.RopstenChainConfig,
Expand Down
3 changes: 3 additions & 0 deletions backend/coins/coin/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
CodeTETH Code = "teth"
// CodeRETH is Ethereum Rinkeby.
CodeRETH Code = "reth"
// CodeGOETH is Ethereum Goerli.
CodeGOETH Code = "goeth"
// CodeERC20TEST is an arbitrarily picked test ERC20 token on Ropsten.
CodeERC20TEST Code = "erc20Test"
// If you add coins, don't forget to update `testnetCoins` below.
Expand All @@ -46,5 +48,6 @@ var TestnetCoins = map[Code]struct{}{
CodeTLTC: {},
CodeTETH: {},
CodeRETH: {},
CodeGOETH: {},
CodeERC20TEST: {},
}
2 changes: 1 addition & 1 deletion backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (backend Backend) DeprecatedCoinActive(code coin.Code) bool {
return backend.DeprecatedBitcoinActive
case coin.CodeLTC, coin.CodeTLTC:
return backend.DeprecatedLitecoinActive
case coin.CodeETH, coin.CodeTETH, coin.CodeRETH, coin.CodeERC20TEST:
case coin.CodeETH, coin.CodeTETH, coin.CodeRETH, coin.CodeGOETH, coin.CodeERC20TEST:
return backend.DeprecatedEthereumActive
default:
panic(fmt.Sprintf("unknown code %s", code))
Expand Down
2 changes: 2 additions & 0 deletions backend/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ func (handlers *Handlers) getConvertFromFiatHandler(r *http.Request) (interface{
switch unit { // HACK: fake rates for testnet coins
case "TBTC", "TLTC", "TETH", "RETH":
unit = unit[1:]
case "GOETH":
unit = unit[2:]
}

rate := handlers.backend.RatesUpdater().LatestPrice()[unit][from]
Expand Down
11 changes: 6 additions & 5 deletions backend/rates/gecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ var (
"ltc": "litecoin",
"eth": "ethereum",
// Useful for testing with testnets.
"tbtc": "bitcoin",
"rbtc": "bitcoin",
"tltc": "litecoin",
"teth": "ethereum",
"reth": "ethereum",
"tbtc": "bitcoin",
"rbtc": "bitcoin",
"tltc": "litecoin",
"teth": "ethereum",
"reth": "ethereum",
"goeth": "ethereum",
// ERC20 tokens as used in the backend.
// Frontend and app config use unprefixed name, without "eth-erc20-".
"eth-erc20-bat": "basic-attention-token",
Expand Down
8 changes: 6 additions & 2 deletions backend/rates/rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ func (updater *RateUpdater) updateLast(ctx context.Context) {
}

// Provide conversion rates for testnets as well, useful for testing.
for _, testnetUnit := range []string{"TBTC", "RBTC", "TLTC", "TETH", "RETH"} {
rates[testnetUnit] = rates[testnetUnit[1:]]
for _, testnetUnit := range []string{"TBTC", "RBTC", "TLTC", "TETH", "RETH", "GOETH"} {
if testnetUnit == "GOETH" {
rates[testnetUnit] = rates[testnetUnit[2:]]
} else {
rates[testnetUnit] = rates[testnetUnit[1:]]
}
}

if reflect.DeepEqual(rates, updater.last) {
Expand Down
1 change: 1 addition & 0 deletions frontends/web/src/components/icon/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const logoMap: LogoMap = {
'eth': [ETH, ETH_GREY],
'teth': [ETH, ETH_GREY],
'reth': [ETH, ETH_GREY],
'goeth': [ETH, ETH_GREY],
'erc20Test': [ETH, ETH_GREY],

'eth-erc20-usdt': [USDT, USDT_GREY],
Expand Down

0 comments on commit ff44918

Please sign in to comment.