2020-03-24 02:12:55 +00:00
|
|
|
package ethdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-05 10:13:35 +00:00
|
|
|
"errors"
|
2020-08-12 13:47:59 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
2020-08-05 10:13:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrAttemptToDeleteNonDeprecatedBucket = errors.New("only buckets from dbutils.DeprecatedBuckets can be deleted")
|
|
|
|
ErrUnknownBucket = errors.New("unknown bucket. add it to dbutils.Buckets")
|
2020-03-24 02:12:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type KV interface {
|
2020-05-27 16:24:34 +00:00
|
|
|
View(ctx context.Context, f func(tx Tx) error) error
|
|
|
|
Update(ctx context.Context, f func(tx Tx) error) error
|
2020-04-04 07:18:10 +00:00
|
|
|
Close()
|
|
|
|
|
2020-08-11 10:35:59 +00:00
|
|
|
Begin(ctx context.Context, parent Tx, writable bool) (Tx, error)
|
2020-03-24 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Tx interface {
|
2020-08-14 06:41:18 +00:00
|
|
|
Cursor(bucket string) Cursor
|
2020-08-26 06:03:50 +00:00
|
|
|
NoValuesCursor(bucket string) NoValuesCursor
|
2020-08-14 06:41:18 +00:00
|
|
|
Get(bucket string, key []byte) (val []byte, err error)
|
2020-04-04 07:18:10 +00:00
|
|
|
|
|
|
|
Commit(ctx context.Context) error
|
2020-06-30 03:48:46 +00:00
|
|
|
Rollback()
|
2020-08-17 07:24:59 +00:00
|
|
|
BucketSize(name string) (uint64, error)
|
2020-08-05 10:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Interface used for buckets migration, don't use it in usual app code
|
|
|
|
type BucketMigrator interface {
|
2020-08-14 06:41:18 +00:00
|
|
|
DropBucket(string) error
|
|
|
|
CreateBucket(string) error
|
|
|
|
ExistsBucket(string) bool
|
|
|
|
ClearBucket(string) error
|
|
|
|
ExistingBuckets() ([]string, error)
|
2020-03-24 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Cursor interface {
|
|
|
|
Prefix(v []byte) Cursor
|
|
|
|
Prefetch(v uint) Cursor
|
|
|
|
|
|
|
|
First() ([]byte, []byte, error)
|
|
|
|
Seek(seek []byte) ([]byte, []byte, error)
|
2020-08-17 07:24:59 +00:00
|
|
|
SeekExact(key []byte) ([]byte, error)
|
2020-03-24 02:12:55 +00:00
|
|
|
Next() ([]byte, []byte, error)
|
2020-08-12 03:49:52 +00:00
|
|
|
Last() ([]byte, []byte, error)
|
2020-06-04 11:19:59 +00:00
|
|
|
|
|
|
|
Put(key []byte, value []byte) error
|
|
|
|
Delete(key []byte) error
|
2020-08-26 06:03:50 +00:00
|
|
|
Append(key []byte, value []byte) error // Returns error if provided data not sorted or has duplicates
|
2020-03-24 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type NoValuesCursor interface {
|
2020-04-04 07:18:10 +00:00
|
|
|
First() ([]byte, uint32, error)
|
|
|
|
Seek(seek []byte) ([]byte, uint32, error)
|
|
|
|
Next() ([]byte, uint32, error)
|
2020-03-24 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 09:35:42 +00:00
|
|
|
type HasStats interface {
|
2020-07-29 04:31:46 +00:00
|
|
|
DiskSize(context.Context) (uint64, error) // db size
|
2020-06-04 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 21:09:30 +00:00
|
|
|
type Backend interface {
|
|
|
|
AddLocal([]byte) ([]byte, error)
|
2020-08-12 13:47:59 +00:00
|
|
|
Etherbase() (common.Address, error)
|
2020-08-18 17:22:49 +00:00
|
|
|
NetVersion() (uint64, error)
|
2020-08-11 21:09:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 02:12:55 +00:00
|
|
|
type DbProvider uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
Bolt DbProvider = iota
|
|
|
|
Remote
|
2020-06-10 06:42:26 +00:00
|
|
|
Lmdb
|
2020-03-24 02:12:55 +00:00
|
|
|
)
|