parser

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 12 Imported by: 1

README

Parser

Descriptions

Parser extracts standardized transactions from raw transactions

Requires
  • Filtered raw data store
  • Data store to save parsed data
Quick start
git clone https://github.com/dezswap/cosmwasm-etl
cd cosmwasm-etl
vim config.yaml # to change environment variables.
export APP_TYPE=parser # one of (aggregator/collector/parser)
make up # starts App, with PostgresQL
make watch # server is automatically restarted when code is edited
# ...
make down # shut down all services
Migrations
make parser-migrate-up             # run migration
make parser-migrate-down           # down migration
make parser-migration-generate  # generate empty migration files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FakerCustomGenerator

func FakerCustomGenerator()

FakerCustomGenerator ...

func IndexOf

func IndexOf[T comparable](slice []T, target T) int

func NewDexApp

func NewDexApp(app TargetApp, srcStore SourceDataStore, repo Repo, logger logging.Logger, c configs.ParserConfig) *dexApp

Types

type Asset

type Asset struct {
	Addr   string `json:"addr"`
	Amount string `json:"amount" faker:"amountString"`
}

func FakeParserAssets

func FakeParserAssets() []Asset

func GetAssetFromAmountAssetString

func GetAssetFromAmountAssetString(amountAsset string) (Asset, error)

func GetAssetsFromAssetsString

func GetAssetsFromAssetsString(amountsAssets string) ([]Asset, error)

type Dex

type Dex interface {
	Runner
	TargetApp
	// contains filtered or unexported methods
}

type DexMixin

type DexMixin struct{}

func (*DexMixin) HasProvide

func (p *DexMixin) HasProvide(pairTxs []*ParsedTx) bool

func (*DexMixin) RemoveDuplicatedTxs

func (p *DexMixin) RemoveDuplicatedTxs(pairTxs []*ParsedTx, transferTxs []*ParsedTx) []ParsedTx

type Mapper

type Mapper interface {
	// return nil if the matched result is not for this parser
	MatchedToParsedTx(eventlog.MatchedResult, ...interface{}) (*ParsedTx, error)
}

type Pair

type Pair struct {
	ContractAddr string   `json:"contractAddr"`
	Assets       []string `json:"assets"`
	LpAddr       string   `json:"lpAddr"`
}

func FakeParserPairs

func FakeParserPairs() []Pair

type PairParsers

type PairParsers struct {
	CreatePairParser Parser
	PairActionParser Parser
	InitialProvide   Parser
	WasmTransfer     Parser
	Transfer         Parser
}

type PairRepo

type PairRepo interface {
	GetPairs() (map[string]Pair, error)
}

type ParsedTx

type ParsedTx struct {
	Hash      string    `json:"hash"`
	Timestamp time.Time `json:"timestamp"` // timestamp of a block

	Type             TxType   `json:"type" faker:"parserTxType"`
	Sender           string   `json:"sender"`
	ContractAddr     string   `json:"contractAddr"`
	Assets           [2]Asset `json:"assets"`
	LpAddr           string   `json:"lpAddr"`
	LpAmount         string   `json:"lpAmount" faker:"amountString"`
	CommissionAmount string   `json:"commissionAmount" faker:"amountString"`

	Meta map[string]interface{} `json:"meta" faker:"meta"`
}

func FakeParserParsedTxs

func FakeParserParsedTxs() []ParsedTx

type Parser

type Parser interface {
	Parse(hash string, timestamp time.Time, raws eventlog.LogResults, optionals ...interface{}) ([]*ParsedTx, error)
	Mapper
}

func NewParser

func NewParser(finder eventlog.LogFinder, mapper Mapper) Parser

type ParserMock

type ParserMock struct{ mock.Mock }

func (*ParserMock) MatchedToParsedTx

func (p *ParserMock) MatchedToParsedTx(result eventlog.MatchedResult, optional ...interface{}) (*ParsedTx, error)

matchedToParsedTx implements parser

func (*ParserMock) Parse

func (p *ParserMock) Parse(hash string, timestamp time.Time, raws eventlog.LogResults, optionals ...interface{}) ([]*ParsedTx, error)

parse implements parser

type PoolInfo

type PoolInfo struct {
	ContractAddr string  `json:"contractAddr"`
	Assets       []Asset `json:"assets"`
	TotalShare   string  `json:"totalShare" faker:"amountString"`
}

func FakeParserPoolInfoTxs

func FakeParserPoolInfoTxs() []PoolInfo

type RawStoreMock

type RawStoreMock struct{ mock.Mock }

func (*RawStoreMock) GetPoolInfos

func (r *RawStoreMock) GetPoolInfos(height uint64) ([]PoolInfo, error)

GetPoolInfos implements RawDataStore

func (*RawStoreMock) GetSourceSyncedHeight

func (r *RawStoreMock) GetSourceSyncedHeight() (uint64, error)

GetSourceSyncedHeight implements RawDataStore

func (*RawStoreMock) GetSourceTxs

func (r *RawStoreMock) GetSourceTxs(height uint64) (RawTxs, error)

GetSourceTxs implements RawDataStore

type RawTx

type RawTx struct {
	Hash       string              `json:"hash"`
	Sender     string              `json:"sender"`
	Timestamp  time.Time           `json:"timestamp,omitempty"`
	LogResults eventlog.LogResults `json:"logResults"`
}

type RawTxs

type RawTxs []RawTx

type Repo

type Repo interface {
	Insert(height uint64, txs []ParsedTx, pools []PoolInfo, pairDto []Pair) error
	GetSyncedHeight() (uint64, error)
	PairRepo
}

type RepoMock

type RepoMock struct{ mock.Mock }

func (*RepoMock) GetPairs

func (m *RepoMock) GetPairs() (map[string]Pair, error)

GetPairs implements Repo

func (*RepoMock) GetSyncedHeight

func (m *RepoMock) GetSyncedHeight() (uint64, error)

GetSyncedHeight implements Repo

func (*RepoMock) Insert

func (m *RepoMock) Insert(height uint64, txs []ParsedTx, pools []PoolInfo, pairDto []Pair) error

Insert implements Repo

type Runner

type Runner interface {
	Run() error
}

type SourceDataStore

type SourceDataStore interface {
	GetSourceSyncedHeight() (uint64, error)
	GetSourceTxs(height uint64) (RawTxs, error)
	GetPoolInfos(height uint64) ([]PoolInfo, error)
}

type TargetApp

type TargetApp interface {
	ParseTxs(tx RawTx, height uint64) ([]ParsedTx, error)
}

type TxType

type TxType string
const (
	CreatePair     TxType = "create_pair"
	Swap           TxType = "swap"
	Provide        TxType = "provide"
	InitialProvide TxType = "initial_provide"
	Withdraw       TxType = "withdraw"
	Transfer       TxType = "transfer"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL