node

package
v0.0.0-...-7ccffc4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultIP        = "127.0.0.1"
	BootstrapPort    = 3000
	BootstrapAccount = "0xe153037747eadbDAA34a3D8c07dBd1F86dc7a17C"
)
View Source
const (
	DefaultMiningDifficulty = 3
)

Variables

This section is empty.

Functions

func Mine

func Mine(ctx context.Context, pb PendingBlock, miningDifficulty uint) (database.Block, error)

Types

type AddPeerResponse

type AddPeerResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

type AddTxRequest

type AddTxRequest struct {
	From    string `json:"from"`
	FromPwd string `json:"from_pwd"`
	To      string `json:"to"`
	Value   uint   `json:"value"`
	Data    string `json:"data"`
}

type AddTxResponse

type AddTxResponse struct {
	Success bool `json:"success"`
}

type AddWalletRequest

type AddWalletRequest struct {
	Password string `json:"password"`
}

type AddWalletResponse

type AddWalletResponse struct {
	Account string `json:"account"`
}

type BalancesResponse

type BalancesResponse struct {
	Hash     database.Hash           `json:"block_hash"`
	Balances map[common.Address]uint `json:"balances"`
}

type CreateWalletRequest

type CreateWalletRequest struct {
	Password string `json:"password"`
}

type CreateWalletResponse

type CreateWalletResponse struct {
	Address string `json:"address"`
}

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type Node

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

func New

func New(dataDir string, ip string, port uint64, acc common.Address, bootstrap PeerNode, miningDifficulty uint) *Node

func (*Node) AddPeer

func (n *Node) AddPeer(peer PeerNode)

func (*Node) AddPendingTX

func (n *Node) AddPendingTX(tx database.SignedTx, fromPeer PeerNode) error

func (*Node) ChangeMiningDifficulty

func (n *Node) ChangeMiningDifficulty(newDifficulty uint)

func (*Node) IsKnownPeer

func (n *Node) IsKnownPeer(peer PeerNode) bool

func (*Node) KnownPeers

func (n *Node) KnownPeers() []PeerNode

Get known peers as an array

func (*Node) LatestBlockHash

func (n *Node) LatestBlockHash() database.Hash

func (*Node) RemovePeer

func (n *Node) RemovePeer(peer PeerNode)

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

type NodeInfo

type NodeInfo struct {
	Nodes        []PeerNode          `json:"nodes"`
	Blocks       []database.Block    `json:"blocks"`
	PendingTXs   []database.SignedTx `json:"pending_txs"`
	PendingBlock PendingBlock        `json:"pending_block"`
}

type PeerNode

type PeerNode struct {
	IP          string         `json:"ip"`
	Port        uint64         `json:"port"`
	IsBootstrap bool           `json:"is_bootstrap"`
	Account     common.Address `json:"account"`
	// contains filtered or unexported fields
}

func NewPeerNode

func NewPeerNode(ip string, port uint64, isBootstrap bool, acc common.Address, connected bool) PeerNode

func (PeerNode) ApiProtocol

func (pn PeerNode) ApiProtocol() string

func (PeerNode) TcpAddress

func (pn PeerNode) TcpAddress() string

type PendingBlock

type PendingBlock struct {
	Parent database.Hash       `json:"parent"`
	Number uint64              `json:"number"`
	Time   uint64              `json:"time"`
	Miner  common.Address      `json:"miner"`
	TXs    []database.SignedTx `json:"txs"`
}

func NewPendingBlock

func NewPendingBlock(parent database.Hash, number uint64, miner common.Address, txs []database.SignedTx) PendingBlock

type StatusResponse

type StatusResponse struct {
	Hash       database.Hash       `json:"block_hash"`
	Number     uint64              `json:"block_number"`
	KnownPeers map[string]PeerNode `json:"peers_known"`
	PendingTXs []database.SignedTx `json:"pending_txs"`
	Account    common.Address      `json:"account"`
}

type SyncResponse

type SyncResponse struct {
	Blocks []database.Block `json:"blocks"`
}

Jump to

Keyboard shortcuts

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