web3

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStringToBigInt

func ConvertStringToBigInt(st string) big.Int

func ConvertStringToInt64

func ConvertStringToInt64(st string) uint64

func EtherToWei

func EtherToWei(etherAmount float64) *big.Int

func EtherToWeiUint64

func EtherToWeiUint64(etherAmount float64) uint64

func GetAddress

func GetAddress(privateKey *ecdsa.PrivateKey) common.Address

func GetAddressFromSignedMessage

func GetAddressFromSignedMessage(message []byte, sig []byte) (common.Address, error)

func GetPublicKey

func GetPublicKey(privateKey *ecdsa.PrivateKey) ecdsa.PublicKey

func ParsePrivateKey

func ParsePrivateKey(privateKey string) (*ecdsa.PrivateKey, error)

func SignMessage

func SignMessage(privateKey *ecdsa.PrivateKey, message []byte) ([]byte, error)

func WeiToEther

func WeiToEther(wei *big.Int) *big.Float

Types

type Contracts

type Contracts struct {
	Token      *token.Token
	Payments   *payments.Payments
	Storage    *storage.Storage
	Users      *users.Users
	JobCreator *jobcreator.Jobcreator
	Mediation  *mediation.Mediation
	Controller *controller.Controller
	Pow        *pow.Pow
}

these are the go-binding wrappers for the various deployed contracts

func NewContracts

func NewContracts(
	options Web3Options,
	client *ethclient.Client,
	callOpts *bind.CallOpts,
) (*Contracts, error)

type ContractsV2

type ContractsV2 struct {
	LilypadPaymentEngine    *lilypadpaymentengine.LilypadPaymentEngine
	LilypadProxy            *lilypadproxy.LilypadProxy
	LilypadModuleDirectory  *lilypadmoduledirectory.LilypadModuleDirectory
	LilypadContractRegistry *lilypadcontractregistry.LilypadContractRegistry
	LilypadStorage          *lilypadstorage.LilypadStorage
	LilypadUser             *lilypaduser.LilypadUser
	LilypadTokenomics       *lilypadtokenomics.LilypadTokenomics
	LilypadToken            *lilypadtoken.LilypadToken
}

These are the Go binding wrappers for the new version of the protocol

func NewContractsV2

func NewContractsV2(
	options Web3Options,
	client *ethclient.Client,
	callOpts *bind.CallOpts,
) (*ContractsV2, error)

Creates the new Go-binding wrapper modules for the new protocol

type EventChannelCollection

type EventChannelCollection interface {
	Start(
		ctx context.Context,
		cm *system.CleanupManager,
		sdk *Web3SDK,
	) error
}

type EventChannels

type EventChannels struct {
	Token      *TokenEventChannels
	Payment    *PaymentEventChannels
	Storage    *StorageEventChannels
	JobCreator *JobCreatorEventChannels
	Mediation  *MediationEventChannels
	Pow        *PowEventChannels
	// contains filtered or unexported fields
}

func NewEventChannels

func NewEventChannels() *EventChannels

func (*EventChannels) Start

func (eventChannels *EventChannels) Start(
	ctx context.Context,
	cm *system.CleanupManager,
	sdk *Web3SDK,
) error

type JobCreatorEventChannels

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

func NewJobCreatorEventChannels

func NewJobCreatorEventChannels() *JobCreatorEventChannels

func (*JobCreatorEventChannels) Start

func (*JobCreatorEventChannels) SubscribeJobAdded

func (t *JobCreatorEventChannels) SubscribeJobAdded(handler func(jobcreator.JobcreatorJobAdded))

type MediationEventChannels

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

func NewMediationEventChannels

func NewMediationEventChannels() *MediationEventChannels

func (*MediationEventChannels) Start

func (*MediationEventChannels) SubscribeMediationRequested

func (m *MediationEventChannels) SubscribeMediationRequested(handler func(mediation.MediationMediationRequested))

type PaymentEventChannels

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

func NewPaymentEventChannels

func NewPaymentEventChannels() *PaymentEventChannels

func (*PaymentEventChannels) Start

func (*PaymentEventChannels) SubscribePayment

func (p *PaymentEventChannels) SubscribePayment(handler func(payments.PaymentsPayment))

type PowEventChannels

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

func NewPowEventChannels

func NewPowEventChannels() *PowEventChannels

func (*PowEventChannels) Start

func (s *PowEventChannels) Start(
	ctx context.Context,
	cm *system.CleanupManager,
	sdk *Web3SDK,
) error

func (*PowEventChannels) SubscribenewPowRound

func (t *PowEventChannels) SubscribenewPowRound(handler func(pow.PowNewPowRound))

type PowValidPOWSubmission

type PowValidPOWSubmission struct {
	WalletAddress    common.Address
	NodeId           string
	Nonce            *big.Int
	StartTimestap    *big.Int
	CompleteTimestap *big.Int
	Challenge        [32]byte
	Difficulty       *big.Int
}

type StorageEventChannels

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

func NewStorageEventChannels

func NewStorageEventChannels() *StorageEventChannels

func (*StorageEventChannels) Start

func (*StorageEventChannels) SubscribeDealStateChange

func (t *StorageEventChannels) SubscribeDealStateChange(handler func(storage.StorageDealStateChange))

type TokenEventChannels

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

func NewTokenEventChannels

func NewTokenEventChannels() *TokenEventChannels

func (*TokenEventChannels) Start

func (t *TokenEventChannels) Start(
	ctx context.Context,
	cm *system.CleanupManager,
	sdk *Web3SDK,
) error

func (*TokenEventChannels) SubscribeTransfer

func (t *TokenEventChannels) SubscribeTransfer(handler func(token.TokenTransfer))

type Web3Options

type Web3Options struct {

	// core settings
	RpcURL     string `json:"rpc_url" toml:"rpc_url"`
	PrivateKey string `json:"private_key" toml:"private_key"`
	ChainID    int    `json:"chain_id" toml:"chain_id"`

	// contract addresses
	ControllerAddress string `json:"controller_address" toml:"controller_address"`
	PaymentsAddress   string `json:"payments_address" toml:"payments_address"`
	StorageAddress    string `json:"storage_address" toml:"storage_address"`
	UsersAddress      string `json:"users_address" toml:"users_address"`
	TokenAddress      string `json:"token_address" toml:"token_address"`
	MediationAddress  string `json:"mediation_address" toml:"mediation_address"`
	JobCreatorAddress string `json:"jobcreator_address" toml:"jobcreator_address"`
	PowAddress        string `json:"pow_address" toml:"pow_address"`

	// V2 Protocol
	LilypadProxyAddress            string `json:"lilypad_proxy_address" toml:"lilypad_proxy_address"`
	LilypadPaymentEngineAddress    string `json:"lilypad_payment_engine_address" toml:"lilypad_payment_engine_address"`
	LilypadStorageAddress          string `json:"lilypad_storage_address" toml:"lilypad_storage_address"`
	LilypadUserAddress             string `json:"lilypad_user_address" toml:"lilypad_user_address"`
	LilypadL2TokenAddress          string `json:"lilypad_l2_token_address" toml:"lilypad_l2_token_address"`
	LilypadL1TokenAddress          string `json:"lilypad_l1_token_address" toml:"lilypad_l1_token_address"`
	LilypadTokenomicsAddress       string `json:"lilypad_tokenomics_address" toml:"lilypad_tokenomics_address"`
	LilypadModuleDirectoryAddress  string `json:"lilypad_module_directory_address" toml:"lilypad_module_directory_address"`
	LilypadContractRegistryAddress string `json:"lilypad_contract_registry_address" toml:"lilypad_contract_registry_address"`

	// this is injected by whatever service we are running
	// it's used for logging tx's
	Service system.Service `json:"-" toml:"-"`
}

type Web3SDK

type Web3SDK struct {
	Options      Web3Options
	PrivateKey   *ecdsa.PrivateKey
	Client       *ethclient.Client
	CallOpts     *bind.CallOpts
	TransactOpts *bind.TransactOpts
	Contracts    *Contracts
	Log          *zerolog.Logger
}

func NewContractSDK

func NewContractSDK(ctx context.Context, options Web3Options, tracer trace.Tracer) (*Web3SDK, error)

func (*Web3SDK) AcceptResult

func (sdk *Web3SDK) AcceptResult(
	dealId string,
) (string, error)

func (*Web3SDK) AddResult

func (sdk *Web3SDK) AddResult(
	dealId string,
	resultsId string,
	dataId string,
	instructionCount uint64,
) (string, error)

func (*Web3SDK) AddUserToList

func (sdk *Web3SDK) AddUserToList(
	serviceType uint8,
) error

func (*Web3SDK) Agree

func (sdk *Web3SDK) Agree(
	deal data.Deal,
) (string, error)

func (*Web3SDK) CheckResult

func (sdk *Web3SDK) CheckResult(
	dealId string,
) (string, error)

func (*Web3SDK) GetAddress

func (sdk *Web3SDK) GetAddress() common.Address

func (*Web3SDK) GetBalance

func (sdk *Web3SDK) GetBalance(address string) (*big.Int, error)

func (*Web3SDK) GetGenerateChallenge

func (sdk *Web3SDK) GetGenerateChallenge(
	ctx context.Context,
	nodeId string,
) (string, *pow.PowGenerateChallenge, error)

func (*Web3SDK) GetLPBalance

func (sdk *Web3SDK) GetLPBalance(address string) (*big.Int, error)

func (*Web3SDK) GetServiceAddresses

func (sdk *Web3SDK) GetServiceAddresses(serviceType string) ([]common.Address, error)

func (*Web3SDK) GetSolverAddresses

func (sdk *Web3SDK) GetSolverAddresses() ([]common.Address, error)

func (*Web3SDK) GetSolverUrl

func (sdk *Web3SDK) GetSolverUrl(address string) (string, error)

func (*Web3SDK) GetUser

func (sdk *Web3SDK) GetUser(
	address common.Address,
) (users.SharedStructsUser, error)

func (*Web3SDK) MediationAcceptResult

func (sdk *Web3SDK) MediationAcceptResult(
	dealId string,
) (string, error)

func (*Web3SDK) MediationRejectResult

func (sdk *Web3SDK) MediationRejectResult(
	dealId string,
) (string, error)

func (*Web3SDK) SendPowSignal

func (sdk *Web3SDK) SendPowSignal(ctx context.Context) (*pow.PowNewPowRound, error)

func (*Web3SDK) SubmitWork

func (sdk *Web3SDK) SubmitWork(
	ctx context.Context,
	nonce *big.Int,
	nodeId string,
) (common.Hash, error)

func (*Web3SDK) UpdateUser

func (sdk *Web3SDK) UpdateUser(
	metadataCID string,
	url string,
	roles []uint8,
) error

func (*Web3SDK) WaitTx

func (sdk *Web3SDK) WaitTx(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)

type Web3SDKV2

type Web3SDKV2 struct {
	Options      Web3Options
	PrivateKey   *ecdsa.PrivateKey
	Client       *ethclient.Client
	CallOpts     *bind.CallOpts
	TransactOpts *bind.TransactOpts
	Contracts    *ContractsV2
	Log          *zerolog.Logger
}

func NewContractSDKV2

func NewContractSDKV2(ctx context.Context, options Web3Options, tracer trace.Tracer) (*Web3SDKV2, error)

func (*Web3SDKV2) AcceptJobPayment

func (sdk *Web3SDKV2) AcceptJobPayment(amount *big.Int) (bool, error)

func (*Web3SDKV2) AcceptResourceProviderCollateral

func (sdk *Web3SDKV2) AcceptResourceProviderCollateral(amount *big.Int) (bool, error)

func (*Web3SDKV2) ApproveTokenTransfer

func (sdk *Web3SDKV2) ApproveTokenTransfer(amount *big.Int, spender common.Address) (string, error)

func (*Web3SDKV2) GetAddress

func (sdk *Web3SDKV2) GetAddress() common.Address

func (*Web3SDKV2) GetBalance

func (sdk *Web3SDKV2) GetBalance(address string) (*big.Int, error)

func (*Web3SDKV2) GetDeal

func (sdk *Web3SDKV2) GetDeal(dealId string) (lilypadproxy.SharedStructsDeal, error)

func (*Web3SDKV2) GetEscrowBalance

func (sdk *Web3SDKV2) GetEscrowBalance(address common.Address) (*big.Int, error)

func (*Web3SDKV2) GetLilypadL2TokenAddress

func (sdk *Web3SDKV2) GetLilypadL2TokenAddress() (common.Address, error)

func (*Web3SDKV2) GetLilypadPaymentEngineAddress

func (sdk *Web3SDKV2) GetLilypadPaymentEngineAddress() (common.Address, error)

func (*Web3SDKV2) GetLilypadStorageAddress

func (sdk *Web3SDKV2) GetLilypadStorageAddress() (common.Address, error)

func (*Web3SDKV2) GetLilypadUserAddress

func (sdk *Web3SDKV2) GetLilypadUserAddress() (common.Address, error)

func (*Web3SDKV2) GetMinimumResourceProviderCollateralAmount

func (sdk *Web3SDKV2) GetMinimumResourceProviderCollateralAmount() (*big.Int, error)

func (*Web3SDKV2) GetResult

func (sdk *Web3SDKV2) GetResult(resultId string) (lilypadproxy.SharedStructsResult, error)

func (*Web3SDKV2) SaveDeal

func (sdk *Web3SDKV2) SaveDeal(deal lilypadproxy.SharedStructsDeal) (bool, error)

func (*Web3SDKV2) SaveResult

func (sdk *Web3SDKV2) SaveResult(result lilypadproxy.SharedStructsResult) (bool, error)

func (*Web3SDKV2) WaitTx

func (sdk *Web3SDKV2) WaitTx(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)

Jump to

Keyboard shortcuts

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