mirror of https://github.com/poanetwork/gecko.git
Return early when finding address already exists
This commit is contained in:
parent
e073b4e8ad
commit
1572b1bd97
|
@ -670,19 +670,17 @@ func (service *Service) ImportKey(r *http.Request, args *ImportKeyArgs, reply *I
|
||||||
return fmt.Errorf("problem saving key while getting existing addresses: %w", err)
|
return fmt.Errorf("problem saving key while getting existing addresses: %w", err)
|
||||||
}
|
}
|
||||||
newAddress := sk.PublicKey().Address()
|
newAddress := sk.PublicKey().Address()
|
||||||
exists := false
|
|
||||||
for _, address := range addresses {
|
for _, address := range addresses {
|
||||||
if newAddress.Equals(address) {
|
if newAddress.Equals(address) {
|
||||||
exists = true
|
reply.Address = service.vm.Format(newAddress.Bytes())
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exists {
|
|
||||||
addresses = append(addresses, newAddress)
|
|
||||||
|
|
||||||
|
addresses = append(addresses, newAddress)
|
||||||
if err := user.SetAddresses(db, addresses); err != nil {
|
if err := user.SetAddresses(db, addresses); err != nil {
|
||||||
return fmt.Errorf("problem saving addresses: %w", err)
|
return fmt.Errorf("problem saving addresses: %w", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
reply.Address = service.vm.Format(newAddress.Bytes())
|
reply.Address = service.vm.Format(newAddress.Bytes())
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue