nodeclient

package
v0.0.0-...-acf744c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

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

View Source
const (
	CommandAddresses        = "addr"
	CommandGetConsensusData = "getcnsdata"
	CommandGetFirstBlocks   = "getfblocks"
	CommandGetBalance       = "getbalance"
	CommandGetState         = "getstate"
	CommandGetUpdates       = "getupdates"
	CommandGetTransaction   = "gettransact"
	CommandCheckBlock       = "checkblock"
	CommandGetBlock         = "getblock" // requests a block by hash
	CommandBlock            = "block"    // send block body

)

Variables

This section is empty.

Functions

This section is empty.

Types

type ComAddresses

type ComAddresses struct {
	AddrFrom  netlib.NodeAddr
	Addresses []netlib.NodeAddr
}

Command to send list of known addresses to other node

type ComBlock

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

type ComCheckBlock

type ComCheckBlock struct {
	BlockHash []byte
	AddrFrom  netlib.NodeAddr
}

Request to check if block exists. Executed before to send new block to node

type ComGetBlock

type ComGetBlock struct {
	BlockHash []byte
	AddrFrom  netlib.NodeAddr
}

To get transaction from other node

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 ComGetConsensusData

type ComGetConsensusData struct {
	ConfigFile []byte
	Module     []byte // this can be long string
}

Response of GetConsensusData request

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 ComGetTransaction

type ComGetTransaction struct {
	TransactionID []byte
	AddrFrom      netlib.NodeAddr
}

To get transaction from other node

type ComGetUnspentTransactions

type ComGetUnspentTransactions struct {
	Address   string
	LastBlock []byte
}

For request to get list of unspent transactions by wallet

type ComGetUpdates

type ComGetUpdates struct {
	LastCheckTime      int64
	CurrentBlockHeight int
	TopBlocks          [][]byte
	AddrFrom           netlib.NodeAddr
}

To get node last updates

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
	Signature []byte
}

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

type ComRequestSQLTransaction

type ComRequestSQLTransaction struct {
	PubKey []byte
	SQL    string
}

To Request new SQL transaction by wallet. Wallet sends SQL command and own pubkey. Server returns transaction but wihout signatures

type ComRequestTransaction

type ComRequestTransaction struct {
	PubKey []byte
	To     string
	Amount float64
}

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 {
	Finished   bool
	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) SendCheckBlock

func (c *NodeClient) SendCheckBlock(addr netlib.NodeAddr, hash []byte) (*ResponseCheckBlock, error)

Check if tranaction exists on other node. To know if to send TX to a node in sync mode

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) SendGetBlock

func (c *NodeClient) SendGetBlock(addr netlib.NodeAddr, blockHash []byte) (*ResponseGetBlock, error)

Request for a block full info form other node

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) SendGetConsensusData

func (c *NodeClient) SendGetConsensusData(address netlib.NodeAddr) (*ComGetConsensusData, error)

Request for consensus information from a node

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)

Get node blockchain height

func (*NodeClient) SendGetTransaction

func (c *NodeClient) SendGetTransaction(addr netlib.NodeAddr, txID []byte) (*ResponseGetTransaction, error)

Get tranaction with sycn request. Wait response

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) SendGetUpdates

func (c *NodeClient) SendGetUpdates(addr netlib.NodeAddr, lastCheckTime int64, blockHeight int, topBlocks [][]byte) (*ResponseGetUpdates, error)

Get last updates

func (*NodeClient) SendInv

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

Send inventory. Blocks hashes or transactions IDs

func (*NodeClient) SendNewTransactionData

func (c *NodeClient) SendNewTransactionData(addr netlib.NodeAddr, from string, txBytes []byte, signature []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) SendRequestNewCurrencyTransaction

func (c *NodeClient) SendRequestNewCurrencyTransaction(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) SendRequestNewSQLTransaction

func (c *NodeClient) SendRequestNewSQLTransaction(addr netlib.NodeAddr,
	PubKey []byte, sqlcommand string) (bool, []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

type ResponseCheckBlock

type ResponseCheckBlock struct {
	Exists bool // True if a node doesn't want to get a body of this TX
}

Response for check block request

type ResponseGetBlock

type ResponseGetBlock struct {
	Block []byte // Transaction serialised
}

Response for transaction request

type ResponseGetTransaction

type ResponseGetTransaction struct {
	Transaction []byte // Transaction serialised
}

Response for transaction request

type ResponseGetUpdates

type ResponseGetUpdates struct {
	CurrentBlockHeight      int
	CountTransactionsInPool int
	Blocks                  [][]byte
	TransactionsInPool      [][]byte
	Nodes                   []netlib.NodeAddrShort
}

Response with updates on a node

Jump to

Keyboard shortcuts

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