mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 12:41:59 +08:00
Compare commits
7 Commits
fix/runes-
...
v0.2.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dad02bf61a | ||
|
|
694baef0aa | ||
|
|
47119c3220 | ||
|
|
6203b104db | ||
|
|
b24f27ec9a | ||
|
|
90f1fd0a6c | ||
|
|
aace33b382 |
@@ -243,39 +243,32 @@ func (d *BitcoinNodeDatasource) prepareRange(fromHeight, toHeight int64) (start,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTransaction fetch transaction from Bitcoin node
|
// GetTransaction fetch transaction from Bitcoin node
|
||||||
func (d *BitcoinNodeDatasource) GetTransactionByHash(ctx context.Context, txHash chainhash.Hash) (*types.Transaction, error) {
|
func (d *BitcoinNodeDatasource) GetRawTransactionAndHeightByTxHash(ctx context.Context, txHash chainhash.Hash) (*wire.MsgTx, int64, error) {
|
||||||
rawTxVerbose, err := d.btcclient.GetRawTransactionVerbose(&txHash)
|
rawTxVerbose, err := d.btcclient.GetRawTransactionVerbose(&txHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get raw transaction")
|
return nil, 0, errors.Wrap(err, "failed to get raw transaction")
|
||||||
}
|
}
|
||||||
|
|
||||||
blockHash, err := chainhash.NewHashFromStr(rawTxVerbose.BlockHash)
|
blockHash, err := chainhash.NewHashFromStr(rawTxVerbose.BlockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to parse block hash")
|
return nil, 0, errors.Wrap(err, "failed to parse block hash")
|
||||||
}
|
}
|
||||||
block, err := d.btcclient.GetBlockVerboseTx(blockHash)
|
block, err := d.btcclient.GetBlockVerbose(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get block header")
|
return nil, 0, errors.Wrap(err, "failed to get block header")
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse tx
|
// parse tx
|
||||||
txBytes, err := hex.DecodeString(rawTxVerbose.Hex)
|
txBytes, err := hex.DecodeString(rawTxVerbose.Hex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to decode transaction hex")
|
return nil, 0, errors.Wrap(err, "failed to decode transaction hex")
|
||||||
}
|
}
|
||||||
var msgTx wire.MsgTx
|
var msgTx wire.MsgTx
|
||||||
if err := msgTx.Deserialize(bytes.NewReader(txBytes)); err != nil {
|
if err := msgTx.Deserialize(bytes.NewReader(txBytes)); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to deserialize transaction")
|
return nil, 0, errors.Wrap(err, "failed to deserialize transaction")
|
||||||
}
|
|
||||||
var txIndex uint32
|
|
||||||
for i, tx := range block.Tx {
|
|
||||||
if tx.Hex == rawTxVerbose.Hex {
|
|
||||||
txIndex = uint32(i)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.ParseMsgTx(&msgTx, block.Height, *blockHash, txIndex), nil
|
return &msgTx, block.Height, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockHeader fetch block header from Bitcoin node
|
// GetBlockHeader fetch block header from Bitcoin node
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ func (p *Processor) txCommitsToRune(ctx context.Context, tx *types.Transaction,
|
|||||||
// It is impossible to verify that input utxo is a P2TR output with just the input.
|
// It is impossible to verify that input utxo is a P2TR output with just the input.
|
||||||
// Need to verify with utxo's pk script.
|
// Need to verify with utxo's pk script.
|
||||||
|
|
||||||
prevTx, err := p.bitcoinClient.GetTransactionByHash(ctx, txIn.PreviousOutTxHash)
|
prevTx, blockHeight, err := p.bitcoinClient.GetRawTransactionAndHeightByTxHash(ctx, txIn.PreviousOutTxHash)
|
||||||
if err != nil && errors.Is(err, errs.NotFound) {
|
if err != nil && errors.Is(err, errs.NotFound) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -479,7 +479,7 @@ func (p *Processor) txCommitsToRune(ctx context.Context, tx *types.Transaction,
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
// input must be mature enough
|
// input must be mature enough
|
||||||
confirmations := tx.BlockHeight - prevTx.BlockHeight + 1
|
confirmations := tx.BlockHeight - blockHeight + 1
|
||||||
if confirmations < runes.RUNE_COMMIT_BLOCKS {
|
if confirmations < runes.RUNE_COMMIT_BLOCKS {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/gaze-network/indexer-network/core/types"
|
"github.com/btcsuite/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Contract interface {
|
type Contract interface {
|
||||||
GetTransactionByHash(ctx context.Context, txHash chainhash.Hash) (*types.Transaction, error)
|
GetRawTransactionAndHeightByTxHash(ctx context.Context, txHash chainhash.Hash) (*wire.MsgTx, int64, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,11 @@ func (h *Client) request(ctx context.Context, reqOptions RequestOptions) (*HttpR
|
|||||||
|
|
||||||
parsedUrl := h.BaseURL()
|
parsedUrl := h.BaseURL()
|
||||||
parsedUrl.Path = path.Join(parsedUrl.Path, reqOptions.path)
|
parsedUrl.Path = path.Join(parsedUrl.Path, reqOptions.path)
|
||||||
parsedUrl.RawQuery = reqOptions.Query.Encode() // TODO: merge query params if base url already have query params
|
baseQuery := parsedUrl.Query()
|
||||||
|
for k, v := range reqOptions.Query {
|
||||||
|
baseQuery[k] = v
|
||||||
|
}
|
||||||
|
parsedUrl.RawQuery = baseQuery.Encode()
|
||||||
|
|
||||||
// remove %20 from url (empty space)
|
// remove %20 from url (empty space)
|
||||||
url := strings.TrimSuffix(parsedUrl.String(), "%20")
|
url := strings.TrimSuffix(parsedUrl.String(), "%20")
|
||||||
|
|||||||
Reference in New Issue
Block a user