Documentation ¶
Overview ¶
Package unpacker provides functionalities to handle and process contracts, including discovery, extraction, validation, and storage of contract data.
Index ¶
- Constants
- func GetStateFromString(state string) (machine.State, error)
- func NewAstHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewCfgHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewConstructorHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewDiscoverContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewErrorContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewEventHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewFinalContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewFunctionHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewMetadataContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewParserContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewProvidersContractHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewProxyHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewStandardsHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewStateVariableHandler(ctx context.Context, u *Unpacker) machine.Handler
- func NewTokenHandler(ctx context.Context, u *Unpacker) machine.Handler
- type AstHandler
- type CfgHandler
- type ConstructorHandler
- 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) AppendStandard(standard standards.Standard)
- func (d *Descriptor) AppendStandardFromString(standard string)
- func (d *Descriptor) AppendStandards(s []standards.Standard)
- func (d *Descriptor) AppendStandardsFromStringArray(s []string)
- func (d *Descriptor) GetAddr() common.Address
- func (d *Descriptor) GetCompletedStates() []machine.State
- func (d *Descriptor) GetCompletedStatesAsStringArray() []string
- func (d *Descriptor) GetContract() *contracts.Contract
- func (d *Descriptor) GetContractEntry() *models.Contract
- func (d *Descriptor) GetContractMetadataModel() *models.Metadata
- func (d *Descriptor) GetContractModel() *models.Contract
- func (d *Descriptor) GetDeployerAddress() common.Address
- func (d *Descriptor) GetFailedStates() []machine.State
- func (d *Descriptor) GetFailedStatesAsStringArray() []string
- func (d *Descriptor) GetHeader() *types.Header
- func (d *Descriptor) GetNetwork() utils.Network
- func (d *Descriptor) GetNetworkID() utils.NetworkID
- func (d *Descriptor) GetNextState() machine.State
- func (d *Descriptor) GetReceipt() *types.Receipt
- func (d *Descriptor) GetStandards() []standards.Standard
- func (d *Descriptor) GetStandardsAsStringArray() []string
- func (d *Descriptor) GetStorageCachePath() string
- func (d *Descriptor) GetTransaction() *types.Transaction
- func (d *Descriptor) GetUnpacker() *Unpacker
- func (d *Descriptor) HasCompletedState(state machine.State) bool
- func (d *Descriptor) HasFailedState(state machine.State) bool
- func (d *Descriptor) HasNextState() bool
- func (d *Descriptor) HasStandard(standard standards.Standard) bool
- func (d *Descriptor) RemoveCompletedState(state machine.State)
- func (d *Descriptor) RemoveFailedState(state machine.State)
- func (d *Descriptor) RemoveFailedStateFromString(state string)
- func (d *Descriptor) RemoveFailedStates(states []machine.State)
- func (d *Descriptor) RemoveFailedStatesFromStringArray(states []string)
- func (d *Descriptor) SetContract(c *contracts.Contract) *contracts.Contract
- func (d *Descriptor) SetContractMetadataModel(c *models.Metadata) *models.Metadata
- func (d *Descriptor) SetContractModel(c *models.Contract) *models.Contract
- func (d *Descriptor) SetDeployerAddress(addr common.Address)
- func (d *Descriptor) SetNextState(state machine.State)
- type DiscoverContractHandler
- type ErrorContractHandler
- type EventHandler
- type FinalContractHandler
- type FunctionHandler
- type MetadataContractHandler
- 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 ParserContractHandler
- type ProvidersContractHandler
- type ProxyHandler
- type StandardsHandler
- type StateProcessTime
- type StateVariableHandler
- type Stats
- type TokenHandler
- type Unpacker
Constants ¶
const ( DiscoverState machine.State = "discover" MetadataState machine.State = "metadata" SourceProvidersState machine.State = "source_providers" SourcesState machine.State = "sources" ParserState machine.State = "parser" CfgState machine.State = "cfg" OpcodesState machine.State = "opcodes" AstState machine.State = "ast" SocialState machine.State = "social" StandardsState machine.State = "standards" ConstructorState machine.State = "constructor" FunctionSignaturesState machine.State = "function_signatures" EventSignaturesState machine.State = "event_signatures" StateVariableState machine.State = "state_variable" TokenState machine.State = "token" ProxyState machine.State = "proxy" FinalState machine.State = "final" ErrorState machine.State = "error" DoneState machine.State = "done" )
Variables ¶
This section is empty.
Functions ¶
func NewConstructorHandler ¶
func NewDiscoverContractHandler ¶
NewDiscoverContractHandler 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 ¶
func NewProvidersContractHandler ¶
NewProvidersContractHandler initializes a new instance of ProvidersContractHandler with a given context and an Unpacker reference. It returns a machine.Handler configured with the necessary callbacks for state transitions.
func NewStandardsHandler ¶
func NewStateVariableHandler ¶
Types ¶
type AstHandler ¶
type AstHandler struct {
// contains filtered or unexported fields
}
type CfgHandler ¶
type CfgHandler struct {
// contains filtered or unexported fields
}
type ConstructorHandler ¶
type ConstructorHandler 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"` Header *types.Header `json:"header"` Tx *types.Transaction `json:"tx"` Receipt *types.Receipt `json:"receipt"` SourcifyMetadata *sourcify.Metadata `json:"sourcifyMetadata"` EntryUnitName string `json:"entryUnitName"` Sources *solgo.Sources `json:"sources"` UnsortedSources *solgo.Sources `json:"unsortedSources"` SaveSources bool SelfDestructed bool `json:"selfDestructed"` Partial bool `json:"partial"` Processed bool `json:"processed"` Stats *Stats `json:"stats"` // contains filtered or unexported fields }
func NewDescriptor ¶
func (*Descriptor) AppendCompletedState ¶
func (d *Descriptor) AppendCompletedState(state machine.State)
func (*Descriptor) AppendCompletedStateFromString ¶
func (d *Descriptor) AppendCompletedStateFromString(state string)
func (*Descriptor) AppendCompletedStates ¶
func (d *Descriptor) AppendCompletedStates(states []machine.State)
func (*Descriptor) AppendCompletedStatesFromStringArray ¶
func (d *Descriptor) AppendCompletedStatesFromStringArray(states []string)
func (*Descriptor) AppendFailedState ¶
func (d *Descriptor) AppendFailedState(state machine.State)
func (*Descriptor) AppendFailedStateFromString ¶
func (d *Descriptor) AppendFailedStateFromString(state string)
func (*Descriptor) AppendFailedStates ¶
func (d *Descriptor) AppendFailedStates(states []machine.State)
func (*Descriptor) AppendFailedStatesFromStringArray ¶
func (d *Descriptor) AppendFailedStatesFromStringArray(states []string)
func (*Descriptor) AppendStandard ¶
func (d *Descriptor) AppendStandard(standard standards.Standard)
func (*Descriptor) AppendStandardFromString ¶
func (d *Descriptor) AppendStandardFromString(standard string)
func (*Descriptor) AppendStandards ¶
func (d *Descriptor) AppendStandards(s []standards.Standard)
func (*Descriptor) AppendStandardsFromStringArray ¶
func (d *Descriptor) AppendStandardsFromStringArray(s []string)
func (*Descriptor) GetAddr ¶
func (d *Descriptor) GetAddr() common.Address
func (*Descriptor) GetCompletedStates ¶
func (d *Descriptor) GetCompletedStates() []machine.State
func (*Descriptor) GetCompletedStatesAsStringArray ¶
func (d *Descriptor) GetCompletedStatesAsStringArray() []string
func (*Descriptor) GetContract ¶
func (d *Descriptor) GetContract() *contracts.Contract
func (*Descriptor) GetContractEntry ¶
func (d *Descriptor) GetContractEntry() *models.Contract
func (*Descriptor) GetContractMetadataModel ¶
func (d *Descriptor) GetContractMetadataModel() *models.Metadata
func (*Descriptor) GetContractModel ¶
func (d *Descriptor) GetContractModel() *models.Contract
func (*Descriptor) GetDeployerAddress ¶
func (d *Descriptor) GetDeployerAddress() common.Address
func (*Descriptor) GetFailedStates ¶
func (d *Descriptor) GetFailedStates() []machine.State
func (*Descriptor) GetFailedStatesAsStringArray ¶
func (d *Descriptor) GetFailedStatesAsStringArray() []string
func (*Descriptor) GetHeader ¶
func (d *Descriptor) GetHeader() *types.Header
func (*Descriptor) GetNetwork ¶
func (d *Descriptor) GetNetwork() utils.Network
func (*Descriptor) GetNetworkID ¶
func (d *Descriptor) GetNetworkID() utils.NetworkID
func (*Descriptor) GetNextState ¶
func (d *Descriptor) GetNextState() machine.State
func (*Descriptor) GetReceipt ¶
func (d *Descriptor) GetReceipt() *types.Receipt
func (*Descriptor) GetStandards ¶
func (d *Descriptor) GetStandards() []standards.Standard
func (*Descriptor) GetStandardsAsStringArray ¶
func (d *Descriptor) GetStandardsAsStringArray() []string
func (*Descriptor) GetStorageCachePath ¶
func (d *Descriptor) GetStorageCachePath() string
func (*Descriptor) GetTransaction ¶
func (d *Descriptor) GetTransaction() *types.Transaction
func (*Descriptor) GetUnpacker ¶
func (d *Descriptor) GetUnpacker() *Unpacker
func (*Descriptor) HasCompletedState ¶
func (d *Descriptor) HasCompletedState(state machine.State) bool
func (*Descriptor) HasFailedState ¶
func (d *Descriptor) HasFailedState(state machine.State) bool
func (*Descriptor) HasNextState ¶
func (d *Descriptor) HasNextState() bool
func (*Descriptor) HasStandard ¶
func (d *Descriptor) HasStandard(standard standards.Standard) bool
func (*Descriptor) RemoveCompletedState ¶
func (d *Descriptor) RemoveCompletedState(state machine.State)
func (*Descriptor) RemoveFailedState ¶
func (d *Descriptor) RemoveFailedState(state machine.State)
func (*Descriptor) RemoveFailedStateFromString ¶
func (d *Descriptor) RemoveFailedStateFromString(state string)
func (*Descriptor) RemoveFailedStates ¶
func (d *Descriptor) RemoveFailedStates(states []machine.State)
func (*Descriptor) RemoveFailedStatesFromStringArray ¶
func (d *Descriptor) RemoveFailedStatesFromStringArray(states []string)
func (*Descriptor) SetContract ¶
func (d *Descriptor) SetContract(c *contracts.Contract) *contracts.Contract
func (*Descriptor) SetContractMetadataModel ¶
func (d *Descriptor) SetContractMetadataModel(c *models.Metadata) *models.Metadata
func (*Descriptor) SetContractModel ¶
func (d *Descriptor) SetContractModel(c *models.Contract) *models.Contract
func (*Descriptor) SetDeployerAddress ¶
func (d *Descriptor) SetDeployerAddress(addr common.Address)
func (*Descriptor) SetNextState ¶
func (d *Descriptor) SetNextState(state machine.State)
type DiscoverContractHandler ¶
type DiscoverContractHandler struct {
// contains filtered or unexported fields
}
DiscoverContractHandler handles the discovery phase of the contract processing workflow. It implements the machine.Handler interface.
func (*DiscoverContractHandler) 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 (*DiscoverContractHandler) 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 EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
type FinalContractHandler ¶
type FinalContractHandler struct {
// contains filtered or unexported fields
}
type FunctionHandler ¶
type FunctionHandler struct {
// contains filtered or unexported fields
}
type MetadataContractHandler ¶
type MetadataContractHandler 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 ParserContractHandler ¶
type ParserContractHandler struct {
// contains filtered or unexported fields
}
type ProvidersContractHandler ¶
type ProvidersContractHandler struct {
// contains filtered or unexported fields
}
ProvidersContractHandler manages the lifecycle and state transitions of smart contracts within the unpacker process. It interfaces with the blockchain network to discover and validate contract source code and metadata, leveraging local caches and external services as necessary.
func (*ProvidersContractHandler) Enter ¶
Enter is called when the ProvidersContractHandler enters a new state. It currently performs no operations and immediately returns the input data unmodified.
func (*ProvidersContractHandler) Exit ¶
Exit is called when the ProvidersContractHandler exits its current state. It currently performs no operations and immediately returns the input data unmodified.
func (*ProvidersContractHandler) Process ¶
Process handles the core logic of the ProvidersContractHandler during its active state. It performs several checks and operations: - Verifies if dependency states are completed. - Attempts to load contract source code from a local cache. - Falls back to discovering source code from external services if not available locally. - Logs errors and updates the contract descriptor with the discovered sources.
type ProxyHandler ¶
type ProxyHandler struct {
// contains filtered or unexported fields
}
type StandardsHandler ¶
type StandardsHandler struct {
// contains filtered or unexported fields
}
type StateProcessTime ¶
type StateVariableHandler ¶
type StateVariableHandler struct {
// contains filtered or unexported fields
}
type Stats ¶
type Stats struct {
StatesProcessingTime map[machine.State]*StateProcessTime `json:"states_processing_time"`
}
func (*Stats) TotalTimeTook ¶
type TokenHandler ¶
type TokenHandler 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)