db

package
v0.11.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeNotFound node not found
	ErrNodeNotFound = errors.New("node not found")
	// ErrFarmNotFound farm not found
	ErrFarmNotFound = errors.New("farm not found")
	//ErrViewNotFound
	ErrNodeResourcesViewNotFound = errors.New("ERROR: relation \"nodes_resources_view\" does not exist (SQLSTATE 42P01)")
	// ErrContractNotFound contract not found
	ErrContractNotFound = errors.New("contract not found")
)

Functions

This section is empty.

Types

type ContractBilling added in v0.11.3

type ContractBilling types.ContractBilling

type DBContract

type DBContract struct {
	ContractID        uint
	TwinID            uint
	State             string
	CreatedAt         uint
	Name              string
	NodeID            uint
	DeploymentData    string
	DeploymentHash    string
	NumberOfPublicIps uint
	Type              string
}

DBContract is contract info

type Database

type Database interface {
	GetStats(ctx context.Context, filter types.StatsFilter) (types.Stats, error)
	GetNode(ctx context.Context, nodeID uint32) (Node, error)
	GetFarm(ctx context.Context, farmID uint32) (Farm, error)
	GetNodes(ctx context.Context, filter types.NodeFilter, limit types.Limit) ([]Node, uint, error)
	GetFarms(ctx context.Context, filter types.FarmFilter, limit types.Limit) ([]Farm, uint, error)
	GetTwins(ctx context.Context, filter types.TwinFilter, limit types.Limit) ([]types.Twin, uint, error)
	GetContracts(ctx context.Context, filter types.ContractFilter, limit types.Limit) ([]DBContract, uint, error)
	GetContract(ctx context.Context, contractID uint32) (DBContract, error)
	GetContractBills(ctx context.Context, contractID uint32, limit types.Limit) ([]ContractBilling, uint, error)
	UpsertNodesGPU(ctx context.Context, nodesGPU []types.NodeGPU) error
	GetLastNodeTwinID(ctx context.Context) (int64, error)
	GetNodeTwinIDsAfter(ctx context.Context, twinID int64) ([]int64, error)
	GetConnectionString() string
}

Database interface for storing and fetching grid info

func NewPostgresDatabase

func NewPostgresDatabase(host string, port int, user, password, dbname string, maxConns int) (Database, error)

NewPostgresDatabase returns a new postgres db client

type Farm

type Farm struct {
	Name            string
	FarmID          int
	TwinID          int
	PricingPolicyID int
	Certification   string
	StellarAddress  string
	Dedicated       bool
	PublicIps       string
}

Farm data about a farm which is calculated from the chain

type Node

type Node struct {
	ID              string
	NodeID          int64
	FarmID          int64
	TwinID          int64
	Country         string
	GridVersion     int64
	City            string
	Uptime          int64
	Created         int64
	FarmingPolicyID int64
	UpdatedAt       int64
	TotalCru        int64
	TotalMru        int64
	TotalSru        int64
	TotalHru        int64
	UsedCru         int64
	UsedMru         int64
	UsedSru         int64
	UsedHru         int64
	Domain          string
	Gw4             string
	Gw6             string
	Ipv4            string
	Ipv6            string
	Certification   string
	FarmDedicated   bool `gorm:"farm_dedicated"`
	RentContractID  int64
	RentedByTwinID  int64
	SerialNumber    string
	Longitude       *float64
	Latitude        *float64
	Power           NodePower `gorm:"type:jsonb"`
	NumGPU          int       `gorm:"num_gpu"`
	ExtraFee        uint64
	HasNodeContract bool `gorm:"has_node_contract"`
}

Node data about a node which is calculated from the chain

type NodeGPU

type NodeGPU struct {
	NodeTwinID int    `gorm:"primaryKey;autoIncrement:false"`
	ID         string `gorm:"primaryKey"`
	Vendor     string
	Device     string
	Contract   int
}

func (NodeGPU) TableName

func (NodeGPU) TableName() string

type NodePower

type NodePower struct {
	State  string `json:"state"`
	Target string `json:"target"`
}

NodePower struct is the farmerbot report for node status

func (*NodePower) Scan

func (np *NodePower) Scan(value interface{}) error

Scan is a custom decoder for jsonb filed. executed while scanning the node.

type NodesDistribution

type NodesDistribution struct {
	Country string `json:"country"`
	Nodes   int64  `json:"nodes"`
}

NodesDistribution is the number of nodes per each country

type PostgresDatabase

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

PostgresDatabase postgres db client

func (*PostgresDatabase) Close

func (d *PostgresDatabase) Close() error

Close the db connection

func (*PostgresDatabase) GetConnectionString added in v0.11.3

func (d *PostgresDatabase) GetConnectionString() string

func (*PostgresDatabase) GetContract added in v0.11.3

func (d *PostgresDatabase) GetContract(ctx context.Context, contractID uint32) (DBContract, error)

GetContract return a single contract info

func (*PostgresDatabase) GetContractBills added in v0.11.3

func (d *PostgresDatabase) GetContractBills(ctx context.Context, contractID uint32, limit types.Limit) ([]ContractBilling, uint, error)

GetContract return a single contract info

func (*PostgresDatabase) GetContracts

func (d *PostgresDatabase) GetContracts(ctx context.Context, filter types.ContractFilter, limit types.Limit) ([]DBContract, uint, error)

GetContracts returns contracts filtered and paginated

func (*PostgresDatabase) GetFarm

func (d *PostgresDatabase) GetFarm(ctx context.Context, farmID uint32) (Farm, error)

GetFarm return farm info

func (*PostgresDatabase) GetFarms

func (d *PostgresDatabase) GetFarms(ctx context.Context, filter types.FarmFilter, limit types.Limit) ([]Farm, uint, error)

GetFarms return farms filtered and paginated

func (*PostgresDatabase) GetLastNodeTwinID added in v0.11.8

func (p *PostgresDatabase) GetLastNodeTwinID(ctx context.Context) (int64, error)

func (*PostgresDatabase) GetNode

func (d *PostgresDatabase) GetNode(ctx context.Context, nodeID uint32) (Node, error)

GetNode returns node info

func (*PostgresDatabase) GetNodeTwinIDsAfter added in v0.11.8

func (p *PostgresDatabase) GetNodeTwinIDsAfter(ctx context.Context, twinID int64) ([]int64, error)

func (*PostgresDatabase) GetNodes

func (d *PostgresDatabase) GetNodes(ctx context.Context, filter types.NodeFilter, limit types.Limit) ([]Node, uint, error)

GetNodes returns nodes filtered and paginated

func (*PostgresDatabase) GetStats added in v0.11.5

func (d *PostgresDatabase) GetStats(ctx context.Context, filter types.StatsFilter) (types.Stats, error)

GetStats returns aggregate info about the grid

func (*PostgresDatabase) GetTwins

func (d *PostgresDatabase) GetTwins(ctx context.Context, filter types.TwinFilter, limit types.Limit) ([]types.Twin, uint, error)

GetTwins returns twins filtered and paginated

func (*PostgresDatabase) UpsertNodesGPU

func (p *PostgresDatabase) UpsertNodesGPU(ctx context.Context, nodesGPU []types.NodeGPU) error

Jump to

Keyboard shortcuts

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