Add RepostedCount, EffectiveAmount prefix rows. Add testdata.
This commit is contained in:
parent
2c9be1d8a8
commit
5fb3b4388a
4 changed files with 191 additions and 0 deletions
|
@ -66,6 +66,9 @@ const (
|
|||
HashXStatus = 'f'
|
||||
HashXMempoolStatus = 'g'
|
||||
|
||||
EffectiveAmount = 'i'
|
||||
RepostedCount = 'j'
|
||||
|
||||
ActivateClaimTXOType = 1
|
||||
ActivatedSupportTXOType = 2
|
||||
|
||||
|
@ -111,6 +114,8 @@ func GetPrefixes() [][]byte {
|
|||
{TouchedHashX},
|
||||
{HashXStatus},
|
||||
{HashXMempoolStatus},
|
||||
{EffectiveAmount},
|
||||
{RepostedCount},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2968,6 +2973,62 @@ func RepostedValueUnpack(value []byte) *RepostedValue {
|
|||
}
|
||||
}
|
||||
|
||||
type RepostedCountKey struct {
|
||||
Prefix []byte `struct:"[1]byte" json:"prefix"`
|
||||
ClaimHash []byte `struct:"[20]byte" json:"claim_hash"`
|
||||
}
|
||||
|
||||
type RepostedCountValue struct {
|
||||
RepostedCount uint32 `json:"reposted_count"`
|
||||
}
|
||||
|
||||
func (kv *RepostedCountKey) NumFields() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (kv *RepostedCountKey) PartialPack(fields int) []byte {
|
||||
// b'>20s'
|
||||
n := len(kv.Prefix) + 20
|
||||
buf := make([]byte, n)
|
||||
offset := 0
|
||||
offset += copy(buf[offset:], kv.Prefix[:1])
|
||||
if fields <= 0 {
|
||||
return buf[:offset]
|
||||
}
|
||||
offset += copy(buf[offset:], kv.ClaimHash[:20])
|
||||
return buf[:offset]
|
||||
}
|
||||
|
||||
func (kv *RepostedCountKey) PackKey() []byte {
|
||||
return kv.PartialPack(kv.NumFields())
|
||||
}
|
||||
|
||||
func (kv *RepostedCountKey) UnpackKey(buf []byte) {
|
||||
// b'>20s'
|
||||
offset := 0
|
||||
kv.Prefix = buf[offset : offset+1]
|
||||
offset += 1
|
||||
kv.ClaimHash = buf[offset : offset+20]
|
||||
offset += 20
|
||||
}
|
||||
|
||||
func (kv *RepostedCountValue) PackValue() []byte {
|
||||
// b'>L'
|
||||
n := 4
|
||||
buf := make([]byte, n)
|
||||
offset := 0
|
||||
binary.BigEndian.PutUint32(buf[offset:], kv.RepostedCount)
|
||||
offset += 4
|
||||
return buf[:offset]
|
||||
}
|
||||
|
||||
func (kv *RepostedCountValue) UnpackValue(buf []byte) {
|
||||
// b'>L'
|
||||
offset := 0
|
||||
kv.RepostedCount = binary.BigEndian.Uint32(buf[offset:])
|
||||
offset += 4
|
||||
}
|
||||
|
||||
type TouchedOrDeletedClaimKey struct {
|
||||
Prefix []byte `struct:"[1]byte" json:"prefix"`
|
||||
Height int32 `json:"height"`
|
||||
|
@ -3462,6 +3523,62 @@ func (kv *HashXStatusValue) UnpackValue(buf []byte) {
|
|||
type HashXMempoolStatusKey = HashXStatusKey
|
||||
type HashXMempoolStatusValue = HashXStatusValue
|
||||
|
||||
type EffectiveAmountKey struct {
|
||||
Prefix []byte `struct:"[1]byte" json:"prefix"`
|
||||
ClaimHash []byte `struct:"[20]byte" json:"claim_hash"`
|
||||
}
|
||||
|
||||
type EffectiveAmountValue struct {
|
||||
EffectiveAmount uint64 `json:"effective_amount"`
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountKey) NumFields() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountKey) PartialPack(fields int) []byte {
|
||||
// b'>20s'
|
||||
n := len(kv.Prefix) + 20
|
||||
buf := make([]byte, n)
|
||||
offset := 0
|
||||
offset += copy(buf[offset:], kv.Prefix[:1])
|
||||
if fields <= 0 {
|
||||
return buf[:offset]
|
||||
}
|
||||
offset += copy(buf[offset:], kv.ClaimHash[:20])
|
||||
return buf[:offset]
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountKey) PackKey() []byte {
|
||||
return kv.PartialPack(kv.NumFields())
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountKey) UnpackKey(buf []byte) {
|
||||
// b'>20s'
|
||||
offset := 0
|
||||
kv.Prefix = buf[offset : offset+1]
|
||||
offset += 1
|
||||
kv.ClaimHash = buf[offset : offset+20]
|
||||
offset += 20
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountValue) PackValue() []byte {
|
||||
// b'>Q'
|
||||
n := 8
|
||||
buf := make([]byte, n)
|
||||
offset := 0
|
||||
binary.BigEndian.PutUint64(buf[offset:], kv.EffectiveAmount)
|
||||
offset += 8
|
||||
return buf[:offset]
|
||||
}
|
||||
|
||||
func (kv *EffectiveAmountValue) UnpackValue(buf []byte) {
|
||||
// b'>Q'
|
||||
offset := 0
|
||||
kv.EffectiveAmount = binary.BigEndian.Uint64(buf[offset:])
|
||||
offset += 8
|
||||
}
|
||||
|
||||
func UnpackGenericKey(key []byte) (BaseKey, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, fmt.Errorf("key length zero")
|
||||
|
@ -4018,4 +4135,20 @@ var prefixRegistry = map[byte]prefixMeta{
|
|||
return &HashXMempoolStatusValue{}
|
||||
},
|
||||
},
|
||||
RepostedCount: {
|
||||
newKey: func() interface{} {
|
||||
return &RepostedCountKey{Prefix: []byte{RepostedCount}}
|
||||
},
|
||||
newValue: func() interface{} {
|
||||
return &RepostedCountValue{}
|
||||
},
|
||||
},
|
||||
EffectiveAmount: {
|
||||
newKey: func() interface{} {
|
||||
return &EffectiveAmountKey{Prefix: []byte{EffectiveAmount}}
|
||||
},
|
||||
newValue: func() interface{} {
|
||||
return &EffectiveAmountValue{}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -326,6 +326,14 @@ func TestRepostedClaim(t *testing.T) {
|
|||
testGeneric(filePath, prefixes.RepostedClaim, 3)(t)
|
||||
}
|
||||
|
||||
func TestRepostedCount(t *testing.T) {
|
||||
prefix := byte(prefixes.RepostedCount)
|
||||
filePath := fmt.Sprintf("../../testdata/%c.csv", prefix)
|
||||
//synthesizeTestData([]byte{prefix}, filePath, []int{20}, []int{4}, [][3]int{})
|
||||
key := &prefixes.RepostedCountKey{}
|
||||
testGeneric(filePath, prefix, key.NumFields())(t)
|
||||
}
|
||||
|
||||
func TestClaimDiff(t *testing.T) {
|
||||
filePath := fmt.Sprintf("../../testdata/%c.csv", prefixes.ClaimDiff)
|
||||
testGeneric(filePath, prefixes.ClaimDiff, 1)(t)
|
||||
|
@ -418,6 +426,14 @@ func TestHashXMempoolStatus(t *testing.T) {
|
|||
testGeneric(filePath, prefix, key.NumFields())(t)
|
||||
}
|
||||
|
||||
func TestEffectiveAmount(t *testing.T) {
|
||||
prefix := byte(prefixes.EffectiveAmount)
|
||||
filePath := fmt.Sprintf("../../testdata/%c.csv", prefix)
|
||||
//synthesizeTestData([]byte{prefix}, filePath, []int{20}, []int{8}, [][3]int{})
|
||||
key := &prefixes.EffectiveAmountKey{}
|
||||
testGeneric(filePath, prefix, key.NumFields())(t)
|
||||
}
|
||||
|
||||
func synthesizeTestData(prefix []byte, filePath string, keyFixed, valFixed []int, valVariable [][3]int) {
|
||||
file, err := os.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
|
|
21
testdata/i.csv
vendored
Normal file
21
testdata/i.csv
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
i,
|
||||
6903dc9970183b8a05d118c84a37c355fe34d95d01,0e74dd23295a4610
|
||||
6916bd29750d8d92b32677eda07e10af313c0019d9,ff0579207ec6e594
|
||||
6926bdfcb4a1ad81f460ad561283584695cd6cea59,b834b13a8918262f
|
||||
6930776827481ec15fa07e0dc266e376846467237d,4bf0a5127a1216dc
|
||||
6955a1eaf08f9468a6c3565fe16b2ae4b726045538,e32029de8b58dd6e
|
||||
69614fa6bc0cea1366377456bc88dda9ec7b6d4c3c,55bf2d8e0e262697
|
||||
6971e7b039dde5797ae167b9783f87c4a67711799d,9197b827b560fc34
|
||||
697765a71d8a4082d056baaae83f8b4af1e124f5e9,62c0d5dfde7ef884
|
||||
6993e121642c01e2edca50d565ff3df1a656e83ebd,1796c74886d45045
|
||||
69af0684076bc64adcbcd621de9c09fd15dade3e17,f9240ab9a9650d9f
|
||||
69b70fdcc95d3b51ec28872a143c7a6fc947e6a58e,a8950968d95759a9
|
||||
69bdb90916f78badec506a895b0edceb47533297f9,331c0ca597601ed7
|
||||
69c276b7070ba79e75c82e4d97a70e4428dd3be058,85c61c842e5bfe7f
|
||||
69cb8215b0c9440227a9e7e76bce468bdb4fa0f714,9c42e1ba41275362
|
||||
69d2556fe7b8fce36a71c78e0001452298903ef81b,f61cf52e7e645bf8
|
||||
69d2677078f1448c0e4295711e61a85a9fb6a280d1,28d57b45b1700cb3
|
||||
69dd979490444cab3efc1e517f83369df6e2e279a3,dad1b5133cc15dd4
|
||||
69e6e6834cf0da132c77af275cbab9885cbbc3f022,df55f9fd0278ca71
|
||||
69ea25444b8d0ab22ac355f4b692b0d7006b672f4a,0703f38a1428ff8e
|
||||
69fcb79c5e463ac4a0e078f9cd24e2c718b66c40d6,5be7b71b6dca5a20
|
|
21
testdata/j.csv
vendored
Normal file
21
testdata/j.csv
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
j,
|
||||
6a2bb6a2e0505748602cb9a194ba8ea4abb6935407,cc786896
|
||||
6a44f45448398072520cd2415044dc3fbfc4f77d94,b5d69fdb
|
||||
6a464f73e50c5ac613e29959eaf7862989381fd2d7,f4a3151d
|
||||
6a615c78bcea987123689221ec5546f4555c7ddf4d,02e0ca23
|
||||
6a86f3151c381d0e7061583051ea2de133976cab73,b1f56fd8
|
||||
6a875a5f2579fce1aed7b452dbcfb982161d9d35ad,fbe72e11
|
||||
6a8edc85a5a8aa78fd6a7f0a9e3755121238ae5dcb,2f3ec916
|
||||
6a90efc239731fa0b83c2a386c1426e8768ceb2123,6b8b1649
|
||||
6a951540c279d1286d7800d205aea75f514b9e8fdb,e78656c9
|
||||
6aa687dae05e6d629d5056e1af651519dfc669f40c,07665a81
|
||||
6abaa8f75ae7182dfa70b293317acd3aaa8d021b5f,f51abc2b
|
||||
6abc6bcaf274827e976bfa8ee5801d24c4b37bb77b,d171f0fe
|
||||
6ac5717e0820d8bcf758690666a7dff87850e58af1,afbe5e50
|
||||
6ac6cfb7ee16de9c7f6498939558881ffa346f0918,00a40c49
|
||||
6ad24f0b126ae7bcdfb70f51b3ade58bbfd22dc94c,739a1ba9
|
||||
6ad89bcd32e80b4b89b6ac066d87e1a1356d7d5e4e,5605f288
|
||||
6ae49f7dcc373786b526e4393ff46d300ee5f4a9dd,dfe41d24
|
||||
6aedfe781fb0ce858856eff6aacc2206525545e476,59508a47
|
||||
6aeffec292f14000b7c073b861f2ad83c5511a2df8,afe94781
|
||||
6afbdd9ec076dbf81511264f00f021c9667e52cb67,51ffc92a
|
|
Loading…
Reference in a new issue