@@ -341,6 +341,10 @@ type activeToken struct {
341341}
342342
343343type accountJSON struct {
344+ // Multiple accounts can belong to the same keystore. For now we replicate the keystore info in
345+ // the accounts. In the future the getAccountsHandler() could return the accounts grouped
346+ // keystore.
347+ Keystore config.Keystore `json:"keystore"`
344348 Active bool `json:"active"`
345349 CoinCode coinpkg.Code `json:"coinCode"`
346350 CoinUnit string `json:"coinUnit"`
@@ -352,10 +356,11 @@ type accountJSON struct {
352356 BlockExplorerTxPrefix string `json:"blockExplorerTxPrefix"`
353357}
354358
355- func newAccountJSON (account accounts.Interface , activeTokens []activeToken ) * accountJSON {
359+ func newAccountJSON (keystore config. Keystore , account accounts.Interface , activeTokens []activeToken ) * accountJSON {
356360 eth , ok := account .Coin ().(* eth.Coin )
357361 isToken := ok && eth .ERC20Token () != nil
358362 return & accountJSON {
363+ Keystore : keystore ,
359364 Active : ! account .Config ().Config .Inactive ,
360365 CoinCode : account .Coin ().Code (),
361366 CoinUnit : account .Coin ().Unit (false ),
@@ -515,27 +520,42 @@ func (handlers *Handlers) getKeystoresHandler(_ *http.Request) interface{} {
515520}
516521
517522func (handlers * Handlers ) getAccountsHandler (_ * http.Request ) interface {} {
518- accounts := []* accountJSON {}
519523 persistedAccounts := handlers .backend .Config ().AccountsConfig ()
524+
525+ accounts := []* accountJSON {}
520526 for _ , account := range handlers .backend .Accounts () {
521527 if account .Config ().Config .HiddenBecauseUnused {
522528 continue
523529 }
524530 var activeTokens []activeToken
531+
532+ persistedAccount := persistedAccounts .Lookup (account .Config ().Config .Code )
533+ if persistedAccount == nil {
534+ handlers .log .WithField ("code" , account .Config ().Config .Code ).Error ("account not found in accounts database" )
535+ continue
536+ }
537+
525538 if account .Coin ().Code () == coinpkg .CodeETH {
526- persistedAccount := persistedAccounts .Lookup (account .Config ().Config .Code )
527- if persistedAccount == nil {
528- handlers .log .WithField ("code" , account .Config ().Config .Code ).Error ("account not found in accounts database" )
529- continue
530- }
531539 for _ , tokenCode := range persistedAccount .ActiveTokens {
532540 activeTokens = append (activeTokens , activeToken {
533541 TokenCode : tokenCode ,
534542 AccountCode : backend .Erc20AccountCode (account .Config ().Config .Code , tokenCode ),
535543 })
536544 }
537545 }
538- accounts = append (accounts , newAccountJSON (account , activeTokens ))
546+
547+ rootFingerprint , err := persistedAccount .SigningConfigurations .RootFingerprint ()
548+ if err != nil {
549+ handlers .log .WithField ("code" , account .Config ().Config .Code ).Error ("could not identify root fingerprint" )
550+ continue
551+ }
552+ keystore , err := persistedAccounts .LookupKeystore (rootFingerprint )
553+ if err != nil {
554+ handlers .log .WithField ("code" , account .Config ().Config .Code ).Error ("could not find keystore of account" )
555+ continue
556+ }
557+
558+ accounts = append (accounts , newAccountJSON (* keystore , account , activeTokens ))
539559 }
540560 return accounts
541561}
0 commit comments