Documentation ¶
Overview ¶
DEPRECATED: This package is deprecated and will be removed in a future release.
Index ¶
- Constants
- func IsAcknowledgmentExist(sessionID string) (bool, error)
- func IsConsumerRegisteredRP(extID string) (bool, error)
- func IsProviderRegisteredRP(extID string) (bool, error)
- type Acknowledgment
- func ExecuteDataUsage(ctx context.Context, downloadBytes, uploadBytes uint64, sessID string, ...) (*Acknowledgment, error)
- func ExecuteSessionInit(ctx context.Context, consExtID, provExtID, apID, sessID string, ...) (*Acknowledgment, error)
- func ExecuteSessionStart(ctx context.Context, sessID string) (*Acknowledgment, error)
- func ExecuteSessionStop(ctx context.Context, sessionID string) (*Acknowledgment, error)
- func RequestAcknowledgment(sessionID string) (*Acknowledgment, error)
- func VerifyAcknowledgmentAccepted(sessionID, accessPointID, consumerExtID, providerExtID string) (*Acknowledgment, error)
- func (m *Acknowledgment) ActiveKey() []byte
- func (m *Acknowledgment) Decode(blob []byte) error
- func (m *Acknowledgment) Encode() []byte
- func (m *Acknowledgment) Key() []byte
- func (m *Acknowledgment) PoolBalance() uint64
- func (m *Acknowledgment) PoolHolderID() string
- func (m *Acknowledgment) PoolID() string
- func (m *Acknowledgment) PoolPayeeID() string
- func (m *Acknowledgment) PoolPayerID() string
- func (m *Acknowledgment) Validate() (err error)
- type Billing
- type Consumer
- func ConsumerFetch(id string) (*Consumer, error)
- func ExecuteConsumerRegister(ctx context.Context, consumer *Consumer) (*Consumer, error)
- func ExecuteConsumerUpdate(ctx context.Context, consumer *Consumer) (*Consumer, error)
- func GetAllConsumers() ([]Consumer, error)
- func NewConsumerFromCfg(cfg *config.Consumer) *Consumer
- func (m *Consumer) Decode(blob []byte) error
- func (m *Consumer) Encode() []byte
- func (m *Consumer) ExternalID() string
- func (m *Consumer) FetchNodeRP() string
- func (m *Consumer) GetType() string
- func (m *Consumer) IsNodeRegisteredRP() string
- func (m *Consumer) RegistrationFuncName() string
- func (m *Consumer) UpdateNodeFuncName() string
- func (m *Consumer) Validate() (err error)
- type DataUsage
- type PoolConfigurator
- type Provider
- func ExecuteProviderRegister(ctx context.Context, provider *Provider) (*Provider, error)
- func ExecuteProviderUpdate(ctx context.Context, provider *Provider) (*Provider, error)
- func GetAllProviders() ([]Provider, error)
- func NewProviderFromCfg(cfg *config.Provider) *Provider
- func ProviderFetch(id string) (*Provider, error)
- func (m *Provider) Decode(blob []byte) error
- func (m *Provider) Encode() []byte
- func (m *Provider) ExternalID() string
- func (m *Provider) FetchNodeRP() string
- func (m *Provider) GetType() string
- func (m *Provider) IsNodeRegisteredRP() string
- func (m *Provider) RegistrationFuncName() string
- func (m *Provider) UpdateNodeFuncName() string
- func (m *Provider) Validate() (err error)
- type ProviderTerms
- func (m *ProviderTerms) Decode(blob []byte) error
- func (m *ProviderTerms) Decrease() *ProviderTerms
- func (m *ProviderTerms) Encode() []byte
- func (m *ProviderTerms) Expired() bool
- func (m *ProviderTerms) GetAmount() (amount uint64)
- func (m *ProviderTerms) GetMinCost() (cost uint64)
- func (m *ProviderTerms) GetPrice() (price uint64)
- func (m *ProviderTerms) GetVolume() int64
- func (m *ProviderTerms) Increase() *ProviderTerms
- func (m *ProviderTerms) Validate() (err error)
- type QoSAutoUpdate
- type TokenPool
- type TokenPoolTransfer
Constants ¶
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" )
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" )
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" )
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 ¶
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 ¶
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 ¶
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.
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 ¶
ConsumerFetch makes smart contract rest api call to magma smart contract ConsumerFetchRP rest point to fetch Consumer info.
func ExecuteConsumerRegister ¶
ExecuteConsumerRegister executes consumer registration magma sc function and returns current Consumer.
func ExecuteConsumerUpdate ¶
ExecuteConsumerUpdate executes update consumer magma sc function and returns updated Consumer.
func GetAllConsumers ¶
GetAllConsumers makes smart contract rest api call to magma smart contract GetAllConsumersRP rest point to retrieve all registered consumer.Consumer.
func NewConsumerFromCfg ¶
NewConsumerFromCfg creates Consumer from config.Consumer.
func (*Consumer) ExternalID ¶
ExternalID represents simple getter for ExtID.
func (*Consumer) FetchNodeRP ¶
FetchNodeRP returns name of magma sc rest point used for fetching consumer's node info.
func (*Consumer) IsNodeRegisteredRP ¶
IsNodeRegisteredRP returns name of magma sc rest point used for checking consumer's node registration.
func (*Consumer) RegistrationFuncName ¶
RegistrationFuncName returns name of magma sc function used for consumer's node registration.
func (*Consumer) UpdateNodeFuncName ¶
UpdateNodeFuncName returns name of magma sc function used for consumer's node updating.
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.
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 ¶
ExecuteProviderRegister executes provider registration magma sc function and returns current Provider.
func ExecuteProviderUpdate ¶
ExecuteProviderUpdate executes update provider magma sc function and returns updated Provider.
func GetAllProviders ¶
GetAllProviders makes smart contract rest api call to magma smart contract GetAllProvidersRP rest point to retrieve all registered provider.Provider.
func NewProviderFromCfg ¶
NewProviderFromCfg creates Provider from config.Provider.
func ProviderFetch ¶
ProviderFetch makes smart contract rest api call to magma smart contract ProviderFetchRP rest point to fetch Provider info.
func (*Provider) ExternalID ¶
ExternalID represents simple getter for ExtID.
func (*Provider) FetchNodeRP ¶
FetchNodeRP returns name of magma sc rest point used for fetching provider's node info.
func (*Provider) IsNodeRegisteredRP ¶
IsNodeRegisteredRP returns name of magma sc rest point used for checking provider's node registration.
func (*Provider) RegistrationFuncName ¶
RegistrationFuncName returns name of magma sc function used for provider's node registration.
func (*Provider) UpdateNodeFuncName ¶
UpdateNodeFuncName returns name of magma sc function used for provider's node updating.
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.
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.