network

package
v0.0.0-...-ed99955 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const ChannelBufSize = 128

Variables

View Source
var (
	GeneralChannel   = "general-channel"
	MiningChannel    = "contract-channel"
	FullNodesChannel = "fullnodes-channel"
)

Functions

func BytesToCmd

func BytesToCmd(bytes []byte) string

func CmdToBytes

func CmdToBytes(cmd string) []byte

func ExtractCmd

func ExtractCmd(request []byte) []byte

func FilterOracleDataMap

func FilterOracleDataMap(contract_map map[string][]transaction.OracleData) (map[string][]transaction.OracleData, map[string]float64)

func GobEncode

func GobEncode(data interface{}) []byte

func PercentageChange

func PercentageChange(old, new float64) float64

func ProtocolInit

func ProtocolInit(c *config.Config, s *Server)

ProtocolInit = init all of the protocol

func RequestBlocks

func RequestBlocks(net *Network) error

func SetupDiscovery

func SetupDiscovery(ctx context.Context, host host.Host)

func ShortID

func ShortID(p peer.ID) string

ShortID returns the last 8 chars of a base58-encoded peer id.

func StartNode

func StartNode(listenPort string, fullNode bool, callback func(*Network))

Types

type ArrayTX

type ArrayTX struct {
	Txes []transaction.Transaction `json:txes`
}

type Channel

type Channel struct {
	Content chan *ChannelContent
	// contains filtered or unexported fields
}

func JoinChannel

func JoinChannel(ctx context.Context, pub *pubsub.PubSub, selfID peer.ID, channelName string, subscribe bool) (*Channel, error)

func (*Channel) ListPeers

func (ch *Channel) ListPeers() []peer.ID

func (*Channel) Publish

func (channel *Channel) Publish(message string, payload []byte, SendTo string) error

type ChannelContent

type ChannelContent struct {
	Message  string
	SendFrom string
	SendTo   string
	Payload  []byte
}

type GOB_BATCH_TX

type GOB_BATCH_TX struct {
	Batch     [][]byte
	TotalSent int
}

type GOB_ORACLE_DATA

type GOB_ORACLE_DATA struct {
	Oracle_Data transaction.OracleData
}

type GOB_TX

type GOB_TX struct {
	TX []byte
}

type GetData

type GetData struct {
	AddrFrom string
	Type     string
	ID       []byte
}

type GetTxes

type GetTxes struct {
	Top_hash string
	FillData bool

	//contract has keytype and top data hash as value
	Contracts map[string]string
}

type MemPool

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

func NewMemPool

func NewMemPool() *MemPool

func (*MemPool) Count

func (m *MemPool) Count() int

func (*MemPool) InMempool

func (m *MemPool) InMempool(tx_hash string) bool

func (*MemPool) PrintMemPool

func (m *MemPool) PrintMemPool()

func (*MemPool) PruneHeight

func (m *MemPool) PruneHeight(block_height int64)

func (*MemPool) SortOracleDataMap

func (m *MemPool) SortOracleDataMap(block_height int64) map[string][]transaction.OracleData

sorts oracle map

type NeedTX

type NeedTX struct {
	Hash string
}

type Network

type Network struct {
	Host             host.Host
	GeneralChannel   *Channel
	MiningChannel    *Channel
	FullNodesChannel *Channel
	Transactions     chan *transaction.Transaction
	Database         *database.Database
	Mempool          *MemPool
}

func (*Network) BroadCastOracleData

func (net *Network) BroadCastOracleData(oracle_data transaction.OracleData)

BroadCastOracleData : broadcast oracle data

func (*Network) BroadCastTX

func (net *Network) BroadCastTX(tx transaction.Transaction)

BroadCastTX : broadcast tx

func (*Network) CreateContract

func (net *Network) CreateContract()

CreateContract make new contract uploaded fron config.json

func (*Network) CreateTrustedData

func (net *Network) CreateTrustedData(block_height int64)

CreateTrustedData creates trusted data source from all known tx

func (*Network) GetContractMap

func (net *Network) GetContractMap() map[string]string

GetContractMap creates contract map and their last known tx

func (*Network) HandleBatchTx

func (net *Network) HandleBatchTx(content *ChannelContent)

func (*Network) HandleData

func (net *Network) HandleData(content *ChannelContent)

func (*Network) HandleGetTxes

func (net *Network) HandleGetTxes(content *ChannelContent)

This function handles request for transactions. It takes a top consensus tx hash. 100 txes per batch

func (*Network) HandleStream

func (net *Network) HandleStream(content *ChannelContent)

func (*Network) HandleSyncCall

func (net *Network) HandleSyncCall(content *ChannelContent)

func (*Network) HandleTx

func (net *Network) HandleTx(content *ChannelContent)

func (*Network) NewConsensusTXFromCore

func (net *Network) NewConsensusTXFromCore(req transaction.NewBlock)

NewConsensusTXFromCore = create v1 tx

func (*Network) NewDataTxFromCore

func (net *Network) NewDataTxFromCore(request []string, height int64, pubkey string)

NewDataTxFromCore = Go through all contracts and send data out

func (*Network) SendData

func (net *Network) SendData(data []byte)

SendData : sendBytes

func (*Network) SendGetTxes

func (net *Network) SendGetTxes(fill bool, contracts map[string]string)

SendGetTxes : Get tansactions not known

func (*Network) SendVersion

func (net *Network) SendVersion()

SendVersion : Send Sync Call

type Server

type Server struct {
	Nodes []string
	P2p   *Network
	// contains filtered or unexported fields
}

func (*Server) RestAPI

func (s *Server) RestAPI()

restAPI() This is the main API that is activated when isCoord == true

func (*Server) SendTx

func (s *Server) SendTx(p *flatend.Provider, tx transaction.Transaction)

SendTx : Send singular tx

type SyncCall

type SyncCall struct {
	TopHash   string
	Contracts map[string]string
}

Jump to

Keyboard shortcuts

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