Skip to content

Commit 201e345

Browse files
authored
Merge pull request #21172 from karalabe/faucet-twitter-mobile
acounts/keystore, cmd/faucet: fix faucet double import, fix twitter url
2 parents 8b83125 + 469b873 commit 201e345

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

accounts/keystore/keystore.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var (
4343
ErrLocked = accounts.NewAuthNeededError("password or unlock")
4444
ErrNoMatch = errors.New("no key for given address or file")
4545
ErrDecrypt = errors.New("could not decrypt key with given password")
46+
47+
// ErrAccountAlreadyExists is returned if an account attempted to import is
48+
// already present in the keystore.
49+
ErrAccountAlreadyExists = errors.New("account alreaady exists")
4650
)
4751

4852
// KeyStoreType is the reflect type of a keystore backend.
@@ -446,7 +450,7 @@ func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (ac
446450
ks.importMu.Lock()
447451
defer ks.importMu.Unlock()
448452
if ks.cache.hasAddress(key.Address) {
449-
return accounts.Account{}, errors.New("account already exists")
453+
return accounts.Account{}, ErrAccountAlreadyExists
450454
}
451455
return ks.importKey(key, newPassphrase)
452456
}
@@ -457,7 +461,7 @@ func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (acco
457461
ks.importMu.Lock()
458462
defer ks.importMu.Unlock()
459463
if ks.cache.hasAddress(key.Address) {
460-
return accounts.Account{}, errors.New("account already exists")
464+
return accounts.Account{}, ErrAccountAlreadyExists
461465
}
462466
return ks.importKey(key, passphrase)
463467
}

cmd/faucet/faucet.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func main() {
170170
log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err)
171171
}
172172
acc, err := ks.Import(blob, pass, pass)
173-
if err != nil {
173+
if err != nil && err != keystore.ErrAccountAlreadyExists {
174174
log.Crit("Failed to import faucet signer account", "err", err)
175175
}
176176
ks.Unlock(acc, pass)
@@ -694,8 +694,11 @@ func authTwitter(url string) (string, string, common.Address, error) {
694694
return "", "", common.Address{}, errors.New("Invalid Twitter status URL")
695695
}
696696
// Twitter's API isn't really friendly with direct links. Still, we don't
697-
// want to do ask read permissions from users, so just load the public posts and
698-
// scrape it for the Ethereum address and profile URL.
697+
// want to do ask read permissions from users, so just load the public posts
698+
// and scrape it for the Ethereum address and profile URL. We need to load
699+
// the mobile page though since the main page loads tweet contents via JS.
700+
url = strings.Replace(url, "https://twitter.com/", "https://mobile.twitter.com/", 1)
701+
699702
res, err := http.Get(url)
700703
if err != nil {
701704
return "", "", common.Address{}, err

0 commit comments

Comments
 (0)