mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 20:52:01 +08:00
refactor: runes processor
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gaze-network/indexer-network/core/types"
|
||||
)
|
||||
|
||||
func (r *runesProcessor) Process(ctx context.Context, blocks []types.Block) error {
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gaze-network/indexer-network/modules/runes/internal/runes"
|
||||
"github.com/gaze-network/uint128"
|
||||
)
|
||||
|
||||
type RuneEntry struct {
|
||||
// EtchingTime is the time when the rune was created.
|
||||
EtchingTime time.Time
|
||||
// Terms is the minting terms of the rune.
|
||||
Terms *runes.Terms
|
||||
// EtchingTxHash is the hash of the transaction that created the rune.
|
||||
EtchingTxHash string
|
||||
SpacedRune runes.SpacedRune
|
||||
BurnedAmount uint128.Uint128
|
||||
// Mints is the number of times that this rune has been minted.
|
||||
Mints uint128.Uint128
|
||||
// Premine is the amount of the rune that was premined.
|
||||
Premine uint128.Uint128
|
||||
// EtchingBlock is the block height where the rune was created.
|
||||
EtchingBlock uint64
|
||||
// Number is the sequential number of the rune, starting from one.
|
||||
Number uint64
|
||||
Symbol rune
|
||||
Divisibility uint8
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/gaze-network/indexer-network/core/indexers"
|
||||
"github.com/gaze-network/indexer-network/core/types"
|
||||
"github.com/gaze-network/indexer-network/modules/runes/internal/runes"
|
||||
"github.com/gaze-network/uint128"
|
||||
)
|
||||
|
||||
var _ indexers.BitcoinProcessor = (*runesProcessor)(nil)
|
||||
|
||||
func toLocationId(txHash *chainhash.Hash, vout uint32) string {
|
||||
return fmt.Sprintf("%si%d", txHash.String(), vout)
|
||||
}
|
||||
|
||||
// TODO: flush internal states to database periodically to avoid memory leak
|
||||
type runesProcessor struct {
|
||||
runeIdToEntry map[runes.RuneId]*RuneEntry
|
||||
outPointToRuneBalances map[string]uint128.Uint128
|
||||
runeToRuneId map[runes.Rune]runes.RuneId
|
||||
}
|
||||
|
||||
func NewRunesProcessor() *runesProcessor {
|
||||
return &runesProcessor{
|
||||
runeIdToEntry: make(map[runes.RuneId]*RuneEntry),
|
||||
outPointToRuneBalances: make(map[string]uint128.Uint128),
|
||||
runeToRuneId: make(map[runes.Rune]runes.RuneId),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *runesProcessor) CurrentBlock() (types.BlockHeader, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *runesProcessor) PrepareData(ctx context.Context, from, to int64) ([]types.Block, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *runesProcessor) RevertData(ctx context.Context, from types.BlockHeader) error {
|
||||
panic("implement me")
|
||||
}
|
||||
23
modules/runes/internal/runes/rune_entry.go
Normal file
23
modules/runes/internal/runes/rune_entry.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package runes
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gaze-network/uint128"
|
||||
)
|
||||
|
||||
type RuneEntry struct {
|
||||
// CompletionTime is the time when the rune was fully minted.
|
||||
CompletionTime time.Time
|
||||
// Terms is the minting terms of the rune.
|
||||
Terms *Terms
|
||||
SpacedRune SpacedRune
|
||||
RuneId RuneId
|
||||
BurnedAmount uint128.Uint128
|
||||
// Mints is the number of times that this rune has been minted.
|
||||
Mints uint128.Uint128
|
||||
// Premine is the amount of the rune that was premined.
|
||||
Premine uint128.Uint128
|
||||
Symbol rune
|
||||
Divisibility uint8
|
||||
}
|
||||
54
modules/runes/processor.go
Normal file
54
modules/runes/processor.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package runes
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/core/indexers"
|
||||
"github.com/gaze-network/indexer-network/core/types"
|
||||
"github.com/gaze-network/indexer-network/modules/runes/internal/datagateway"
|
||||
)
|
||||
|
||||
var _ indexers.BitcoinProcessor = (*Processor)(nil)
|
||||
|
||||
type Processor struct {
|
||||
runesProcessorDG datagateway.RunesProcessorDataGateway
|
||||
}
|
||||
|
||||
type NewRunesProcessorParams struct {
|
||||
RunesProcessorDG datagateway.RunesProcessorDataGateway
|
||||
}
|
||||
|
||||
func NewRunesProcessor(params NewRunesProcessorParams) *Processor {
|
||||
return &Processor{
|
||||
runesProcessorDG: params.RunesProcessorDG,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Processor) Process(ctx context.Context, blocks []types.Block) error {
|
||||
for _, block := range blocks {
|
||||
for _, tx := range block.Transactions {
|
||||
if err := r.processTx(tx, block.BlockHeader); err != nil {
|
||||
return errors.Wrap(err, "failed to process tx")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Processor) processTx(tx *wire.MsgTx, blockHeader types.BlockHeader) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *Processor) CurrentBlock() (types.BlockHeader, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *Processor) PrepareData(ctx context.Context, from, to int64) ([]types.Block, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (r *Processor) RevertData(ctx context.Context, from types.BlockHeader) error {
|
||||
panic("implement me")
|
||||
}
|
||||
Reference in New Issue
Block a user