fix: edict flaws were ignored

This commit is contained in:
Gaze
2024-04-15 23:14:48 +07:00
parent 3c8c1d55f6
commit fc9789f351
3 changed files with 65 additions and 0 deletions

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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(),
},
)
})
}