blockchain

package
v0.0.0-...-edcad5e Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseWEthAddr = strings.ToLower("0x4200000000000000000000000000000000000006")
	BaseUsdcAddr = strings.ToLower("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913")
	BaseUsdAddr  = strings.ToLower("0xB79DD08EA68A908A97220C76d19A6aA9cBDE4376")
	BaseDaiAddr  = strings.ToLower("0x50c5725949a6f0c72e6c4a641f24049a917db0cb")
)
View Source
var (
	// ETHAddr is ethereum address
	ETHAddr = strings.ToLower("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")

	// WETHAddr is wrapped ETH address
	WETHAddr = strings.ToLower("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")

	// USDTAddr is usdt address
	USDTAddr = strings.ToLower("0xdac17f958d2ee523a2206206994597c13d831ec7")

	// USDCAddr is usdc address
	USDCAddr = strings.ToLower("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")

	// DAIAddr is dai address
	DAIAddr = strings.ToLower("0x6b175474e89094c44da98b954eedeac495271d0f")

	// FraxAddr is frax address
	FraxAddr = strings.ToLower("0x853d955acef822db058eb8505911ed77f175b99e")

	// Wbtc is frax address
	WBTCAddr = strings.ToLower("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599")
)

Functions

func EthToWei

func EthToWei(n float64) *big.Int

EthToWei converts Gwei as a float to Wei as a big int

func IsValidTxHash

func IsValidTxHash(tx string) bool

IsValidTxHash return if address is zero

func IsZeroAddress

func IsZeroAddress(address ethereum.Address) bool

IsZeroAddress return if address is zero

func NewEthereumClient

func NewEthereumClient(ethereumNodeURL string) (*ethclient.Client, error)

NewEthereumClientFromFlag returns Ethereum client from flag variable, or error if occurs

func NodeTypeStrings

func NodeTypeStrings() []string

NodeTypeStrings returns a slice of all String values of the enum

Types

type BlockTimeResolver

type BlockTimeResolver struct {
	// contains filtered or unexported fields
}

BlockTimeResolver is a helper to get transaction timestamp from block number. It has a cache for one block.

func NewBlockTimeResolver

func NewBlockTimeResolver(log *zap.SugaredLogger, nodePool *NodePool, timeout time.Duration) (*BlockTimeResolver, error)

NewBlockTimeResolver returns BlockTimeResolver instance given a ethereum client.

func (*BlockTimeResolver) Resolve

func (btr *BlockTimeResolver) Resolve(chain cm.Chain, blockNumber uint64) (time.Time, error)

Resolve returns timestamp from block number. It cachedHeaders block number and block header to reduces the number of request to node.

func (*BlockTimeResolver) Sync

func (btr *BlockTimeResolver) Sync(chain cm.Chain, fromBlock, toBlock uint64) error

type BlockTimeResolverInterface

type BlockTimeResolverInterface interface {
	Sync(chain common.Chain, fromBlock, toBlock uint64) error
	Resolve(chain common.Chain, blockNumber uint64) (time.Time, error)
}

BlockTimeResolverInterface define the functionality

type ChainNode

type ChainNode struct {
	// contains filtered or unexported fields
}

type MockBlockTimeResolve

type MockBlockTimeResolve struct {
	// contains filtered or unexported fields
}

MockBlockTimeResolve is the mock implementation of blockTimeResolver for testing

func NewMockBlockTimeResolve

func NewMockBlockTimeResolve(ts time.Time) *MockBlockTimeResolve

NewMockBlockTimeResolve creates new instance of MockBlockTimeResolve

func (*MockBlockTimeResolve) Resolve

func (btr *MockBlockTimeResolve) Resolve(_ uint64) (time.Time, error)

Resolve return current time as mock result for block time

type NodePool

type NodePool struct {
	// contains filtered or unexported fields
}

func NewNodePool

func NewNodePool(log *zap.SugaredLogger, infuraUrl, infuraKey string, infuraNodeRelaxDuration time.Duration) (*NodePool, error)

func (*NodePool) FilterLogs

func (n *NodePool) FilterLogs(chain cm.Chain, query ether.FilterQuery) ([]types.Log, error)

func (*NodePool) GetBlockNumber

func (n *NodePool) GetBlockNumber(chain cm.Chain) (uint64, error)

func (*NodePool) GetBlockTimeStamp

func (n *NodePool) GetBlockTimeStamp(chain cm.Chain, timeout time.Duration, blockNumber uint64) (*types.Header, error)

func (*NodePool) GetDecimal

func (n *NodePool) GetDecimal(chain cm.Chain, address common.Address, timeout time.Duration) (uint8, error)

func (*NodePool) GetTxData

func (n *NodePool) GetTxData(chain cm.Chain, txHash common.Hash, timeout time.Duration) (*types.Receipt, common.Address, error)

type NodeType

type NodeType uint64

enumer -type=NodeType -linecomment -json=true -text=true -sql=true

const (
	NodeInfura NodeType = iota + 1 // infura
)

func NodeTypeString

func NodeTypeString(s string) (NodeType, error)

NodeTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func NodeTypeValues

func NodeTypeValues() []NodeType

NodeTypeValues returns all values of the enum

func (NodeType) IsANodeType

func (i NodeType) IsANodeType() bool

IsANodeType returns "true" if the value is listed in the enum definition. "false" otherwise

func (NodeType) MarshalJSON

func (i NodeType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for NodeType

func (NodeType) MarshalText

func (i NodeType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for NodeType

func (*NodeType) Scan

func (i *NodeType) Scan(value interface{}) error

func (NodeType) String

func (i NodeType) String() string

func (*NodeType) UnmarshalJSON

func (i *NodeType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for NodeType

func (*NodeType) UnmarshalText

func (i *NodeType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for NodeType

func (NodeType) Value

func (i NodeType) Value() (driver.Value, error)

type TokenAmountFormatter

type TokenAmountFormatter struct {
	// contains filtered or unexported fields
}

TokenAmountFormatter is a helper to convert token amount from/to wei

func NewTokenAmountFormatter

func NewTokenAmountFormatter(log *zap.SugaredLogger, nodePool *NodePool) (*TokenAmountFormatter, error)

NewTokenAmountFormatter returns a new TokenAmountFormatter instance.

func (*TokenAmountFormatter) FromWei

func (f *TokenAmountFormatter) FromWei(chain cm.Chain, address common.Address, amount *big.Int) (float64, error)

FromWei formats the given amount in wei to human friendly number with token decimals from contract.

func (*TokenAmountFormatter) GetDecimals

func (f *TokenAmountFormatter) GetDecimals(chain cm.Chain, address common.Address) (int64, error)

GetDecimals return decimals of a token

type TokenAmountFormatterInterface

type TokenAmountFormatterInterface interface {
	FromWei(cm.Chain, common.Address, *big.Int) (float64, error)
	GetDecimals(cm.Chain, common.Address) (int64, error)
}

TokenAmountFormatterInterface interface convert token amount from/to wei

Jump to

Keyboard shortcuts

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