From 6bad71605e778213d3d1cdaa41a3fe6da78cb559 Mon Sep 17 00:00:00 2001 From: Agusx1211 Date: Wed, 7 Feb 2024 19:28:50 +0000 Subject: [PATCH] Compression manager sanity checks --- compressor/manager.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/compressor/manager.go b/compressor/manager.go index 4c7aebd..5a775d3 100644 --- a/compressor/manager.go +++ b/compressor/manager.go @@ -49,7 +49,27 @@ func NewCompressorManager( updateInterval uint, trailBlocks uint, batchSize uint, -) *CompressorManager { +) (*CompressorManager, error) { + if userStorage { + if updateInterval == 0 { + return nil, fmt.Errorf("update interval must be greater than 0") + } + + if batchSize == 0 { + return nil, fmt.Errorf("batch size must be greater than 0") + } + } + + // Check if the contract exists + code, err := provider.CodeAt(context, contract, nil) + if err != nil { + return nil, err + } + + if len(code) == 0 { + return nil, fmt.Errorf("contract %s does not exist", contract.Hex()) + } + c := CompressorManager{ instance: &CompressorInstance{ Context: context, @@ -68,7 +88,7 @@ func NewCompressorManager( c.StartIndexUpdater() - return &c + return &c, nil } func (cm *CompressorManager) SetOnLoadedIndexes(f func(uint, uint)) {