diff --git a/db/db.go b/db/db.go index ed12d19..a712521 100644 --- a/db/db.go +++ b/db/db.go @@ -2,15 +2,13 @@ package db import ( "bytes" - "encoding/binary" "encoding/hex" "encoding/json" "fmt" "log" - "reflect" + "os" "github.com/lbryio/hub/db/prefixes" - "github.com/lbryio/lbry.go/v2/extras/errors" "github.com/linxGnu/grocksdb" ) @@ -27,124 +25,6 @@ type IterOptions struct { RawValue bool } -type PrefixRowKV struct { - Key interface{} - Value interface{} -} - -type UTXOKey struct { - Prefix []byte `json:"prefix"` - HashX []byte `json:"hashx"` - TxNum uint32 `json:"tx_num"` - Nout uint16 `json:"nout"` -} - -type UTXOValue struct { - Amount uint64 `json:"amount"` -} - -func UnpackGenericKey(key []byte) (byte, interface{}, error) { - if len(key) == 0 { - return 0x0, nil, errors.Base("key length zero") - } - firstByte := key[0] - switch firstByte { - case prefixes.ClaimToSupport: - case prefixes.SupportToClaim: - - case prefixes.ClaimToTXO: - case prefixes.TXOToClaim: - - case prefixes.ClaimToChannel: - case prefixes.ChannelToClaim: - - case prefixes.ClaimShortIdPrefix: - case prefixes.EffectiveAmount: - case prefixes.ClaimExpiration: - - case prefixes.ClaimTakeover: - case prefixes.PendingActivation: - case prefixes.ActivatedClaimAndSupport: - case prefixes.ActiveAmount: - - case prefixes.Repost: - case prefixes.RepostedClaim: - - case prefixes.Undo: - case prefixes.ClaimDiff: - - case prefixes.Tx: - case prefixes.BlockHash: - case prefixes.Header: - case prefixes.TxNum: - case prefixes.TxCount: - case prefixes.TxHash: - return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte) - case prefixes.UTXO: - return prefixes.UTXO, UTXOKeyUnpack(key), nil - case prefixes.HashXUTXO: - case prefixes.HashXHistory: - case prefixes.DBState: - case prefixes.ChannelCount: - case prefixes.SupportAmount: - case prefixes.BlockTXs: - } - return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte) -} - -func UnpackGenericValue(key, value []byte) (byte, interface{}, error) { - if len(key) == 0 { - return 0x0, nil, errors.Base("key length zero") - } - if len(value) == 0 { - return 0x0, nil, errors.Base("value length zero") - } - - firstByte := key[0] - switch firstByte { - case prefixes.ClaimToSupport: - case prefixes.SupportToClaim: - - case prefixes.ClaimToTXO: - case prefixes.TXOToClaim: - - case prefixes.ClaimToChannel: - case prefixes.ChannelToClaim: - - case prefixes.ClaimShortIdPrefix: - case prefixes.EffectiveAmount: - case prefixes.ClaimExpiration: - - case prefixes.ClaimTakeover: - case prefixes.PendingActivation: - case prefixes.ActivatedClaimAndSupport: - case prefixes.ActiveAmount: - - case prefixes.Repost: - case prefixes.RepostedClaim: - - case prefixes.Undo: - case prefixes.ClaimDiff: - - case prefixes.Tx: - case prefixes.BlockHash: - case prefixes.Header: - case prefixes.TxNum: - case prefixes.TxCount: - case prefixes.TxHash: - return 0x0, nil, nil - case prefixes.UTXO: - return prefixes.UTXO, UTXOValueUnpack(value), nil - case prefixes.HashXUTXO: - case prefixes.HashXHistory: - case prefixes.DBState: - case prefixes.ChannelCount: - case prefixes.SupportAmount: - case prefixes.BlockTXs: - } - return 0x0, nil, nil -} - // NewIterateOptions creates a defualt options structure for a db iterator. func NewIterateOptions() *IterOptions { return &IterOptions{ @@ -211,18 +91,8 @@ func (o *IterOptions) WithRawValue(rawValue bool) *IterOptions { return o } -func (k *UTXOKey) String() string { - return fmt.Sprintf( - "%s(hashX=%s, tx_num=%d, nout=%d)", - reflect.TypeOf(k), - hex.EncodeToString(k.HashX), - k.TxNum, - k.Nout, - ) -} - -func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV { - ch := make(chan *PrefixRowKV) +func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *prefixes.PrefixRowKV { + ch := make(chan *prefixes.PrefixRowKV) ro := grocksdb.NewDefaultReadOptions() ro.SetFillCache(opts.FillCache) @@ -286,7 +156,7 @@ func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV { //keyArgs := []reflect.Value{reflect.ValueOf(newKeyData)} //unpackKeyFnResult := unpackKeyFnValue.Call(keyArgs) //outKey = unpackKeyFnResult[0].Interface() - _, outKey, err = UnpackGenericKey(newKeyData) + _, outKey, err = prefixes.UnpackGenericKey(newKeyData) if err != nil { log.Println(err) } @@ -304,7 +174,7 @@ func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV { //unpackValueFnResult := unpackValueFnValue.Call(valueArgs) //outValue = unpackValueFnResult[0].Interface() if !opts.RawValue { - _, outValue, err = UnpackGenericValue(newKeyData, newValueData) + _, outValue, err = prefixes.UnpackGenericValue(newKeyData, newValueData) if err != nil { log.Println(err) } @@ -316,7 +186,7 @@ func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV { key.Free() value.Free() - ch <- &PrefixRowKV{ + ch <- &prefixes.PrefixRowKV{ Key: outKey, Value: outValue, } @@ -328,92 +198,6 @@ func Iter(db *grocksdb.DB, opts *IterOptions) <-chan *PrefixRowKV { return ch } -func (k *UTXOKey) PackKey() []byte { - prefixLen := 1 - // b'>11sLH' - n := prefixLen + 11 + 4 + 2 - key := make([]byte, n) - copy(key, k.Prefix) - copy(key[prefixLen:], k.HashX) - binary.BigEndian.PutUint32(key[prefixLen+11:], k.TxNum) - binary.BigEndian.PutUint16(key[prefixLen+15:], k.Nout) - - return key -} - -// UTXOKeyPackPartialNFields creates a pack partial key function for n fields. -func UTXOKeyPackPartialNFields(nFields int) func(*UTXOKey) []byte { - return func(u *UTXOKey) []byte { - return UTXOKeyPackPartial(u, nFields) - } -} - -// UTXOKeyPackPartial packs a variable number of fields for a UTXOKey into -// a byte array. -func UTXOKeyPackPartial(k *UTXOKey, nFields int) []byte { - // Limit nFields between 0 and number of fields, we always at least need - // the prefix, and we never need to iterate past the number of fields. - if nFields > 3 { - nFields = 3 - } - if nFields < 0 { - nFields = 0 - } - - // b'>11sLH' - prefixLen := 1 - var n = prefixLen - for i := 0; i <= nFields; i++ { - switch i { - case 1: - n += 11 - case 2: - n += 4 - case 3: - n += 2 - } - } - - key := make([]byte, n) - - for i := 0; i <= nFields; i++ { - switch i { - case 0: - copy(key, k.Prefix) - case 1: - copy(key[prefixLen:], k.HashX) - case 2: - binary.BigEndian.PutUint32(key[prefixLen+11:], k.TxNum) - case 3: - binary.BigEndian.PutUint16(key[prefixLen+15:], k.Nout) - } - } - - return key -} - -func UTXOKeyUnpack(key []byte) *UTXOKey { - return &UTXOKey{ - Prefix: key[:1], - HashX: key[1:12], - TxNum: binary.BigEndian.Uint32(key[12:]), - Nout: binary.BigEndian.Uint16(key[16:]), - } -} - -func (k *UTXOValue) PackValue() []byte { - value := make([]byte, 8) - binary.BigEndian.PutUint64(value, k.Amount) - - return value -} - -func UTXOValueUnpack(value []byte) *UTXOValue { - return &UTXOValue{ - Amount: binary.BigEndian.Uint64(value), - } -} - func GetDB(name string) (*grocksdb.DB, error) { opts := grocksdb.NewDefaultOptions() // db, err := grocksdb.OpenDb(opts, name) @@ -425,14 +209,14 @@ func GetDB(name string) (*grocksdb.DB, error) { return db, nil } -func ReadPrefixN(db *grocksdb.DB, prefix []byte, n int) []*PrefixRowKV { +func ReadPrefixN(db *grocksdb.DB, prefix []byte, n int) []*prefixes.PrefixRowKV { ro := grocksdb.NewDefaultReadOptions() ro.SetFillCache(false) it := db.NewIterator(ro) defer it.Close() - res := make([]*PrefixRowKV, n) + res := make([]*prefixes.PrefixRowKV, n) var i = 0 it.Seek(prefix) @@ -440,7 +224,7 @@ func ReadPrefixN(db *grocksdb.DB, prefix []byte, n int) []*PrefixRowKV { key := it.Key() value := it.Value() - res[i] = &PrefixRowKV{ + res[i] = &prefixes.PrefixRowKV{ Key: key.Data(), Value: value.Data(), } @@ -497,8 +281,8 @@ func OpenAndWriteDB(db *grocksdb.DB, options *IterOptions, out string) { var i = 0 for kv := range ch { - key := kv.Key.(*UTXOKey) - value := kv.Value.(*UTXOValue) + key := kv.Key.(*prefixes.UTXOKey) + value := kv.Value.(*prefixes.UTXOValue) keyMarshal, err := json.Marshal(key) if err != nil { @@ -514,3 +298,62 @@ func OpenAndWriteDB(db *grocksdb.DB, options *IterOptions, out string) { i++ } } + +func ReadWriteRawN(db *grocksdb.DB, options *IterOptions, out string, n int) { + + options.RawKey = true + options.RawValue = true + ch := Iter(db, options) + + file, err := os.Create(out) + if err != nil { + log.Println(err) + return + } + defer file.Close() + + var i = 0 + for kv := range ch { + log.Println(i) + if i >= n { + return + } + key := kv.Key.([]byte) + value := kv.Value.([]byte) + keyHex := hex.EncodeToString(key) + valueHex := hex.EncodeToString(value) + log.Println(keyHex) + log.Println(valueHex) + file.WriteString(keyHex) + file.WriteString(",") + file.WriteString(valueHex) + file.WriteString("\n") + + i++ + } +} + +func GenerateTestData() { + dbVal, err := GetDB("/mnt/d/data/wallet/lbry-rocksdb/") + if err != nil { + log.Fatalln(err) + } + + // options := &IterOptions{ + // FillCache: false, + // Prefix: []byte{prefixes.HashXUTXO}, + // Start: nil, + // Stop: nil, + // IncludeStart: true, + // IncludeStop: false, + // IncludeKey: true, + // IncludeValue: true, + // RawKey: true, + // RawValue: true, + // } + options := NewIterateOptions() + options.WithRawKey(true).WithRawValue(true) + options.WithPrefix([]byte{prefixes.HashXUTXO}) + + ReadWriteRawN(dbVal, options, "./resources/hashx_utxo.csv", 10) +} diff --git a/db/db_test.go b/db/db_test.go index c2ae131..c0d9a7b 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -1,14 +1,68 @@ package db import ( + "encoding/csv" "encoding/hex" "fmt" "log" + "os" "testing" "github.com/lbryio/hub/db/prefixes" + "github.com/linxGnu/grocksdb" ) +const tmpPath = "../resources/tmp_rocksdb/" + +func TestHashXUTXO(t *testing.T) { + + tests := []struct { + name string + filePath string + }{ + { + name: "Read HashX_UTXO correctly", + filePath: "../resources/hashx_utxo.csv", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + log.Println(tt.filePath) + file, err := os.Open(tt.filePath) + if err != nil { + log.Println(err) + } + reader := csv.NewReader(file) + records, err := reader.ReadAll() + if err != nil { + log.Println(err) + } + + wOpts := grocksdb.NewDefaultWriteOptions() + opts := grocksdb.NewDefaultOptions() + opts.SetCreateIfMissing(true) + // opts.SetDBPaths([]*grocksdb.DBPath{grocksdb.NewDBPath(tmpPath, 10000)}) + db, err := grocksdb.OpenDb(opts, "tmp") + defer db.Close() + if err != nil { + log.Println(err) + } + for _, record := range records { + key, err := hex.DecodeString(record[0]) + if err != nil { + log.Println(err) + } + val, err := hex.DecodeString(record[1]) + if err != nil { + log.Println(err) + } + db.Put(wOpts, key, val) + } + }) + } +} + func TestReadUTXO2(t *testing.T) { tests := []struct { @@ -38,13 +92,13 @@ func TestReadUTXO2(t *testing.T) { if err != nil { log.Println(err) } - stopKey := &UTXOKey{ + stopKey := &prefixes.UTXOKey{ Prefix: []byte{prefixes.UTXO}, HashX: b, TxNum: 0, Nout: 0, } - stop := UTXOKeyPackPartial(stopKey, 1) + stop := prefixes.UTXOKeyPackPartial(stopKey, 1) options := &IterOptions{ FillCache: false, @@ -66,7 +120,7 @@ func TestReadUTXO2(t *testing.T) { var i = 0 for kv := range ch { log.Println(kv.Key) - got := kv.Value.(*UTXOValue).Amount + got := kv.Value.(*prefixes.UTXOValue).Amount if got != tt.want[i] { t.Errorf("got: %d, want: %d\n", got, tt.want[i]) } @@ -184,13 +238,13 @@ func TestUTXOKey_String(t *testing.T) { hashx: []byte("AAAAAAAAAA"), txnum: 0, nout: 0, - want: "*db.UTXOKey(hashX=41414141414141414141, tx_num=0, nout=0)", + want: "*prefixes.UTXOKey(hashX=41414141414141414141, tx_num=0, nout=0)", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - key := &UTXOKey{ + key := &prefixes.UTXOKey{ Prefix: tt.prefix, HashX: tt.hashx, TxNum: tt.txnum, diff --git a/db/prefixes/prefixes.go b/db/prefixes/prefixes.go index 9c0f7ed..49eccff 100644 --- a/db/prefixes/prefixes.go +++ b/db/prefixes/prefixes.go @@ -1,5 +1,15 @@ package prefixes +import ( + "encoding/binary" + "encoding/hex" + "fmt" + "reflect" + "strings" + + "github.com/lbryio/lbry.go/extras/errors" +) + const ( ClaimToSupport = 'K' SupportToClaim = 'L' @@ -38,4 +48,1070 @@ const ( ChannelCount = 'Z' SupportAmount = 'a' BlockTXs = 'b' + + ACTIVATED_CLAIM_TXO_TYPE = 1 + ACTIVATED_SUPPORT_TXO_TYPE = 2 ) + +type PrefixRowKV struct { + Key interface{} + Value interface{} +} + +type UTXOKey struct { + Prefix []byte `json:"prefix"` + HashX []byte `json:"hashx"` + TxNum uint32 `json:"tx_num"` + Nout uint16 `json:"nout"` +} + +type UTXOValue struct { + Amount uint64 `json:"amount"` +} + +type HashXUTXOKey struct { + Prefix []byte `json:"prefix"` + ShortTXHash []byte `json:"short_tx_hash"` + TxNum uint32 `json:"tx_num"` + Nout uint16 `json:"nout"` +} + +type HashXUTXOValue struct { + HashX []byte `json:"hashx"` +} + +/* +class HashXHistoryKey(NamedTuple): + hashX: bytes + height: int + + def __str__(self): + return f"{self.__class__.__name__}(hashX={self.hashX.hex()}, height={self.height})" + + +class HashXHistoryValue(NamedTuple): + hashXes: typing.List[int] +*/ + +type HashXHistoryKey struct { + Prefix []byte `json:"prefix"` + HashX []byte `json:"hashx"` + Height uint32 `json:"height"` +} + +type HashXHistoryValue struct { + HashXes []uint32 `json:"hashxes"` +} + +/* +class BlockHashKey(NamedTuple): + height: int + + +class BlockHashValue(NamedTuple): + block_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(block_hash={self.block_hash.hex()})" +*/ + +type BlockHashKey struct { + Prefix []byte `json:"prefix"` + Height uint32 `json:"height"` +} + +type BlockHashValue struct { + BlockHash []byte `json:"block_hash"` +} + +/* +class BlockTxsKey(NamedTuple): + height: int + + +class BlockTxsValue(NamedTuple): + tx_hashes: typing.List[bytes] +*/ + +type BlockTxsKey struct { + Prefix []byte `json:"prefix"` + Height uint32 `json:"height"` +} + +type BlockTxsValue struct { + TxHashes []byte `json:"tx_hashes"` +} + +/* +class TxCountKey(NamedTuple): + height: int + + +class TxCountValue(NamedTuple): + tx_count: int +*/ + +type TxCountKey struct { + Prefix []byte `json:"prefix"` + Height uint32 `json:"height"` +} + +type TxCountValue struct { + TxCount uint32 `json:"tx_count"` +} + +/* +class TxHashKey(NamedTuple): + tx_num: int + + +class TxHashValue(NamedTuple): + tx_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(tx_hash={self.tx_hash.hex()})" +*/ + +type TxHashKey struct { + Prefix []byte `json:"prefix"` + TxNum uint32 `json:"tx_num"` +} + +type TxHashValue struct { + TxHash []byte `json:"tx_hash"` +} + +/* +class TxNumKey(NamedTuple): + tx_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(tx_hash={self.tx_hash.hex()})" + + +class TxNumValue(NamedTuple): + tx_num: int +*/ + +type TxNumKey struct { + Prefix []byte `json:"prefix"` + TxHash []byte `json:"tx_hash"` +} + +type TxNumValue struct { + TxNum int32 `json:"tx_num"` +} + +/* +class TxKey(NamedTuple): + tx_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(tx_hash={self.tx_hash.hex()})" + + +class TxValue(NamedTuple): + raw_tx: bytes + + def __str__(self): + return f"{self.__class__.__name__}(raw_tx={base64.b64encode(self.raw_tx)})" +*/ + +type TxKey struct { + Prefix []byte `json:"prefix"` + TxHash []byte `json:"tx_hash"` +} + +type TxValue struct { + RawTx []byte `json:"raw_tx"` +} + +/* +class BlockHeaderKey(NamedTuple): + height: int + + +class BlockHeaderValue(NamedTuple): + header: bytes + + def __str__(self): + return f"{self.__class__.__name__}(header={base64.b64encode(self.header)})" +*/ + +type BlockHeaderKey struct { + Prefix []byte `json:"prefix"` + Height int32 `json:"height"` +} + +type BlockHeaderValue struct { + Header []byte `json:"header"` +} + +/* + +class ClaimToTXOKey(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" + + +class ClaimToTXOValue(typing.NamedTuple): + tx_num: int + position: int + root_tx_num: int + root_position: int + amount: int + # activation: int + channel_signature_is_valid: bool + name: str + + @property + def normalized_name(self) -> str: + try: + return normalize_name(self.name) + except UnicodeDecodeError: + return self.name +*/ + +type ClaimToTXOKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` +} + +type ClaimToTXOValue struct { + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` + RootTxNum int32 `json:"root_tx_num"` + RootPosition int32 `json:"root_position"` + Amount int32 `json:"amount"` + ChannelSignatureIsValid bool `json:"channel_signature_is_valid"` + Name string `json:"name"` +} + +func (v *ClaimToTXOValue) NormalizedName() string { + //TODO implemented + return v.Name +} + +/* +class TXOToClaimKey(typing.NamedTuple): + tx_num: int + position: int + + +class TXOToClaimValue(typing.NamedTuple): + claim_hash: bytes + name: str + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})" +*/ + +type TXOToClaimKey struct { + Prefix []byte `json:"prefix"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type TXOToClaimValue struct { + ClaimHash []byte `json:"claim_hash"` + Name string `json:"name"` +} + +/* +class ClaimShortIDKey(typing.NamedTuple): + normalized_name: str + partial_claim_id: str + root_tx_num: int + root_position: int + + def __str__(self): + return f"{self.__class__.__name__}(normalized_name={self.normalized_name}, " \ + f"partial_claim_id={self.partial_claim_id}, " \ + f"root_tx_num={self.root_tx_num}, root_position={self.root_position})" + + +class ClaimShortIDValue(typing.NamedTuple): + tx_num: int + position: int +*/ + +type ClaimShortIDKey struct { + Prefix []byte `json:"prefix"` + NormalizedName string `json:"normalized_name"` + PartialClaimId string `json:"partial_claim_id"` + RootTxNum int32 `json:"root_tx_num"` + RootPosition int32 `json:"root_position"` +} + +type ClaimShortIDValue struct { + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +/* +class ClaimToChannelKey(typing.NamedTuple): + claim_hash: bytes + tx_num: int + position: int + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, " \ + f"tx_num={self.tx_num}, position={self.position})" + + +class ClaimToChannelValue(typing.NamedTuple): + signing_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(signing_hash={self.signing_hash.hex()})" +*/ + +type ClaimToChannelKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type ClaimToChannelValue struct { + SigningHash []byte `json:"signing_hash"` +} + +/* +class ChannelToClaimKey(typing.NamedTuple): + signing_hash: bytes + name: str + tx_num: int + position: int + + def __str__(self): + return f"{self.__class__.__name__}(signing_hash={self.signing_hash.hex()}, name={self.name}, " \ + f"tx_num={self.tx_num}, position={self.position})" + + +class ChannelToClaimValue(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" +*/ + +type ChannelToClaimKey struct { + Prefix []byte `json:"prefix"` + SigningHash []byte `json:"signing_hash"` + Name string `json:"name"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type ChannelToClaimValue struct { + ClaimHash []byte `json:"claim_hash"` +} + +/* + +class ChannelCountKey(typing.NamedTuple): + channel_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(channel_hash={self.channel_hash.hex()})" + + +class ChannelCountValue(typing.NamedTuple): + count: int +*/ + +type ChannelCountKey struct { + Prefix []byte `json:"prefix"` + ChannelHash []byte `json:"channel_hash"` +} + +type ChannelCountValue struct { + Count int32 `json:"count"` +} + +/* +class SupportAmountKey(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" + + +class SupportAmountValue(typing.NamedTuple): + amount: int +*/ + +type SupportAmountKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` +} + +type SupportAmountValue struct { + Amount int32 `json:"amount"` +} + +/* + +class ClaimToSupportKey(typing.NamedTuple): + claim_hash: bytes + tx_num: int + position: int + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, tx_num={self.tx_num}, " \ + f"position={self.position})" + + +class ClaimToSupportValue(typing.NamedTuple): + amount: int +*/ + +type ClaimToSupportKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type ClaimToSupportValue struct { + Amount int32 `json:"amount"` +} + +/* +class SupportToClaimKey(typing.NamedTuple): + tx_num: int + position: int + + +class SupportToClaimValue(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" +*/ + +type SupportToClaimKey struct { + Prefix []byte `json:"prefix"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type SupportToClaimValue struct { + ClaimHash []byte `json:"claim_hash"` +} + +/* +class ClaimExpirationKey(typing.NamedTuple): + expiration: int + tx_num: int + position: int + + +class ClaimExpirationValue(typing.NamedTuple): + claim_hash: bytes + normalized_name: str + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, normalized_name={self.normalized_name})" +*/ + +type ClaimExpirationKey struct { + Prefix []byte `json:"prefix"` + Expiration int32 `json:"expiration"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type ClaimExpirationValue struct { + ClaimHash []byte `json:"claim_hash"` + NormalizedName string `json:"normalized_name"` +} + +/* +class ClaimTakeoverKey(typing.NamedTuple): + normalized_name: str + + +class ClaimTakeoverValue(typing.NamedTuple): + claim_hash: bytes + height: int + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, height={self.height})" +*/ + +type ClaimTakeoverKey struct { + Prefix []byte `json:"prefix"` + NormalizedName string `json:"normalized_name"` +} + +type ClaimTakeoverValue struct { + ClaimHash []byte `json:"claim_hash"` + Height int32 `json:"height"` +} + +func (v *ClaimTakeoverValue) String() string { + return fmt.Sprintf( + "%s(claim_hash=%s, height=%d)", + reflect.TypeOf(v), + hex.EncodeToString(v.ClaimHash), + v.Height, + ) +} + +/* + +class PendingActivationKey(typing.NamedTuple): + height: int + txo_type: int + tx_num: int + position: int + + @property + def is_support(self) -> bool: + return self.txo_type == ACTIVATED_SUPPORT_TXO_TYPE + + @property + def is_claim(self) -> bool: + return self.txo_type == ACTIVATED_CLAIM_TXO_TYPE + + +class PendingActivationValue(typing.NamedTuple): + claim_hash: bytes + normalized_name: str + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, normalized_name={self.normalized_name})" +*/ + +type PendingActivationKey struct { + Prefix []byte `json:"prefix"` + Height int32 `json:"height"` + TxoType int32 `json:"txo_height"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +func (k *PendingActivationKey) IsSupport() bool { + return k.TxoType == ACTIVATED_SUPPORT_TXO_TYPE +} + +func (k *PendingActivationKey) IsClaim() bool { + return k.TxoType == ACTIVATED_CLAIM_TXO_TYPE +} + +type PendingActivationValue struct { + ClaimHash []byte `json:"claim_hash"` + NormalizedName string `json:"normalized_name"` +} + +/* +class ActivationKey(typing.NamedTuple): + txo_type: int + tx_num: int + position: int + + +class ActivationValue(typing.NamedTuple): + height: int + claim_hash: bytes + normalized_name: str + + def __str__(self): + return f"{self.__class__.__name__}(height={self.height}, claim_hash={self.claim_hash.hex()}, " \ + f"normalized_name={self.normalized_name})" +*/ + +type ActivationKey struct { + Prefix []byte `json:"prefix"` + TxType int32 `json:"txo_type"` + TxNum int32 `json:"txo_num"` + Position int32 `json:"position"` +} + +type ActivationValue struct { + Height int32 `json:"height"` + ClaimHash []byte `json:"claim_hash"` + NormalizedName string `json:"normalized_name"` +} + +/* + +class ActiveAmountKey(typing.NamedTuple): + claim_hash: bytes + txo_type: int + activation_height: int + tx_num: int + position: int + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, txo_type={self.txo_type}, " \ + f"activation_height={self.activation_height}, tx_num={self.tx_num}, position={self.position})" + + +class ActiveAmountValue(typing.NamedTuple): + amount: int +*/ + +type ActiveAmountKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` + TxoType int32 `json:"txo_type"` + ActivationHeight int32 `json:"activation_height"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type ActiveAmountValue struct { + Amount int32 `json:"amount"` +} + +/* + +class EffectiveAmountKey(typing.NamedTuple): + normalized_name: str + effective_amount: int + tx_num: int + position: int + + +class EffectiveAmountValue(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" +*/ + +type EffectiveAmountKey struct { + Prefix []byte `json:"prefix"` + NormalizedName string `json:"normalized_name"` + EffectiveAmount int32 `json:"effective_amount"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type EffectiveAmountValue struct { + ClaimHash []byte `json:"claim_hash"` +} + +/* + +class RepostKey(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" + + +class RepostValue(typing.NamedTuple): + reposted_claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(reposted_claim_hash={self.reposted_claim_hash.hex()})" +*/ + +type RepostKey struct { + Prefix []byte `json:"prefix"` + ClaimHash []byte `json:"claim_hash"` +} + +type RepostValue struct { + RepostedClaimHash []byte `json:"reposted_claim_hash"` +} + +/* + +class RepostedKey(typing.NamedTuple): + reposted_claim_hash: bytes + tx_num: int + position: int + + def __str__(self): + return f"{self.__class__.__name__}(reposted_claim_hash={self.reposted_claim_hash.hex()}, " \ + f"tx_num={self.tx_num}, position={self.position})" + + +class RepostedValue(typing.NamedTuple): + claim_hash: bytes + + def __str__(self): + return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})" +*/ + +type RepostedKey struct { + Prefix []byte `json:"prefix"` + RepostedClaimHash []byte `json:"reposted_claim_hash"` + TxNum int32 `json:"tx_num"` + Position int32 `json:"position"` +} + +type RepostedValue struct { + ClaimHash []byte `json:"claim_hash"` +} + +/* +class TouchedOrDeletedClaimKey(typing.NamedTuple): + height: int + + +class TouchedOrDeletedClaimValue(typing.NamedTuple): + touched_claims: typing.Set[bytes] + deleted_claims: typing.Set[bytes] + + def __str__(self): + return f"{self.__class__.__name__}(" \ + f"touched_claims={','.join(map(lambda x: x.hex(), self.touched_claims))}," \ + f"deleted_claims={','.join(map(lambda x: x.hex(), self.deleted_claims))})" + + +*/ + +type TouchedOrDeletedClaimKey struct { + Prefix []byte `json:"prefix"` + Height int32 `json:"height"` +} + +type TouchedOrDeletedClaimValue struct { + TouchedClaims [][]byte `json:"touched_claims"` + DeletedClaims [][]byte `json:"deleted_claims"` +} + +func (v *TouchedOrDeletedClaimValue) String() string { + touchedSB := strings.Builder{} + touchedLen := len(v.TouchedClaims) + for i, claim := range v.TouchedClaims { + touchedSB.WriteString(hex.EncodeToString(claim)) + if i < touchedLen-1 { + touchedSB.WriteString(",") + } + } + + deletedSB := strings.Builder{} + deletedLen := len(v.DeletedClaims) + for i, claim := range v.DeletedClaims { + deletedSB.WriteString(hex.EncodeToString(claim)) + if i < deletedLen-1 { + deletedSB.WriteString(",") + } + } + + return fmt.Sprintf( + "%s(touched_claims=%s, deleted_claims=%s)", + reflect.TypeOf(v), + touchedSB.String(), + deletedSB.String(), + ) +} + +// +// HashXUTXOKey / HashXUTXOValue +// + +func (k *HashXUTXOKey) String() string { + return fmt.Sprintf( + "%s(short_tx_hash=%s, tx_num=%d, nout=%d)", + reflect.TypeOf(k), + hex.EncodeToString(k.ShortTXHash), + k.TxNum, + k.Nout, + ) +} + +func (v *HashXUTXOValue) String() string { + return fmt.Sprintf( + "%s(hashX=%s)", + reflect.TypeOf(v), + hex.EncodeToString(v.HashX), + ) +} + +func (k *HashXUTXOKey) PackKey() []byte { + prefixLen := 1 + // b'>4sLH' + n := prefixLen + 4 + 4 + 2 + key := make([]byte, n) + copy(key, k.Prefix) + copy(key[prefixLen:], k.ShortTXHash) + binary.BigEndian.PutUint32(key[prefixLen+4:], k.TxNum) + binary.BigEndian.PutUint16(key[prefixLen+8:], k.Nout) + + return key +} + +func (v *HashXUTXOValue) PackValue() []byte { + value := make([]byte, 11) + copy(value, v.HashX) + + return value +} + +// HashXUTXOKeyPackPartialNFields creates a pack partial key function for n fields. +func HashXUTXOKeyPackPartialNFields(nFields int) func(*HashXUTXOKey) []byte { + return func(u *HashXUTXOKey) []byte { + return HashXUTXOKeyPackPartial(u, nFields) + } +} + +// HashXUTXOKeyPackPartial packs a variable number of fields into a byte +// array +func HashXUTXOKeyPackPartial(k *HashXUTXOKey, nFields int) []byte { + // Limit nFields between 0 and number of fields, we always at least need + // the prefix, and we never need to iterate past the number of fields. + if nFields > 3 { + nFields = 3 + } + if nFields < 0 { + nFields = 0 + } + + // b'>4sLH' + prefixLen := 1 + var n = prefixLen + for i := 0; i <= nFields; i++ { + switch i { + case 1: + n += 4 + case 2: + n += 4 + case 3: + n += 2 + } + } + + key := make([]byte, n) + + for i := 0; i <= nFields; i++ { + switch i { + case 0: + copy(key, k.Prefix) + case 1: + copy(key[prefixLen:], k.ShortTXHash) + case 2: + binary.BigEndian.PutUint32(key[prefixLen+4:], k.TxNum) + case 3: + binary.BigEndian.PutUint16(key[prefixLen+8:], k.Nout) + } + } + + return key +} + +func HashXUTXOKeyUnpack(key []byte) *HashXUTXOKey { + return &HashXUTXOKey{ + Prefix: key[:1], + ShortTXHash: key[1:5], + TxNum: binary.BigEndian.Uint32(key[5:]), + Nout: binary.BigEndian.Uint16(key[9:]), + } +} + +func HashXUTXOValueUnpack(value []byte) *HashXUTXOValue { + return &HashXUTXOValue{ + HashX: value[:11], + } +} + +// +// UTXOKey / UTXOValue +// + +func (k *UTXOKey) String() string { + return fmt.Sprintf( + "%s(hashX=%s, tx_num=%d, nout=%d)", + reflect.TypeOf(k), + hex.EncodeToString(k.HashX), + k.TxNum, + k.Nout, + ) +} + +func (k *UTXOKey) PackKey() []byte { + prefixLen := 1 + // b'>11sLH' + n := prefixLen + 11 + 4 + 2 + key := make([]byte, n) + copy(key, k.Prefix) + copy(key[prefixLen:], k.HashX) + binary.BigEndian.PutUint32(key[prefixLen+11:], k.TxNum) + binary.BigEndian.PutUint16(key[prefixLen+15:], k.Nout) + + return key +} + +func (k *UTXOValue) PackValue() []byte { + value := make([]byte, 8) + binary.BigEndian.PutUint64(value, k.Amount) + + return value +} + +// UTXOKeyPackPartialNFields creates a pack partial key function for n fields. +func UTXOKeyPackPartialNFields(nFields int) func(*UTXOKey) []byte { + return func(u *UTXOKey) []byte { + return UTXOKeyPackPartial(u, nFields) + } +} + +// UTXOKeyPackPartial packs a variable number of fields for a UTXOKey into +// a byte array. +func UTXOKeyPackPartial(k *UTXOKey, nFields int) []byte { + // Limit nFields between 0 and number of fields, we always at least need + // the prefix, and we never need to iterate past the number of fields. + if nFields > 3 { + nFields = 3 + } + if nFields < 0 { + nFields = 0 + } + + // b'>11sLH' + prefixLen := 1 + var n = prefixLen + for i := 0; i <= nFields; i++ { + switch i { + case 1: + n += 11 + case 2: + n += 4 + case 3: + n += 2 + } + } + + key := make([]byte, n) + + for i := 0; i <= nFields; i++ { + switch i { + case 0: + copy(key, k.Prefix) + case 1: + copy(key[prefixLen:], k.HashX) + case 2: + binary.BigEndian.PutUint32(key[prefixLen+11:], k.TxNum) + case 3: + binary.BigEndian.PutUint16(key[prefixLen+15:], k.Nout) + } + } + + return key +} + +func UTXOKeyUnpack(key []byte) *UTXOKey { + return &UTXOKey{ + Prefix: key[:1], + HashX: key[1:12], + TxNum: binary.BigEndian.Uint32(key[12:]), + Nout: binary.BigEndian.Uint16(key[16:]), + } +} + +func UTXOValueUnpack(value []byte) *UTXOValue { + return &UTXOValue{ + Amount: binary.BigEndian.Uint64(value), + } +} + +func UnpackGenericKey(key []byte) (byte, interface{}, error) { + if len(key) == 0 { + return 0x0, nil, errors.Base("key length zero") + } + firstByte := key[0] + switch firstByte { + case ClaimToSupport: + case SupportToClaim: + + case ClaimToTXO: + case TXOToClaim: + + case ClaimToChannel: + case ChannelToClaim: + + case ClaimShortIdPrefix: + case EffectiveAmount: + case ClaimExpiration: + + case ClaimTakeover: + case PendingActivation: + case ActivatedClaimAndSupport: + case ActiveAmount: + + case Repost: + case RepostedClaim: + + case Undo: + case ClaimDiff: + + case Tx: + case BlockHash: + case Header: + case TxNum: + case TxCount: + case TxHash: + return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte) + case UTXO: + return UTXO, UTXOKeyUnpack(key), nil + case HashXUTXO: + case HashXHistory: + case DBState: + case ChannelCount: + case SupportAmount: + case BlockTXs: + } + return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte) +} + +func UnpackGenericValue(key, value []byte) (byte, interface{}, error) { + if len(key) == 0 { + return 0x0, nil, errors.Base("key length zero") + } + if len(value) == 0 { + return 0x0, nil, errors.Base("value length zero") + } + + firstByte := key[0] + switch firstByte { + case ClaimToSupport: + case SupportToClaim: + + case ClaimToTXO: + case TXOToClaim: + + case ClaimToChannel: + case ChannelToClaim: + + case ClaimShortIdPrefix: + case EffectiveAmount: + case ClaimExpiration: + + case ClaimTakeover: + case PendingActivation: + case ActivatedClaimAndSupport: + case ActiveAmount: + + case Repost: + case RepostedClaim: + + case Undo: + case ClaimDiff: + + case Tx: + case BlockHash: + case Header: + case TxNum: + case TxCount: + case TxHash: + return 0x0, nil, nil + case UTXO: + return UTXO, UTXOValueUnpack(value), nil + case HashXUTXO: + case HashXHistory: + case DBState: + case ChannelCount: + case SupportAmount: + case BlockTXs: + } + return 0x0, nil, nil +} diff --git a/go.mod b/go.mod index b6b44e9..542074f 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.16 require ( github.com/ReneKroon/ttlcache/v2 v2.8.1 github.com/akamensky/argparse v1.2.2 + github.com/lbryio/lbry.go v1.1.2 github.com/lbryio/lbry.go/v2 v2.7.2-0.20210625145058-2b155597bf57 github.com/linxGnu/grocksdb v1.6.42 github.com/olivere/elastic/v7 v7.0.24 diff --git a/go.sum b/go.sum index f191980..4e2e132 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-sdk-go v1.38.3/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -46,8 +47,10 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.1.1 h1:ljK/pL5ltg3qoN+OtN6yCv9HWSfMwxSx90GJCZQxYNg= github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= +github.com/go-ini/ini v1.38.2/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-ini/ini v1.48.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -55,6 +58,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU= github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -63,6 +67,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -88,8 +93,12 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/rpc v1.1.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= @@ -105,9 +114,11 @@ github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlT github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -119,17 +130,25 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8= +github.com/lbryio/lbry.go v1.1.2 h1:Dyxc+glT/rVWJwHfIf7vjlPYYbjzrQz5ARmJd5Hp69c= +github.com/lbryio/lbry.go v1.1.2/go.mod h1:JtyI30bU51rm0LZ/po3mQuzf++14OWb6kR/6mMRAmKU= github.com/lbryio/lbry.go/v2 v2.7.2-0.20210625145058-2b155597bf57 h1:Dzg3a7M9EWS48D0mbYInBjeqX/LB5qRuDgG29ktpmw8= github.com/lbryio/lbry.go/v2 v2.7.2-0.20210625145058-2b155597bf57/go.mod h1:I1q8W9fwU+t0IWNiprPgE1SorWQwcO6ser0nzP3L5Pk= +github.com/lbryio/lbryschema.go v0.0.0-20190428231007-c54836bca002/go.mod h1:dAzPCBj3CKKWBGYBZxK6tKBP5SCgY2tqd9SnQd/OyKo= github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04/go.mod h1:fbG/dzobG8r95KzMwckXiLMHfFjZaBRQqC9hPs2XAQ4= +github.com/lbryio/types v0.0.0-20190422033210-321fb2abda9c/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/lbryio/types v0.0.0-20201019032447-f0b4476ef386/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/linxGnu/grocksdb v1.6.42 h1:nJLoXFuzwBwQQQrXTUgRGRz1QRm7y8pR6CNV/gwrbqs= github.com/linxGnu/grocksdb v1.6.42/go.mod h1:JcMMDBFaDNhRXFYcYXmgQwb/RarSld1PulTI7UzE+w0= +github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0= +github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg= github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5/go.mod h1:H0aPCWffGOaDcjkw1iB7W9DVLp6GXmfcJY/7YZCWPA4= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -137,6 +156,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM= github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/olivere/elastic/v7 v7.0.24 h1:9ZcCQP3Pvgese7TaypYiVAL49sCEphyIwkVxtRf8jb8= @@ -172,8 +192,10 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561/go.mod h1:lvjGftC8oe7XPtyrOidaMi0rp5B9+XY/ZRUynGnuaxQ= github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -183,8 +205,10 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= +github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -195,9 +219,11 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= @@ -250,6 +276,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190520201301-c432e742b0af/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -270,7 +297,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -291,11 +320,14 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20210524171403-669157292da3 h1:xFyh6GBb+NO1L0xqb978I3sBPQpk6FrKO0jJGRvdj/0= google.golang.org/genproto v0.0.0-20210524171403-669157292da3/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= @@ -324,6 +356,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.48.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/karalabe/cookiejar.v1 v1.0.0-20141109175019-e1490cae028c h1:4GYkPhjcYLPrPAnoxHVQlH/xcXtWN8pEgqBnHrPAs8c= gopkg.in/karalabe/cookiejar.v1 v1.0.0-20141109175019-e1490cae028c/go.mod h1:xd7qpr5uPMNy4hsRJ5JEBXA8tJjTFmUI1soCjlCIgAE= @@ -340,5 +373,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= +honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index 0f98bf5..3506cb6 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "encoding/hex" "fmt" "log" "time" @@ -32,40 +31,56 @@ func main() { return } else if args.CmdType == server.DBCmd { - dbVal, err := db.GetDB("./resources/asdf.db") + //dbVal, err := db.GetDB("./resources/asdf.db") + dbVal, err := db.GetDB("/mnt/d/data/wallet/lbry-rocksdb/") if err != nil { log.Fatalln(err) } - b, err := hex.DecodeString("000013") - if err != nil { - log.Println(err) - } - stopKey := &db.UTXOKey{ - Prefix: []byte{prefixes.UTXO}, - HashX: b, - TxNum: 0, - Nout: 0, - } - stop := db.UTXOKeyPackPartial(stopKey, 1) - - log.Println(stop) - log.Print(hex.EncodeToString(stop)) - options := &db.IterOptions{ FillCache: false, - Prefix: []byte{prefixes.UTXO}, + Prefix: []byte{prefixes.HashXUTXO}, Start: nil, - Stop: stop, + Stop: nil, IncludeStart: true, IncludeStop: false, IncludeKey: true, IncludeValue: true, - RawKey: false, - RawValue: false, + RawKey: true, + RawValue: true, } - db.OpenAndWriteDB(dbVal, options, "./resources/asdf2.db") + db.ReadWriteRawN(dbVal, options, "./resources/hashx_utxo.csv", 10) + + // b, err := hex.DecodeString("000013") + // if err != nil { + // log.Println(err) + // } + // stopKey := &prefixes.UTXOKey{ + // Prefix: []byte{prefixes.UTXO}, + // HashX: b, + // TxNum: 0, + // Nout: 0, + // } + // stop := prefixes.UTXOKeyPackPartial(stopKey, 1) + + // log.Println(stop) + // log.Print(hex.EncodeToString(stop)) + + // options := &db.IterOptions{ + // FillCache: false, + // Prefix: []byte{prefixes.UTXO}, + // Start: nil, + // Stop: stop, + // IncludeStart: true, + // IncludeStop: false, + // IncludeKey: true, + // IncludeValue: true, + // RawKey: false, + // RawValue: false, + // } + + // db.OpenAndWriteDB(dbVal, options, "./resources/asdf2.db") return } diff --git a/resources/hashx_utxo.csv b/resources/hashx_utxo.csv new file mode 100644 index 0000000..c8b29ad --- /dev/null +++ b/resources/hashx_utxo.csv @@ -0,0 +1,10 @@ +680000003101376ce80000,6aabbc5b0b56a74c30b79c +680000004e030ee0020001,1aac16a91b039bc0973f24 +6800000080035180170001,e78d6cdf8bc312467c990e +680000009c019436d70000,38930e4a08cecad14adcd3 +68000000e002bcc37a0000,3257a0392780be8431f88c +6800000150003a51fa0003,d5520675286583e90224d0 +6800000150003a51fa0009,aaf3e77ac447ca99aac1a6 +68000001f1016aa3bc0001,9411eafd5cd93aea6e4f05 +680000020d01145ea60000,7e34e265da8283646e6deb +680000021a0343a97e0000,ea55b4498d415d92b556e6