magmasc

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

DEPRECATED: This package is deprecated and will be removed in a future release.

Index

Constants

View Source
const (
	// Address represents the address of the Magma smart contract.
	// Used while making requests to smart contract's rest points and executing smart contracts functions.
	Address = "11f8411db41e34cea7c100f19faff32da8f3cd5a80635731cec06f32d08089be"

	// GetAllConsumersRP represents MagmaSC relative path.
	// Used to list all registered in the blockchain consumers.
	GetAllConsumersRP = "/allConsumers"

	// GetAllProvidersRP represents MagmaSC relative path.
	// Used to list all registered in the blockchain providers.
	GetAllProvidersRP = "/allProviders"
)
View Source
const (
	// AcknowledgmentPrefix represents prefix to save into storage.
	AcknowledgmentPrefix = "ackn"

	// AcknowledgmentActivePrefixPart represents prefix part to save into storage.
	AcknowledgmentActivePrefixPart = "act"

	// AcknowledgmentRP represents MagmaSC relative path.
	// Used to retrieve accepted acknowledgment.
	AcknowledgmentRP = "/acknowledgmentAccepted"

	// IsAcknowledgmentExistRP represents MagmaSC relative path.
	// Used to check existing of acknowledgment.
	IsAcknowledgmentExistRP = "/acknowledgmentExist"

	// VerifyAcknowledgmentAcceptedRP represents MagmaSC relative path.
	// Used to verify accepting Provider's terms by Consumer.
	VerifyAcknowledgmentAcceptedRP = "/acknowledgmentAcceptedVerify"
)
View Source
const (
	// ConsumerRegisterFuncName represents MagmaSC function.
	// Used to register bandwidth-marketplace's node.
	ConsumerRegisterFuncName = "consumer_register"

	// ConsumerSessionStartFuncName represents MagmaSC function.
	// Used to start session.
	ConsumerSessionStartFuncName = "consumer_session_start"

	// ConsumerSessionStopFuncName represents MagmaSC function.
	// Used to stop session.
	ConsumerSessionStopFuncName = "consumer_session_stop"

	// ConsumerUpdateFuncName represents MagmaSC function.
	// Used to update consumer node info.
	ConsumerUpdateFuncName = "consumer_update"

	// ConsumerFetchRP represents MagmaSC relative path.
	// Used to fetch consumer info.
	ConsumerFetchRP = "/consumerFetch"

	// ConsumerRegisteredRP represents MagmaSC relative path.
	// Used to fetch consumer registered info.
	ConsumerRegisteredRP = "/consumerExist"
)
View Source
const (
	// TermsExpiredDuration represents value for
	// minimal duration of provider terms that will pass check it's expired.
	TermsExpiredDuration = 1 * 60 // 1 minute

	// ProviderDataUsageFuncName represents MagmaSC function.
	// Used to update session info about data usages and collecting payments data
	// from consumer to provider.
	ProviderDataUsageFuncName = "provider_data_usage"

	// ProviderRegisterFuncName represents MagmaSC function.
	// Used to register bandwidth-marketplace's node.
	ProviderRegisterFuncName = "provider_register"

	// ProviderUpdateFuncName represents MagmaSC function.
	// Used for updating provider terms.
	ProviderUpdateFuncName = "provider_update"

	// ProviderSessionInitFuncName represents MagmaSC function.
	// Used for initializing session by a provider.
	ProviderSessionInitFuncName = "provider_session_init"

	// ProviderFetchRP represents MagmaSC relative path.
	// Used to fetch provider info.
	ProviderFetchRP = "/providerFetch"

	// ProviderRegisteredRP represents MagmaSC relative path.
	// Used to fetch provider registered info.
	ProviderRegisteredRP = "/providerExist"
)

Variables

This section is empty.

Functions

func IsAcknowledgmentExist

func IsAcknowledgmentExist(sessionID string) (bool, error)

IsAcknowledgmentExist makes smart contract rest api call to magma smart contract IsAcknowledgmentExistRP rest point to ensure that Acknowledgment with provided session ID exist in the blockchain.

func IsConsumerRegisteredRP

func IsConsumerRegisteredRP(extID string) (bool, error)

IsConsumerRegisteredRP makes smart contract rest api call to magma smart contract ConsumerRegisteredRP rest point to check registration of the consumer with provided external ID.

func IsProviderRegisteredRP

func IsProviderRegisteredRP(extID string) (bool, error)

IsProviderRegisteredRP makes smart contract rest api call to magma smart contract ProviderRegisteredRP rest point to check registration of the provider with provided external ID.

Types

type Acknowledgment

type Acknowledgment struct {
	SessionID     string        `json:"session_id"`
	AccessPointID string        `json:"access_point_id"`
	Billing       Billing       `json:"billing"`
	Consumer      *Consumer     `json:"consumer,omitempty"`
	Provider      *Provider     `json:"provider,omitempty"`
	Terms         ProviderTerms `json:"terms"`
	TokenPool     *TokenPool    `json:"token_pool,omitempty"`
}

Acknowledgment contains the necessary data obtained when the consumer accepts the provider terms and stores in the state of the blockchain as a result of performing the consumerAcceptTerms MagmaSmartContract function.

func ExecuteDataUsage

func ExecuteDataUsage(
	ctx context.Context, downloadBytes, uploadBytes uint64, sessID string, sessTime uint32) (*Acknowledgment, error)

ExecuteDataUsage executes ProviderDataUsageFuncName and returns current Acknowledgment.

func ExecuteSessionInit

func ExecuteSessionInit(ctx context.Context, consExtID, provExtID, apID, sessID string, terms ProviderTerms) (*Acknowledgment, error)

ExecuteSessionInit executes session init magma sc function and returns Acknowledgment.

func ExecuteSessionStart

func ExecuteSessionStart(ctx context.Context, sessID string) (*Acknowledgment, error)

ExecuteSessionStart starts session for provided IDs by executing ConsumerSessionStartFuncName.

func ExecuteSessionStop

func ExecuteSessionStop(ctx context.Context, sessionID string) (*Acknowledgment, error)

ExecuteSessionStop requests Acknowledgment from the blockchain and executes ConsumerSessionStopFuncName and verifies including the transaction in the blockchain.

Returns Acknowledgment for session with provided ID.

func RequestAcknowledgment

func RequestAcknowledgment(sessionID string) (*Acknowledgment, error)

RequestAcknowledgment makes smart contract rest api call to magma smart contract AcknowledgmentRP rest point to retrieve Acknowledgment.

func VerifyAcknowledgmentAccepted

func VerifyAcknowledgmentAccepted(sessionID, accessPointID, consumerExtID, providerExtID string) (*Acknowledgment, error)

VerifyAcknowledgmentAccepted makes smart contract rest api call to magma smart contract VerifyAcknowledgmentAcceptedRP rest point to ensure that Acknowledgment with provided IDs was accepted.

func (*Acknowledgment) ActiveKey

func (m *Acknowledgment) ActiveKey() []byte

ActiveKey returns key used for operations with storage.Storage AcknowledgmentPrefix + AcknowledgmentActivePrefixPart + Acknowledgment.SessionID.

func (*Acknowledgment) Decode

func (m *Acknowledgment) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*Acknowledgment) Encode

func (m *Acknowledgment) Encode() []byte

Encode implements util.Serializable interface.

func (*Acknowledgment) Key

func (m *Acknowledgment) Key() []byte

Key returns key with AcknowledgmentPrefix. Used for operations with storage.Storage.

func (*Acknowledgment) PoolBalance

func (m *Acknowledgment) PoolBalance() uint64

PoolBalance implements PoolConfigurator interface.

func (*Acknowledgment) PoolHolderID

func (m *Acknowledgment) PoolHolderID() string

PoolHolderID implements PoolConfigurator interface.

func (*Acknowledgment) PoolID

func (m *Acknowledgment) PoolID() string

PoolID implements PoolConfigurator interface.

func (*Acknowledgment) PoolPayeeID

func (m *Acknowledgment) PoolPayeeID() string

PoolPayeeID implements PoolConfigurator interface.

func (*Acknowledgment) PoolPayerID

func (m *Acknowledgment) PoolPayerID() string

PoolPayerID implements PoolConfigurator interface.

func (*Acknowledgment) Validate

func (m *Acknowledgment) Validate() (err error)

Validate checks Acknowledgment for correctness. If it is not return errInvalidAcknowledgment.

type Billing

type Billing struct {
	Amount      uint64         `json:"amount"`
	DataUsage   DataUsage      `json:"data_usage"`
	CompletedAt time.Timestamp `json:"completed_at,omitempty"`
}

Billing represents all info about data usage.

func (*Billing) CalcAmount

func (m *Billing) CalcAmount(terms ProviderTerms)

CalcAmount calculates and sets the billing Amount value by given price. NOTE: the cost value must be represented in token units per megabyte.

func (*Billing) Decode

func (m *Billing) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*Billing) Encode

func (m *Billing) Encode() []byte

Encode implements util.Serializable interface.

func (*Billing) Validate

func (m *Billing) Validate(dataUsage *DataUsage) (err error)

Validate checks given data usage is correctness for the billing.

type Consumer

type Consumer struct {
	ID    string `json:"id"`
	ExtID string `json:"ext_id"`
	Host  string `json:"host,omitempty"`
}

Consumer represents consumers node stored in blockchain.

func ConsumerFetch

func ConsumerFetch(id string) (*Consumer, error)

ConsumerFetch makes smart contract rest api call to magma smart contract ConsumerFetchRP rest point to fetch Consumer info.

func ExecuteConsumerRegister

func ExecuteConsumerRegister(ctx context.Context, consumer *Consumer) (*Consumer, error)

ExecuteConsumerRegister executes consumer registration magma sc function and returns current Consumer.

func ExecuteConsumerUpdate

func ExecuteConsumerUpdate(ctx context.Context, consumer *Consumer) (*Consumer, error)

ExecuteConsumerUpdate executes update consumer magma sc function and returns updated Consumer.

func GetAllConsumers

func GetAllConsumers() ([]Consumer, error)

GetAllConsumers makes smart contract rest api call to magma smart contract GetAllConsumersRP rest point to retrieve all registered consumer.Consumer.

func NewConsumerFromCfg

func NewConsumerFromCfg(cfg *config.Consumer) *Consumer

NewConsumerFromCfg creates Consumer from config.Consumer.

func (*Consumer) Decode

func (m *Consumer) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*Consumer) Encode

func (m *Consumer) Encode() []byte

Encode implements util.Serializable interface.

func (*Consumer) ExternalID

func (m *Consumer) ExternalID() string

ExternalID represents simple getter for ExtID.

func (*Consumer) FetchNodeRP

func (m *Consumer) FetchNodeRP() string

FetchNodeRP returns name of magma sc rest point used for fetching consumer's node info.

func (*Consumer) GetType

func (m *Consumer) GetType() string

GetType returns node type.

func (*Consumer) IsNodeRegisteredRP

func (m *Consumer) IsNodeRegisteredRP() string

IsNodeRegisteredRP returns name of magma sc rest point used for checking consumer's node registration.

func (*Consumer) RegistrationFuncName

func (m *Consumer) RegistrationFuncName() string

RegistrationFuncName returns name of magma sc function used for consumer's node registration.

func (*Consumer) UpdateNodeFuncName

func (m *Consumer) UpdateNodeFuncName() string

UpdateNodeFuncName returns name of magma sc function used for consumer's node updating.

func (*Consumer) Validate

func (m *Consumer) Validate() (err error)

Validate checks the Consumer for correctness. If it is not return errInvalidConsumer.

type DataUsage

type DataUsage struct {
	DownloadBytes uint64 `json:"download_bytes"`
	UploadBytes   uint64 `json:"upload_bytes"`
	SessionID     string `json:"session_id"`
	SessionTime   uint32 `json:"session_time"`
}

DataUsage represents session data sage implementation.

func (*DataUsage) Decode

func (m *DataUsage) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*DataUsage) Encode

func (m *DataUsage) Encode() []byte

Encode implements util.Serializable interface.

func (*DataUsage) Validate

func (m *DataUsage) Validate() (err error)

Validate checks DataUsage for correctness.

type PoolConfigurator

type PoolConfigurator interface {
	// PoolBalance returns the amount value of token pool.
	PoolBalance() uint64

	// PoolID returns the token pool ID.
	PoolID() string

	// PoolHolderID returns the token pool holder ID.
	PoolHolderID() string

	// PoolPayerID returns the token pool payer ID.
	PoolPayerID() string

	// PoolPayeeID returns the token pool payee ID.
	PoolPayeeID() string
}

PoolConfigurator represents a pool config interface.

type Provider

type Provider struct {
	ID       string `json:"id"`
	ExtID    string `json:"ext_id"`
	Host     string `json:"host,omitempty"`
	MinStake int64  `json:"min_stake,omitempty"`
}

Provider represents providers node stored in blockchain.

func ExecuteProviderRegister

func ExecuteProviderRegister(ctx context.Context, provider *Provider) (*Provider, error)

ExecuteProviderRegister executes provider registration magma sc function and returns current Provider.

func ExecuteProviderUpdate

func ExecuteProviderUpdate(ctx context.Context, provider *Provider) (*Provider, error)

ExecuteProviderUpdate executes update provider magma sc function and returns updated Provider.

func GetAllProviders

func GetAllProviders() ([]Provider, error)

GetAllProviders makes smart contract rest api call to magma smart contract GetAllProvidersRP rest point to retrieve all registered provider.Provider.

func NewProviderFromCfg

func NewProviderFromCfg(cfg *config.Provider) *Provider

NewProviderFromCfg creates Provider from config.Provider.

func ProviderFetch

func ProviderFetch(id string) (*Provider, error)

ProviderFetch makes smart contract rest api call to magma smart contract ProviderFetchRP rest point to fetch Provider info.

func (*Provider) Decode

func (m *Provider) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*Provider) Encode

func (m *Provider) Encode() []byte

Encode implements util.Serializable interface.

func (*Provider) ExternalID

func (m *Provider) ExternalID() string

ExternalID represents simple getter for ExtID.

func (*Provider) FetchNodeRP

func (m *Provider) FetchNodeRP() string

FetchNodeRP returns name of magma sc rest point used for fetching provider's node info.

func (*Provider) GetType

func (m *Provider) GetType() string

GetType returns Provider's type.

func (*Provider) IsNodeRegisteredRP

func (m *Provider) IsNodeRegisteredRP() string

IsNodeRegisteredRP returns name of magma sc rest point used for checking provider's node registration.

func (*Provider) RegistrationFuncName

func (m *Provider) RegistrationFuncName() string

RegistrationFuncName returns name of magma sc function used for provider's node registration.

func (*Provider) UpdateNodeFuncName

func (m *Provider) UpdateNodeFuncName() string

UpdateNodeFuncName returns name of magma sc function used for provider's node updating.

func (*Provider) Validate

func (m *Provider) Validate() (err error)

Validate checks Provider for correctness. If it is not return errInvalidProvider.

type ProviderTerms

type ProviderTerms struct {
	AccessPointID   string         `json:"apid"`                        // access point id
	Price           float32        `json:"price"`                       // tokens per Megabyte
	PriceAutoUpdate float32        `json:"price_auto_update,omitempty"` // price change on auto update
	MinCost         float32        `json:"min_cost"`                    // minimal cost for a session
	Volume          int64          `json:"volume"`                      // bytes per a session
	QoS             *magma.QoS     `json:"qos"`                         // quality of service guarantee
	QoSAutoUpdate   *QoSAutoUpdate `json:"qos_auto_update,omitempty"`   // qos change on auto update
	ProlongDuration time.Duration  `json:"prolong_duration,omitempty"`  // duration in seconds to prolong the terms
	ExpiredAt       time.Timestamp `json:"expired_at,omitempty"`        // timestamp till a session valid
}

ProviderTerms represents a provider and service terms.

func NewProviderTerms

func NewProviderTerms() *ProviderTerms

NewProviderTerms returns a new constructed provider terms.

func (*ProviderTerms) Decode

func (m *ProviderTerms) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*ProviderTerms) Decrease

func (m *ProviderTerms) Decrease() *ProviderTerms

Decrease makes automatically Decrease provider terms by config.

func (*ProviderTerms) Encode

func (m *ProviderTerms) Encode() []byte

Encode implements util.Serializable interface.

func (*ProviderTerms) Expired

func (m *ProviderTerms) Expired() bool

Expired returns if terms already expired.

func (*ProviderTerms) GetAmount

func (m *ProviderTerms) GetAmount() (amount uint64)

GetAmount returns calculated amount value of provider terms.

func (*ProviderTerms) GetMinCost

func (m *ProviderTerms) GetMinCost() (cost uint64)

GetMinCost returns calculated min cost value of provider terms.

func (*ProviderTerms) GetPrice

func (m *ProviderTerms) GetPrice() (price uint64)

GetPrice returns calculated price value of provider terms. NOTE: the price value will be represented in token units per megabyte.

func (*ProviderTerms) GetVolume

func (m *ProviderTerms) GetVolume() int64

GetVolume returns value of the provider terms volume. If the Volume is empty it will be calculated by the provider terms.

func (*ProviderTerms) Increase

func (m *ProviderTerms) Increase() *ProviderTerms

Increase makes automatically Increase provider terms by config.

func (*ProviderTerms) Validate

func (m *ProviderTerms) Validate() (err error)

Validate checks ProviderTerms for correctness. If it is not return errInvalidProviderTerms.

type QoSAutoUpdate

type QoSAutoUpdate struct {
	DownloadMbps float32 `json:"download_mbps"`
	UploadMbps   float32 `json:"upload_mbps"`
}

QoSAutoUpdate represents data of qos terms on auto update.

type TokenPool

type TokenPool struct {
	ID        string              `json:"id"`
	Balance   int64               `json:"balance"`
	HolderID  string              `json:"holder_id"`
	PayerID   string              `json:"payer_id"`
	PayeeID   string              `json:"payee_id"`
	Transfers []TokenPoolTransfer `json:"transfers,omitempty"`
}

TokenPool represents token pool implementation.

func (*TokenPool) Decode

func (m *TokenPool) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*TokenPool) Encode

func (m *TokenPool) Encode() []byte

Encode implements util.Serializable interface.

type TokenPoolTransfer

type TokenPoolTransfer struct {
	TxnHash    string `json:"txn_hash,omitempty"`
	FromPool   string `json:"from_pool,omitempty"`
	ToPool     string `json:"to_pool,omitempty"`
	Value      int64  `json:"value,omitempty"`
	FromClient string `json:"from_client,omitempty"`
	ToClient   string `json:"to_client,omitempty"`
}

TokenPoolTransfer stores info about token transfers from pool to pool.

func (*TokenPoolTransfer) Decode

func (m *TokenPoolTransfer) Decode(blob []byte) error

Decode implements util.Serializable interface.

func (*TokenPoolTransfer) Encode

func (m *TokenPoolTransfer) Encode() []byte

Encode implements util.Serializable interface.

Jump to

Keyboard shortcuts

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