engine

package
v0.0.0-...-7a1e3be Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SignatureHeader is the header that contains the signature of the request
	SignatureHeader = "X-Signature"
	// AddressHeader is the header that contains the address of the sender
	AddressHeader = "X-Address"
	// AppVersionHeader is the header that contains the app version of the sender
	AppVersionHeader = "X-App-Version"
)
View Source
const ImplementationStorageSlotKey = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
View Source
const PushMessageAnonymousBody = "%s %s received"
View Source
const PushMessageAnonymousDescriptionBody = "%s"
View Source
const PushMessageAnonymousDescriptionTitle = "%s %s (%s) received"

success

View Source
const PushMessageAnonymousTitle = "%s"
View Source
const PushMessageBody = "%s %s received from %s"
View Source
const PushMessageSendingAnonymousBody = "Receiving %s %s..."
View Source
const PushMessageSendingAnonymousDescriptionBody = "%s"
View Source
const PushMessageSendingAnonymousDescriptionTitle = "Receiving %s %s (%s)..."

sending

View Source
const PushMessageSendingAnonymousTitle = "%s"
View Source
const PushMessageTitle = "%s - %s"
View Source
const Version = "0.0.0"

there is no need to change this value manually, it will be replaced by the build system

Variables

View Source
var (
	// Allowed function signatures
	FuncSigSingle             = crypto.Keccak256([]byte("execute(address,uint256,bytes)"))[:4]
	FuncSigBatch              = crypto.Keccak256([]byte("executeBatch(address[],uint256[],bytes[])"))[:4]
	FuncSigSafeExecFromModule = crypto.Keccak256([]byte("execTransactionFromModule(address,uint256,bytes,uint8)"))[:4]
)
View Source
var SafeAbi = `` /* 19398-byte string literal not displayed */

Functions

func GenerateHexPrivateKey

func GenerateHexPrivateKey() (string, string, error)

generate a new private key

func GenerateJSONBQuery

func GenerateJSONBQuery(prefix string, start int, data map[string]any) (string, []any)

func GeneratePrivateKey

func GeneratePrivateKey() (*ecdsa.PrivateKey, error)

generate a new private key

func GetAddressFromContext

func GetAddressFromContext(ctx context.Context) (string, bool)

get address from context if exists

func ParseJSONBFilters

func ParseJSONBFilters(query url.Values, prefix string) map[string]any

func RandomString

func RandomString(length int) string

func StringWithCharset

func StringWithCharset(length int, charset string) string

Types

type ArgType

type ArgType struct {
	Name    string
	Indexed bool
}

type Community

type Community struct {
	Name         string `json:"name"`
	Description  string `json:"description"`
	URL          string `json:"url"`
	Alias        string `json:"alias"`
	Hidden       bool   `json:"hidden,omitempty"`
	CustomDomain string `json:"custom_domain,omitempty"`
	Theme        *Theme `json:"theme,omitempty"`
}

type CommunityConfig

type CommunityConfig struct {
	Community Community         `json:"community"`
	Scan      CommunityScan     `json:"scan"`
	Indexer   CommunityIndexer  `json:"indexer"`
	IPFS      CommunityIPFS     `json:"ipfs"`
	Node      CommunityNode     `json:"node"`
	ERC4337   CommunityERC4337  `json:"erc4337"`
	Token     CommunityToken    `json:"token"`
	Profile   CommunityProfile  `json:"profile"`
	Plugins   []CommunityPlugin `json:"plugins,omitempty"`
	Version   int               `json:"version"`
}

type CommunityERC4337

type CommunityERC4337 struct {
	RPCURL                string `json:"rpc_url"`
	PaymasterAddress      string `json:"paymaster_address"`
	EntrypointAddress     string `json:"entrypoint_address"`
	AccountFactoryAddress string `json:"account_factory_address"`
	PaymasterRPCURL       string `json:"paymaster_rpc_url"`
	PaymasterType         string `json:"paymaster_type"`
}

type CommunityIPFS

type CommunityIPFS struct {
	URL string `json:"url"`
}

type CommunityIndexer

type CommunityIndexer struct {
	URL     string `json:"url"`
	IPFSURL string `json:"ipfs_url"`
	Key     string `json:"key"`
}

type CommunityNode

type CommunityNode struct {
	ChainID int    `json:"chain_id"`
	URL     string `json:"url"`
	WSURL   string `json:"ws_url"`
}

type CommunityPlugin

type CommunityPlugin struct {
	Name string `json:"name"`
	Icon string `json:"icon"`
	URL  string `json:"url"`
}

type CommunityProfile

type CommunityProfile struct {
	Address string `json:"address"`
}

type CommunityScan

type CommunityScan struct {
	URL  string `json:"url"`
	Name string `json:"name"`
}

type CommunityToken

type CommunityToken struct {
	Standard string `json:"standard"`
	Address  string `json:"address"`
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals int    `json:"decimals"`
}

type ContextKey

type ContextKey string
const (
	ContextKeyAddress   ContextKey = AddressHeader
	ContextKeySignature ContextKey = SignatureHeader
)

type EVMRequester

type EVMRequester interface {
	Context() context.Context
	Backend() bind.ContractBackend

	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	BaseFee() (*big.Int, error)
	EstimateGasPrice() (*big.Int, error)
	EstimateGasLimit(msg ethereum.CallMsg) (uint64, error)
	NewTx(nonce uint64, from, to common.Address, data []byte, extraGas bool) (*types.Transaction, error)
	SendTransaction(tx *types.Transaction) error
	StorageAt(addr common.Address, slot common.Hash) ([]byte, error)

	ChainID() (*big.Int, error)
	Call(method string, result any, params json.RawMessage) error
	LatestBlock() (*big.Int, error)
	FilterLogs(q ethereum.FilterQuery) ([]types.Log, error)
	BlockTime(number *big.Int) (uint64, error)
	CallContract(call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	ListenForLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) error

	WaitForTx(tx *types.Transaction, timeout int) error

	Close()
}

type EVMType

type EVMType string
const (
	EVMTypeEthereum EVMType = "ethereum"
	EVMTypeOptimism EVMType = "optimism"
	EVMTypeCelo     EVMType = "celo"
)

type Event

type Event struct {
	Contract       string    `json:"contract"`
	EventSignature string    `json:"event_signature"`
	Name           string    `json:"name"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

func (*Event) ConstructABIFromEventSignature

func (e *Event) ConstructABIFromEventSignature() (string, error)

ConstructABIFromEventSignature constructs an ABI from an event signature Example: Transfer(from address, to address, value uint256) Returns: {"name":"Transfer","type":"event","inputs":[{"name":"from","type":"address","indexed":false},{"name":"to","type":"address","indexed":false},{"name":"value","type":"uint256","indexed":false}]}

Example: Transfer(from indexed address, to indexed address, value uint256) Returns: {"name":"Transfer","type":"event","inputs":[{"name":"from","type":"address", "indexed": true},{"name":"to","type":"address", "indexed": true},{"name":"value","type":"uint256", "indexed": false}]}

func (*Event) GetTopic0FromEventSignature

func (e *Event) GetTopic0FromEventSignature() common.Hash

func (*Event) IsValidData

func (e *Event) IsValidData(data map[string]any) bool

IsValidData checks if the provided data contains exactly all the argument names returned by ParseEventSignature, plus the "topic" field, no more and no less.

func (*Event) ParseEventSignature

func (e *Event) ParseEventSignature() (string, []string, []ArgType)

Parse human readable event signature Example: Transfer(address from, address to, uint256 value) Returns: ("Transfer", ["from", "to", "value"], [{Name: "address", Indexed: false}, {Name: "address", Indexed: false}, {Name: "uint256", Indexed: false}])

Example: Transfer(address,address,uint256) Returns: ("Transfer", ["0", "1", "2"], [{Name: "address", Indexed: false}, {Name: "address", Indexed: false}, {Name: "uint256", Indexed: false}])

Example: Transfer(address indexed from, address indexed to, uint256 value) Returns: ("Transfer", ["from", "to", "value"], [{Name: "address", Indexed: true}, {Name: "address", Indexed: true}, {Name: "uint256", Indexed: false}])

Example: Transfer(address indexed, address indexed, uint256) Returns: ("Transfer", ["0", "1", "2"], [{Name: "address", Indexed: true}, {Name: "address", Indexed: true}, {Name: "uint256", Indexed: false}])

Example: Transfer (index_topic_1 address from, index_topic_2 address to, uint256 value) Returns: ("Transfer", ["from", "to", "value"], [{Name: "address", Indexed: true}, {Name: "address", Indexed: true}, {Name: "uint256", Indexed: false}])

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

type JsonRPCRequest

type JsonRPCRequest struct {
	Version string          `json:"jsonrpc"`
	ID      any             `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

type JsonRPCResponse

type JsonRPCResponse struct {
	Version string        `json:"jsonrpc"`
	ID      any           `json:"id"`
	Result  any           `json:"result"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

type Log

type Log struct {
	Hash      string           `json:"hash"`
	TxHash    string           `json:"tx_hash"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
	Nonce     int64            `json:"nonce"`
	Sender    string           `json:"sender"`
	To        string           `json:"to"`
	Value     *big.Int         `json:"value"`
	Data      *json.RawMessage `json:"data"`
	ExtraData *json.RawMessage `json:"extra_data"`
	Status    LogStatus        `json:"status"`
}

func (*Log) GenerateUniqueHash

func (t *Log) GenerateUniqueHash() string

generate hash for transfer using a provided index, from, to and the tx hash

func (*Log) GetPoolTopic

func (t *Log) GetPoolTopic() *string

func (*Log) MatchesQuery

func (l *Log) MatchesQuery(query string) bool

func (*Log) ToJSON

func (t *Log) ToJSON() []byte

Convert a log to json bytes

func (*Log) ToRounded

func (t *Log) ToRounded(decimals int64) float64

func (*Log) ToWSMessage

func (l *Log) ToWSMessage(t WSMessageType) *WSMessageLog

func (*Log) Update

func (t *Log) Update(tx *Log)

Update updates the transfer using the given transfer

type LogStatus

type LogStatus string
const (
	LogStatusUnknown LogStatus = ""
	LogStatusSending LogStatus = "sending"
	LogStatusPending LogStatus = "pending"
	LogStatusSuccess LogStatus = "success"
	LogStatusFail    LogStatus = "fail"

	TEMP_HASH_PREFIX = "TEMP_HASH"
)

func LogStatusFromString

func LogStatusFromString(s string) (LogStatus, error)

type Message

type Message struct {
	ID         string
	CreatedAt  time.Time
	RetryCount int
	Message    any
	Response   *chan MessageResponse
}

func NewTxMessage

func NewTxMessage(pm, entrypoint common.Address, chainId *big.Int, userop UserOp, data, xdata *json.RawMessage) *Message

func (*Message) Close

func (m *Message) Close()

func (*Message) Respond

func (m *Message) Respond(data any, err error)

func (*Message) WaitForResponse

func (m *Message) WaitForResponse() (any, error)

type MessageResponse

type MessageResponse struct {
	Data any
	Err  error
}

type Profile

type Profile struct {
	Account     string `json:"account"`
	Username    string `json:"username"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Image       string `json:"image"`
	ImageMedium string `json:"image_medium"`
	ImageSmall  string `json:"image_small"`
}

type PushDescription

type PushDescription struct {
	Description string `json:"description"`
}

type PushMessage

type PushMessage struct {
	Tokens []*PushToken
	Title  string
	Body   string
	Data   []byte
	Silent bool
}

func NewAnonymousPushMessage

func NewAnonymousPushMessage(token []*PushToken, community, amount, symbol string, tx *Log) *PushMessage

func NewPushMessage

func NewPushMessage(token []*PushToken, community, name, amount, symbol, username string) *PushMessage

func NewSilentPushMessage

func NewSilentPushMessage(token []*PushToken, tx *Log) *PushMessage

type PushToken

type PushToken struct {
	Token   string
	Account string
}

type RPCHandlerFunc

type RPCHandlerFunc func(r *http.Request) (any, error)
type Sponsor struct {
	Contract   string    `json:"contract"`
	PrivateKey string    `json:"private_key"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

type Theme

type Theme struct {
	PrimaryColor string `json:"primaryColor"`
}

type Topic

type Topic struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Value any    `json:"value"`
}

type Topics

type Topics []Topic

func ParseTopicsFromHashes

func ParseTopicsFromHashes(event *Event, topicHashes []common.Hash, data []byte) (Topics, error)

func (*Topics) GenerateTopicQuery

func (t *Topics) GenerateTopicQuery(start int) (string, []any)

func (Topics) MarshalJSON

func (t Topics) MarshalJSON() ([]byte, error)

func (*Topics) String

func (t *Topics) String() string

func (Topics) Value

func (t Topics) Value() (driver.Value, error)

type UserOp

type UserOp struct {
	Sender               common.Address `json:"sender"               mapstructure:"sender"               validate:"required"`
	Nonce                *big.Int       `json:"nonce"                mapstructure:"nonce"                validate:"required"`
	InitCode             []byte         `json:"initCode"             mapstructure:"initCode"             validate:"required"`
	CallData             []byte         `json:"callData"             mapstructure:"callData"             validate:"required"`
	CallGasLimit         *big.Int       `json:"callGasLimit"         mapstructure:"callGasLimit"         validate:"required"`
	VerificationGasLimit *big.Int       `json:"verificationGasLimit" mapstructure:"verificationGasLimit" validate:"required"`
	PreVerificationGas   *big.Int       `json:"preVerificationGas"   mapstructure:"preVerificationGas"   validate:"required"`
	MaxFeePerGas         *big.Int       `json:"maxFeePerGas"         mapstructure:"maxFeePerGas"         validate:"required"`
	MaxPriorityFeePerGas *big.Int       `json:"maxPriorityFeePerGas" mapstructure:"maxPriorityFeePerGas" validate:"required"`
	PaymasterAndData     []byte         `json:"paymasterAndData"     mapstructure:"paymasterAndData"     validate:"required"`
	Signature            []byte         `json:"signature"            mapstructure:"signature"            validate:"required"`
}

func (*UserOp) Copy

func (u *UserOp) Copy() UserOp

func (*UserOp) MarshalJSON

func (op *UserOp) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoding of the UserOperation.

func (*UserOp) UnmarshalJSON

func (op *UserOp) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a JSON encoding of the UserOperation.

type UserOpMessage

type UserOpMessage struct {
	Paymaster  common.Address
	EntryPoint common.Address
	ChainId    *big.Int
	UserOp     UserOp
	Data       any
	ExtraData  any
}

type WSMessage

type WSMessage struct {
	PoolID string        `json:"pool_id"`
	Type   WSMessageType `json:"type"`
	ID     string        `json:"id"`
}

type WSMessageCreator

type WSMessageCreator interface {
	ToWSMessage(t WSMessageType) *WSMessageLog
	MatchesQuery(query string) bool
}

type WSMessageDataType

type WSMessageDataType string
const (
	WSMessageDataTypeLog WSMessageDataType = "log"
)

type WSMessageLog

type WSMessageLog struct {
	WSMessage
	DataType WSMessageDataType `json:"data_type"`
	Data     Log               `json:"data"`
}

type WSMessageType

type WSMessageType string
const (
	WSMessageTypeNew    WSMessageType = "new"
	WSMessageTypeUpdate WSMessageType = "update"
	WSMessageTypeRemove WSMessageType = "remove"
)

type WebhookMessager

type WebhookMessager interface {
	Notify(ctx context.Context, message string) error
	NotifyWarning(ctx context.Context, errorMessage error) error
	NotifyError(ctx context.Context, errorMessage error) error
}

Jump to

Keyboard shortcuts

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