fix: rune types

This commit is contained in:
Gaze
2024-04-09 23:29:32 +07:00
parent d8705b9890
commit e035cf8a2a
3 changed files with 19 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ package runes
import (
"math"
"github.com/btcsuite/btcd/wire"
"github.com/gaze-network/indexer-network/core/types"
"github.com/gaze-network/uint128"
"github.com/samber/lo"
)
@@ -31,7 +31,7 @@ func (fields Fields) Take(tag Tag) *uint128.Uint128 {
return &first
}
func MessageFromIntegers(tx *wire.MsgTx, payload []uint128.Uint128) Message {
func MessageFromIntegers(tx *types.Transaction, payload []uint128.Uint128) Message {
flaws := Flaws(0)
var edicts []Edict
fields := make(map[Tag][]uint128.Uint128)

View File

@@ -7,9 +7,9 @@ import (
"slices"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/cockroachdb/errors"
"github.com/gaze-network/indexer-network/common/errs"
"github.com/gaze-network/indexer-network/core/types"
"github.com/gaze-network/indexer-network/pkg/leb128"
"github.com/gaze-network/uint128"
"github.com/samber/lo"
@@ -144,7 +144,7 @@ func (r Runestone) Encipher() ([]byte, error) {
// DecipherRunestone deciphers a runestone from a transaction. If the runestone is a cenotaph, the runestone is returned with Cenotaph set to true and Flaws set to the bitmask of flaws that caused the runestone to be a cenotaph.
// If no runestone is found, nil is returned.
func DecipherRunestone(tx *wire.MsgTx) (*Runestone, error) {
func DecipherRunestone(tx *types.Transaction) (*Runestone, error) {
payload, flaws := runestonePayloadFromTx(tx)
if flaws != 0 {
return &Runestone{
@@ -297,7 +297,7 @@ func DecipherRunestone(tx *wire.MsgTx) (*Runestone, error) {
}, nil
}
func runestonePayloadFromTx(tx *wire.MsgTx) ([]byte, Flaws) {
func runestonePayloadFromTx(tx *types.Transaction) ([]byte, Flaws) {
for _, output := range tx.TxOut {
tokenizer := txscript.MakeScriptTokenizer(0, output.PkScript)

View File

@@ -6,7 +6,7 @@ import (
"github.com/Cleverse/go-utilities/utils"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/gaze-network/indexer-network/core/types"
"github.com/gaze-network/indexer-network/pkg/leb128"
"github.com/gaze-network/uint128"
"github.com/samber/lo"
@@ -22,7 +22,7 @@ func encodeLEB128VarIntsToPayload(integers []uint128.Uint128) []byte {
}
func TestDecipherRunestone(t *testing.T) {
testDecipherTx := func(name string, tx *wire.MsgTx, expected *Runestone) {
testDecipherTx := func(name string, tx *types.Transaction, expected *Runestone) {
t.Run(name, func(t *testing.T) {
t.Parallel()
runestone, err := DecipherRunestone(tx)
@@ -39,11 +39,11 @@ func TestDecipherRunestone(t *testing.T) {
AddData(payload).
Script()
assert.NoError(t, err)
tx := &wire.MsgTx{
tx := &types.Transaction{
Version: 2,
LockTime: 0,
TxIn: []*wire.TxIn{},
TxOut: []*wire.TxOut{
TxIn: []*types.TxIn{},
TxOut: []*types.TxOut{
{
PkScript: pkScript,
Value: 0,
@@ -54,11 +54,11 @@ func TestDecipherRunestone(t *testing.T) {
}
testDecipherPkScript := func(name string, pkScript []byte, expected *Runestone) {
tx := &wire.MsgTx{
tx := &types.Transaction{
Version: 2,
LockTime: 0,
TxIn: []*wire.TxIn{},
TxOut: []*wire.TxOut{
TxIn: []*types.TxIn{},
TxOut: []*types.TxOut{
{
PkScript: pkScript,
Value: 0,
@@ -75,11 +75,11 @@ func TestDecipherRunestone(t *testing.T) {
)
testDecipherTx(
"deciphering_transaction_with_non_op_return_output_returns_none",
&wire.MsgTx{
&types.Transaction{
Version: 2,
LockTime: 0,
TxIn: []*wire.TxIn{},
TxOut: []*wire.TxOut{},
TxIn: []*types.TxIn{},
TxOut: []*types.TxOut{},
},
nil,
)
@@ -178,11 +178,11 @@ func TestDecipherRunestone(t *testing.T) {
)
testDecipherTx(
"invalid_input_scripts_are_skipped_when_searching_for_runestone",
&wire.MsgTx{
&types.Transaction{
Version: 2,
LockTime: 0,
TxIn: []*wire.TxIn{},
TxOut: []*wire.TxOut{
TxIn: []*types.TxIn{},
TxOut: []*types.TxOut{
{
PkScript: utils.Must(txscript.NewScriptBuilder().
AddOp(txscript.OP_RETURN).