Skip to content

Commit

Permalink
update archive IPNS and add support for non-existing archive accounts
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Nov 24, 2023
1 parent 101d965 commit 3ecc76c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion types/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vochain/indexer/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3ecc76c

Please sign in to comment.