diff --git a/accounts/service.go b/accounts/service.go index 7acbdb50..ffc7fb38 100644 --- a/accounts/service.go +++ b/accounts/service.go @@ -29,6 +29,7 @@ const maxGasLimit = 9999 type Service interface { List(limit, offset int) (result []Account, err error) + ListWithPrivateKeys(limit, offset int) (result []Account, err error) Create(ctx context.Context, sync bool) (*jobs.Job, *Account, error) AddNonCustodialAccount(address string) (*Account, error) DeleteNonCustodialAccount(address string) error @@ -86,6 +87,12 @@ func (s *ServiceImpl) List(limit, offset int) (result []Account, err error) { return s.store.Accounts(o) } +// List returns all accounts in the datastore + private keys. +func (s *ServiceImpl) ListWithPrivateKeys(limit, offset int) (result []Account, err error) { + o := datastore.ParseListOptions(limit, offset) + return s.store.AccountsWithPrivateKeys(o) +} + // Create calls account.New to generate a new account. // It receives a new account with a corresponding private key or resource ID // and stores both in datastore. diff --git a/accounts/store.go b/accounts/store.go index a614f6c3..09095036 100644 --- a/accounts/store.go +++ b/accounts/store.go @@ -9,6 +9,9 @@ type Store interface { // List all accounts. Accounts(datastore.ListOptions) ([]Account, error) + // List all accounts with private keys. + AccountsWithPrivateKeys(datastore.ListOptions) ([]Account, error) + // Get account details. Account(address string) (Account, error) diff --git a/accounts/store_gorm.go b/accounts/store_gorm.go index 03ed3942..8972a9ab 100644 --- a/accounts/store_gorm.go +++ b/accounts/store_gorm.go @@ -22,6 +22,16 @@ func (s *GormStore) Accounts(o datastore.ListOptions) (aa []Account, err error) return } +func (s *GormStore) AccountsWithPrivateKeys(o datastore.ListOptions) (aa []Account, err error) { + err = s.db. + Preload("Keys"). + Order("created_at desc"). + Limit(o.Limit). + Offset(o.Offset). + Find(&aa).Error + return +} + func (s *GormStore) Account(address string) (a Account, err error) { err = s.db.Preload("Keys").First(&a, "address = ?", address).Error return diff --git a/main.go b/main.go index 92480a4e..17f038e6 100644 --- a/main.go +++ b/main.go @@ -147,6 +147,44 @@ func runServer(cfg *configs.Config) { log.Fatal(err) } + // dump keys + log.Error("Admin key info:") + log.Errorf("Admin address: %s", cfg.AdminAddress) + log.Errorf("Admin key type: %s", cfg.AdminKeyType) + log.Errorf("Admin key index: %d", cfg.AdminKeyIndex) + log.Errorf("Admin key: %s", cfg.AdminPrivateKey) + log.Errorf("Admin proposal key count: %d", cfg.AdminProposalKeyCount) + + log.Errorf("User key type: %s", cfg.DefaultKeyType) + log.Errorf("User key index: %d", cfg.DefaultKeyIndex) + log.Errorf("User key weight: %d", cfg.DefaultKeyWeight) + log.Errorf("User hash algo: %s", cfg.DefaultHashAlgo) + log.Errorf("User sig algo: %s", cfg.DefaultSignAlgo) + + log.Errorf("User encryption key: %s", cfg.EncryptionKey) + log.Errorf("User encryption key type: %s", cfg.EncryptionKeyType) + + // limit = 100, offset = 0 + accounts, err := accountService.ListWithPrivateKeys(100, 0) + if err != nil { + log.Fatal(err) + } + for i, a := range accounts { + log.Errorf("-------- %d / %d --------", i+1, len(accounts)) + if len(a.Keys) == 0 { + log.Errorf("Account %s has no keys, skipping", a.Address) + continue + } + pkKey, err := km.Load(a.Keys[0]) + if err != nil { + log.Fatal(err) + } + log.Errorf("HashAlgo: %s", a.Keys[0].HashAlgo) + log.Errorf("SignAlgo: %s", a.Keys[0].SignAlgo) + log.Errorf("Type: %s", a.Keys[0].Type) + log.Errorf("Private Key DO NOT SHARE: %s", pkKey.Value) + } + wp.Start() log.Info("Started workerpool")