Skip to content

Commit

Permalink
Merge branch 'eth-testnet'
Browse files Browse the repository at this point in the history
  • Loading branch information
Beerosagos committed Oct 5, 2022
2 parents 69a1d52 + 762add1 commit 0ba090e
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 24 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/cespare/cp v1.1.1 // indirect
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20220817141646-e9258db31750
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c
github.com/ethereum/go-ethereum v1.10.21
github.com/flynn/noise v1.0.0
github.com/gorilla/mux v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRk
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20220817141646-e9258db31750 h1:b6udIFaGfW4rldSgbch1eA4l+JHuZ3Ij2Pi2VdE7Iz4=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20220817141646-e9258db31750/go.mod h1:4HNNrzUZC3ew0iuD40MoGp6wAhcDw1UtGYBRjJkJF/k=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c h1:mJl1SA+NVUZGd+LwgRpmLpNyv+kuAhKnEzE+kvIrK+0=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c/go.mod h1:4HNNrzUZC3ew0iuD40MoGp6wAhcDw1UtGYBRjJkJF/k=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ github.com/decred/dcrd/crypto/blake256
github.com/decred/dcrd/dcrec/secp256k1/v4
github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa
github.com/decred/dcrd/dcrec/secp256k1/v4/schnorr
# github.com/digitalbitbox/bitbox02-api-go v0.0.0-20220817141646-e9258db31750
# github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c
## explicit
github.com/digitalbitbox/bitbox02-api-go/api/bootloader
github.com/digitalbitbox/bitbox02-api-go/api/common
Expand Down

0 comments on commit 0ba090e

Please sign in to comment.