chain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainClient

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

ChainClient blockchain chain connection

func NewChainClient

func NewChainClient(cm *config.ConfigManager, api *gsrpc.SubstrateAPI) (*ChainClient, error)

func (*ChainClient) AddResourceDuration

func (cc *ChainClient) AddResourceDuration(index uint64, duration int) error

func (*ChainClient) CalculateInstanceOverdue

func (cc *ChainClient) CalculateInstanceOverdue(orderIndex uint64) time.Duration

func (*ChainClient) CalculateProviderOverdue

func (cc *ChainClient) CalculateProviderOverdue(agreementIndex uint64) time.Duration

calculate instance expiration time

func (*ChainClient) ChangeResourceStatus

func (cc *ChainClient) ChangeResourceStatus(index uint64) error

func (*ChainClient) CheckExtrinsicSuccess

func (cc *ChainClient) CheckExtrinsicSuccess(header *types.Header, call string) error

CheckExtrinsicSuccess verify that the transaction is successful

func (*ChainClient) GetEvent

func (cc *ChainClient) GetEvent(blockNumber uint64) (*MyEventRecords, error)

func (*ChainClient) GetOrder

func (cc *ChainClient) GetOrder(resourceIndex uint64) (*ComputingOrder, error)

func (*ChainClient) GetResource

func (cc *ChainClient) GetResource(resourceIndex uint64) (*ComputingResource, error)

func (*ChainClient) Heartbeat

func (cc *ChainClient) Heartbeat(agreementindex uint64) error

func (*ChainClient) LoadKeyFromChain

func (cc *ChainClient) LoadKeyFromChain() ([]string, error)

LoadKeyFromChain Get the public Yue of the current node from the chain

func (*ChainClient) ModifyResourcePrice

func (cc *ChainClient) ModifyResourcePrice(index uint64, unitPrice int64) error

func (*ChainClient) OrderExec

func (cc *ChainClient) OrderExec(orderIndex uint64) error

OrderExec order execution

func (*ChainClient) RegisterResource

func (cc *ChainClient) RegisterResource(r ResourceInfo) error

Register chain

func (*ChainClient) RemoveResource

func (cc *ChainClient) RemoveResource(index uint64) error

func (*ChainClient) ReportStatus

func (cc *ChainClient) ReportStatus() error

ReportStatus Timing the virtual machine to report the service status

type ComputingOrder

type ComputingOrder struct {
	Index      types.U64
	TenantInfo struct {
		AccountId types.AccountID
		PublicKey types.Text
	}
	Price          types.U128
	ResourceIndex  types.U64
	Create         types.U32
	RentDuration   types.U32
	Status         Status
	AgreementIndex types.U64
}

type ComputingResource

type ComputingResource struct {
	Index     types.U64
	AccountId types.AccountID
	PeerId    types.Text
	Config    struct {
		Cpu      types.U64
		Memory   types.U64
		System   types.Text
		CpuModel types.Text
	}
	RentalStatistics struct {
		RentalCount    types.U32
		RentalDuration types.U32
		FaultCount     types.U32
		FaultDuration  types.U32
	}
	RentalInfo struct {
		RentUnitPrice types.U128
		RentDuration  types.U32
		EndOfRent     types.U32
	}
	Status Status
}

type EventProviderRegisterResourceSuccess

type EventProviderRegisterResourceSuccess struct {
	Phase            types.Phase
	AccountId        types.AccountID
	Index            types.U64
	PeerId           string
	Cpu              types.U64
	Memory           types.U64
	System           string
	CpuModel         string
	PriceHour        types.U128
	RentDurationHour types.U32
	Topics           []types.Hash
}

type EventResourceOrderCreateOrderSuccess

type EventResourceOrderCreateOrderSuccess struct {
	Phase         types.Phase
	AccountId     types.AccountID
	OrderIndex    types.U64
	ResourceIndex types.U64
	Duration      types.U32
	PublicKey     string
	Topics        []types.Hash
}

type EventResourceOrderOrderExecSuccess

type EventResourceOrderOrderExecSuccess struct {
	Phase          types.Phase
	AccountId      types.AccountID
	OrderIndex     types.U64
	ResourceIndex  types.U64
	AgreementIndex types.U64
	Topics         []types.Hash
}

type EventResourceOrderReNewOrderSuccess

type EventResourceOrderReNewOrderSuccess struct {
	Phase          types.Phase
	AccountId      types.AccountID
	OrderIndex     types.U64
	ResourceIndex  types.U64
	AgreementIndex types.U64
	Topics         []types.Hash
}

type EventResourceOrderWithdrawLockedOrderPriceSuccess

type EventResourceOrderWithdrawLockedOrderPriceSuccess struct {
	Phase      types.Phase
	AccountId  types.AccountID
	OrderIndex types.U64
	OrderPrice types.U128
	Topics     []types.Hash
}

type LinkClient

type LinkClient struct {
	Config *config.Config
}

func (*LinkClient) AddResourceDuration

func (c *LinkClient) AddResourceDuration(index uint64, duration int) error

func (*LinkClient) CalculateInstanceOverdue

func (c *LinkClient) CalculateInstanceOverdue(agreementIndex uint64) time.Duration

func (*LinkClient) ChangeResourceStatus

func (c *LinkClient) ChangeResourceStatus(index uint64) error

func (*LinkClient) Heartbeat

func (c *LinkClient) Heartbeat(agreementindex uint64) error

func (*LinkClient) Heatbeat

func (c *LinkClient) Heatbeat(agreementindex uint64) error

Heatbeat ReportStatus Timing the virtual machine to report the service status

func (*LinkClient) LoadKeyFromChain

func (c *LinkClient) LoadKeyFromChain() ([]string, error)

LoadKeyFromChain Get the public Yue of the current node from the chain

func (*LinkClient) LoadRegistryInfoFromChain

func (c *LinkClient) LoadRegistryInfoFromChain() (*ResourceInfo, error)

LoadRegistryInfoFromChain load registration information from the chain

func (*LinkClient) ModifyResourcePrice

func (c *LinkClient) ModifyResourcePrice(index uint64, unitPrice int64) error

func (*LinkClient) OrderExec

func (c *LinkClient) OrderExec(orderIndex uint64) error

func (*LinkClient) RegisterResource

func (c *LinkClient) RegisterResource(r ResourceInfo) error

RegisterResource Register chain

func (*LinkClient) RemoveResource

func (c *LinkClient) RemoveResource(index uint64) error

type MyEventRecords

type MyEventRecords struct {
	types.EventRecords
	Provider_RegisterResourceSuccess              []EventProviderRegisterResourceSuccess //nolint:stylecheck,golint
	ResourceOrder_CreateOrderSuccess              []EventResourceOrderCreateOrderSuccess //nolint:stylecheck,golint
	ResourceOrder_OrderExecSuccess                []EventResourceOrderOrderExecSuccess
	ResourceOrder_ReNewOrderSuccess               []EventResourceOrderReNewOrderSuccess
	ResourceOrder_WithdrawLockedOrderPriceSuccess []EventResourceOrderWithdrawLockedOrderPriceSuccess
}

type RentalAgreement

type RentalAgreement struct {
	Index      types.U64
	Provider   types.AccountID
	TenantInfo struct {
		AccountId types.AccountID
		PublicKey string
	}
	PeerId        string
	ResourceIndex types.U64
	Config        struct {
		Cpu      types.U64
		Memory   types.U64
		System   string
		CpuModel string
	}
	RentalInfo struct {
		RentUnitPrice types.U128
		RentDuration  types.U32
		EndOfRent     types.U32
	}
	Price         types.U128
	LockPrice     types.U128
	PenaltyAmount types.U128
	ReceiveAmount types.U128
	Start         types.U32
	End           types.U32
	Calculation   types.U32
}

type ReportClient

type ReportClient interface {
	// RegisterResource resource registration
	RegisterResource(ResourceInfo) error
	// RemoveResource resource deletion
	RemoveResource(index uint64) error
	// ModifyResourcePrice modify resource unit price
	ModifyResourcePrice(index uint64, unitPrice int64) error
	// ChangeResourceStatus modify resource status to unused
	ChangeResourceStatus(index uint64) error

	// AddResourceDuration add resource rental time
	AddResourceDuration(index uint64, duration int) error

	// Heartbeat protocol heartbeat report
	Heartbeat(agreementindex uint64) error

	// OrderExec
	OrderExec(orderIndex uint64) error

	LoadKeyFromChain() ([]string, error)

	CalculateInstanceOverdue(agreementIndex uint64) time.Duration
}

ReportClient data reporting interface

type ResourceInfo

type ResourceInfo struct {
	PeerId     string    `json:"peerId"`
	Cpu        uint64    `json:"cpu"`
	Memory     uint64    `json:"memory"`
	System     string    `json:"system"`
	Image      string    `json:"image"`
	CpuModel   string    `json:"cpuModel"`
	VmType     string    `json:"vmType"`
	Creator    string    `json:"creator"`
	ExpireTime time.Time `json:"expireTime"`
	User       string    `json:"user"`
	Status     int       `json:"status"`
	Price      int64     `json:"price"`
}

ResourceInfo resource information

type Status

type Status struct {
	IsInuse   bool
	IsLocked  bool
	IsUnused  bool
	IsOffline bool
}

func (*Status) Decode

func (m *Status) Decode(decoder scale.Decoder) error

func (*Status) Encode

func (m *Status) Encode(encoder scale.Encoder) error

Jump to

Keyboard shortcuts

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