accounts

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package accounts provides functionality to interact with blockchain accounts and manage their associated states and transactions using Ethereum and Unpack libraries.

Package accounts provides functionality to interact with blockchain accounts and manage their associated states and transitions. It includes facilities to capture account-related events from a blockchain, process and transform these events into a more consumable format, and persist them into a storage system for further analysis or real-time monitoring purposes.

Index

Constants

View Source
const (
	DiscoverState machine.State = "discover"
	CreatorState  machine.State = "creator"
	NameState     machine.State = "name"
	TagsState     machine.State = "tags"
	BalanceState  machine.State = "balance"
	FinalState    machine.State = "final"
	ErrorState    machine.State = "error"
	DoneState     machine.State = "done"
)

Variables

This section is empty.

Functions

func GetStateFromString

func GetStateFromString(state string) (machine.State, error)

func NewCreatorHandler

func NewCreatorHandler(ctx context.Context, u *Unpacker) machine.Handler

func NewDiscoverHandler

func NewDiscoverHandler(ctx context.Context, u *Unpacker) machine.Handler

NewDiscoverHandler creates a new instance of DiscoverContractHandler. It sets up the handler with the provided context and Unpacker instance, and returns it as a machine.Handler.

func NewErrorContractHandler

func NewErrorContractHandler(ctx context.Context, u *Unpacker) machine.Handler

NewErrorContractHandler initializes a new instance of ErrorContractHandler with a given context and unpacker reference. It returns a machine.Handler configured with Enter, Process, and Exit strategies for handling error states.

func NewFinalContractHandler

func NewFinalContractHandler(ctx context.Context, u *Unpacker) machine.Handler

func NewNameHandler

func NewNameHandler(ctx context.Context, u *Unpacker) machine.Handler

func NewTagsHandler

func NewTagsHandler(ctx context.Context, u *Unpacker) machine.Handler

Types

type Addr

type Addr struct {
	NamedAddr utils.NamedAddr  `json:"namedAddr"`
	Account   *models.Account  `json:"account"`
	Contract  *models.Contract `json:"contract"`
	Token     *models.Token    `json:"token"`
}

func (*Addr) String

func (a *Addr) String() string

type CreatorHandler

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

func (*CreatorHandler) Enter

func (dh *CreatorHandler) Enter(data machine.Data) (machine.Data, error)

func (*CreatorHandler) Exit

func (dh *CreatorHandler) Exit(data machine.Data) (machine.Data, error)

func (*CreatorHandler) Process

func (dh *CreatorHandler) Process(data machine.Data) (machine.State, machine.Data, error)

type Descriptor

type Descriptor struct {
	Network          utils.Network   `json:"network"`
	NetworkID        utils.NetworkID `json:"networkId"`
	Addr             common.Address  `json:"addr"`
	BlockNumber      *big.Int        `json:"blockNumber"`
	TxHash           common.Hash     `json:"txHash"`
	CreatorTxReceipt *types.Receipt  `json:"creatorTxReceipt"
`
	InitialModel *models.Account `json:"initialModel"`
	Model        *models.Account `json:"model"`

	Partial   bool `json:"partial"`
	Processed bool `json:"processed"`

	Stats *Stats `json:"stats"`
	// contains filtered or unexported fields
}

Descriptor represents the state and context of a blockchain account, including transaction details and state transitions managed by a state machine.

func EventToDescriptor

func EventToDescriptor(event *events.Account) *Descriptor

func NewDescriptor

func NewDescriptor(u *Unpacker, network utils.Network, networkId utils.NetworkID, addr common.Address) *Descriptor

NewDescriptor creates a new Descriptor instance with initial values for the given Unpacker, network configuration, and account address.

func (*Descriptor) AppendCompletedState

func (d *Descriptor) AppendCompletedState(state machine.State)

AppendCompletedState adds a state to the list of completed states for this Descriptor if it is not already present.

func (*Descriptor) AppendCompletedStateFromString

func (d *Descriptor) AppendCompletedStateFromString(state string)

func (*Descriptor) AppendCompletedStates

func (d *Descriptor) AppendCompletedStates(states []machine.State)

AppendCompletedStates adds multiple states to the list of completed states for this Descriptor.

func (*Descriptor) AppendCompletedStatesFromStringArray

func (d *Descriptor) AppendCompletedStatesFromStringArray(states []string)

AppendCompletedStatesFromStringArray adds multiple states to the list of completed states for this Descriptor.

func (*Descriptor) AppendFailedState

func (d *Descriptor) AppendFailedState(state machine.State)

AppendFailedState adds a state to the list of failed states for this Descriptor if it is not already present.

func (*Descriptor) AppendFailedStateFromString

func (d *Descriptor) AppendFailedStateFromString(state string)

AppendFailedStateFromString adds a state to the list of failed states for this Descriptor if it is not already present.

func (*Descriptor) AppendFailedStates

func (d *Descriptor) AppendFailedStates(states []machine.State)

AppendFailedStates adds multiple states to the list of failed states for this Descriptor.

func (*Descriptor) AppendFailedStatesFromStringArray

func (d *Descriptor) AppendFailedStatesFromStringArray(states []string)

AppendFailedStatesFromStringArray adds multiple states to the list of failed states for this Descriptor.

func (*Descriptor) GetAddr

func (d *Descriptor) GetAddr() common.Address

GetAddr returns the Ethereum address associated with this Descriptor.

func (*Descriptor) GetBlockNumber

func (d *Descriptor) GetBlockNumber() *big.Int

GetBlockNumber returns the block header number from the blockchain for this transaction.

func (*Descriptor) GetCompletedStates

func (d *Descriptor) GetCompletedStates() []machine.State

GetCompletedStates returns a list of all completed states for this Descriptor.

func (*Descriptor) GetCompletedStatesAsStringArray

func (d *Descriptor) GetCompletedStatesAsStringArray() []string

GetCompletedStatesAsStringArray returns a list of all completed states as string array for this Descriptor.

func (*Descriptor) GetFailedStates

func (d *Descriptor) GetFailedStates() []machine.State

GetFailedStates returns a list of all failed states for this Descriptor.

func (*Descriptor) GetFailedStatesAsStringArray

func (d *Descriptor) GetFailedStatesAsStringArray() []string

GetFailedStatesAsStringArray returns a list of all failed states as string array for this Descriptor.

func (*Descriptor) GetModel

func (d *Descriptor) GetModel() *models.Account

func (*Descriptor) GetNetwork

func (d *Descriptor) GetNetwork() utils.Network

GetNetwork returns the blockchain network associated with this Descriptor.

func (*Descriptor) GetNetworkID

func (d *Descriptor) GetNetworkID() utils.NetworkID

GetNetworkID returns the network ID associated with this Descriptor.

func (*Descriptor) GetNextState

func (d *Descriptor) GetNextState() machine.State

GetNextState returns the next state for this Descriptor.

func (*Descriptor) GetTransactionHash

func (d *Descriptor) GetTransactionHash() common.Hash

GetTransactionHash returns the transaction hash associated with this Descriptor.

func (*Descriptor) GetUnpacker

func (d *Descriptor) GetUnpacker() *Unpacker

GetUnpacker retrieves the Unpacker associated with this Descriptor.

func (*Descriptor) HasCompletedState

func (d *Descriptor) HasCompletedState(state machine.State) bool

HasCompletedState checks if the given state is marked as completed for this Descriptor.

func (*Descriptor) HasFailedState

func (d *Descriptor) HasFailedState(state machine.State) bool

HasFailedState checks if the given state is marked as failed for this Descriptor.

func (*Descriptor) HasModel

func (d *Descriptor) HasModel() bool

func (*Descriptor) HasNextState

func (d *Descriptor) HasNextState() bool

HasNextState checks if there is a next state set for this Descriptor.

func (*Descriptor) RemoveCompletedState

func (d *Descriptor) RemoveCompletedState(state machine.State)

RemoveCompletedState removes a state from the list of completed states for this Descriptor.

func (*Descriptor) RemoveFailedState

func (d *Descriptor) RemoveFailedState(state machine.State)

RemoveFailedState removes a state from the list of failed states for this Descriptor.

func (*Descriptor) RemoveFailedStates

func (d *Descriptor) RemoveFailedStates(states []machine.State)

RemoveFailedStates removes multiple states from the list of failed states for this Descriptor.

func (*Descriptor) SetNextState

func (d *Descriptor) SetNextState(state machine.State)

SetNextState sets the next state for this Descriptor.

type DiscoverHandler

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

DiscoverHandler handles the discovery phase of the contract processing workflow. It implements the machine.Handler interface.

func (*DiscoverHandler) Enter

func (dh *DiscoverHandler) Enter(data machine.Data) (machine.Data, error)

Enter is the initial state of the handler. It performs any setup required before processing. Currently, it simply passes through the data without modification.

func (*DiscoverHandler) Exit

func (dh *DiscoverHandler) Exit(data machine.Data) (machine.Data, error)

Exit is the final state of the handler. It performs any cleanup required after processing. Currently, it simply passes through the data without modification.

func (*DiscoverHandler) Process

func (dh *DiscoverHandler) Process(data machine.Data) (machine.State, machine.Data, error)

Process handles the main logic of discovering contract details and dependencies. It validates contract information and updates the contract's state based on discovery outcomes.

type ErrorContractHandler

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

ErrorContractHandler defines a handler for processing contracts that have encountered errors. It embeds context for runtime control and a reference to the Unpacker for accessing shared functionalities.

func (*ErrorContractHandler) Enter

func (dh *ErrorContractHandler) Enter(data machine.Data) (machine.Data, error)

Enter prepares the handler for processing an error state. It can be used to initialize or reset state before the core error handling logic is executed. Currently, it simply returns the input data unchanged.

func (*ErrorContractHandler) Exit

func (dh *ErrorContractHandler) Exit(data machine.Data) (machine.Data, error)

Exit performs any necessary cleanup after the error processing is complete. This could involve releasing resources, logging, or other finalization activities. Currently, it returns the data unchanged.

func (*ErrorContractHandler) Process

Process executes the main logic for handling contracts in an error state. This function transitions the contract to a final or resolution state, effectively marking the error handling as complete. Currently, it marks the process as done without altering the data. @TODO: Metrics should be written at this stage. I don't think anything else is necessary for now.

type FinalContractHandler

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

func (*FinalContractHandler) Enter

func (dh *FinalContractHandler) Enter(data machine.Data) (machine.Data, error)

func (*FinalContractHandler) Exit

func (dh *FinalContractHandler) Exit(data machine.Data) (machine.Data, error)

func (*FinalContractHandler) Process

type HolderType

type HolderType string
var (
	// HumpbackHolderType 5000+ ETH
	HumpbackHolderType HolderType = "humpback"

	// WhaleHolderType Up to 5000 ETH
	WhaleHolderType HolderType = "whale"

	// SharkHolderType Up to 1000 ETH
	SharkHolderType HolderType = "shark"

	// DolphinHolderType Up to 500 ETH
	DolphinHolderType HolderType = "dolphin"

	// OctopusHolderType Up to 100 ETH
	OctopusHolderType HolderType = "octopus"

	// FishHolderType Up to 50 ETH
	FishHolderType HolderType = "fish"

	// CrabHolderType Up to 10 ETH
	CrabHolderType HolderType = "crab"

	// ShrimpHolderType Up to 1 ETH
	ShrimpHolderType HolderType = "shrimp"

	// UnknownHolderType we could not detect the holder type
	UnknownHolderType HolderType = "unknown"
)

func (HolderType) String

func (h HolderType) String() string

type NameHandler

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

func (*NameHandler) Enter

func (dh *NameHandler) Enter(data machine.Data) (machine.Data, error)

func (*NameHandler) Exit

func (dh *NameHandler) Exit(data machine.Data) (machine.Data, error)

func (*NameHandler) Process

func (dh *NameHandler) Process(data machine.Data) (machine.State, machine.Data, error)

type Option

type Option func(*Unpacker) error

Option defines a functional option for configuring the Unpacker.

func WithBindingsManager

func WithBindingsManager(bindManager *bindings.Manager) Option

WithBindingsManager configures the Unpacker with a specific bindings manager for smart contract interaction.

func WithCache

func WithCache(chce *cache.Redis) Option

func WithDb

func WithDb(d db.Adapter) Option

WithDb configures the Unpacker with a specific database for persistent storage.

func WithEtherScanProvider

func WithEtherScanProvider(etherscan *etherscan.Provider) Option

WithEtherScanProvider configures the Unpacker with a specific EtherScan provider for Ethereum blockchain data.

func WithJetStreamContext

func WithJetStreamContext(jsCtx nats.JetStreamContext) Option

WithJetStreamContext configures the Unpacker with a specific NATS JetStream context for advanced messaging capabilities.

func WithLabelManager

func WithLabelManager(lm *labels.LabelManager) Option

func WithNats

func WithNats(nsConn *nats.Conn) Option

WithNats configures the Unpacker with a specific NATS connection for messaging.

func WithPool

func WithPool(pool *clients.ClientPool) Option

WithPool configures the Unpacker with a specific client pool for blockchain interactions.

func WithSourcify

func WithSourcify(sm *sourcify.Client) Option

WithSourcify configures the Unpacker with a sourcify client

func WithStateManager

func WithStateManager(sm *state.State) Option

WithStateManager configures the Unpacker with a specific state manager for application state tracking.

func WithStorage

func WithStorage(sm *storage.Storage) Option

WithStorage configures the Unpacker with a storage manager

type StateProcessTime

type StateProcessTime struct {
	Start time.Time     `json:"start"`
	End   time.Time     `json:"end"`
	Took  time.Duration `json:"took"`
}

type Stats

type Stats struct {
	StatesProcessingTime map[machine.State]*StateProcessTime `json:"states_processing_time"`
}

func (*Stats) ToPretty

func (s *Stats) ToPretty() string

func (*Stats) TotalTimeTook

func (s *Stats) TotalTimeTook() time.Duration

type TagsHandler

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

func (*TagsHandler) Enter

func (dh *TagsHandler) Enter(data machine.Data) (machine.Data, error)

func (*TagsHandler) Exit

func (dh *TagsHandler) Exit(data machine.Data) (machine.Data, error)

func (*TagsHandler) Process

func (dh *TagsHandler) Process(data machine.Data) (machine.State, machine.Data, error)

type Unpacker

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

Unpacker orchestrates blockchain data extraction and processing. It leverages a client pool for blockchain interaction, etherscan for blockchain data, NATS for messaging, a bindings manager for smart contract interaction, and a database for persistent storage.

func NewUnpacker

func NewUnpacker(ctx context.Context, opts ...Option) (*Unpacker, error)

NewUnpacker creates a new Unpacker instance with optional configurations. It initializes the Unpacker with a context and applies any provided configuration options.

func (*Unpacker) RegisterMachineStates

func (u *Unpacker) RegisterMachineStates(sm *machine.StateMachine) error

func (*Unpacker) Unpack

func (u *Unpacker) Unpack(ctx context.Context, descriptor *Descriptor, state machine.State) (*Descriptor, error)

Jump to

Keyboard shortcuts

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