network

package
v0.0.0-...-bc7c564 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateConnection = errors.New("Duplicate connection")
	ErrLoopbackConnection  = errors.New("Loopback connection")
)

Functions

func WithNode

func WithNode(config Config, peers *PeersList, peerUpdates <-chan PeerInfo, onNewConnection func(context.Context, *Connection) error, fn func(node Node) error) error

func WithRpcServer

func WithRpcServer(hostPort string, handlers map[string]interface{}, callback func() error) error

Types

type API

type API interface {
	GetBlockCount(ctx context.Context) (int, error)
	GetBlock(ctx context.Context, params *struct{ Block uint32 }) (*Block, error)
	GetAccount(ctx context.Context, params *struct{ Account uint32 }) (*Account, error)
	GetPending(ctx context.Context) ([]Operation, error)
	ExecuteOperations(ctx context.Context, params *struct{ RawOperations string }) (bool, error)
	FindOperation(ctx context.Context, params *struct{ Ophash string }) (*Operation, error)
	GetAccountOperations(ctx context.Context, params *struct{ Account uint32 }) ([]Operation, error)
	GetBlockOperations(ctx context.Context, params *struct{ Block uint32 }) ([]Operation, error)
	GetBlockTemplate(_ context.Context, params *struct {
		Reserve_size   uint64
		Wallet_address string
	}) (*BlockTemplate, error)
	SubmitBlock(_ context.Context, params []string) (*SubmitBlock, error)
}

type Account

type Account struct {
	Account    uint32  `json:"account"`
	Balance    float64 `json:"balance"`
	EncPubkey  string  `json:"enc_pubkey"`
	NOperation uint32  `json:"n_operation"`
	UpdatedB   uint32  `json:"updated_b"`
}

type Block

type Block struct {
	Block       uint32  `json:"block"`
	EncPubkey   string  `json:"enc_pubkey"`
	Fee         float64 `json:"fee"`
	Hashratekhs uint64  `json:"hashratekhs"`
	Maturation  uint32  `json:"maturation"`
	Nonce       uint32  `json:"nonce"`
	Operations  uint64  `json:"operations"`
	Oph         string  `json:"oph"`
	Payload     string  `json:"payload"`
	Pow         string  `json:"pow"`
	Reward      float64 `json:"reward"`
	Sbh         string  `json:"sbh"`
	Target      uint32  `json:"target"`
	Timestamp   uint32  `json:"timestamp"`
	Ver         uint16  `json:"ver"`
	VerA        uint16  `json:"ver_a"`
}

type BlockTemplate

type BlockTemplate struct {
	Difficulty         uint64 `json:"difficulty"`
	Height             uint64 `json:"height"`
	Reserved_offset    uint64 `json:"reserved_offset"`
	Expected_reward    uint64 `json:"expected_reward"`
	Prev_hash          string `json:"prev_hash"`
	Blocktemplate_blob string `json:"blocktemplate_blob"`
	Blockhashing_blob  string `json:"blockhashing_blob"`
	Status             string `json:"status"`
}

type Config

type Config struct {
	ListenAddr     string
	MaxIncoming    uint32
	MaxOutgoing    uint32
	TimeoutConnect time.Duration
}

type Connection

type Connection struct {
	Address        string
	Outgoing       bool
	Transport      io.ReadWriteCloser
	OnStateUpdated func()
}

type Node

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

func (*Node) AddPeer

func (node *Node) AddPeer(address string) error

func (*Node) AddPeerSerialized

func (node *Node) AddPeerSerialized(serialized []byte) error

func (*Node) GetPeersByNetwork

func (node *Node) GetPeersByNetwork(network string) map[string]Peer

type Operation

type Operation struct {
	Account        uint32  `json:"account"`
	Amount         float64 `json:"amount"`
	Block          uint32  `json:"block"`
	Dest_account   uint32  `json:"dest_account"`
	Fee            float64 `json:"fee"`
	Opblock        uint32  `json:"opblock"`
	Ophash         string  `json:"ophash"`
	Optxt          *string `json:"optxt"`
	Optype         uint8   `json:"optype"`
	Payload        string  `json:"payload"`
	Sender_account uint32  `json:"sender_account"`
	Time           uint32  `json:"time"`
}

type Peer

type Peer struct {
	Address              string
	LastConnectTimestamp uint32
	ReconnectPenalty     uint32
	LastSeen             uint64
}

type PeerInfo

type PeerInfo struct {
	Host        string
	Port        uint16
	LastConnect uint32
}

type PeersList

type PeersList struct {
	Connected map[string]*Peer
	Forbidden map[string]struct{}
	Queued    *ordered_map.OrderedMap
	Lock      sync.RWMutex
}

func NewPeersList

func NewPeersList() *PeersList

func (*PeersList) Add

func (this *PeersList) Add(address string, peer *Peer) bool

func (*PeersList) AddSerialized

func (this *PeersList) AddSerialized(serialized []byte) error

func (*PeersList) Forbid

func (p *PeersList) Forbid(address string)

func (*PeersList) GetAllSeen

func (this *PeersList) GetAllSeen() map[string]Peer

func (*PeersList) ScheduleReconnect

func (this *PeersList) ScheduleReconnect(maxActive int) []*Peer

func (*PeersList) SetDisconnected

func (this *PeersList) SetDisconnected(peer *Peer)

type SubmitBlock

type SubmitBlock struct {
	Status string `json:"status"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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