blockchainapi

package
v0.0.0-...-2515fb6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const DecimalsMOR = 18

Variables

View Source
var (
	ErrPrKey             = errors.New("cannot get private key")
	ErrTxOpts            = errors.New("failed to get transactOpts")
	ErrNonce             = errors.New("failed to get nonce")
	ErrEstimateGas       = errors.New("failed to estimate gas")
	ErrSignTx            = errors.New("failed to sign transaction")
	ErrSendTx            = errors.New("failed to send transaction")
	ErrWaitMined         = errors.New("failed to wait for transaction to be mined")
	ErrSessionStore      = errors.New("failed to store session")
	ErrSessionReport     = errors.New("failed to get session report from provider")
	ErrSessionUserReport = errors.New("failed to get session report from user")

	ErrBid         = errors.New("failed to get bid")
	ErrProvider    = errors.New("failed to get provider")
	ErrTokenSupply = errors.New("failed to parse token supply")
	ErrBudget      = errors.New("failed to parse token budget")
	ErrMyAddress   = errors.New("failed to get my address")
	ErrInitSession = errors.New("failed to initiate session")
	ErrApprove     = errors.New("failed to approve")
	ErrMarshal     = errors.New("failed to marshal open session payload")
	ErrOpenOwnBid  = errors.New("cannot open session with own bid")

	ErrNoBid = errors.New("no bids available")
	ErrModel = errors.New("can't get model")
)

Functions

func FromDecimal

func FromDecimal(value *big.Int, decimals int) float64

func ToDecimal

func ToDecimal(value float64, decimals int) *big.Int

Types

type BlockchainController

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

func NewBlockchainController

func NewBlockchainController(service *BlockchainService, log lib.ILogger) *BlockchainController

func (*BlockchainController) RegisterRoutes

func (c *BlockchainController) RegisterRoutes(r interfaces.Router)

type BlockchainService

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

func NewBlockchainService

func NewBlockchainService(
	ethClient i.EthClient,
	mc multicall.MulticallBackend,
	diamonContractAddr common.Address,
	morTokenAddr common.Address,
	explorer *ExplorerClient,
	privateKey i.PrKeyProvider,
	proxyService *proxyapi.ProxyServiceSender,
	sessionRepo *sessionrepo.SessionRepositoryCached,
	scorerAlgo *rating.Rating,
	log lib.ILogger,
	legacyTx bool,
) *BlockchainService

func (*BlockchainService) Approve

func (s *BlockchainService) Approve(ctx context.Context, spender common.Address, amount *big.Int) (common.Hash, error)

func (*BlockchainService) CheckConnectivity

func (s *BlockchainService) CheckConnectivity(ctx context.Context, url string, addr common.Address) (time.Duration, error)

func (*BlockchainService) CheckPortOpen

func (s *BlockchainService) CheckPortOpen(ctx context.Context, urlStr string) (bool, error)

func (*BlockchainService) ClaimProviderBalance

func (s *BlockchainService) ClaimProviderBalance(ctx context.Context, sessionID [32]byte) (common.Hash, error)

func (*BlockchainService) CloseSession

func (s *BlockchainService) CloseSession(ctx context.Context, sessionID common.Hash) (common.Hash, error)

func (*BlockchainService) CreateNewBid

func (s *BlockchainService) CreateNewBid(ctx context.Context, modelID common.Hash, pricePerSecond *lib.BigInt) (*structs.Bid, error)

func (*BlockchainService) CreateNewModel

func (s *BlockchainService) CreateNewModel(ctx context.Context, modelID common.Hash, ipfsID common.Hash, fee *lib.BigInt, stake *lib.BigInt, name string, tags []string) (*structs.Model, error)

func (*BlockchainService) CreateNewProvider

func (s *BlockchainService) CreateNewProvider(ctx context.Context, stake *lib.BigInt, endpoint string) (*structs.Provider, error)

func (*BlockchainService) DeleteBid

func (s *BlockchainService) DeleteBid(ctx context.Context, bidId common.Hash) (common.Hash, error)

func (*BlockchainService) DeregisterModel

func (s *BlockchainService) DeregisterModel(ctx context.Context, modelId common.Hash) (common.Hash, error)

func (*BlockchainService) DeregisterProdiver

func (s *BlockchainService) DeregisterProdiver(ctx context.Context) (common.Hash, error)

func (*BlockchainService) GetActiveBidsByModel

func (s *BlockchainService) GetActiveBidsByModel(ctx context.Context, modelId common.Hash, offset *big.Int, limit uint8, order r.Order) ([]*structs.Bid, error)

func (*BlockchainService) GetActiveBidsByProvider

func (s *BlockchainService) GetActiveBidsByProvider(ctx context.Context, provider common.Address, offset *big.Int, limit uint8, order r.Order) ([]*structs.Bid, error)

func (*BlockchainService) GetActiveBidsByProviderCount

func (s *BlockchainService) GetActiveBidsByProviderCount(ctx context.Context, provider common.Address) (*big.Int, error)

func (*BlockchainService) GetAllBidsWithRating

func (s *BlockchainService) GetAllBidsWithRating(ctx context.Context, modelAgentID [32]byte) ([][32]byte, []m.IBidStorageBid, []sr.IStatsStorageProviderModelStats, []pr.IProviderStorageProvider, error)

func (*BlockchainService) GetAllModels

func (s *BlockchainService) GetAllModels(ctx context.Context) ([]*structs.Model, error)

func (*BlockchainService) GetAllProviders

func (s *BlockchainService) GetAllProviders(ctx context.Context) ([]*structs.Provider, error)

func (*BlockchainService) GetAllowance

func (s *BlockchainService) GetAllowance(ctx context.Context, spender common.Address) (*big.Int, error)

func (*BlockchainService) GetBalance

func (s *BlockchainService) GetBalance(ctx context.Context) (eth *big.Int, mor *big.Int, err error)

func (*BlockchainService) GetBidByID

func (s *BlockchainService) GetBidByID(ctx context.Context, ID common.Hash) (*structs.Bid, error)

func (*BlockchainService) GetBidsByModelAgent

func (s *BlockchainService) GetBidsByModelAgent(ctx context.Context, modelId [32]byte, offset *big.Int, limit uint8, order r.Order) ([]*structs.Bid, error)

func (*BlockchainService) GetBidsByProvider

func (s *BlockchainService) GetBidsByProvider(ctx context.Context, providerAddr common.Address, offset *big.Int, limit uint8, order r.Order) ([]*structs.Bid, error)

func (*BlockchainService) GetLatestBlock

func (s *BlockchainService) GetLatestBlock(ctx context.Context) (uint64, error)

func (*BlockchainService) GetModels

func (s *BlockchainService) GetModels(ctx context.Context, offset *big.Int, limit uint8, order r.Order) ([]*structs.Model, error)

func (*BlockchainService) GetMyAddress

func (s *BlockchainService) GetMyAddress(ctx context.Context) (common.Address, error)

func (*BlockchainService) GetProvider

func (s *BlockchainService) GetProvider(ctx context.Context, providerAddr common.Address) (*structs.Provider, error)

GetMyAddress returns the provider by its wallet address, returns nil if provider is not registered

func (*BlockchainService) GetProviderClaimableBalance

func (s *BlockchainService) GetProviderClaimableBalance(ctx context.Context, sessionID common.Hash) (*big.Int, error)

func (*BlockchainService) GetProviders

func (s *BlockchainService) GetProviders(ctx context.Context, offset *big.Int, limit uint8, order r.Order) ([]*structs.Provider, error)

func (*BlockchainService) GetRatedBids

func (s *BlockchainService) GetRatedBids(ctx context.Context, modelID common.Hash) ([]structs.ScoredBid, error)

func (*BlockchainService) GetSession

func (s *BlockchainService) GetSession(ctx context.Context, sessionID common.Hash) (*structs.Session, error)

func (*BlockchainService) GetSessions

func (s *BlockchainService) GetSessions(ctx context.Context, user, provider common.Address, offset *big.Int, limit uint8, order r.Order) ([]*structs.Session, error)

func (*BlockchainService) GetSessionsIds

func (s *BlockchainService) GetSessionsIds(ctx context.Context, user, provider common.Address, offset *big.Int, limit uint8, order r.Order) ([]common.Hash, error)

func (*BlockchainService) GetTodaysBudget

func (s *BlockchainService) GetTodaysBudget(ctx context.Context) (*big.Int, error)

func (*BlockchainService) GetTokenSupply

func (s *BlockchainService) GetTokenSupply(ctx context.Context) (*big.Int, error)

func (*BlockchainService) GetTransactions

func (s *BlockchainService) GetTransactions(ctx context.Context, page uint64, limit uint8) ([]structs.RawTransaction, error)

func (*BlockchainService) ModelExists

func (s *BlockchainService) ModelExists(ctx context.Context, modelID common.Hash) (bool, error)

func (*BlockchainService) OpenSession

func (s *BlockchainService) OpenSession(ctx context.Context, approval, approvalSig []byte, stake *big.Int, directPayment bool) (common.Hash, error)

func (*BlockchainService) OpenSessionByModelId

func (s *BlockchainService) OpenSessionByModelId(ctx context.Context, modelID common.Hash, duration *big.Int, directPayment bool, isFailoverEnabled bool, omitProvider common.Address) (common.Hash, error)

func (*BlockchainService) SendETH

func (s *BlockchainService) SendETH(ctx context.Context, to common.Address, amount *big.Int) (common.Hash, error)

func (*BlockchainService) SendMOR

func (s *BlockchainService) SendMOR(ctx context.Context, to common.Address, amount *big.Int) (common.Hash, error)

type EventsListener

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

func NewEventsListener

func NewEventsListener(sessionRepo *sessionrepo.SessionRepositoryCached, sessionRouter *registries.SessionRouter, wallet interfaces.Wallet, logWatcher contracts.LogWatcher, log *lib.Logger) *EventsListener

func (*EventsListener) Run

func (e *EventsListener) Run(ctx context.Context) error

type ExplorerClient

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

func NewExplorerClient

func NewExplorerClient(explorerApiUrl string, morTokenAddr common.Address, retryDelay time.Duration, maxRetries uint8) *ExplorerClient

func (*ExplorerClient) GetEthTransactions

func (e *ExplorerClient) GetEthTransactions(ctx context.Context, address common.Address, page uint64, limit uint8) ([]structs.RawTransaction, error)

func (*ExplorerClient) GetTokenTransactions

func (e *ExplorerClient) GetTokenTransactions(ctx context.Context, address common.Address, page uint64, limit uint8) ([]structs.RawTransaction, error)

type ModelStats

type ModelStats struct {
	TpsScaled1000 s.LibSDSD
	TtftMs        s.LibSDSD
	TotalDuration s.LibSDSD
	Count         int
}

type SessionExpiryHandler

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

func NewSessionExpiryHandler

func NewSessionExpiryHandler(blockchainService *BlockchainService, sessionStorage *storages.SessionStorage, wallet interfaces.Wallet, log lib.ILogger) *SessionExpiryHandler

func (*SessionExpiryHandler) Run

Run starts the session autoclose process, checking every minute if any session has ended and closes it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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