blockchain

package
v5.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 AddressToHex

func AddressToHex(address *common.Address) string

AddressToHex converts Ethereum address to hex string representation.

func BytesToBase64

func BytesToBase64(bytes []byte) string

BytesToBase64 converts array of bytes to base64 string.

func ConvertBase64Encoding

func ConvertBase64Encoding(str string) ([32]byte, error)

func CreateEthereumClients

func CreateEthereumClients() (*EthereumClient, *EthereumClient, error)

func EstimateGas

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

func HexToAddress

func HexToAddress(str string) common.Address

HexToAddress converts hex string to Ethreum address.

func HexToBytes

func HexToBytes(str string) []byte

HexToBytes converts hex string to bytes array.

func MakeTopicFilterer

func MakeTopicFilterer(param string) [][32]byte

MakeTopicFilterer is used to generate a filter for querying Ethereum logs or contract events. Ethereum topics (such as for events) are 32-byte fixed-size values (common for hashing in Ethereum logs). This function takes a string parameter, converts it into a 32-byte array, and returns it in a slice. This allows developers to create filters when looking for specific events or log entries based on the topic.

func ParseSignature

func ParseSignature(jobSignatureBytes []byte) (uint8, [32]byte, [32]byte, error)

ParseSignature parses Ethereum signature.

func SetGas

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

func StringToBytes32

func StringToBytes32(str string) [32]byte

func ToChecksumAddress

func ToChecksumAddress(hexAddress string) string

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"`
}

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 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

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)

Get the connection time out defined

func (OrganizationMetaData) GetGroupId

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

Return the group id in bytes

func (OrganizationMetaData) GetGroupIdString

func (metaData OrganizationMetaData) GetGroupIdString() string

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

Pass the group Name and retrieve the details of the payment address/ recipient address.

func (*OrganizationMetaData) GetPaymentExpirationThreshold

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

Payment expiration threshold

func (OrganizationMetaData) GetPaymentStorageEndPoints

func (metaData OrganizationMetaData) GetPaymentStorageEndPoints() []string

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

func (OrganizationMetaData) GetRequestTimeOut

func (metaData OrganizationMetaData) GetRequestTimeOut() time.Duration

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"`
}

Structure 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 struct {
	// contains filtered or unexported fields
}

func NewProcessor

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

NewProcessor creates a new blockchain processor

func (*Processor) Close

func (processor *Processor) Close()

func (*Processor) CurrentBlock

func (processor *Processor) CurrentBlock() (currentBlock *big.Int, err error)

func (*Processor) Enabled

func (processor *Processor) Enabled() (enabled bool)

func (*Processor) EscrowContractAddress

func (processor *Processor) EscrowContractAddress() common.Address

func (*Processor) GetEthHttpClient

func (processor *Processor) GetEthHttpClient() *ethclient.Client

func (*Processor) GetEthWSClient

func (processor *Processor) GetEthWSClient() *ethclient.Client

func (*Processor) HasIdentity

func (processor *Processor) HasIdentity() bool

func (*Processor) MultiPartyEscrow

func (processor *Processor) MultiPartyEscrow() *MultiPartyEscrow

func (*Processor) MultiPartyEscrowChannel

func (processor *Processor) MultiPartyEscrowChannel(channelID *big.Int) (channel *MultiPartyEscrowChannel, ok bool, err error)

func (*Processor) ReconnectToWsClient

func (processor *Processor) ReconnectToWsClient() error

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"`
	ProtoFile                 protoreflect.FileDescriptor `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)

methodFullName , ex "/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 methodFullName , ex "/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
	SingularityNetToken     *SingularityNetToken
	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