Help us shape the future of Go! Take the 2026 Go Developer Survey

chain

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeMap = map[string]reflect.Type{
	"u8":           reflect.TypeOf(types.U8(0)),
	"u16":          reflect.TypeOf(types.U16(0)),
	"u32":          reflect.TypeOf(types.U32(0)),
	"u64":          reflect.TypeOf(types.U64(0)),
	"u128":         reflect.TypeOf(types.U128{}),
	"u256":         reflect.TypeOf(types.U256{}),
	"i8":           reflect.TypeOf(types.I8(0)),
	"i16":          reflect.TypeOf(types.I16(0)),
	"i32":          reflect.TypeOf(types.I32(0)),
	"i64":          reflect.TypeOf(types.I64(0)),
	"i128":         reflect.TypeOf(types.I128{}),
	"i256":         reflect.TypeOf(types.I256{}),
	"bool":         reflect.TypeOf(types.Bool(false)),
	"text":         reflect.TypeOf(types.Text("")),
	"hash":         reflect.TypeOf(types.Hash{}),
	"address":      reflect.TypeOf(types.Address{}),
	"AccountId":    reflect.TypeOf(types.AccountID{}),
	"BalanceOf<T>": reflect.TypeOf(types.U128{}),
}

Functions

func DecodeEventRecordsWithIgnoreError added in v1.2.0

func DecodeEventRecordsWithIgnoreError(e types.EventRecordsRaw, m *types.Metadata, t interface{}) error

Types

type AccountInfo added in v1.1.0

type AccountInfo struct {
	Address string
	Amount  types.U128
}

type AccountInfoCustom added in v1.1.0

type AccountInfoCustom struct {
	Nonce       types.U32
	Consumers   types.U32
	Providers   types.U32
	Sufficients types.U32
	Data        struct {
		Free       types.U128
		Reserved   types.U128
		MiscFrozen types.U128
		FreeFrozen types.U128
	}
}

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) CalculateResourceOverdue added in v1.1.0

func (cc *ChainClient) CalculateResourceOverdue(expireBlock uint64) (time.Duration, error)

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) GetAccountInfo added in v1.1.0

func (cc *ChainClient) GetAccountInfo() (*AccountInfo, error)

func (*ChainClient) GetAgreementIndex added in v1.1.0

func (cc *ChainClient) GetAgreementIndex(orderIndex uint64) (uint64, error)

func (*ChainClient) GetEvent

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

func (*ChainClient) GetGatewayNodes added in v1.1.0

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

func (*ChainClient) GetMarketStackInfo added in v1.3.0

func (cc *ChainClient) GetMarketStackInfo() (*StakingAmount, error)

func (*ChainClient) GetOrder

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

func (*ChainClient) GetResource

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

func (*ChainClient) GetReward added in v1.3.0

func (cc *ChainClient) GetReward() (*MarketIncome, error)

func (*ChainClient) GetStakingInfo added in v1.1.0

func (cc *ChainClient) GetStakingInfo() (*StakingAmount, 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) PayoutReward added in v1.3.0

func (cc *ChainClient) PayoutReward() error

func (*ChainClient) ProcessApplyFreeResource added in v1.2.0

func (cc *ChainClient) ProcessApplyFreeResource(index uint64, peerId string) error

func (*ChainClient) ReceiveIncome added in v1.1.0

func (cc *ChainClient) ReceiveIncome() error

func (*ChainClient) ReceiveIncomeJudge added in v1.1.0

func (cc *ChainClient) ReceiveIncomeJudge() bool

func (*ChainClient) RegisterResource

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

Register chain

func (*ChainClient) ReleaseApplyFreeResource added in v1.2.0

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

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

func (*ChainClient) StakingAmount added in v1.1.0

func (cc *ChainClient) StakingAmount(unitPrice int64) error

func (*ChainClient) WithdrawStakingAmount added in v1.1.0

func (cc *ChainClient) WithdrawStakingAmount(unitPrice int64) error

type ComputingOrder

type ComputingOrder struct {
	Index      types.U64
	TenantInfo struct {
		AccountId types.AccountID
		PublicKey types.Text
	}
	ResourceIndex  types.U64
	Create         types.U32
	RentDuration   types.U32
	Time           Duration
	Status         OrderStatus
	AgreementIndex types.OptionU64
}

type ComputingResource

type ComputingResource struct {
	Index     types.U64       `json:"index"`
	AccountId types.AccountID `json:"accountId"`
	PeerId    types.Text      `json:"peerId"`
	Config    struct {
		Cpu      types.U64  `json:"cpu"`
		Memory   types.U64  `json:"memory"`
		System   types.Text `json:"system"`
		CpuModel types.Text `json:"cpuModel"`
	} `json:"config"`
	RentalStatistics struct {
		RentalCount    types.U32 `json:"rentalCount"`
		RentalDuration types.U32 `json:"rentalDuration"`
		FaultCount     types.U32 `json:"faultCount"`
		FaultDuration  types.U32 `json:"faultDuration"`
	} `json:"rentalStatistics"`
	RentalInfo struct {
		RentPrice    types.U128 `json:"rentPrice"`
		RentDuration types.U32  `json:"rentDuration"`
		EndOfRent    types.U32  `json:"endOfRent"`
	} `json:"rentalInfo"`
	Status Status `json:"status"`
}

type Duration added in v1.1.0

type Duration struct {
	Secs  types.U64
	Nanos types.U32
}

type EventBalancesWithdraw added in v1.3.3

type EventBalancesWithdraw struct {
	Phase   types.Phase
	Who     types.AccountID
	Balance types.U128
	Topics  []types.Hash
}

type EventMarketMoney added in v1.2.0

type EventMarketMoney struct {
	Phase  types.Phase
	Money  types.U128
	Topics []types.Hash
}

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
	DeployType    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
	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 MarketIncome added in v1.3.0

type MarketIncome struct {
	LastEraIndex types.U32
	TotalIncome  types.U128
}

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
	Balances_Withdraw                             []EventBalancesWithdraw
}

type OrderStatus added in v1.1.0

type OrderStatus struct {
	IsPending  bool
	IsFinished bool
	IsCanceled bool
}

func (*OrderStatus) Decode added in v1.1.0

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

func (*OrderStatus) Encode added in v1.1.0

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

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(resourceIndex 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(orderIndex uint64) time.Duration

	GetAgreementIndex(orderIndex uint64) (uint64, error)

	//GetResource get vm resource
	GetResource(resourceIndex uint64) (*ComputingResource, error)

	CalculateResourceOverdue(expireBlock uint64) (time.Duration, error)

	ReceiveIncome() error

	GetAccountInfo() (*AccountInfo, error)

	GetStakingInfo() (*StakingAmount, error)

	GetMarketStackInfo() (*StakingAmount, error)

	StakingAmount(unitPrice int64) error

	WithdrawStakingAmount(unitPrice int64) error

	ReceiveIncomeJudge() bool

	GetGatewayNodes() ([]string, error)

	ProcessApplyFreeResource(index uint64, peerId string) error

	ReleaseApplyFreeResource(index uint64) error

	GetReward() (*MarketIncome, error)

	PayoutReward() error
}

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         uint64    `json:"price"`
	ResourceIndex uint64    `json:"resource_index"`
}

ResourceInfo 资源信息

type StakingAmount added in v1.1.0

type StakingAmount struct {
	Amount       types.U128
	ActiveAmount types.U128
	LockAmount   types.U128
}

type Status

type Status struct {
	IsInuse   bool `json:"isInuse"`
	IsLocked  bool `json:"isLocked"`
	IsUnused  bool `json:"isUnused"`
	IsOffline bool `json:"isOffline"`
}

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