mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 12:41:59 +08:00
feat(btc): add revert data to processor
Co-authored-by: Gaze <dev@gaze.network>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user