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
- type ComAddresses
- type ComBlock
- type ComCheckBlock
- type ComGetBlock
- type ComGetBlocks
- type ComGetConsensusData
- type ComGetData
- type ComGetFirstBlocksData
- type ComGetHistoryTransactions
- type ComGetNodeState
- type ComGetTransaction
- type ComGetUnspentTransactions
- type ComGetUpdates
- type ComGetWalletBalance
- type ComHistoryTransaction
- type ComInv
- type ComManageNode
- type ComNewTransaction
- type ComNewTransactionData
- type ComRequestSQLTransaction
- type ComRequestTransaction
- type ComRequestTransactionData
- type ComTx
- type ComUnspentTransaction
- type ComUnspentTransactions
- type ComVersion
- type ComWalletBalance
- type NodeClient
- func (c *NodeClient) BuildCommandData(command string, data interface{}) ([]byte, error)
- func (c *NodeClient) BuildCommandDataWithAuth(command string, data interface{}) ([]byte, error)
- func (c *NodeClient) CheckNodeAddress(address netlib.NodeAddr) error
- func (c *NodeClient) SendAddNode(node netlib.NodeAddr) error
- func (c *NodeClient) SendAddrList(address netlib.NodeAddr, addresses []netlib.NodeAddr) error
- func (c *NodeClient) SendBlock(addr netlib.NodeAddr, BlockSerialised []byte) error
- func (c *NodeClient) SendCheckBlock(addr netlib.NodeAddr, hash []byte) (*ResponseCheckBlock, error)
- func (c *NodeClient) SendData(addr netlib.NodeAddr, data []byte) error
- func (c *NodeClient) SendDataWaitResponse(addr netlib.NodeAddr, data []byte, datapayload interface{}) error
- func (c *NodeClient) SendGetBalance(addr netlib.NodeAddr, address string) (ComWalletBalance, error)
- func (c *NodeClient) SendGetBlock(addr netlib.NodeAddr, blockHash []byte) (*ResponseGetBlock, error)
- func (c *NodeClient) SendGetBlocks(address netlib.NodeAddr, startfrom []byte) error
- func (c *NodeClient) SendGetBlocksUpper(address netlib.NodeAddr, startfrom []byte) error
- func (c *NodeClient) SendGetConsensusData(address netlib.NodeAddr) (*ComGetConsensusData, error)
- func (c *NodeClient) SendGetData(address netlib.NodeAddr, kind string, id []byte) error
- func (c *NodeClient) SendGetFirstBlocks(address netlib.NodeAddr) (*ComGetFirstBlocksData, error)
- func (c *NodeClient) SendGetHistory(addr netlib.NodeAddr, address string) ([]ComHistoryTransaction, error)
- func (c *NodeClient) SendGetNodes() ([]netlib.NodeAddr, error)
- func (c *NodeClient) SendGetState() (ComGetNodeState, error)
- func (c *NodeClient) SendGetTransaction(addr netlib.NodeAddr, txID []byte) (*ResponseGetTransaction, error)
- func (c *NodeClient) SendGetUnspent(addr netlib.NodeAddr, address string, chaintip []byte) (ComUnspentTransactions, error)
- func (c *NodeClient) SendGetUpdates(addr netlib.NodeAddr, lastCheckTime int64, blockHeight int, topBlocks [][]byte) (*ResponseGetUpdates, error)
- func (c *NodeClient) SendInv(address netlib.NodeAddr, kind string, items [][]byte) error
- func (c *NodeClient) SendNewTransactionData(addr netlib.NodeAddr, from string, txBytes []byte, signature []byte) ([]byte, error)
- func (c *NodeClient) SendRemoveNode(node netlib.NodeAddr) error
- func (c *NodeClient) SendRequestNewCurrencyTransaction(addr netlib.NodeAddr, PubKey []byte, to string, amount float64) ([]byte, []byte, error)
- func (c *NodeClient) SendRequestNewSQLTransaction(addr netlib.NodeAddr, PubKey []byte, sqlcommand string) (bool, []byte, []byte, error)
- func (c *NodeClient) SendTx(addr netlib.NodeAddr, tnxserialised []byte) error
- func (c *NodeClient) SendVersion(addr netlib.NodeAddr, bestHeight int) error
- func (c *NodeClient) SendVoid(address netlib.NodeAddr) error
- func (c *NodeClient) SetAuthStr(auth string)
- func (c *NodeClient) SetNodeAddress(address netlib.NodeAddr)
- type ResponseCheckBlock
- type ResponseGetBlock
- type ResponseGetTransaction
- type ResponseGetUpdates
Constants ¶
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 ¶
Command to send list of known addresses to other node
type ComCheckBlock ¶
Request to check if block exists. Executed before to send new block to node
type ComGetBlock ¶
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 ¶
Response of GetConsensusData request
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 ¶
To get transaction from other node
type ComGetUnspentTransactions ¶
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 ComManageNode ¶
To send nodes manage command.
type ComNewTransaction ¶
New Transaction command. Is used by lite wallets
type ComNewTransactionData ¶
New Transaction Data command. It includes prepared TX and signatures for imputs
type ComRequestSQLTransaction ¶
To Request new SQL transaction by wallet. Wallet sends SQL command and own pubkey. Server returns transaction but wihout signatures
type ComRequestTransaction ¶
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 ¶
Response on prepare transaction request. Returns transaction without signs and data to sign
type ComUnspentTransaction ¶
Unspent Transaction record
type ComUnspentTransactions ¶
type ComUnspentTransactions struct { Transactions []ComUnspentTransaction LastBlock []byte }
Lit of unspent transactions returned on request
type ComVersion ¶
Version mesage to other nodes
type ComWalletBalance ¶
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 ¶
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 ¶
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) 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