asdf
This commit is contained in:
parent
9a0a44e688
commit
f248bd3fab
3 changed files with 10 additions and 67 deletions
65
db/db.go
65
db/db.go
|
@ -27,23 +27,7 @@ type IterOptions struct {
|
||||||
RawValue bool
|
RawValue bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrefixRow struct {
|
|
||||||
//KeyStruct interface{}
|
|
||||||
//ValueStruct interface{}
|
|
||||||
Prefix []byte
|
|
||||||
//KeyPackFunc interface{}
|
|
||||||
//ValuePackFunc interface{}
|
|
||||||
//KeyUnpackFunc interface{}
|
|
||||||
//ValueUnpackFunc interface{}
|
|
||||||
DB *grocksdb.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
type PrefixRowKV struct {
|
type PrefixRowKV struct {
|
||||||
Key []byte
|
|
||||||
Value []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type PrefixRowKV2 struct {
|
|
||||||
Key interface{}
|
Key interface{}
|
||||||
Value interface{}
|
Value interface{}
|
||||||
}
|
}
|
||||||
|
@ -162,14 +146,6 @@ func UnpackGenericValue(key, value []byte) (byte, interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIterateOptions creates a defualt options structure for a db iterator.
|
// NewIterateOptions creates a defualt options structure for a db iterator.
|
||||||
// Default values:
|
|
||||||
// FillCache: false,
|
|
||||||
// Start: nil,
|
|
||||||
// Stop: nil,
|
|
||||||
// IncludeStart: true,
|
|
||||||
// IncludeStop: false,
|
|
||||||
// IncludeKey: true,
|
|
||||||
// IncludeValue: false,
|
|
||||||
func NewIterateOptions() *IterOptions {
|
func NewIterateOptions() *IterOptions {
|
||||||
return &IterOptions{
|
return &IterOptions{
|
||||||
FillCache: false,
|
FillCache: false,
|
||||||
|
@ -245,8 +221,8 @@ func (k *UTXOKey) String() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV2 {
|
func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV {
|
||||||
ch := make(chan *PrefixRowKV2)
|
ch := make(chan *PrefixRowKV)
|
||||||
|
|
||||||
ro := grocksdb.NewDefaultReadOptions()
|
ro := grocksdb.NewDefaultReadOptions()
|
||||||
ro.SetFillCache(opts.FillCache)
|
ro.SetFillCache(opts.FillCache)
|
||||||
|
@ -340,7 +316,7 @@ func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV2 {
|
||||||
key.Free()
|
key.Free()
|
||||||
value.Free()
|
value.Free()
|
||||||
|
|
||||||
ch <- &PrefixRowKV2{
|
ch <- &PrefixRowKV{
|
||||||
Key: outKey,
|
Key: outKey,
|
||||||
Value: outValue,
|
Value: outValue,
|
||||||
}
|
}
|
||||||
|
@ -515,42 +491,14 @@ func OpenDB(name string, start string) int {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenAndWriteDB(prIn *PrefixRow, options *IterOptions, out string) {
|
func OpenAndWriteDB(db *grocksdb.DB, options *IterOptions, out string) {
|
||||||
// Write db
|
|
||||||
//opts := grocksdb.NewDefaultOptions()
|
|
||||||
//opts.SetCreateIfMissing(true)
|
|
||||||
//db, err := grocksdb.OpenDb(opts, out)
|
|
||||||
//if err != nil {
|
|
||||||
// log.Println(err)
|
|
||||||
//}
|
|
||||||
//wo := grocksdb.NewDefaultWriteOptions()
|
|
||||||
//defer db.Close()
|
|
||||||
|
|
||||||
options.Prefix = prIn.Prefix
|
ch := Iter(db, options)
|
||||||
ch := Iter(prIn.DB, options)
|
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
for kv := range ch {
|
for kv := range ch {
|
||||||
key := kv.Key.(*UTXOKey)
|
key := kv.Key.(*UTXOKey)
|
||||||
value := kv.Value.(*UTXOValue)
|
value := kv.Value.(*UTXOValue)
|
||||||
//var unpackedKey *UTXOKey = nil
|
|
||||||
//var unpackedValue *UTXOValue = nil
|
|
||||||
|
|
||||||
//if key != nil {
|
|
||||||
// unpackKeyFnValue := reflect.ValueOf(prIn.KeyUnpackFunc)
|
|
||||||
// keyArgs := []reflect.Value{reflect.ValueOf(key)}
|
|
||||||
// unpackKeyFnResult := unpackKeyFnValue.Call(keyArgs)
|
|
||||||
// unpackedKey = unpackKeyFnResult[0].Interface().(*UTXOKey)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//if value != nil {
|
|
||||||
// unpackValueFnValue := reflect.ValueOf(prIn.ValueUnpackFunc)
|
|
||||||
// valueArgs := []reflect.Value{reflect.ValueOf(value)}
|
|
||||||
// unpackValueFnResult := unpackValueFnValue.Call(valueArgs)
|
|
||||||
// unpackedValue = unpackValueFnResult[0].Interface().(*UTXOValue)
|
|
||||||
//}
|
|
||||||
|
|
||||||
//log.Println(key, value)
|
|
||||||
|
|
||||||
keyMarshal, err := json.Marshal(key)
|
keyMarshal, err := json.Marshal(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -563,9 +511,6 @@ func OpenAndWriteDB(prIn *PrefixRow, options *IterOptions, out string) {
|
||||||
|
|
||||||
log.Println(string(keyMarshal), string(valMarshal))
|
log.Println(string(keyMarshal), string(valMarshal))
|
||||||
|
|
||||||
//if err := db.Put(wo, key, value); err != nil {
|
|
||||||
// log.Println(err)
|
|
||||||
//}
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ const (
|
||||||
EffectiveAmount = 'D'
|
EffectiveAmount = 'D'
|
||||||
ClaimExpiration = 'O'
|
ClaimExpiration = 'O'
|
||||||
|
|
||||||
ActiveAmount = 'S'
|
|
||||||
ClaimTakeover = 'P'
|
ClaimTakeover = 'P'
|
||||||
PendingActivation = 'Q'
|
PendingActivation = 'Q'
|
||||||
ActivatedClaimAndSupport = 'R'
|
ActivatedClaimAndSupport = 'R'
|
||||||
|
ActiveAmount = 'S'
|
||||||
|
|
||||||
Repost = 'V'
|
Repost = 'V'
|
||||||
RepostedClaim = 'W'
|
RepostedClaim = 'W'
|
||||||
|
|
10
main.go
10
main.go
|
@ -37,11 +37,6 @@ func main() {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pr := &db.PrefixRow{
|
|
||||||
Prefix: []byte{prefixes.UTXO},
|
|
||||||
DB: dbVal,
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := hex.DecodeString("000013")
|
b, err := hex.DecodeString("000013")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -59,15 +54,18 @@ func main() {
|
||||||
|
|
||||||
options := &db.IterOptions{
|
options := &db.IterOptions{
|
||||||
FillCache: false,
|
FillCache: false,
|
||||||
|
Prefix: []byte{prefixes.UTXO},
|
||||||
Start: nil,
|
Start: nil,
|
||||||
Stop: stop,
|
Stop: stop,
|
||||||
IncludeStart: true,
|
IncludeStart: true,
|
||||||
IncludeStop: false,
|
IncludeStop: false,
|
||||||
IncludeKey: true,
|
IncludeKey: true,
|
||||||
IncludeValue: true,
|
IncludeValue: true,
|
||||||
|
RawKey: false,
|
||||||
|
RawValue: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
db.OpenAndWriteDB(pr, options, "./resources/asdf2.db")
|
db.OpenAndWriteDB(dbVal, options, "./resources/asdf2.db")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue