Catchup to python-herald schema. Plus lots of refactoring. #49

Merged
moodyjon merged 18 commits from schema_catchup into master 2022-08-16 07:45:42 +02:00
Showing only changes of commit d42ac9feab - Show all commits

View file

@ -3222,13 +3222,13 @@ func UTXOValueUnpack(value []byte) *UTXOValue {
type TrendingNotificationKey struct { type TrendingNotificationKey struct {
Prefix []byte `struct:"[1]byte" json:"prefix"` Prefix []byte `struct:"[1]byte" json:"prefix"`
Height uint32 `struct:"uint32" json:"height"` Height uint32 `json:"height"`
ClaimHash []byte `struct:"[20]byte" json:"claim_hash"` ClaimHash []byte `struct:"[20]byte" json:"claim_hash"`
} }
type TrendingNotificationValue struct { type TrendingNotificationValue struct {
PreviousAmount uint64 `struct:"uint64" json:"previous_amount"` PreviousAmount uint64 `json:"previous_amount"`
NewAmount uint64 `struct:"uint64" json:"new_amount"` NewAmount uint64 `json:"new_amount"`
} }
func (kv *TrendingNotificationKey) NumFields() int { func (kv *TrendingNotificationKey) NumFields() int {
@ -3302,7 +3302,7 @@ func (kv *MempoolTxKey) NumFields() int {
return 1 return 1
} }
func (kv *MempoolTxKey) Pack(fields int) []byte { func (kv *MempoolTxKey) PartialPack(fields int) []byte {
// b'>32s' // b'>32s'
n := len(kv.Prefix) + 32 n := len(kv.Prefix) + 32
buf := make([]byte, n) buf := make([]byte, n)
@ -3315,6 +3315,10 @@ func (kv *MempoolTxKey) Pack(fields int) []byte {
return buf[:offset] return buf[:offset]
} }
func (kv *MempoolTxKey) PackKey() []byte {
return kv.PartialPack(kv.NumFields())
}
func (kv *MempoolTxKey) UnpackKey(buf []byte) { func (kv *MempoolTxKey) UnpackKey(buf []byte) {
// b'>32s' // b'>32s'
offset := 0 offset := 0
@ -3342,7 +3346,7 @@ func (kv *MempoolTxValue) UnpackValue(buf []byte) {
type TouchedHashXKey struct { type TouchedHashXKey struct {
Prefix []byte `struct:"[1]byte" json:"prefix"` Prefix []byte `struct:"[1]byte" json:"prefix"`
Height uint32 `struct:"uint32" json:"height"` Height uint32 `json:"height"`
} }
type TouchedHashXValue struct { type TouchedHashXValue struct {
@ -3394,6 +3398,7 @@ func (kv *TouchedHashXValue) PackValue() []byte {
func (kv *TouchedHashXValue) UnpackValue(buf []byte) { func (kv *TouchedHashXValue) UnpackValue(buf []byte) {
// variable length bytes // variable length bytes
n := len(buf) n := len(buf)
kv.TouchedHashXs = make([][]byte, n/11)
for i, offset := 0, 0; offset+11 <= n; i, offset = i+1, offset+11 { for i, offset := 0, 0; offset+11 <= n; i, offset = i+1, offset+11 {
kv.TouchedHashXs[i] = buf[offset : offset+11] kv.TouchedHashXs[i] = buf[offset : offset+11]
} }