fix: not found error

This commit is contained in:
Gaze
2024-04-15 16:30:44 +07:00
parent cc6a28e738
commit d94925853e
3 changed files with 6 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ type RunesReaderDataGateway interface {
// Cannot use []byte as map key, so we're returning as slice.
GetBalancesByRuneId(ctx context.Context, runeId runes.RuneId, blockHeight uint64) ([]*entity.Balance, error)
// GetBalancesByPkScriptAndRuneId returns the balance for the given pkScript and runeId at the given blockHeight.
GetBalancesByPkScriptAndRuneId(ctx context.Context, pkScript []byte, runeId runes.RuneId, blockHeight uint64) (*entity.Balance, error)
GetBalanceByPkScriptAndRuneId(ctx context.Context, pkScript []byte, runeId runes.RuneId, blockHeight uint64) (*entity.Balance, error)
}
type RunesWriterDataGateway interface {

View File

@@ -360,8 +360,11 @@ func (p *Processor) getTxInputsPkScripts(ctx context.Context, tx *types.Transact
func (p *Processor) updateNewBalances(ctx context.Context, tx *types.Transaction, txInputsPkScripts map[int][]byte, inputBalances map[int]map[runes.RuneId]uint128.Uint128, allocated map[int]map[runes.RuneId]uint128.Uint128) error {
// getCurrentBalance returns the current balance of the pkScript and runeId since last flush
getCurrentBalance := func(ctx context.Context, pkScript []byte, runeId runes.RuneId) (uint128.Uint128, error) {
balance, err := p.runesDg.GetBalancesByPkScriptAndRuneId(ctx, pkScript, runeId, uint64(tx.BlockHeight-1))
balance, err := p.runesDg.GetBalanceByPkScriptAndRuneId(ctx, pkScript, runeId, uint64(tx.BlockHeight-1))
if err != nil {
if errors.Is(err, errs.NotFound) {
return uint128.Zero, nil
}
return uint128.Uint128{}, errors.Wrap(err, "failed to get balance by pk script and rune id")
}
return balance.Amount, nil

View File

@@ -219,7 +219,7 @@ func (r *Repository) GetBalancesByRuneId(ctx context.Context, runeId runes.RuneI
return result, nil
}
func (r *Repository) GetBalancesByPkScriptAndRuneId(ctx context.Context, pkScript []byte, runeId runes.RuneId, blockHeight uint64) (*entity.Balance, error) {
func (r *Repository) GetBalanceByPkScriptAndRuneId(ctx context.Context, pkScript []byte, runeId runes.RuneId, blockHeight uint64) (*entity.Balance, error) {
balance, err := r.queries.GetBalanceByPkScriptAndRuneId(ctx, gen.GetBalanceByPkScriptAndRuneIdParams{
Pkscript: hex.EncodeToString(pkScript),
RuneID: runeId.String(),