diff --git a/api/accounts.go b/api/accounts.go index bb880bc19..62bd78ca0 100644 --- a/api/accounts.go +++ b/api/accounts.go @@ -128,10 +128,33 @@ func (a *API) accountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er } addr := common.HexToAddress(ctx.URLParam("address")) acc, err := a.vocapp.State.GetAccount(addr, true) - if err != nil || acc == nil { + if err != nil { return ErrAccountNotFound.With(addr.Hex()) } + // If the account does not exist in state, try to retrieve it from the indexer. + // This is a fallback for the case where the account is not in state but it is in the process archive. + if acc == nil { + indexerEntities := a.indexer.EntityList(1, 0, ctx.URLParam("address")) + if len(indexerEntities) == 0 { + return ErrAccountNotFound.With(addr.Hex()) + } + var data []byte + if data, err = json.Marshal(Account{ + Address: addr.Bytes(), + Nonce: 0, + Balance: 0, + ElectionIndex: uint32(indexerEntities[0].ProcessCount), + InfoURL: "", + Metadata: &AccountMetadata{ + Name: LanguageString{"default": addr.Hex()}, + }, + }); err != nil { + return err + } + return ctx.Send(data, apirest.HTTPstatusOK) + } + // Try to retrieve the account info metadata accMetadata := &AccountMetadata{} if a.storage != nil { diff --git a/types/consts.go b/types/consts.go index a1211def3..f6b9ce29e 100644 --- a/types/consts.go +++ b/types/consts.go @@ -33,7 +33,7 @@ const ( EntityIDsize = EthereumAddressSize // ArchiveURL is the default URL where the archive is retrieved from. - ArchiveURL = "/ipns/k2k4r8mdn544n7f8nprwqeo27jr1v1unsu74th57s1j8mumjck7y7cbz" + ArchiveURL = "/ipns/k2k4r8otxrf176h1i08txap0ep6ynr1jac0vymozi068eedml7gk1595" // DefaultBlockTime is the default block time in seconds. DefaultBlockTime = 12 * time.Second diff --git a/vochain/indexer/archive.go b/vochain/indexer/archive.go index 2945b9707..1310f4d2e 100644 --- a/vochain/indexer/archive.go +++ b/vochain/indexer/archive.go @@ -44,11 +44,11 @@ func (idx *Indexer) ImportArchive(archive []*ArchiveProcess) ([]*ArchiveProcess, added := []*ArchiveProcess{} for _, p := range archive { if idx.App.ChainID() == p.ChainID { - log.Debugw("skipping import of archive process from current chain", "chainID", p.ChainID, "processID", p.ProcessInfo.ID.String()) + // skip process from current chain continue } if p.ProcessInfo == nil { - log.Debugw("skipping import of archive process with nil process info") + // skip process without process info continue }