Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import (
  2. "log"
  3.  
  4. "github.com/ethereum/go-ethereum/accounts"
  5. "github.com/ethereum/go-ethereum/accounts/keystore"
  6. "github.com/ethereum/go-ethereum/common"
  7. )
  8.  
  9. type KeyStore struct {
  10. Handle *keystore.KeyStore
  11. }
  12.  
  13. func SetUpKeyStore(kp string) *KeyStore {
  14. ks := &KeyStore{}
  15. ks.Handle = keystore.NewKeyStore(kp, keystore.LightScryptN, keystore.LightScryptP)
  16. return ks
  17. }
  18.  
  19. func (ks *KeyStore) CreateNewKeys(password string) accounts.Account {
  20. account, err := ks.Handle.NewAccount(password)
  21. if err != nil {
  22. log.Panic(err)
  23. }
  24. return account
  25. }
  26.  
  27. func (ks *KeyStore) GetKeysByAddress(address string) accounts.Account {
  28.  
  29. var account accounts.Account
  30. var err error
  31. if ks.Handle.HasAddress(common.HexToAddress(address)) {
  32. if account, err = ks.Handle.Find(accounts.Account{Address: common.HexToAddress(address)}); err != nil {
  33. log.Panic(err)
  34. }
  35. }
  36. return account
  37. }
  38.  
  39. func (ks *KeyStore) GetAllKeys() []accounts.Account {
  40.  
  41. return ks.Handle.Accounts()
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement