blockchain

package
v6.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const MockedCurrentBlock = 100

Variables

View Source
var (
	// HashPrefix32Bytes is an Ethereum signature prefix: see https://github.com/ethereum/go-ethereum/blob/bf468a81ec261745b25206b2a596eb0ee0a24a74/internal/ethapi/api.go#L361
	HashPrefix32Bytes = []byte("\x19Ethereum Signed Message:\n32")
)

Functions

func EstimateGas

func EstimateGas(wallet *bind.TransactOpts) (opts *bind.TransactOpts)

func SetGas

func SetGas(wallet *bind.TransactOpts, gasLimit uint64) (opts *bind.TransactOpts)

Types

type AddOns

type AddOns struct {
	DiscountInPercentage float64 `json:"discountInPercentage"`
	AddOnCostInAGIX      int     `json:"addOnCostInAGIX"`
	Name                 string  `json:"name"`
}

type EthereumClient

type EthereumClient struct {
	EthClient *ethclient.Client
	RawClient *rpc.Client
}

func CreateHTTPEthereumClient

func CreateHTTPEthereumClient() (*EthereumClient, error)

func CreateWSEthereumClient

func CreateWSEthereumClient() (*EthereumClient, error)

func (*EthereumClient) Close

func (ethereumClient *EthereumClient) Close()

type Group

type Group struct {
	GroupName        string   `json:"group_name"`
	GroupID          string   `json:"group_id"`
	PaymentDetails   Payment  `json:"payment"`
	LicenseEndpoints []string `json:"license_server_endpoints"`
}

Group Structure to hold the individual group details, an Organization can have multiple groups

type Licenses

type Licenses struct {
	Subscriptions Subscriptions `json:"subscriptions,omitempty"`
	Tiers         []Tier        `json:"tiers"`
}

type MethodPricing

type MethodPricing struct {
	MethodName  string   `json:"method_name"`
	PriceInCogs *big.Int `json:"price_in_cogs"`
}

type MockProcessor

type MockProcessor struct {
	mock.Mock
	EnabledFlag bool
	// contains filtered or unexported fields
}

func NewMockProcessor

func NewMockProcessor(enabled bool) *MockProcessor

func (*MockProcessor) Close

func (m *MockProcessor) Close()

func (*MockProcessor) CompareWithLatestBlockNumber

func (m *MockProcessor) CompareWithLatestBlockNumber(blockNumberPassed *big.Int, allowedBlockChainDifference uint64) error

func (*MockProcessor) ConnectToWsClient

func (m *MockProcessor) ConnectToWsClient() error

func (*MockProcessor) CurrentBlock

func (m *MockProcessor) CurrentBlock() (*big.Int, error)

func (*MockProcessor) Enabled

func (m *MockProcessor) Enabled() bool

func (*MockProcessor) EscrowContractAddress

func (m *MockProcessor) EscrowContractAddress() common.Address

func (*MockProcessor) GetEthHttpClient

func (m *MockProcessor) GetEthHttpClient() *ethclient.Client

func (*MockProcessor) GetEthWSClient

func (m *MockProcessor) GetEthWSClient() *ethclient.Client

func (*MockProcessor) HasIdentity

func (m *MockProcessor) HasIdentity() bool

func (*MockProcessor) MultiPartyEscrow

func (m *MockProcessor) MultiPartyEscrow() *MultiPartyEscrow

func (*MockProcessor) MultiPartyEscrowChannel

func (m *MockProcessor) MultiPartyEscrowChannel(channelID *big.Int) (channel *MultiPartyEscrowChannel, ok bool, err error)

func (*MockProcessor) ReconnectToWsClient

func (m *MockProcessor) ReconnectToWsClient() error

type MultiPartyEscrowChannel

type MultiPartyEscrowChannel struct {
	Sender     common.Address
	Recipient  common.Address
	GroupId    [32]byte
	Value      *big.Int
	Nonce      *big.Int
	Expiration *big.Int
	Signer     common.Address
}

type OrganizationGroup

type OrganizationGroup struct {
	Endpoints      []string  `json:"endpoints"`
	GroupID        string    `json:"group_id"`
	GroupName      string    `json:"group_name"`
	Pricing        []Pricing `json:"pricing"`
	FreeCalls      int       `json:"free_calls"`
	FreeCallSigner string    `json:"free_call_signer_address"`
	Licenses       Licenses  `json:"licenses,omitempty"`
	AddOns         []AddOns  `json:"addOns,omitempty"`
}

type OrganizationMetaData

type OrganizationMetaData struct {
	OrgName string  `json:"org_name"`
	OrgID   string  `json:"org_id"`
	Groups  []Group `json:"groups"`
	// contains filtered or unexported fields
}

func GetOrganizationMetaData

func GetOrganizationMetaData() *OrganizationMetaData

GetOrganizationMetaData will be used to load the Organization metadata when Daemon starts To be part of components

func GetOrganizationMetaDataFromIPFS

func GetOrganizationMetaDataFromIPFS(hash string) (*OrganizationMetaData, error)

func InitOrganizationMetaDataFromJson

func InitOrganizationMetaDataFromJson(jsonData []byte) (metaData *OrganizationMetaData, err error)

InitOrganizationMetaDataFromJson Construct the Organization metadata from the JSON Passed

func (*OrganizationMetaData) GetConnectionTimeOut

func (metaData *OrganizationMetaData) GetConnectionTimeOut() (connectionTimeOut time.Duration)

GetConnectionTimeOut Get the connection time out defined

func (*OrganizationMetaData) GetGroupId

func (metaData *OrganizationMetaData) GetGroupId() [32]byte

GetGroupId Return the group id in bytes

func (*OrganizationMetaData) GetGroupIdString

func (metaData *OrganizationMetaData) GetGroupIdString() string

GetGroupIdString Get the Group ID the Daemon needs to associate itself to, requests belonging to a different group if will be rejected

func (*OrganizationMetaData) GetLicenseEndPoints

func (metaData *OrganizationMetaData) GetLicenseEndPoints() []string

func (*OrganizationMetaData) GetPaymentAddress

func (metaData *OrganizationMetaData) GetPaymentAddress() common.Address

GetPaymentAddress retrieve the details of the payment address/ recipient address for current group.

func (*OrganizationMetaData) GetPaymentExpirationThreshold

func (metaData *OrganizationMetaData) GetPaymentExpirationThreshold() *big.Int

GetPaymentExpirationThreshold get expiration threshold

func (*OrganizationMetaData) GetPaymentStorageEndPoints

func (metaData *OrganizationMetaData) GetPaymentStorageEndPoints() []string

GetPaymentStorageEndPoints Get the End points of the Payment Storage used to update the storage state

func (*OrganizationMetaData) GetRequestTimeOut

func (metaData *OrganizationMetaData) GetRequestTimeOut() time.Duration

GetRequestTimeOut Get the Request time out defined

type Payment

type Payment struct {
	PaymentAddress              string                      `json:"payment_address"`
	PaymentExpirationThreshold  *big.Int                    `json:"payment_expiration_threshold"`
	PaymentChannelStorageType   string                      `json:"payment_channel_storage_type"`
	PaymentChannelStorageClient PaymentChannelStorageClient `json:"payment_channel_storage_client"`
}

type PaymentChannelStorageClient

type PaymentChannelStorageClient struct {
	ConnectionTimeout string   `json:"connection_timeout" mapstructure:"connection_timeout"`
	RequestTimeout    string   `json:"request_timeout" mapstructure:"request_timeout"`
	Endpoints         []string `json:"endpoints"`
}

PaymentChannelStorageClient to hold the storage details of the payment

type Pricing

type Pricing struct {
	PriceModel     string           `json:"price_model"`
	PriceInCogs    *big.Int         `json:"price_in_cogs,omitempty"`
	PackageName    string           `json:"package_name,omitempty"`
	Default        bool             `json:"default,omitempty"`
	PricingDetails []PricingDetails `json:"details,omitempty"`
}

type PricingDetails

type PricingDetails struct {
	ServiceName   string          `json:"service_name"`
	MethodPricing []MethodPricing `json:"method_pricing"`
}

type Processor

type Processor interface {
	ReconnectToWsClient() error
	ConnectToWsClient() error
	Enabled() bool
	EscrowContractAddress() common.Address
	MultiPartyEscrow() *MultiPartyEscrow
	GetEthHttpClient() *ethclient.Client
	GetEthWSClient() *ethclient.Client
	CurrentBlock() (*big.Int, error)
	CompareWithLatestBlockNumber(blockNumberPassed *big.Int, allowedBlockChainDifference uint64) error
	HasIdentity() bool
	Close()
	MultiPartyEscrowChannel(channelID *big.Int) (channel *MultiPartyEscrowChannel, ok bool, err error)
}

func NewProcessor

func NewProcessor(metadata *ServiceMetadata) (Processor, error)

NewProcessor creates a new blockchain processor

type ServiceMetadata

type ServiceMetadata struct {
	Version          int                 `json:"version"`
	DisplayName      string              `json:"display_name"`
	Encoding         string              `json:"encoding"`
	ServiceType      string              `json:"service_type"`
	Groups           []OrganizationGroup `json:"groups"`
	ModelIpfsHash    string              `json:"model_ipfs_hash"`
	ServiceApiSource string              `json:"service_api_source"`
	MpeAddress       string              `json:"mpe_address"`

	DynamicPriceMethodMapping map[string]string `json:"dynamic_pricing"`
	TrainingMethods           []string          `json:"training_methods"`
	TrainingMetadata          map[string]any    `json:"training_metadata"`
	ProtoDescriptors          linker.Files      `json:"-"`
	ProtoFiles                map[string]string `json:"-"`
	// contains filtered or unexported fields
}

func GetServiceMetaDataFromIPFS

func GetServiceMetaDataFromIPFS(hash string) (*ServiceMetadata, error)

func InitServiceMetaDataFromJson

func InitServiceMetaDataFromJson(jsonData []byte) (*ServiceMetadata, error)

func ReadServiceMetaDataFromLocalFile

func ReadServiceMetaDataFromLocalFile(filename string) (*ServiceMetadata, error)

func ServiceMetaData

func ServiceMetaData() *ServiceMetadata

func (*ServiceMetadata) FreeCallSignerAddress

func (metaData *ServiceMetadata) FreeCallSignerAddress() common.Address

func (*ServiceMetadata) GetDefaultPricing

func (metaData *ServiceMetadata) GetDefaultPricing() Pricing

func (*ServiceMetadata) GetDisplayName

func (metaData *ServiceMetadata) GetDisplayName() string

func (*ServiceMetadata) GetDynamicPricingMethodAssociated

func (metaData *ServiceMetadata) GetDynamicPricingMethodAssociated(methodFullName string) (pricingMethod string, isDynamicPricingEligible bool)

GetDynamicPricingMethodAssociated accept methodFullName, example "/example_service.Calculator/add"

func (*ServiceMetadata) GetFreeCallsAllowed

func (metaData *ServiceMetadata) GetFreeCallsAllowed() int

func (*ServiceMetadata) GetLicenses

func (metaData *ServiceMetadata) GetLicenses() Licenses

func (*ServiceMetadata) GetMpeAddress

func (metaData *ServiceMetadata) GetMpeAddress() common.Address

func (*ServiceMetadata) GetServiceType

func (metaData *ServiceMetadata) GetServiceType() string

func (*ServiceMetadata) GetVersion

func (metaData *ServiceMetadata) GetVersion() int

func (*ServiceMetadata) GetWireEncoding

func (metaData *ServiceMetadata) GetWireEncoding() string

func (*ServiceMetadata) IsFreeCallAllowed

func (metaData *ServiceMetadata) IsFreeCallAllowed() bool

func (*ServiceMetadata) IsModelTraining

func (metaData *ServiceMetadata) IsModelTraining(methodFullName string) (useModelTrainingEndPoint bool)

IsModelTraining accept methodFullName, example "/example_service.Calculator/add"

type SimulatedEthereumEnvironment

type SimulatedEthereumEnvironment struct {
	SingnetPrivateKey       *ecdsa.PrivateKey
	SingnetWallet           *bind.TransactOpts
	ClientWallet            *bind.TransactOpts
	ClientPrivateKey        *ecdsa.PrivateKey
	ServerWallet            *bind.TransactOpts
	ServerPrivateKey        *ecdsa.PrivateKey
	Backend                 *simulated.Backend
	FetToken                *FetchToken
	MultiPartyEscrowAddress common.Address
	MultiPartyEscrow        *MultiPartyEscrow
}

func GetSimulatedEthereumEnvironment

func GetSimulatedEthereumEnvironment() (env SimulatedEthereumEnvironment)

func (*SimulatedEthereumEnvironment) Commit

func (*SimulatedEthereumEnvironment) MpeDeposit

func (*SimulatedEthereumEnvironment) MpeOpenChannel

func (env *SimulatedEthereumEnvironment) MpeOpenChannel(from *bind.TransactOpts, to *bind.TransactOpts, amount int64, expiration int64, groupId [32]byte) *SimulatedEthereumEnvironment

func (*SimulatedEthereumEnvironment) SnetApproveMpe

func (*SimulatedEthereumEnvironment) SnetTransferTokens

type Subscription

type Subscription struct {
	PeriodInDays         int     `json:"periodInDays"`
	DiscountInPercentage float64 `json:"discountInPercentage"`
	PlanName             string  `json:"planName"`
	LicenseCost          big.Int `json:"licenseCost"`
	GrpcServiceName      string  `json:"grpcServiceName,omitempty"`
	GrpcMethodName       string  `json:"grpcMethodName,omitempty"`
}

type Subscriptions

type Subscriptions struct {
	Type         string         `json:"type"`
	DetailsURL   string         `json:"detailsUrl"`
	IsActive     string         `json:"isActive"`
	Subscription []Subscription `json:"subscription"`
}

type Tier

type Tier struct {
	Type            string      `json:"type"`
	PlanName        string      `json:"planName"`
	GrpcServiceName string      `json:"grpcServiceName,omitempty"`
	GrpcMethodName  string      `json:"grpcMethodName,omitempty"`
	Range           []TierRange `json:"range"`
	DetailsURL      string      `json:"detailsUrl"`
	IsActive        string      `json:"isActive"`
}

type TierRange

type TierRange struct {
	High                 int     `json:"high"`
	DiscountInPercentage float64 `json:"DiscountInPercentage"`
}

type Tiers

type Tiers struct {
	Tiers Tier `json:"tier"`
}

Jump to

Keyboard shortcuts

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