diff --git a/db/db_get.go b/db/db_get.go index b4761e8..d9857b9 100644 --- a/db/db_get.go +++ b/db/db_get.go @@ -519,13 +519,13 @@ func (db *ReadOnlyDBColumnFamily) GetDBState() (*prefixes.DBStateValue, error) { return value, nil } -func (db *ReadOnlyDBColumnFamily) EffectiveAmountNameIter(normalizedName string) <-chan *prefixes.PrefixRowKV { - handle, err := db.EnsureHandle(prefixes.EffectiveAmount) +func (db *ReadOnlyDBColumnFamily) BidOrderNameIter(normalizedName string) <-chan *prefixes.PrefixRowKV { + handle, err := db.EnsureHandle(prefixes.BidOrder) if err != nil { return nil } - key := prefixes.NewEffectiveAmountKey(normalizedName) + key := prefixes.NewBidOrderKey(normalizedName) var rawKeyPrefix []byte = nil rawKeyPrefix = key.PartialPack(1) options := NewIterateOptions().WithCfHandle(handle).WithPrefix(rawKeyPrefix) diff --git a/db/db_resolve.go b/db/db_resolve.go index 07b991a..33970fc 100644 --- a/db/db_resolve.go +++ b/db/db_resolve.go @@ -281,15 +281,15 @@ func (db *ReadOnlyDBColumnFamily) ResolveParsedUrl(parsed *PathSegment) (*Resolv // Resolve by amount ordering log.Warn("resolving by amount ordering") - ch := db.EffectiveAmountNameIter(normalizedName) + ch := db.BidOrderNameIter(normalizedName) var i = 0 for kv := range ch { if i+1 < amountOrder { i++ continue } - key := kv.Key.(*prefixes.EffectiveAmountKey) - claimVal := kv.Value.(*prefixes.EffectiveAmountValue) + key := kv.Key.(*prefixes.BidOrderKey) + claimVal := kv.Value.(*prefixes.BidOrderValue) claimTxo, err := db.GetCachedClaimTxo(claimVal.ClaimHash, true) if err != nil { return nil, err diff --git a/db/prefixes/prefixes.go b/db/prefixes/prefixes.go index 0b22431..064e12d 100644 --- a/db/prefixes/prefixes.go +++ b/db/prefixes/prefixes.go @@ -32,7 +32,7 @@ const ( ChannelToClaim = 'J' ClaimShortIdPrefix = 'F' - EffectiveAmount = 'D' + BidOrder = 'D' ClaimExpiration = 'O' ClaimTakeover = 'P' @@ -83,7 +83,7 @@ func GetPrefixes() [][]byte { {ClaimToChannel}, {ChannelToClaim}, {ClaimShortIdPrefix}, - {EffectiveAmount}, + {BidOrder}, {ClaimExpiration}, {ClaimTakeover}, {PendingActivation}, @@ -2665,7 +2665,7 @@ func ActiveAmountValueUnpack(value []byte) *ActiveAmountValue { type OnesComplementEffectiveAmount uint64 -type EffectiveAmountKey struct { +type BidOrderKey struct { Prefix []byte `struct:"[1]byte" json:"prefix"` LengthEncodedNormalizedName // fields NormalizedNameLen, NormalizedName EffectiveAmount OnesComplementEffectiveAmount `json:"effective_amount"` @@ -2673,18 +2673,18 @@ type EffectiveAmountKey struct { Position uint16 `json:"position"` } -type EffectiveAmountValue struct { +type BidOrderValue struct { ClaimHash []byte `struct:"[20]byte" json:"claim_hash"` } -func NewEffectiveAmountKey(normalizedName string) *EffectiveAmountKey { - return &EffectiveAmountKey{ - Prefix: []byte{EffectiveAmount}, +func NewBidOrderKey(normalizedName string) *BidOrderKey { + return &BidOrderKey{ + Prefix: []byte{BidOrder}, LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(normalizedName), } } -func (k *EffectiveAmountKey) PackKey() []byte { +func (k *BidOrderKey) PackKey() []byte { prefixLen := 1 // 2 byte length field, plus number of bytes in name nameLen := len(k.NormalizedName) @@ -2703,7 +2703,7 @@ func (k *EffectiveAmountKey) PackKey() []byte { return key } -func (v *EffectiveAmountValue) PackValue() []byte { +func (v *BidOrderValue) PackValue() []byte { // b'>20s' value := make([]byte, 20) copy(value, v.ClaimHash[:20]) @@ -2711,11 +2711,11 @@ func (v *EffectiveAmountValue) PackValue() []byte { return value } -func (kv *EffectiveAmountKey) NumFields() int { +func (kv *BidOrderKey) NumFields() int { return 4 } -func (k *EffectiveAmountKey) PartialPack(fields int) []byte { +func (k *BidOrderKey) PartialPack(fields int) []byte { // Limit fields between 0 and number of fields, we always at least need // the prefix, and we never need to iterate past the number of fields. nameLen := len(k.NormalizedName) @@ -2763,10 +2763,10 @@ func (k *EffectiveAmountKey) PartialPack(fields int) []byte { return key } -func EffectiveAmountKeyUnpack(key []byte) *EffectiveAmountKey { +func BidOrderKeyUnpack(key []byte) *BidOrderKey { prefixLen := 1 nameLen := binary.BigEndian.Uint16(key[prefixLen:]) - return &EffectiveAmountKey{ + return &BidOrderKey{ Prefix: key[:prefixLen], LengthEncodedNormalizedName: NewLengthEncodedNormalizedName(string(key[prefixLen+2 : prefixLen+2+int(nameLen)])), EffectiveAmount: OnesComplementEffectiveAmount(OnesCompTwiddle64 - binary.BigEndian.Uint64(key[prefixLen+2+int(nameLen):])), @@ -2775,8 +2775,8 @@ func EffectiveAmountKeyUnpack(key []byte) *EffectiveAmountKey { } } -func EffectiveAmountValueUnpack(value []byte) *EffectiveAmountValue { - return &EffectiveAmountValue{ +func BidOrderValueUnpack(value []byte) *BidOrderValue { + return &BidOrderValue{ ClaimHash: value[:20], } } @@ -3651,18 +3651,18 @@ var prefixRegistry = map[byte]prefixMeta{ return ClaimShortIDValueUnpack(buf) }, }, - EffectiveAmount: { + BidOrder: { newKey: func() interface{} { - return &EffectiveAmountKey{Prefix: []byte{EffectiveAmount}} + return &BidOrderKey{Prefix: []byte{BidOrder}} }, newValue: func() interface{} { - return &EffectiveAmountValue{} + return &BidOrderValue{} }, newKeyUnpack: func(buf []byte) interface{} { - return EffectiveAmountKeyUnpack(buf) + return BidOrderKeyUnpack(buf) }, newValueUnpack: func(buf []byte) interface{} { - return EffectiveAmountValueUnpack(buf) + return BidOrderValueUnpack(buf) }, }, ClaimExpiration: { diff --git a/db/prefixes/prefixes_test.go b/db/prefixes/prefixes_test.go index 0882849..248e377 100644 --- a/db/prefixes/prefixes_test.go +++ b/db/prefixes/prefixes_test.go @@ -311,9 +311,9 @@ func TestActiveAmount(t *testing.T) { testGeneric(filePath, prefixes.ActiveAmount, 5)(t) } -func TestEffectiveAmount(t *testing.T) { - filePath := fmt.Sprintf("../../testdata/%c.csv", prefixes.EffectiveAmount) - testGeneric(filePath, prefixes.EffectiveAmount, 4)(t) +func TestBidOrder(t *testing.T) { + filePath := fmt.Sprintf("../../testdata/%c.csv", prefixes.BidOrder) + testGeneric(filePath, prefixes.BidOrder, 4)(t) } func TestRepost(t *testing.T) {