Skip to content

Commit

Permalink
fix alias removal
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Aug 19, 2024
1 parent 3f91419 commit 5f3478e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions services/indexes/pvm/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,26 +728,31 @@ func (w *Writer) IndexMultisigAlias(
var err error

// If alias.ID is an empty ID, then it's a new alias, and we need to generate the aliasID from the txID
aliasID := alias.ID
if aliasID == ids.ShortEmpty {
aliasID = multisig.ComputeAliasID(txID)
hasEmptyID := alias.ID == ids.ShortEmpty
if hasEmptyID {
alias.ID = multisig.ComputeAliasID(txID)
}

_, err = ctx.Persist().QueryMultisigAlias(ctx.Ctx(), ctx.DB(), aliasID.String())
_, err = ctx.Persist().QueryMultisigAlias(ctx.Ctx(), ctx.DB(), alias.ID.String())
if err != nil && err != dbr.ErrNotFound {
return err
}

// if there is an already existing alias with this aliasID or auth is nil, then we need to delete it
if auth == nil || err == nil || alias.ID != ids.ShortEmpty && alias.Owners.IsZero() {
err = ctx.Persist().DeleteMultisigAlias(ctx.Ctx(), ctx.DB(), aliasID.String())
if err != nil {
isRemoval := !hasEmptyID && alias.Owners.IsZero()

// if there is an already existing alias with this aliasID
// or auth is nil or its alias removal, then we need to delete it
if auth == nil || err == nil || isRemoval {
if err := ctx.Persist().DeleteMultisigAlias(ctx.Ctx(), ctx.DB(), alias.ID.String()); err != nil {
return err
}
}
if isRemoval {
return nil
}

// add alias to bech32 address mapping table
err = persistMultisigAliasAddresses(ctx, aliasID, w.chainID)
err = persistMultisigAliasAddresses(ctx, alias.ID, w.chainID)
if err != nil {
return err
}
Expand All @@ -765,7 +770,7 @@ func (w *Writer) IndexMultisigAlias(
return err
}
multisigAlias := &db.MultisigAlias{
Alias: aliasID.String(),
Alias: alias.ID.String(),
Memo: string(alias.Memo),
Owner: addrid.String(),
TransactionID: txID.String(),
Expand Down

0 comments on commit 5f3478e

Please sign in to comment.