unpacker

package
v0.9.9-rc3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package unpacker provides functionalities to handle and process contracts, including discovery, extraction, validation, and storage of contract data.

Index

Constants

View Source
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 GetStateFromString

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

func NewAstHandler

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

func NewCfgHandler

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

func NewConstructorHandler

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

func NewDiscoverContractHandler

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

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

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 NewEventHandler

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

func NewFinalContractHandler

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

func NewFunctionHandler

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

func NewMetadataContractHandler

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

func NewParserContractHandler

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

func NewProvidersContractHandler

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

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 NewProxyHandler

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

func NewStandardsHandler

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

func NewStateVariableHandler

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

func NewTokenHandler

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

Types

type AstHandler

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

func (*AstHandler) Enter

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

func (*AstHandler) Exit

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

func (*AstHandler) Process

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

type CfgHandler

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

func (*CfgHandler) Enter

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

func (*CfgHandler) Exit

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

func (*CfgHandler) Process

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

type ConstructorHandler

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

func (*ConstructorHandler) Enter

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

func (*ConstructorHandler) Exit

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

func (*ConstructorHandler) Process

func (dh *ConstructorHandler) 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"`
	Header           *types.Header      `json:"header"`
	Tx               *types.Transaction `json:"tx"`
	Receipt          *types.Receipt     `json:"receipt"`
	SourcifyMetadata *sourcify.Metadata `json:"sourcifyMetadata"`
	EntryUnitName    string             `json:"entryUnitName"`
	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 NewDescriptor(u *Unpacker, network utils.Network, networkId utils.NetworkID, addr common.Address) *Descriptor

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.

func (*DiscoverContractHandler) Process

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 EventHandler

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

func (*EventHandler) Enter

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

func (*EventHandler) Exit

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

func (*EventHandler) Process

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

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 FunctionHandler

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

func (*FunctionHandler) Enter

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

func (*FunctionHandler) Exit

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

func (*FunctionHandler) Process

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

type MetadataContractHandler

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

func (*MetadataContractHandler) Enter

func (*MetadataContractHandler) Exit

func (*MetadataContractHandler) Process

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 ParserContractHandler

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

func (*ParserContractHandler) Enter

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

func (*ParserContractHandler) Exit

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

func (*ParserContractHandler) Process

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
}

func (*ProxyHandler) Enter

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

func (*ProxyHandler) Exit

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

func (*ProxyHandler) Process

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

type StandardsHandler

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

func (*StandardsHandler) Enter

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

func (*StandardsHandler) Exit

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

func (*StandardsHandler) Process

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

type StateProcessTime

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

type StateVariableHandler

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

func (*StateVariableHandler) Enter

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

func (*StateVariableHandler) Exit

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

func (*StateVariableHandler) Process

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 TokenHandler

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

func (*TokenHandler) Enter

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

func (*TokenHandler) Exit

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

func (*TokenHandler) Process

func (dh *TokenHandler) 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