From 2c9be1d8a804f81d02a4c4cd1c7b15cd34131e75 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:02:19 -0400 Subject: [PATCH] Rename prefix EffectiveAmount -> BidOrder. --- db/db_get.go | 6 +++--- db/db_resolve.go | 6 +++--- db/prefixes/prefixes.go | 40 ++++++++++++++++++------------------ db/prefixes/prefixes_test.go | 6 +++--- 4 files changed, 29 insertions(+), 29 deletions(-) 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) {