nodeclient

package
v0.0.0-...-f7c9202 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: MIT Imports: 11 Imported by: 4

Documentation

Overview

This is the network client for communication with nodes It is used by nodes to communicate with other nodes and by lite wallets to communicate with nodes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComBlock

type ComBlock struct {
	AddrFrom netlib.NodeAddr
	Block    []byte
}

type ComGetBlocks

type ComGetBlocks struct {
	AddrFrom  netlib.NodeAddr
	StartFrom []byte // has of block from which to start and go down or go up in case of Up command
}

this struct can be used for 2 commands. to get blocks starting from some block to down or to up

type ComGetData

type ComGetData struct {
	AddrFrom netlib.NodeAddr
	Type     string
	ID       []byte
}

type ComGetFirstBlocksData

type ComGetFirstBlocksData struct {
	Blocks [][]byte // lowest block first
	// it is serialised BlockShort structure
	Height int
}

Response of GetBlock request

type ComGetHistoryTransactions

type ComGetHistoryTransactions struct {
	Address string
}

Request for history of transactions

type ComGetNodeState

type ComGetNodeState struct {
	Host                  string
	BlocksNumber          int
	ExpectingBlocksHeight int
	TransactionsCached    int
	UnspentOutputs        int
}

To get node state

type ComGetUnspentTransactions

type ComGetUnspentTransactions struct {
	Address   string
	LastBlock []byte
}

For request to get list of unspent transactions by wallet

type ComGetWalletBalance

type ComGetWalletBalance struct {
	Address string
}

Request for a wallet balance

type ComHistoryTransaction

type ComHistoryTransaction struct {
	IOType bool // In (false) or Out (true)
	TXID   []byte
	Amount float64
	From   string
	To     string
}

Record of transaction in list of history transactions

type ComInv

type ComInv struct {
	AddrFrom netlib.NodeAddr
	Type     string
	Items    [][]byte
}

Request for inventory. It can be used to get blocks and transactions from other node

type ComManageNode

type ComManageNode struct {
	Node netlib.NodeAddr
}

To send nodes manage command.

type ComNewTransaction

type ComNewTransaction struct {
	Address string
	TX      []byte
}

New Transaction command. Is used by lite wallets

type ComNewTransactionData

type ComNewTransactionData struct {
	Address    string
	TX         []byte
	Signatures [][]byte
}

New Transaction Data command. It includes prepared TX and signatures for imputs

type ComRequestTransaction

type ComRequestTransaction struct {
	PubKey    []byte
	To        string
	Amount    float64
	Signature []byte // to confirm request is from owner of PubKey (TODO)
}

To Request new transaction by wallet. Wallet sends address where to send and amount to send and own pubkey. Server returns transaction but wihout signatures

type ComRequestTransactionData

type ComRequestTransactionData struct {
	TX         []byte
	DataToSign [][]byte
}

Response on prepare transaction request. Returns transaction without signs and data to sign

type ComTx

type ComTx struct {
	AddFrom     netlib.NodeAddr
	Transaction []byte // Transaction serialised
}

Transaction to send to other node

type ComUnspentTransaction

type ComUnspentTransaction struct {
	TXID   []byte
	Vout   int
	Amount float64
	IsBase bool
	From   string
}

Unspent Transaction record

type ComUnspentTransactions

type ComUnspentTransactions struct {
	Transactions []ComUnspentTransaction
	LastBlock    []byte
}

Lit of unspent transactions returned on request

type ComVersion

type ComVersion struct {
	Version    int
	BestHeight int
	AddrFrom   netlib.NodeAddr
}

Version mesage to other nodes

type ComWalletBalance

type ComWalletBalance struct {
	Total    float64
	Approved float64
	Pending  float64
}

Wallet Balance response

type NodeClient

type NodeClient struct {
	DataDir     string
	NodeAddress netlib.NodeAddr
	Address     string // wallet address
	Logger      *utils.LoggerMan
	NodeNet     *netlib.NodeNetwork
	NodeAuthStr string
}

func (*NodeClient) BuildCommandData

func (c *NodeClient) BuildCommandData(command string, data interface{}) ([]byte, error)

Builds a command data. It prepares a slice of bytes from given data

func (*NodeClient) BuildCommandDataWithAuth

func (c *NodeClient) BuildCommandDataWithAuth(command string, data interface{}) ([]byte, error)

Builds a command data. It prepares a slice of bytes from given data

func (*NodeClient) CheckNodeAddress

func (c *NodeClient) CheckNodeAddress(address netlib.NodeAddr) error

Check if node address looks fine

func (*NodeClient) SendAddNode

func (c *NodeClient) SendAddNode(node netlib.NodeAddr) error

Request to add new node to contacts

func (*NodeClient) SendAddrList

func (c *NodeClient) SendAddrList(address netlib.NodeAddr, addresses []netlib.NodeAddr) error

Send list of nodes addresses to other node

func (*NodeClient) SendBlock

func (c *NodeClient) SendBlock(addr netlib.NodeAddr, BlockSerialised []byte) error

Send block to other node

func (*NodeClient) SendData

func (c *NodeClient) SendData(addr netlib.NodeAddr, data []byte) error

Sends prepared command to a node. This doesn't wait any response

func (*NodeClient) SendDataWaitResponse

func (c *NodeClient) SendDataWaitResponse(addr netlib.NodeAddr, data []byte, datapayload interface{}) error

Send data to a node and wait for response

func (*NodeClient) SendGetBalance

func (c *NodeClient) SendGetBalance(addr netlib.NodeAddr, address string) (ComWalletBalance, error)

Request for list of unspent transactions outputs It can be used by wallet to see a state of balance

func (*NodeClient) SendGetBlocks

func (c *NodeClient) SendGetBlocks(address netlib.NodeAddr, startfrom []byte) error

Sedn request to get list of blocks on other node.

func (*NodeClient) SendGetBlocksUpper

func (c *NodeClient) SendGetBlocksUpper(address netlib.NodeAddr, startfrom []byte) error

Request for blocks but result must be upper from some starting block

func (*NodeClient) SendGetData

func (c *NodeClient) SendGetData(address netlib.NodeAddr, kind string, id []byte) error

Request for a transaction or a block to get full info by ID or Hash

func (*NodeClient) SendGetFirstBlocks

func (c *NodeClient) SendGetFirstBlocks(address netlib.NodeAddr) (*ComGetFirstBlocksData, error)

Request for list of first blocks in blockchain. This is used by new nodes TODO we can use SendGetBlocksUpper and empty hash. This will e same

func (*NodeClient) SendGetHistory

func (c *NodeClient) SendGetHistory(addr netlib.NodeAddr, address string) ([]ComHistoryTransaction, error)

Request for history of transaction from a wallet

func (*NodeClient) SendGetNodes

func (c *NodeClient) SendGetNodes() ([]netlib.NodeAddr, error)

Request for list of nodes in contacts

func (*NodeClient) SendGetState

func (c *NodeClient) SendGetState() (ComGetNodeState, error)

Request to remove a node from contacts

func (*NodeClient) SendGetUnspent

func (c *NodeClient) SendGetUnspent(addr netlib.NodeAddr, address string, chaintip []byte) (ComUnspentTransactions, error)

Request for list of unspent transactions outputs It can be used by wallet to see a state of balance

func (*NodeClient) SendInv

func (c *NodeClient) SendInv(address netlib.NodeAddr, kind string, items [][]byte) error

Send inventory. Blocks hashes or transactions IDs

func (*NodeClient) SendNewTransaction

func (c *NodeClient) SendNewTransaction(addr netlib.NodeAddr, from string, tx []byte) ([]byte, error)

Send new transaction from a wallet to a node

func (*NodeClient) SendNewTransactionData

func (c *NodeClient) SendNewTransactionData(addr netlib.NodeAddr, from string, txBytes []byte, signatures [][]byte) ([]byte, error)

Send new transaction from a wallet to a node

func (*NodeClient) SendRemoveNode

func (c *NodeClient) SendRemoveNode(node netlib.NodeAddr) error

Request to remove a node from contacts

func (*NodeClient) SendRequestNewTransaction

func (c *NodeClient) SendRequestNewTransaction(addr netlib.NodeAddr,
	PubKey []byte, to string, amount float64) ([]byte, [][]byte, error)

Request to prepare new transaction by wallet. It returns a transaction without signature. Wallet has to sign it and then use SendNewTransaction to send completed transaction

func (*NodeClient) SendTx

func (c *NodeClient) SendTx(addr netlib.NodeAddr, tnxserialised []byte) error

Send Transaction to other node

func (*NodeClient) SendVersion

func (c *NodeClient) SendVersion(addr netlib.NodeAddr, bestHeight int) error

Send own version and blockchain state to other node

func (*NodeClient) SendVoid

func (c *NodeClient) SendVoid(address netlib.NodeAddr) error

Send void commant to other node It is used by a node to send to itself only when we want to stop a node And unblock port listetining

func (*NodeClient) SetAuthStr

func (c *NodeClient) SetAuthStr(auth string)

Check if node address looks fine

func (*NodeClient) SetNodeAddress

func (c *NodeClient) SetNodeAddress(address netlib.NodeAddr)

Set currrent node address , to include itin requests to other nodes

Jump to

Keyboard shortcuts

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