Tx and big refactor
This commit is contained in:
parent
46cbf2280d
commit
78931448e6
4 changed files with 587 additions and 1756 deletions
|
@ -91,6 +91,12 @@ func (v *UndoValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UndoKeyPackPartialKey(key *UndoKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return UndoKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UndoKeyPackPartialNFields(nFields int) func(*UndoKey) []byte {
|
func UndoKeyPackPartialNFields(nFields int) func(*UndoKey) []byte {
|
||||||
return func(u *UndoKey) []byte {
|
return func(u *UndoKey) []byte {
|
||||||
return UndoKeyPackPartial(u, nFields)
|
return UndoKeyPackPartial(u, nFields)
|
||||||
|
@ -209,6 +215,13 @@ func (v *HashXUTXOValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HashXUTXOKeyPackPartialKey creates a pack partial key function for n fields.
|
||||||
|
func HashXUTXOKeyPackPartialKey(key *HashXUTXOKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return HashXUTXOKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HashXUTXOKeyPackPartialNFields creates a pack partial key function for n fields.
|
// HashXUTXOKeyPackPartialNFields creates a pack partial key function for n fields.
|
||||||
func HashXUTXOKeyPackPartialNFields(nFields int) func(*HashXUTXOKey) []byte {
|
func HashXUTXOKeyPackPartialNFields(nFields int) func(*HashXUTXOKey) []byte {
|
||||||
return func(u *HashXUTXOKey) []byte {
|
return func(u *HashXUTXOKey) []byte {
|
||||||
|
@ -330,6 +343,13 @@ func (v *HashXHistoryValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HashXHistoryKeyPackPartialKey creates a pack partial key function for n fields.
|
||||||
|
func HashXHistoryKeyPackPartialKey(key *HashXHistoryKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return HashXHistoryKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HashXHistoryKeyPackPartialNFields creates a pack partial key function for n fields.
|
// HashXHistoryKeyPackPartialNFields creates a pack partial key function for n fields.
|
||||||
func HashXHistoryKeyPackPartialNFields(nFields int) func(*HashXHistoryKey) []byte {
|
func HashXHistoryKeyPackPartialNFields(nFields int) func(*HashXHistoryKey) []byte {
|
||||||
return func(u *HashXHistoryKey) []byte {
|
return func(u *HashXHistoryKey) []byte {
|
||||||
|
@ -435,6 +455,12 @@ func (v *BlockHashValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BlockHashKeyPackPartialKey(key *BlockHashKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return BlockHashKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BlockHashKeyPackPartialNFields(nFields int) func(*BlockHashKey) []byte {
|
func BlockHashKeyPackPartialNFields(nFields int) func(*BlockHashKey) []byte {
|
||||||
return func(u *BlockHashKey) []byte {
|
return func(u *BlockHashKey) []byte {
|
||||||
return BlockHashKeyPackPartial(u, nFields)
|
return BlockHashKeyPackPartial(u, nFields)
|
||||||
|
@ -595,6 +621,83 @@ type TxValue struct {
|
||||||
RawTx []byte `json:"raw_tx"`
|
RawTx []byte `json:"raw_tx"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k *TxKey) PackKey() []byte {
|
||||||
|
prefixLen := 1
|
||||||
|
// b'>L'
|
||||||
|
n := prefixLen + 32
|
||||||
|
key := make([]byte, n)
|
||||||
|
copy(key, k.Prefix)
|
||||||
|
copy(key[prefixLen:], k.TxHash[:32])
|
||||||
|
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *TxValue) PackValue() []byte {
|
||||||
|
value := make([]byte, len(v.RawTx))
|
||||||
|
copy(value, v.RawTx)
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func TxKeyPackPartialKey(key *TxKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return TxKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TxKeyPackPartialNFields(nFields int) func(*TxKey) []byte {
|
||||||
|
return func(u *TxKey) []byte {
|
||||||
|
return TxKeyPackPartial(u, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TxKeyPackPartial(k *TxKey, 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 > 1 {
|
||||||
|
nFields = 1
|
||||||
|
}
|
||||||
|
if nFields < 0 {
|
||||||
|
nFields = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
prefixLen := 1
|
||||||
|
var n = prefixLen
|
||||||
|
for i := 0; i <= nFields; i++ {
|
||||||
|
switch i {
|
||||||
|
case 1:
|
||||||
|
n += 32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
key := make([]byte, n)
|
||||||
|
|
||||||
|
for i := 0; i <= nFields; i++ {
|
||||||
|
switch i {
|
||||||
|
case 0:
|
||||||
|
copy(key, k.Prefix)
|
||||||
|
case 1:
|
||||||
|
copy(key[prefixLen:], k.TxHash[:32])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
func TxKeyUnpack(key []byte) *TxKey {
|
||||||
|
prefixLen := 1
|
||||||
|
return &TxKey{
|
||||||
|
Prefix: key[:prefixLen],
|
||||||
|
TxHash: key[prefixLen : prefixLen+32],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TxValueUnpack(value []byte) *TxValue {
|
||||||
|
return &TxValue{
|
||||||
|
RawTx: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class BlockHeaderKey(NamedTuple):
|
class BlockHeaderKey(NamedTuple):
|
||||||
height: int
|
height: int
|
||||||
|
@ -634,6 +737,12 @@ func (v *BlockHeaderValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BlockHeaderKeyPackPartialKey(key *BlockHeaderKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return BlockHeaderKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BlockHeaderKeyPackPartialNFields(nFields int) func(*BlockHeaderKey) []byte {
|
func BlockHeaderKeyPackPartialNFields(nFields int) func(*BlockHeaderKey) []byte {
|
||||||
return func(u *BlockHeaderKey) []byte {
|
return func(u *BlockHeaderKey) []byte {
|
||||||
return BlockHeaderKeyPackPartial(u, nFields)
|
return BlockHeaderKeyPackPartial(u, nFields)
|
||||||
|
@ -766,6 +875,12 @@ func (v *ClaimToTXOValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimToTXOKeyPackPartialKey(key *ClaimToTXOKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimToTXOKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimToTXOKeyPackPartialNFields(nFields int) func(*ClaimToTXOKey) []byte {
|
func ClaimToTXOKeyPackPartialNFields(nFields int) func(*ClaimToTXOKey) []byte {
|
||||||
return func(u *ClaimToTXOKey) []byte {
|
return func(u *ClaimToTXOKey) []byte {
|
||||||
return ClaimToTXOKeyPackPartial(u, nFields)
|
return ClaimToTXOKeyPackPartial(u, nFields)
|
||||||
|
@ -875,6 +990,12 @@ func (v *TXOToClaimValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TXOToClaimKeyPackPartialKey(key *TXOToClaimKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return TXOToClaimKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TXOToClaimKeyPackPartialNFields(nFields int) func(*TXOToClaimKey) []byte {
|
func TXOToClaimKeyPackPartialNFields(nFields int) func(*TXOToClaimKey) []byte {
|
||||||
return func(u *TXOToClaimKey) []byte {
|
return func(u *TXOToClaimKey) []byte {
|
||||||
return TXOToClaimKeyPackPartial(u, nFields)
|
return TXOToClaimKeyPackPartial(u, nFields)
|
||||||
|
@ -992,6 +1113,12 @@ func (v *ClaimShortIDValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimShortIDKeyPackPartialKey(key *ClaimShortIDKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimShortIDKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimShortIDKeyPackPartialNFields(nFields int) func(*ClaimShortIDKey) []byte {
|
func ClaimShortIDKeyPackPartialNFields(nFields int) func(*ClaimShortIDKey) []byte {
|
||||||
return func(u *ClaimShortIDKey) []byte {
|
return func(u *ClaimShortIDKey) []byte {
|
||||||
return ClaimShortIDKeyPackPartial(u, nFields)
|
return ClaimShortIDKeyPackPartial(u, nFields)
|
||||||
|
@ -1118,6 +1245,12 @@ func (v *ClaimToChannelValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimToChannelKeyPackPartialKey(key *ClaimToChannelKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimToChannelKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimToChannelKeyPackPartialNFields(nFields int) func(*ClaimToChannelKey) []byte {
|
func ClaimToChannelKeyPackPartialNFields(nFields int) func(*ClaimToChannelKey) []byte {
|
||||||
return func(u *ClaimToChannelKey) []byte {
|
return func(u *ClaimToChannelKey) []byte {
|
||||||
return ClaimToChannelKeyPackPartial(u, nFields)
|
return ClaimToChannelKeyPackPartial(u, nFields)
|
||||||
|
@ -1235,6 +1368,12 @@ func (v *ChannelToClaimValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChannelToClaimKeyPackPartialKey(key *ChannelToClaimKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ChannelToClaimKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ChannelToClaimKeyPackPartialNFields(nFields int) func(*ChannelToClaimKey) []byte {
|
func ChannelToClaimKeyPackPartialNFields(nFields int) func(*ChannelToClaimKey) []byte {
|
||||||
return func(u *ChannelToClaimKey) []byte {
|
return func(u *ChannelToClaimKey) []byte {
|
||||||
return ChannelToClaimKeyPackPartial(u, nFields)
|
return ChannelToClaimKeyPackPartial(u, nFields)
|
||||||
|
@ -1396,6 +1535,12 @@ func (v *ClaimToSupportValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimToSupportKeyPackPartialKey(key *ClaimToSupportKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimToSupportKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimToSupportKeyPackPartialNFields(nFields int) func(*ClaimToSupportKey) []byte {
|
func ClaimToSupportKeyPackPartialNFields(nFields int) func(*ClaimToSupportKey) []byte {
|
||||||
return func(u *ClaimToSupportKey) []byte {
|
return func(u *ClaimToSupportKey) []byte {
|
||||||
return ClaimToSupportKeyPackPartial(u, nFields)
|
return ClaimToSupportKeyPackPartial(u, nFields)
|
||||||
|
@ -1502,6 +1647,12 @@ func (v *SupportToClaimValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SupportToClaimKeyPackPartialKey(key *SupportToClaimKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return SupportToClaimKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func SupportToClaimKeyPackPartialNFields(nFields int) func(*SupportToClaimKey) []byte {
|
func SupportToClaimKeyPackPartialNFields(nFields int) func(*SupportToClaimKey) []byte {
|
||||||
return func(u *SupportToClaimKey) []byte {
|
return func(u *SupportToClaimKey) []byte {
|
||||||
return SupportToClaimKeyPackPartial(u, nFields)
|
return SupportToClaimKeyPackPartial(u, nFields)
|
||||||
|
@ -1611,6 +1762,12 @@ func (v *ClaimExpirationValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimExpirationKeyPackPartialKey(key *ClaimExpirationKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimExpirationKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimExpirationKeyPackPartialNFields(nFields int) func(*ClaimExpirationKey) []byte {
|
func ClaimExpirationKeyPackPartialNFields(nFields int) func(*ClaimExpirationKey) []byte {
|
||||||
return func(u *ClaimExpirationKey) []byte {
|
return func(u *ClaimExpirationKey) []byte {
|
||||||
return ClaimExpirationKeyPackPartial(u, nFields)
|
return ClaimExpirationKeyPackPartial(u, nFields)
|
||||||
|
@ -1730,6 +1887,12 @@ func (v *ClaimTakeoverValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClaimTakeoverKeyPackPartialKey(key *ClaimTakeoverKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ClaimTakeoverKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClaimTakeoverKeyPackPartialNFields(nFields int) func(*ClaimTakeoverKey) []byte {
|
func ClaimTakeoverKeyPackPartialNFields(nFields int) func(*ClaimTakeoverKey) []byte {
|
||||||
return func(u *ClaimTakeoverKey) []byte {
|
return func(u *ClaimTakeoverKey) []byte {
|
||||||
return ClaimTakeoverKeyPackPartial(u, nFields)
|
return ClaimTakeoverKeyPackPartial(u, nFields)
|
||||||
|
@ -1858,6 +2021,12 @@ func (v *PendingActivationValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PendingActivationKeyPackPartialKey(key *PendingActivationKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return PendingActivationKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func PendingActivationKeyPackPartialNFields(nFields int) func(*PendingActivationKey) []byte {
|
func PendingActivationKeyPackPartialNFields(nFields int) func(*PendingActivationKey) []byte {
|
||||||
return func(u *PendingActivationKey) []byte {
|
return func(u *PendingActivationKey) []byte {
|
||||||
return PendingActivationKeyPackPartial(u, nFields)
|
return PendingActivationKeyPackPartial(u, nFields)
|
||||||
|
@ -1984,6 +2153,12 @@ func (v *ActivationValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ActivationKeyPackPartialKey(key *ActivationKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ActivationKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ActivationKeyPackPartialNFields(nFields int) func(*ActivationKey) []byte {
|
func ActivationKeyPackPartialNFields(nFields int) func(*ActivationKey) []byte {
|
||||||
return func(u *ActivationKey) []byte {
|
return func(u *ActivationKey) []byte {
|
||||||
return ActivationKeyPackPartial(u, nFields)
|
return ActivationKeyPackPartial(u, nFields)
|
||||||
|
@ -2104,6 +2279,12 @@ func (v *ActiveAmountValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ActiveAmountKeyPackPartialKey(key *ActiveAmountKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return ActiveAmountKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ActiveAmountKeyPackPartialNFields(nFields int) func(*ActiveAmountKey) []byte {
|
func ActiveAmountKeyPackPartialNFields(nFields int) func(*ActiveAmountKey) []byte {
|
||||||
return func(u *ActiveAmountKey) []byte {
|
return func(u *ActiveAmountKey) []byte {
|
||||||
return ActiveAmountKeyPackPartial(u, nFields)
|
return ActiveAmountKeyPackPartial(u, nFields)
|
||||||
|
@ -2235,6 +2416,12 @@ func (v *EffectiveAmountValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EffectiveAmountKeyPackPartialKey(key *EffectiveAmountKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return EffectiveAmountKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func EffectiveAmountKeyPackPartialNFields(nFields int) func(*EffectiveAmountKey) []byte {
|
func EffectiveAmountKeyPackPartialNFields(nFields int) func(*EffectiveAmountKey) []byte {
|
||||||
return func(u *EffectiveAmountKey) []byte {
|
return func(u *EffectiveAmountKey) []byte {
|
||||||
return EffectiveAmountKeyPackPartial(u, nFields)
|
return EffectiveAmountKeyPackPartial(u, nFields)
|
||||||
|
@ -2352,6 +2539,12 @@ func (v *RepostValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RepostKeyPackPartialKey(key *RepostKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return RepostKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func RepostKeyPackPartialNFields(nFields int) func(*RepostKey) []byte {
|
func RepostKeyPackPartialNFields(nFields int) func(*RepostKey) []byte {
|
||||||
return func(u *RepostKey) []byte {
|
return func(u *RepostKey) []byte {
|
||||||
return RepostKeyPackPartial(u, nFields)
|
return RepostKeyPackPartial(u, nFields)
|
||||||
|
@ -2456,6 +2649,12 @@ func (v *RepostedValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RepostedKeyPackPartialKey(key *RepostedKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return RepostedKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func RepostedKeyPackPartialNFields(nFields int) func(*RepostedKey) []byte {
|
func RepostedKeyPackPartialNFields(nFields int) func(*RepostedKey) []byte {
|
||||||
return func(u *RepostedKey) []byte {
|
return func(u *RepostedKey) []byte {
|
||||||
return RepostedKeyPackPartial(u, nFields)
|
return RepostedKeyPackPartial(u, nFields)
|
||||||
|
@ -2629,6 +2828,12 @@ func (v *TouchedOrDeletedClaimValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TouchedOrDeletedClaimKeyPackPartialKey(key *TouchedOrDeletedClaimKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return TouchedOrDeletedClaimKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TouchedOrDeletedClaimPackPartialNFields(nFields int) func(*TouchedOrDeletedClaimKey) []byte {
|
func TouchedOrDeletedClaimPackPartialNFields(nFields int) func(*TouchedOrDeletedClaimKey) []byte {
|
||||||
return func(u *TouchedOrDeletedClaimKey) []byte {
|
return func(u *TouchedOrDeletedClaimKey) []byte {
|
||||||
return TouchedOrDeletedClaimKeyPackPartial(u, nFields)
|
return TouchedOrDeletedClaimKeyPackPartial(u, nFields)
|
||||||
|
@ -2730,7 +2935,12 @@ func (k *UTXOValue) PackValue() []byte {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTXOKeyPackPartialNFields creates a pack partial key function for n fields.
|
func UTXOKeyPackPartialKey(key *UTXOKey) func(int) []byte {
|
||||||
|
return func(nFields int) []byte {
|
||||||
|
return UTXOKeyPackPartial(key, nFields)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UTXOKeyPackPartialNFields(nFields int) func(*UTXOKey) []byte {
|
func UTXOKeyPackPartialNFields(nFields int) func(*UTXOKey) []byte {
|
||||||
return func(u *UTXOKey) []byte {
|
return func(u *UTXOKey) []byte {
|
||||||
return UTXOKeyPackPartial(u, nFields)
|
return UTXOKeyPackPartial(u, nFields)
|
||||||
|
@ -2797,76 +3007,267 @@ func UTXOValueUnpack(value []byte) *UTXOValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnpackGenericKey(key []byte) (byte, interface{}, error) {
|
func generic(voidstar interface{}, firstByte byte, function byte, functionName string) (byte, interface{}, error) {
|
||||||
if len(key) == 0 {
|
var data []byte
|
||||||
return 0x0, nil, errors.Base("key length zero")
|
if function < 2 {
|
||||||
|
data = voidstar.([]byte)
|
||||||
}
|
}
|
||||||
firstByte := key[0]
|
switch uint16(firstByte) | uint16(function)<<8 {
|
||||||
switch firstByte {
|
|
||||||
case ClaimToSupport:
|
case ClaimToSupport:
|
||||||
return ClaimToSupport, ClaimToSupportKeyUnpack(key), nil
|
return ClaimToSupport, ClaimToSupportKeyUnpack(data), nil
|
||||||
|
case ClaimToSupport | 1<<8:
|
||||||
|
return ClaimToSupport, ClaimToSupportValueUnpack(data), nil
|
||||||
|
case ClaimToSupport | 2<<8:
|
||||||
|
return ClaimToSupport, voidstar.(*ClaimToSupportKey).PackKey(), nil
|
||||||
|
case ClaimToSupport | 3<<8:
|
||||||
|
return ClaimToSupport, voidstar.(*ClaimToSupportValue).PackValue(), nil
|
||||||
|
case ClaimToSupport | 4<<8:
|
||||||
|
return ClaimToSupport, ClaimToSupportKeyPackPartialKey(voidstar.(*ClaimToSupportKey)), nil
|
||||||
case SupportToClaim:
|
case SupportToClaim:
|
||||||
return SupportToClaim, SupportToClaimKeyUnpack(key), nil
|
return SupportToClaim, SupportToClaimKeyUnpack(data), nil
|
||||||
|
case SupportToClaim | 1<<8:
|
||||||
|
return SupportToClaim, SupportToClaimValueUnpack(data), nil
|
||||||
|
case SupportToClaim | 2<<8:
|
||||||
|
return SupportToClaim, voidstar.(*SupportToClaimKey).PackKey(), nil
|
||||||
|
case SupportToClaim | 3<<8:
|
||||||
|
return SupportToClaim, voidstar.(*SupportToClaimValue).PackValue(), nil
|
||||||
|
case SupportToClaim | 4<<8:
|
||||||
|
return SupportToClaim, SupportToClaimKeyPackPartialKey(voidstar.(*SupportToClaimKey)), nil
|
||||||
case ClaimToTXO:
|
case ClaimToTXO:
|
||||||
return ClaimToTXO, ClaimToTXOKeyUnpack(key), nil
|
return ClaimToTXO, ClaimToTXOKeyUnpack(data), nil
|
||||||
|
case ClaimToTXO | 1<<8:
|
||||||
|
return ClaimToTXO, ClaimToTXOValueUnpack(data), nil
|
||||||
|
case ClaimToTXO | 2<<8:
|
||||||
|
return ClaimToTXO, voidstar.(*ClaimToTXOKey).PackKey(), nil
|
||||||
|
case ClaimToTXO | 3<<8:
|
||||||
|
return ClaimToTXO, voidstar.(*ClaimToTXOValue).PackValue(), nil
|
||||||
|
case ClaimToTXO | 4<<8:
|
||||||
|
return ClaimToTXO, ClaimToTXOKeyPackPartialKey(voidstar.(*ClaimToTXOKey)), nil
|
||||||
case TXOToClaim:
|
case TXOToClaim:
|
||||||
return TXOToClaim, TXOToClaimKeyUnpack(key), nil
|
return TXOToClaim, TXOToClaimKeyUnpack(data), nil
|
||||||
|
case TXOToClaim | 1<<8:
|
||||||
|
return TXOToClaim, TXOToClaimValueUnpack(data), nil
|
||||||
|
case TXOToClaim | 2<<8:
|
||||||
|
return TXOToClaim, voidstar.(*TXOToClaimKey).PackKey(), nil
|
||||||
|
case TXOToClaim | 3<<8:
|
||||||
|
return TXOToClaim, voidstar.(*TXOToClaimValue).PackValue(), nil
|
||||||
|
case TXOToClaim | 4<<8:
|
||||||
|
return TXOToClaim, TXOToClaimKeyPackPartialKey(voidstar.(*TXOToClaimKey)), nil
|
||||||
|
|
||||||
case ClaimToChannel:
|
case ClaimToChannel:
|
||||||
return ClaimToChannel, ClaimToChannelKeyUnpack(key), nil
|
return ClaimToChannel, ClaimToChannelKeyUnpack(data), nil
|
||||||
|
case ClaimToChannel | 1<<8:
|
||||||
|
return ClaimToChannel, ClaimToChannelValueUnpack(data), nil
|
||||||
|
case ClaimToChannel | 2<<8:
|
||||||
|
return ClaimToChannel, voidstar.(*ClaimToChannelKey).PackKey(), nil
|
||||||
|
case ClaimToChannel | 3<<8:
|
||||||
|
return ClaimToChannel, voidstar.(*ClaimToChannelValue).PackValue(), nil
|
||||||
|
case ClaimToChannel | 4<<8:
|
||||||
|
return ClaimToChannel, ClaimToChannelKeyPackPartialKey(voidstar.(*ClaimToChannelKey)), nil
|
||||||
case ChannelToClaim:
|
case ChannelToClaim:
|
||||||
return ChannelToClaim, ChannelToClaimKeyUnpack(key), nil
|
return ChannelToClaim, ChannelToClaimKeyUnpack(data), nil
|
||||||
|
case ChannelToClaim | 1<<8:
|
||||||
|
return ChannelToClaim, ChannelToClaimValueUnpack(data), nil
|
||||||
|
case ChannelToClaim | 2<<8:
|
||||||
|
return ChannelToClaim, voidstar.(*ChannelToClaimKey).PackKey(), nil
|
||||||
|
case ChannelToClaim | 3<<8:
|
||||||
|
return ChannelToClaim, voidstar.(*ChannelToClaimValue).PackValue(), nil
|
||||||
|
case ChannelToClaim | 4<<8:
|
||||||
|
return ChannelToClaim, ChannelToClaimKeyPackPartialKey(voidstar.(*ChannelToClaimKey)), nil
|
||||||
|
|
||||||
case ClaimShortIdPrefix:
|
case ClaimShortIdPrefix:
|
||||||
return ClaimShortIdPrefix, ClaimShortIDKeyUnpack(key), nil
|
return ClaimShortIdPrefix, ClaimShortIDKeyUnpack(data), nil
|
||||||
|
case ClaimShortIdPrefix | 1<<8:
|
||||||
|
return ClaimShortIdPrefix, ClaimShortIDValueUnpack(data), nil
|
||||||
|
case ClaimShortIdPrefix | 2<<8:
|
||||||
|
return ClaimShortIdPrefix, voidstar.(*ClaimShortIDKey).PackKey(), nil
|
||||||
|
case ClaimShortIdPrefix | 3<<8:
|
||||||
|
return ClaimShortIdPrefix, voidstar.(*ClaimShortIDValue).PackValue(), nil
|
||||||
|
case ClaimShortIdPrefix | 4<<8:
|
||||||
|
return ClaimShortIdPrefix, ClaimShortIDKeyPackPartialKey(voidstar.(*ClaimShortIDKey)), nil
|
||||||
case EffectiveAmount:
|
case EffectiveAmount:
|
||||||
return EffectiveAmount, EffectiveAmountKeyUnpack(key), nil
|
return EffectiveAmount, EffectiveAmountKeyUnpack(data), nil
|
||||||
|
case EffectiveAmount | 1<<8:
|
||||||
|
return EffectiveAmount, EffectiveAmountValueUnpack(data), nil
|
||||||
|
case EffectiveAmount | 2<<8:
|
||||||
|
return EffectiveAmount, voidstar.(*EffectiveAmountKey).PackKey(), nil
|
||||||
|
case EffectiveAmount | 3<<8:
|
||||||
|
return EffectiveAmount, voidstar.(*EffectiveAmountValue).PackValue(), nil
|
||||||
|
case EffectiveAmount | 4<<8:
|
||||||
|
return EffectiveAmount, EffectiveAmountKeyPackPartialKey(voidstar.(*EffectiveAmountKey)), nil
|
||||||
case ClaimExpiration:
|
case ClaimExpiration:
|
||||||
return ClaimExpiration, ClaimExpirationKeyUnpack(key), nil
|
return ClaimExpiration, ClaimExpirationKeyUnpack(data), nil
|
||||||
|
case ClaimExpiration | 1<<8:
|
||||||
|
return ClaimExpiration, ClaimExpirationValueUnpack(data), nil
|
||||||
|
case ClaimExpiration | 2<<8:
|
||||||
|
return ClaimExpiration, voidstar.(*ClaimExpirationKey).PackKey(), nil
|
||||||
|
case ClaimExpiration | 3<<8:
|
||||||
|
return ClaimExpiration, voidstar.(*ClaimExpirationValue).PackValue(), nil
|
||||||
|
case ClaimExpiration | 4<<8:
|
||||||
|
return ClaimExpiration, ClaimExpirationKeyPackPartialKey(voidstar.(*ClaimExpirationKey)), nil
|
||||||
|
|
||||||
case ClaimTakeover:
|
case ClaimTakeover:
|
||||||
return ClaimTakeover, ClaimTakeoverKeyUnpack(key), nil
|
return ClaimTakeover, ClaimTakeoverKeyUnpack(data), nil
|
||||||
|
case ClaimTakeover | 1<<8:
|
||||||
|
return ClaimTakeover, ClaimTakeoverValueUnpack(data), nil
|
||||||
|
case ClaimTakeover | 2<<8:
|
||||||
|
return ClaimTakeover, voidstar.(*ClaimTakeoverKey).PackKey(), nil
|
||||||
|
case ClaimTakeover | 3<<8:
|
||||||
|
return ClaimTakeover, voidstar.(*ClaimTakeoverValue).PackValue(), nil
|
||||||
|
case ClaimTakeover | 4<<8:
|
||||||
|
return ClaimTakeover, ClaimTakeoverKeyPackPartialKey(voidstar.(*ClaimTakeoverKey)), nil
|
||||||
case PendingActivation:
|
case PendingActivation:
|
||||||
return PendingActivation, PendingActivationKeyUnpack(key), nil
|
return PendingActivation, PendingActivationKeyUnpack(data), nil
|
||||||
|
case PendingActivation | 1<<8:
|
||||||
|
return PendingActivation, PendingActivationValueUnpack(data), nil
|
||||||
|
case PendingActivation | 2<<8:
|
||||||
|
return PendingActivation, voidstar.(*PendingActivationKey).PackKey(), nil
|
||||||
|
case PendingActivation | 3<<8:
|
||||||
|
return PendingActivation, voidstar.(*PendingActivationValue).PackValue(), nil
|
||||||
|
case PendingActivation | 4<<8:
|
||||||
|
return PendingActivation, PendingActivationKeyPackPartialKey(voidstar.(*PendingActivationKey)), nil
|
||||||
case ActivatedClaimAndSupport:
|
case ActivatedClaimAndSupport:
|
||||||
return ActivatedClaimAndSupport, ActivationKeyUnpack(key), nil
|
return ActivatedClaimAndSupport, ActivationKeyUnpack(data), nil
|
||||||
|
case ActivatedClaimAndSupport | 1<<8:
|
||||||
|
return ActivatedClaimAndSupport, ActivationValueUnpack(data), nil
|
||||||
|
case ActivatedClaimAndSupport | 2<<8:
|
||||||
|
return ActivatedClaimAndSupport, voidstar.(*ActivationKey).PackKey(), nil
|
||||||
|
case ActivatedClaimAndSupport | 3<<8:
|
||||||
|
return ActivatedClaimAndSupport, voidstar.(*ActivationValue).PackValue(), nil
|
||||||
|
case ActivatedClaimAndSupport | 4<<8:
|
||||||
|
return ActivatedClaimAndSupport, ActivationKeyPackPartialKey(voidstar.(*ActivationKey)), nil
|
||||||
case ActiveAmount:
|
case ActiveAmount:
|
||||||
return ActiveAmount, ActiveAmountKeyUnpack(key), nil
|
return ActiveAmount, ActiveAmountKeyUnpack(data), nil
|
||||||
|
case ActiveAmount | 1<<8:
|
||||||
|
return ActiveAmount, ActiveAmountValueUnpack(data), nil
|
||||||
|
case ActiveAmount | 2<<8:
|
||||||
|
return ActiveAmount, voidstar.(*ActiveAmountKey).PackKey(), nil
|
||||||
|
case ActiveAmount | 3<<8:
|
||||||
|
return ActiveAmount, voidstar.(*ActiveAmountValue).PackValue(), nil
|
||||||
|
case ActiveAmount | 4<<8:
|
||||||
|
return ActiveAmount, ActiveAmountKeyPackPartialKey(voidstar.(*ActiveAmountKey)), nil
|
||||||
|
|
||||||
case Repost:
|
case Repost:
|
||||||
return Repost, RepostKeyUnpack(key), nil
|
return Repost, RepostKeyUnpack(data), nil
|
||||||
|
case Repost | 1<<8:
|
||||||
|
return Repost, RepostValueUnpack(data), nil
|
||||||
|
case Repost | 2<<8:
|
||||||
|
return Repost, voidstar.(*RepostKey).PackKey(), nil
|
||||||
|
case Repost | 3<<8:
|
||||||
|
return Repost, voidstar.(*RepostValue).PackValue(), nil
|
||||||
|
case Repost | 4<<8:
|
||||||
|
return Repost, RepostKeyPackPartialKey(voidstar.(*RepostKey)), nil
|
||||||
case RepostedClaim:
|
case RepostedClaim:
|
||||||
return RepostedClaim, RepostedKeyUnpack(key), nil
|
return RepostedClaim, RepostedKeyUnpack(data), nil
|
||||||
|
case RepostedClaim | 1<<8:
|
||||||
|
return RepostedClaim, RepostedValueUnpack(data), nil
|
||||||
|
case RepostedClaim | 2<<8:
|
||||||
|
return RepostedClaim, voidstar.(*RepostedKey).PackKey(), nil
|
||||||
|
case RepostedClaim | 3<<8:
|
||||||
|
return RepostedClaim, voidstar.(*RepostedValue).PackValue(), nil
|
||||||
|
case RepostedClaim | 4<<8:
|
||||||
|
return RepostedClaim, RepostedKeyPackPartialKey(voidstar.(*RepostedKey)), nil
|
||||||
|
|
||||||
case Undo:
|
case Undo:
|
||||||
return Undo, UndoKeyUnpack(key), nil
|
return Undo, UndoKeyUnpack(data), nil
|
||||||
|
case Undo | 1<<8:
|
||||||
|
return Undo, UndoValueUnpack(data), nil
|
||||||
|
case Undo | 2<<8:
|
||||||
|
return Undo, voidstar.(*UndoKey).PackKey(), nil
|
||||||
|
case Undo | 3<<8:
|
||||||
|
return Undo, voidstar.(*UndoValue).PackValue(), nil
|
||||||
|
case Undo | 4<<8:
|
||||||
|
return Undo, UndoKeyPackPartialKey(voidstar.(*UndoKey)), nil
|
||||||
case ClaimDiff:
|
case ClaimDiff:
|
||||||
return ClaimDiff, TouchedOrDeletedClaimKeyUnpack(key), nil
|
return ClaimDiff, TouchedOrDeletedClaimKeyUnpack(data), nil
|
||||||
|
case ClaimDiff | 1<<8:
|
||||||
|
return ClaimDiff, TouchedOrDeletedClaimValueUnpack(data), nil
|
||||||
|
case ClaimDiff | 2<<8:
|
||||||
|
return ClaimDiff, voidstar.(*TouchedOrDeletedClaimKey).PackKey(), nil
|
||||||
|
case ClaimDiff | 3<<8:
|
||||||
|
return ClaimDiff, voidstar.(*TouchedOrDeletedClaimValue).PackValue(), nil
|
||||||
|
case ClaimDiff | 4<<8:
|
||||||
|
return ClaimDiff, TouchedOrDeletedClaimKeyPackPartialKey(voidstar.(*TouchedOrDeletedClaimKey)), nil
|
||||||
|
|
||||||
case Tx:
|
case Tx:
|
||||||
return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte)
|
return Tx, TxKeyUnpack(data), nil
|
||||||
|
case Tx | 1<<8:
|
||||||
|
return Tx, TxValueUnpack(data), nil
|
||||||
|
case Tx | 2<<8:
|
||||||
|
return Tx, voidstar.(*TxKey).PackKey(), nil
|
||||||
|
case Tx | 3<<8:
|
||||||
|
return Tx, voidstar.(*TxValue).PackValue(), nil
|
||||||
|
case Tx | 4<<8:
|
||||||
|
return Tx, TxKeyPackPartialKey(voidstar.(*TxKey)), nil
|
||||||
case BlockHash:
|
case BlockHash:
|
||||||
return BlockHash, BlockHashKeyUnpack(key), nil
|
return BlockHash, BlockHashKeyUnpack(data), nil
|
||||||
|
case BlockHash | 1<<8:
|
||||||
|
return BlockHash, BlockHashValueUnpack(data), nil
|
||||||
|
case BlockHash | 2<<8:
|
||||||
|
return BlockHash, voidstar.(*BlockHashKey).PackKey(), nil
|
||||||
|
case BlockHash | 3<<8:
|
||||||
|
return BlockHash, voidstar.(*BlockHashValue).PackValue(), nil
|
||||||
|
case BlockHash | 4<<8:
|
||||||
|
return BlockHash, BlockHashKeyPackPartialKey(voidstar.(*BlockHashKey)), nil
|
||||||
case Header:
|
case Header:
|
||||||
return Header, BlockHeaderKeyUnpack(key), nil
|
return Header, BlockHeaderKeyUnpack(data), nil
|
||||||
|
case Header | 1<<8:
|
||||||
|
return Header, BlockHeaderValueUnpack(data), nil
|
||||||
|
case Header | 2<<8:
|
||||||
|
return Header, voidstar.(*BlockHeaderKey).PackKey(), nil
|
||||||
|
case Header | 3<<8:
|
||||||
|
return Header, voidstar.(*BlockHeaderValue).PackValue(), nil
|
||||||
|
case Header | 4<<8:
|
||||||
|
return Header, BlockHeaderKeyPackPartialKey(voidstar.(*BlockHeaderKey)), nil
|
||||||
case TxNum:
|
case TxNum:
|
||||||
return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte)
|
return 0x0, nil, errors.Base("%s function for %v not implemented", functionName, firstByte)
|
||||||
case TxCount:
|
case TxCount:
|
||||||
case TxHash:
|
case TxHash:
|
||||||
return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte)
|
return 0x0, nil, errors.Base("%s function for %v not implemented", functionName, firstByte)
|
||||||
case UTXO:
|
case UTXO:
|
||||||
return UTXO, UTXOKeyUnpack(key), nil
|
return UTXO, UTXOKeyUnpack(data), nil
|
||||||
|
case UTXO | 1<<8:
|
||||||
|
return UTXO, UTXOValueUnpack(data), nil
|
||||||
|
case UTXO | 2<<8:
|
||||||
|
return UTXO, voidstar.(*UTXOKey).PackKey(), nil
|
||||||
|
case UTXO | 3<<8:
|
||||||
|
return UTXO, voidstar.(*UTXOValue).PackValue(), nil
|
||||||
|
case UTXO | 4<<8:
|
||||||
|
return UTXO, UTXOKeyPackPartialKey(voidstar.(*UTXOKey)), nil
|
||||||
case HashXUTXO:
|
case HashXUTXO:
|
||||||
return UTXO, HashXUTXOKeyUnpack(key), nil
|
return UTXO, HashXUTXOKeyUnpack(data), nil
|
||||||
|
case HashXUTXO | 1<<8:
|
||||||
|
return UTXO, HashXUTXOValueUnpack(data), nil
|
||||||
|
case HashXUTXO | 2<<8:
|
||||||
|
return UTXO, voidstar.(*HashXUTXOKey).PackKey(), nil
|
||||||
|
case HashXUTXO | 3<<8:
|
||||||
|
return UTXO, voidstar.(*HashXUTXOValue).PackValue(), nil
|
||||||
|
case HashXUTXO | 4<<8:
|
||||||
|
return UTXO, HashXUTXOKeyPackPartialKey(voidstar.(*HashXUTXOKey)), nil
|
||||||
case HashXHistory:
|
case HashXHistory:
|
||||||
return HashXHistory, HashXHistoryKeyUnpack(key), nil
|
return HashXHistory, HashXHistoryKeyUnpack(data), nil
|
||||||
|
case HashXHistory | 1<<8:
|
||||||
|
return HashXHistory, HashXHistoryValueUnpack(data), nil
|
||||||
|
case HashXHistory | 2<<8:
|
||||||
|
return HashXHistory, voidstar.(*HashXHistoryKey).PackKey(), nil
|
||||||
|
case HashXHistory | 3<<8:
|
||||||
|
return HashXHistory, voidstar.(*HashXHistoryValue).PackValue(), nil
|
||||||
|
case HashXHistory | 4<<8:
|
||||||
|
return HashXHistory, HashXHistoryKeyPackPartialKey(voidstar.(*HashXHistoryKey)), nil
|
||||||
case DBState:
|
case DBState:
|
||||||
case ChannelCount:
|
case ChannelCount:
|
||||||
case SupportAmount:
|
case SupportAmount:
|
||||||
case BlockTXs:
|
case BlockTXs:
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0x0, nil, errors.Base("key unpack function for %v not implemented", firstByte)
|
return 0x0, nil, errors.Base("%s function for %v not implemented", functionName, firstByte)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnpackGenericKey(key []byte) (byte, interface{}, error) {
|
||||||
|
if len(key) == 0 {
|
||||||
|
return 0x0, nil, errors.Base("key length zero")
|
||||||
|
}
|
||||||
|
return generic(key, key[0], 0, "unpack key")
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnpackGenericValue(key, value []byte) (byte, interface{}, error) {
|
func UnpackGenericValue(key, value []byte) (byte, interface{}, error) {
|
||||||
|
@ -2876,71 +3277,30 @@ func UnpackGenericValue(key, value []byte) (byte, interface{}, error) {
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return 0x0, nil, errors.Base("value length zero")
|
return 0x0, nil, errors.Base("value length zero")
|
||||||
}
|
}
|
||||||
|
return generic(value, key[0], 1, "unpack value")
|
||||||
firstByte := key[0]
|
|
||||||
switch firstByte {
|
|
||||||
case ClaimToSupport:
|
|
||||||
return ClaimToSupport, ClaimToSupportValueUnpack(value), nil
|
|
||||||
case SupportToClaim:
|
|
||||||
return SupportToClaim, SupportToClaimValueUnpack(value), nil
|
|
||||||
|
|
||||||
case ClaimToTXO:
|
|
||||||
return ClaimToTXO, ClaimToTXOValueUnpack(value), nil
|
|
||||||
case TXOToClaim:
|
|
||||||
return TXOToClaim, TXOToClaimValueUnpack(value), nil
|
|
||||||
|
|
||||||
case ClaimToChannel:
|
|
||||||
return ClaimToChannel, ClaimToChannelValueUnpack(value), nil
|
|
||||||
case ChannelToClaim:
|
|
||||||
return ChannelToClaim, ChannelToClaimValueUnpack(value), nil
|
|
||||||
|
|
||||||
case ClaimShortIdPrefix:
|
|
||||||
return ClaimShortIdPrefix, ClaimShortIDValueUnpack(value), nil
|
|
||||||
case EffectiveAmount:
|
|
||||||
return EffectiveAmount, EffectiveAmountValueUnpack(value), nil
|
|
||||||
case ClaimExpiration:
|
|
||||||
return ClaimExpiration, ClaimExpirationValueUnpack(value), nil
|
|
||||||
|
|
||||||
case ClaimTakeover:
|
|
||||||
return ClaimTakeover, ClaimTakeoverValueUnpack(value), nil
|
|
||||||
case PendingActivation:
|
|
||||||
return PendingActivation, PendingActivationValueUnpack(value), nil
|
|
||||||
case ActivatedClaimAndSupport:
|
|
||||||
return ActivatedClaimAndSupport, ActivationValueUnpack(value), nil
|
|
||||||
case ActiveAmount:
|
|
||||||
return ActiveAmount, ActiveAmountValueUnpack(value), nil
|
|
||||||
|
|
||||||
case Repost:
|
|
||||||
return Repost, RepostValueUnpack(value), nil
|
|
||||||
case RepostedClaim:
|
|
||||||
return RepostedClaim, RepostedValueUnpack(value), nil
|
|
||||||
|
|
||||||
case Undo:
|
|
||||||
return Undo, UndoValueUnpack(value), nil
|
|
||||||
case ClaimDiff:
|
|
||||||
return ClaimDiff, TouchedOrDeletedClaimValueUnpack(value), nil
|
|
||||||
|
|
||||||
case Tx:
|
|
||||||
return 0x0, nil, errors.Base("value unpack not implemented for key %v", key)
|
|
||||||
case BlockHash:
|
|
||||||
return BlockHash, BlockHashValueUnpack(value), nil
|
|
||||||
case Header:
|
|
||||||
return Header, BlockHeaderValueUnpack(value), nil
|
|
||||||
case TxNum:
|
|
||||||
return 0x0, nil, errors.Base("value unpack not implemented for key %v", key)
|
|
||||||
case TxCount:
|
|
||||||
case TxHash:
|
|
||||||
return 0x0, nil, errors.Base("value unpack not implemented for key %v", key)
|
|
||||||
case UTXO:
|
|
||||||
return UTXO, UTXOValueUnpack(value), nil
|
|
||||||
case HashXUTXO:
|
|
||||||
return HashXUTXO, HashXUTXOValueUnpack(value), nil
|
|
||||||
case HashXHistory:
|
|
||||||
return HashXHistory, HashXHistoryValueUnpack(value), nil
|
|
||||||
case DBState:
|
|
||||||
case ChannelCount:
|
|
||||||
case SupportAmount:
|
|
||||||
case BlockTXs:
|
|
||||||
}
|
}
|
||||||
return 0x0, nil, errors.Base("value unpack not implemented for key %v", key)
|
|
||||||
|
func PackPartialGenericKey(prefix byte, key interface{}, nFields int) (byte, []byte, error) {
|
||||||
|
if key == nil {
|
||||||
|
return 0x0, nil, errors.Base("key length zero")
|
||||||
|
}
|
||||||
|
x, y, z := generic(key, prefix, 4, "pack partial key")
|
||||||
|
res := y.(func(int) []byte)(nFields)
|
||||||
|
return x, res, z
|
||||||
|
}
|
||||||
|
|
||||||
|
func PackGenericKey(prefix byte, key interface{}) (byte, []byte, error) {
|
||||||
|
if key == nil {
|
||||||
|
return 0x0, nil, errors.Base("key length zero")
|
||||||
|
}
|
||||||
|
x, y, z := generic(key, prefix, 2, "pack key")
|
||||||
|
return x, y.([]byte), z
|
||||||
|
}
|
||||||
|
|
||||||
|
func PackGenericValue(prefix byte, value interface{}) (byte, []byte, error) {
|
||||||
|
if value == nil {
|
||||||
|
return 0x0, nil, errors.Base("value length zero")
|
||||||
|
}
|
||||||
|
x, y, z := generic(value, prefix, 3, "pack value")
|
||||||
|
return x, y.([]byte), z
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
4
main.go
4
main.go
|
@ -38,7 +38,7 @@ func main() {
|
||||||
|
|
||||||
options := &db.IterOptions{
|
options := &db.IterOptions{
|
||||||
FillCache: false,
|
FillCache: false,
|
||||||
Prefix: []byte{prefixes.HashXHistory},
|
Prefix: []byte{prefixes.Tx},
|
||||||
Start: nil,
|
Start: nil,
|
||||||
Stop: nil,
|
Stop: nil,
|
||||||
IncludeStart: true,
|
IncludeStart: true,
|
||||||
|
@ -49,7 +49,7 @@ func main() {
|
||||||
RawValue: true,
|
RawValue: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
db.ReadWriteRawN(dbVal, options, "./resources/hashx_history.csv", 10)
|
db.ReadWriteRawN(dbVal, options, "./resources/tx.csv", 10)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
10
resources/tx.csv
Normal file
10
resources/tx.csv
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
4200000031a2e262d60074f07330d7187907e5b02be8f9b3c60cdc03d776314912,0200000001d922db1c8020a8a101ccab3a9dff62eccd8660c9351bf91af8dc481544395821010000006a473044022047bbe0eec4931aa332ac089dfb56bac095e4e2f11258f95f8dc11f2d915399b802207cbe15f5c1ad882ef7cf7c987c5380a56613c7bbfd56e4a8e4161a46fd522a84012103e1a29d4cb998f7a6a165f1a2aaa524f319a59beb4f9336f542175ddecc6cac03feffffff0200ca9a3b000000001976a914028b4111c923a411ba165760cacea097b9b0b77588ac567d1329400000001976a914bc3826102bebb5ab7d88cb080b5234b67aac787888ac4ad50c00
|
||||||
|
420000004e91edda0f9cd3bcef9565a31e6bbbd34c731483e03ec7d8819158ac30,02000000018fb565983ddfc193da15f68414712779a7de703babef37c1b30fb8956abbd034010000006a4730440220011f6c22ecafdfc03fde256c0676b7d840e8aacd9e75a02fde40862451d97b7f022072a8093343d900d5543a00e648352a7c7cf2389d89a5863d33c34e44f3acaa590121036be4ec00fc805765e824a604fecc376cdc33cd3a8d175fad63980e16e79d8809feffffff026e39190d000000001976a9146911aebb1ec343bb432aa3edf9f08e4f110a541e88ac40787d01000000001976a914ea2faaf77fab748cddca231f9d528c43c2f3a78e88ac02340f00
|
||||||
|
420000008070865693cd82ed0f59896e34973adbff0583fb8a1293919591446075,02000000017c0ac8ee47ebdcbf4c36a0f1ff0a77347658099b734e65bd662ca510b91385b2000000006a473044022023da5a18003e6db9144b691ea77cb267b911678e15cecab4d22c52b4ced6ad3302203ba4e2cb7d1ad2c88aa89827767cea76c1805a366598fc53513807f3e5db78cd0121022c949b389ff428dc58ca8f0803dab7cde26cbc0a12b26ef758853c1266f9e543feffffff023dabb942020000001976a91440ee9a09269bdd2f3532b8bc18d792cd435de79488ac002d3101000000001976a914b4158a6a1b7505068bc5df3b0f76a02cc38014d788ac9a880f00
|
||||||
|
420000009c24d4d9187749a1f8f6d6c0f92a5e98817f5efcd427a5593344a45a2e,0200000001bda00a971cebc8727690779e84d00ba4d7393032ff0d75e11909c3ede2c7f48c010000006a473044022077d431faca3342ec9cb7701b96490cb67e5b1b3c70efb8bf6f92aa183321c71202207a9de1cb8508264f97bf2cae258571acef93d520d4743fa71b332684f99c082d0121030c29115cd040efdb5b3617e180074e78c2c9a75613c32701241ad9f8985f3abcfeffffff0240787d01000000001976a914c154d27978ee4c3002ad934e858e63c58550b1ae88acc47d6ab0070000001976a914d1ea863ff9311b80837f43732d4f26b7e183862088aca36c0d00
|
||||||
|
42000000cee66b136a85596df24ece60bbd1392f70204fd2f144f059e5195ee3c9,0100000001f5013c21bd5c858f7eed0df58e9471e148d8924962d7cadd1b775358029076f9010000006a47304402205348d7b22894f7ed8f8d44fa73a65ea9d8124e4b0b88d816b0f8b6714b897da702204093e051c09c86c33b6dcd4285670a1d442622f5b687ac028514e5b44718fd4e012103c633b45b4d49c485c67b7d96920fa6a26ae30a07c0fb9f0ae8f85c00a19b8825feffffff0273e25769000000001976a914999d5b0e3d5efcf601c711127b91841afbf5c37a88acf6268a0d090000001976a914816f8bd268c614b3ae8b564fa531ece6e1d0297188ac522f0200
|
||||||
|
42000000e0bf96accd4eda4d871c5bc8c0ebb14509b896a867095f9b419f9b04f2,0200000001d17c8a33cddad3b6a1f34248e9457b359c59e80a5541c017fd5ab1c8b21f0d2b010000006a473044022036102bd4d4e28909a17e189d23d640fd0f1111f45eb5639f68da70317e04831602201a317ae0af0930d27c280a91ced77c4c6dccda7eb297f7bf73023106762e88c8012102913606374e2b055d06fb4fb8250ca65ca66ecf4154916722e11cf3487555b2f0feffffff0240787d01000000001976a914c13e9599dafeb20e2e7cf994941d44e1e1e88ce588ace9cba36d020000001976a9149db9398216b2ad3726aa8d5a3391a20d460f494388ac7ac40e00
|
||||||
|
420000011daab2a9f45cca3d0bac6fee69324af4757b1c4e8c3a362efbb6e8a09d,02000000019161a7c7a985bd44afafebe044df38df82ecdba417ea3244235572257b201068000000006a473044022077ed0bb436d9a7bd1a83f680cef81d9b8cbd2b74de310f32859c49077e009f90022020faea4599352a9d42c50b7a4eeeda1ba31121e5a0817ae0b650f35ae79a06d6012102ad6c243af5779b873b171b79cbe65cda7cf8c5d35865ecaf796912e888150c3cfeffffff02f8c2bc74040000001976a91420195c8e1c81eb3bb03452d855591d4099db08d588ac00c2eb0b000000001976a9148bc70b6256cff9f4e645bb1431548aad757ba56388ac1ec30b00
|
||||||
|
4200000150116856ce8ce06604b9584e61afb3b613a8a5a512ab260e7f0cbe5496,010000000183843af3333d4b751745b90321b1e7c9f32b23299ac6ed160ef1d7f079a7b5f8000000006a4730440220761f40ffdc87d217f84adb43132a78f9db3a16bf9303876c6a871abb253823be02202357dadaed6701134e68f2fe41bb883da82d550c431fb1f36ef6b97ad2c3e19e012103d77e3266f1ed4533e3bd5464aebedbf0a3d2b7ec677cca6996a8548d73e50af6feffffff1147164d1f000000001976a91466f157283bbc18c616f825c2ad2d9c6108a0e96f88acd680a626000000001976a914ae0ee727bf91e4f9f70664a8a0936d7ff81d3d5888ac9b425a1e000000001976a9146fd65fe059c85fe1cb704efc80c81f0275ab7cb188ac71222212000000001976a914c2daa42a9414bc6b70b395b79d8b54556c918a2288ac0549ce27000000001976a91438b1ce845765a1a749117bbd1c6fea9adcf2784088acb420011e000000001976a914213a5c1975e979b60a24bf72809f3d7205ee925888ac58c50621000000001976a914fc6a1f55c1bb2dd382df728d75c893406bfadb5d88ac9183621e000000001976a914ad70928b870c76b899cf9d66f1ee5b258976721088ac19eb3a0c000000001976a91421ba33ab978890434c8cfd31db9789fe5af0e73c88acb755ea1e000000001976a914c2003ddf455851be985e349830dc0d7dc619205c88ac125a3f27000000001976a91411b58fd67f6b389a5bfd592db92fdcfe613214aa88acd674713f000000001976a914514f9d058cad9251b816ae609b847582e759519188ac205e3007000000001976a91417066054003dd148297c6f1922db8bcbe185ba3b88acb562931f000000001976a9149481776b356d441567601fc713e9516ccf85ebb688ace2c8184e000000001976a914dd705e9e15c0c0e0a714f6b79b8618aa840f9b2c88acc3fb0ba6050000001976a91419bef2dcb05c86662c08ef2848819a685dd0dcdc88ac5d258c06000000001976a9142479394dc4ef5e61bcb9c60ef8f3f27dffa57fdb88ac20fb0700
|
||||||
|
420000015ba8df5c3ed80d0fc364136de02e3ba9d9550cbb1ecef03b97fcdf0621,0100000001e50a9a7f3bcd2d4c0c3dc60d96b3e008a247e80e0b114d34b38399ac6ed6ea620c0000006b4830450221009b8beec62aac1e7096071b3fbbaa4cc1846ef8781ea8a9a2a8d6c1d918f359b6022074f04dd3da2c67e2e293c4a1eaf69931512a060af6665740e6084f03a6fbff22012103b5f96b51c7b567b747b9cc14e46daab5200acc37052e149e213939e103f69aa6ffffffff0134b7f505000000001976a914e75d6c70d420ffaef75def1a94469f2dc6546a3588ac00000000
|
||||||
|
42000001d4a53fc92321415631862a791f8680241ed172e579534713f68a6869ba,01000000025b09f3192aa1f9e436b4b282143f0668acd6fb7c90cdbfef0a69d84d036e702a000000006b483045022100df7687542decdaaabf1bb67b1f6809a697f54264a09c8e9dc33c5527fd6ef16302200fab534e44fad5d86a65a645a0b8ebfb9644dd3ecac65b8745706076a430c2dc0121029d7cd706d4da4a71441a1dc4a6109fdb481112d749f19174cb025e95bfafbc94ffffffff5b09f3192aa1f9e436b4b282143f0668acd6fb7c90cdbfef0a69d84d036e702a010000006a47304402204849b7a22292f1dd6af210da076b523330640e5bb31673d3dfd394067d17b23902201813fd1f1a91399b64b0cb0c309d41aa2c066f69403ca90ca046af6c609182810121029d7cd706d4da4a71441a1dc4a6109fdb481112d749f19174cb025e95bfafbc94ffffffff0240420f0000000000c6b70b406372617a7964696e676f14f9407ef9b87c18020796dd434fad2bca5c727acc4c8700125a0a583056301006072a8648ce3d020106052b8104000a03420004b906153f96ff0567979424eca1a19691df7d23be28901c248b6fe7986cf740f7631f5a36f6d03d26bd97e37e83e1320808400202dd4dbad81467f1570ff763d152282a2668747470733a2f2f737065652e63682f312f623530383737333436313932626433382e6a70676d6d76a91439ed14bafdb75ee4f06f134de8aee0b845c3bd3588ac40a01000000000001976a91439ed14bafdb75ee4f06f134de8aee0b845c3bd3588ac00000000
|
|
Loading…
Reference in a new issue