feat(btc): add revert data to processor

Co-authored-by: Gaze <dev@gaze.network>
This commit is contained in:
Gaze
2024-04-17 00:20:26 +07:00
parent 495386e575
commit a008c20fb2
3 changed files with 11 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ type BitcoinDataGateway interface {
type BitcoinWriterDataDataGateway interface {
InsertBlock(context.Context, *types.Block) error
ReverBlocks(context.Context, int64) error
RevertBlocks(context.Context, int64) error
}
type BitcoinReaderDataDataGateway interface {

View File

@@ -84,6 +84,8 @@ func (p *Processor) GetIndexedBlock(ctx context.Context, height int64) (types.Bl
}
func (p *Processor) RevertData(ctx context.Context, from int64) error {
// TODO: revert synced data to the specified block for re-indexing
if err := p.bitcoinDg.RevertBlocks(ctx, from); err != nil {
return errors.WithStack(err)
}
return nil
}

View File

@@ -67,3 +67,10 @@ func (r *Repository) InsertBlock(ctx context.Context, block *types.Block) error
return nil
}
func (r *Repository) RevertBlocks(ctx context.Context, from int64) error {
if err := r.queries.RevertData(ctx, int32(from)); err != nil {
return errors.Wrap(err, "failed to revert data")
}
return nil
}