From 469b8739ebbe45997d8e287bcd441544ebfebfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 4 Jun 2020 08:59:26 +0300 Subject: [PATCH] acounts/keystore, cmd/faucet: fix faucet double import, fix twitter url --- accounts/keystore/keystore.go | 8 ++++++-- cmd/faucet/faucet.go | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 47fa376ed..80458a12f 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -43,6 +43,10 @@ var ( ErrLocked = accounts.NewAuthNeededError("password or unlock") ErrNoMatch = errors.New("no key for given address or file") ErrDecrypt = errors.New("could not decrypt key with given password") + + // ErrAccountAlreadyExists is returned if an account attempted to import is + // already present in the keystore. + ErrAccountAlreadyExists = errors.New("account alreaady exists") ) // KeyStoreType is the reflect type of a keystore backend. @@ -446,7 +450,7 @@ func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (ac ks.importMu.Lock() defer ks.importMu.Unlock() if ks.cache.hasAddress(key.Address) { - return accounts.Account{}, errors.New("account already exists") + return accounts.Account{}, ErrAccountAlreadyExists } return ks.importKey(key, newPassphrase) } @@ -457,7 +461,7 @@ func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (acco ks.importMu.Lock() defer ks.importMu.Unlock() if ks.cache.hasAddress(key.Address) { - return accounts.Account{}, errors.New("account already exists") + return accounts.Account{}, ErrAccountAlreadyExists } return ks.importKey(key, passphrase) } diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index e86f8533d..c4cce57ce 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -170,7 +170,7 @@ func main() { log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err) } acc, err := ks.Import(blob, pass, pass) - if err != nil { + if err != nil && err != keystore.ErrAccountAlreadyExists { log.Crit("Failed to import faucet signer account", "err", err) } ks.Unlock(acc, pass) @@ -694,8 +694,11 @@ func authTwitter(url string) (string, string, common.Address, error) { return "", "", common.Address{}, errors.New("Invalid Twitter status URL") } // Twitter's API isn't really friendly with direct links. Still, we don't - // want to do ask read permissions from users, so just load the public posts and - // scrape it for the Ethereum address and profile URL. + // want to do ask read permissions from users, so just load the public posts + // and scrape it for the Ethereum address and profile URL. We need to load + // the mobile page though since the main page loads tweet contents via JS. + url = strings.Replace(url, "https://twitter.com/", "https://mobile.twitter.com/", 1) + res, err := http.Get(url) if err != nil { return "", "", common.Address{}, err