37 lines
885 B
Go
Raw Normal View History

package db_config
import (
2023-10-18 23:10:53 +02:00
"bytes"
"context"
"math"
2023-10-18 23:10:53 +02:00
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/ethdb/cbor"
)
type DatabaseConfiguration struct{ PruneDepth uint64 }
var DefaultDatabaseConfiguration = DatabaseConfiguration{PruneDepth: math.MaxUint64}
2023-10-18 23:10:53 +02:00
func WriteConfigurationIfNotExist(ctx context.Context, tx kv.RwTx, cfg DatabaseConfiguration) error {
var b bytes.Buffer
if err := cbor.Encoder(&b).Encode(cfg); err != nil {
return err
}
2023-10-18 23:10:53 +02:00
return tx.Put(kv.DatabaseInfo, []byte("config"), b.Bytes())
}
2023-10-18 23:10:53 +02:00
func ReadConfiguration(ctx context.Context, tx kv.Tx) (DatabaseConfiguration, error) {
var cfg DatabaseConfiguration
2023-10-18 23:10:53 +02:00
cfgEncoded, err := tx.GetOne(kv.DatabaseInfo, []byte("config"))
if err != nil {
2023-10-18 23:10:53 +02:00
return cfg, err
}
if err := cbor.Decoder(bytes.NewReader(cfgEncoded)).Decode(&cfg); err != nil {
return cfg, err
}
2023-10-18 23:10:53 +02:00
return cfg, err
}