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
- func GetStateFromString(state string) (machine.State, error)
- func NewCreatorHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewDiscoverHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewErrorContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewFinalContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewNameHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewTagsHandler(ctx context.Context, u *Unpacker) machine.Handler
- type Addr
- type CreatorHandler
- type Descriptor
- func (d *Descriptor) AppendCompletedState(state machine.State)
- func (d *Descriptor) AppendCompletedStateFromString(state string)
- func (d *Descriptor) AppendCompletedStates(states []machine.State)
- func (d *Descriptor) AppendCompletedStatesFromStringArray(states []string)
- func (d *Descriptor) AppendFailedState(state machine.State)
- func (d *Descriptor) AppendFailedStateFromString(state string)
- func (d *Descriptor) AppendFailedStates(states []machine.State)
- func (d *Descriptor) AppendFailedStatesFromStringArray(states []string)
- func (d *Descriptor) GetAddr() common.Address
- func (d *Descriptor) GetBlockNumber() *big.Int
- func (d *Descriptor) GetCompletedStates() []machine.State
- func (d *Descriptor) GetCompletedStatesAsStringArray() []string
- func (d *Descriptor) GetFailedStates() []machine.State
- func (d *Descriptor) GetFailedStatesAsStringArray() []string
- func (d *Descriptor) GetModel() *models.Account
- func (d *Descriptor) GetNetwork() utils.Network
- func (d *Descriptor) GetNetworkID() utils.NetworkID
- func (d *Descriptor) GetNextState() machine.State
- func (d *Descriptor) GetTransactionHash() common.Hash
- func (d *Descriptor) GetUnpacker() *Unpacker
- func (d *Descriptor) HasCompletedState(state machine.State) bool
- func (d *Descriptor) HasFailedState(state machine.State) bool
- func (d *Descriptor) HasModel() bool
- func (d *Descriptor) HasNextState() bool
- func (d *Descriptor) RemoveCompletedState(state machine.State)
- func (d *Descriptor) RemoveFailedState(state machine.State)
- func (d *Descriptor) RemoveFailedStates(states []machine.State)
- func (d *Descriptor) SetNextState(state machine.State)
- type DiscoverHandler
- type ErrorContractHandler
- type FinalContractHandler
- type HolderType
- type NameHandler
- type Option
- func WithBindingsManager(bindManager *bindings.Manager) Option
- func WithCache(chce *cache.Redis) Option
- func WithDb(d db.Adapter) Option
- func WithEtherScanProvider(etherscan *etherscan.Provider) Option
- func WithJetStreamContext(jsCtx nats.JetStreamContext) Option
- func WithLabelManager(lm *labels.LabelManager) Option
- func WithNats(nsConn *nats.Conn) Option
- func WithPool(pool *clients.ClientPool) Option
- func WithSourcify(sm *sourcify.Client) Option
- func WithStateManager(sm *state.State) Option
- func WithStorage(sm *storage.Storage) Option
- type StateProcessTime
- type Stats
- type TagsHandler
- type Unpacker
Constants ¶
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 NewDiscoverHandler ¶
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 ¶
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 ¶
Types ¶
type Addr ¶
type CreatorHandler ¶
type CreatorHandler struct {
// contains filtered or unexported fields
}
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 ¶
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 ¶
Exit is the final state of the handler. It performs any cleanup required after processing. Currently, it simply passes through the data without modification.
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 ¶
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 ¶
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
}
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
}
type Option ¶
Option defines a functional option for configuring the Unpacker.
func WithBindingsManager ¶
WithBindingsManager configures the Unpacker with a specific bindings manager for smart contract interaction.
func WithEtherScanProvider ¶
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 ¶
WithStateManager configures the Unpacker with a specific state manager for application state tracking.
func WithStorage ¶
WithStorage configures the Unpacker with a storage manager
type StateProcessTime ¶
type Stats ¶
type Stats struct {
StatesProcessingTime map[machine.State]*StateProcessTime `json:"states_processing_time"`
}
func (*Stats) TotalTimeTook ¶
type TagsHandler ¶
type TagsHandler struct {
// contains filtered or unexported fields
}
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 ¶
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)