nodes

package
v0.0.0-...-9dc0c09 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_NODE_ENDPOINT = "/status"
	BLOCKS_NODE_ENDPOINT = "/blocks"
)
View Source
const NODES_DOMAIN_URL = "/api/nodes"

Variables

This section is empty.

Functions

func NodesRegister

func NodesRegister(router *gin.RouterGroup, env *NodesEnv)

func RunDomain

func RunDomain(
	r *gin.Engine,
	nodeService *NodeService,
	state models.State,
	transactionService services.TransactionService,
	blockService services.BlockService,
	syncNodeRefreshIntervalInSeconds uint32,
	createNewBlockIntervalInSeconds uint32,
	middlewares ...gin.HandlerFunc,
) error

Types

type BlockHeaderResponse

type BlockHeaderResponse struct {
	Parent models.Hash `json:"parent"`
	Height uint64      `json:"height"`
	Nonce  uint32      `json:"nonce"`
	Time   uint64      `json:"time"`
}

type BlockHeight

type BlockHeight uint64

type BlockResponse

type BlockResponse struct {
	Header BlockHeaderResponse   `json:"header"`
	Txs    []TransactionResponse `json:"transactions"`
}

type BlockSerializer

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

blocks

func (*BlockSerializer) Response

func (n *BlockSerializer) Response() BlockResponse

type BlocksResponse

type BlocksResponse struct {
	Blocks []BlockResponse `json:"blocks"`
}

type BlocksSerializer

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

func (*BlocksSerializer) Response

func (n *BlocksSerializer) Response() BlocksResponse

type ListBlocksParam

type ListBlocksParam struct {
	From string `json:"from" binding:"required,hash"`
}

type NetworkNode

type NetworkNode struct {
	Name        string
	IsBootstrap bool
	IsActive    bool
}

type NetworkNodeAddress

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

func NewNetworkNodeAddress

func NewNetworkNodeAddress(ip string, port uint64) NetworkNodeAddress

func (NetworkNodeAddress) Ip

func (n NetworkNodeAddress) Ip() string

func (NetworkNodeAddress) Port

func (n NetworkNodeAddress) Port() uint64

func (NetworkNodeAddress) String

func (n NetworkNodeAddress) String() string

type NetworkNodeFromDB

type NetworkNodeFromDB struct {
	Nodes map[NetworkNodeName]NetworkNodeRecord
}

type NetworkNodeName

type NetworkNodeName string

type NetworkNodeRecord

type NetworkNodeRecord struct {
	Address      string
	Port         uint64
	Is_bootstrap bool
	Is_active    bool
}

type NetworkNodeResponse

type NetworkNodeResponse struct {
	Name        string `json:"name"`
	Ip          string `json:"ip"`
	Port        uint64 `json:"port"`
	IsBootstrap bool   `json:"is_bootstrap"`
	IsActive    bool   `json:"is_active"`
}

type NetworkNodeStatus

type NetworkNodeStatus struct {
	Hash         models.Hash
	Height       uint64
	NetworkNodes map[NetworkNodeAddress]NetworkNode
}

type NetworkNodesResponse

type NetworkNodesResponse struct {
	Hash                models.Hash           `json:"block_hash"`
	Height              uint64                `json:"block_height"`
	NetworkNodeResponse []NetworkNodeResponse `json:"network_nodes"`
}

type NodeGetStatusResponse

type NodeGetStatusResponse struct {
	Status NetworkNodesResponse `json:"status"`
}

type NodeSerializer

type NodeSerializer struct {
	models.State
	// contains filtered or unexported fields
}

nodes

func (*NodeSerializer) Response

func (n *NodeSerializer) Response() NetworkNodesResponse

type NodeService

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

func NewNodeService

func NewNodeService(nodeDatabasePath string) (*NodeService, error)

func (*NodeService) Add

func (u *NodeService) Add(nodes map[NetworkNodeAddress]NetworkNode) error

Add nodes in the database, return error otherwise

func (*NodeService) List

List nodes in the network if found, nil otherwise

type NodeTaskManager

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

func NewNodeTaskManager

func NewNodeTaskManager(
	syncNodeRefreshIntervalInSeconds uint32,
	createNewBlockIntervalInSeconds uint32,
	nodeService *NodeService,
	state models.State,
	transactionService services.TransactionService,
	blockService services.BlockService,
) (*NodeTaskManager, error)

NewNodeTaskManager handles all the background tasks needed for a node to sync its status as well as mining new blocks

func (*NodeTaskManager) RunMine

func (n *NodeTaskManager) RunMine(ctx context.Context)

RunMine starts mining a new block when a new transaction is being submitted

func (*NodeTaskManager) RunSync

func (n *NodeTaskManager) RunSync(ctx context.Context)

RunSync starts the process of syncing the list of nodes within the network as well as this node's database

type NodesEnv

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

func (NodesEnv) NodeListBlocks

func (env NodesEnv) NodeListBlocks(c *gin.Context)

NodeListBlocks Get blocks from a specific hash specified in the payload

func (NodesEnv) NodeStatus

func (env NodesEnv) NodeStatus(c *gin.Context)

type TransactionResponse

type TransactionResponse struct {
	From   models.Account `json:"from"`
	To     models.Account `json:"to"`
	Value  uint           `json:"value"`
	Reason string         `json:"reason"`
	Time   uint64         `json:"time"`
}

Jump to

Keyboard shortcuts

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