mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 04:35:13 +08:00
fix: edict flaws were ignored
This commit is contained in:
@@ -2,10 +2,12 @@ package runes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/common/errs"
|
||||
)
|
||||
|
||||
type RuneId struct {
|
||||
@@ -79,11 +81,17 @@ func (r RuneId) Delta(next RuneId) (uint64, uint32) {
|
||||
// Next calculates the next RuneId given a block delta and tx index delta.
|
||||
func (r RuneId) Next(blockDelta uint64, txIndexDelta uint32) (RuneId, error) {
|
||||
if blockDelta == 0 {
|
||||
if math.MaxUint32-r.TxIndex < txIndexDelta {
|
||||
return RuneId{}, errs.OverflowUint32
|
||||
}
|
||||
return NewRuneId(
|
||||
r.BlockHeight,
|
||||
r.TxIndex+txIndexDelta,
|
||||
)
|
||||
}
|
||||
if math.MaxUint64-r.BlockHeight < blockDelta {
|
||||
return RuneId{}, errs.OverflowUint64
|
||||
}
|
||||
return NewRuneId(
|
||||
r.BlockHeight+blockDelta,
|
||||
txIndexDelta,
|
||||
|
||||
@@ -173,6 +173,7 @@ func DecipherRunestone(tx *types.Transaction) (*Runestone, error) {
|
||||
}
|
||||
message := MessageFromIntegers(tx, integers)
|
||||
edicts, fields := message.Edicts, message.Fields
|
||||
flaws |= message.Flaws
|
||||
|
||||
flags, err := ParseFlags(lo.FromPtr(fields.Take(TagFlags)))
|
||||
if err != nil {
|
||||
|
||||
@@ -507,4 +507,60 @@ func TestDecipherRunestone(t *testing.T) {
|
||||
},
|
||||
)
|
||||
})
|
||||
t.Run("runestone_with_edict_id_with_zero_block_and_nonzero_tx_is_cenotaph", func(t *testing.T) {
|
||||
testDecipherInteger(
|
||||
t,
|
||||
[]uint128.Uint128{
|
||||
TagBody.Uint128(),
|
||||
uint128.From64(0),
|
||||
uint128.From64(1),
|
||||
uint128.From64(2),
|
||||
uint128.From64(0),
|
||||
},
|
||||
&Runestone{
|
||||
Cenotaph: true,
|
||||
Flaws: FlawFlagEdictRuneId.Mask(),
|
||||
},
|
||||
)
|
||||
})
|
||||
t.Run("runestone_with_overflowing_edict_id_delta_is_cenotaph_1", func(t *testing.T) {
|
||||
testDecipherInteger(
|
||||
t,
|
||||
[]uint128.Uint128{
|
||||
TagBody.Uint128(),
|
||||
uint128.From64(1),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
uint128.From64(math.MaxUint64),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
},
|
||||
&Runestone{
|
||||
Cenotaph: true,
|
||||
Flaws: FlawFlagEdictRuneId.Mask(),
|
||||
},
|
||||
)
|
||||
})
|
||||
t.Run("runestone_with_overflowing_edict_id_delta_is_cenotaph_2", func(t *testing.T) {
|
||||
testDecipherInteger(
|
||||
t,
|
||||
[]uint128.Uint128{
|
||||
TagBody.Uint128(),
|
||||
uint128.From64(1),
|
||||
uint128.From64(1),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
uint128.From64(math.MaxUint64),
|
||||
uint128.From64(0),
|
||||
uint128.From64(0),
|
||||
},
|
||||
&Runestone{
|
||||
Cenotaph: true,
|
||||
Flaws: FlawFlagEdictRuneId.Mask(),
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user