ports

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ports provides an adapter management center and enables plug-ins for adapter modules to enhance extendibility and maintainability.

This development has only three small goals:
1. Micro code refactoring - change the original code as little as possible;
2. Determine the interface - provides an adapter interface (AdapterController)
	to enable plug-ins for adapter modules;
3. Centralized adapter management - provides a pool interface (Ports)
	to enhance extendibility and maintainability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Consensus2of3

func Consensus2of3(value int) int

Consensus2of3 Calculate number of consensus

func GetAdapterKey

func GetAdapterKey(a Adapter) string

GetAdapterKey Gen an adapter key

func GetAdapterKeyByConfig

func GetAdapterKeyByConfig(c *AdapterConfig) string

GetAdapterKeyByConfig Gen an adapter key from adapter config

func GetAdapters

func GetAdapters(chainName string) (map[string]Adapter, error)

GetAdapters Get all Adapters for the specified chain

func GetNodeAddress

func GetNodeAddress(a Adapter) string

GetNodeAddress Gen a node address

func ParseNodeAddress

func ParseNodeAddress(nodeAddr string) (string, int, error)

ParseNodeAddress parse node address to get ip and port

func RegisterAdapter

func RegisterAdapter(config *AdapterConfig) error

RegisterAdapter Check, create and register an Adapter

Types

type Adapter

type Adapter interface {
	SubmitTx(chainID string, tx *txs.TxQcp) error
	ObtainTx(chainID string, sequence int64) (*txs.TxQcp, error)
	QuerySequence(chainID string, inout string) (int64, error)
	GetSequence() int64
	// Count Calculate the total and consensus number for chain
	Count() (totalNumber int, consensusNumber int)
	GetChainName() string
	GetIP() string
	GetPort() int
}

Adapter Chain adapter interface for consensus engine ( consensus.ConsEngine ) and ferry ( consensus.Ferry )

type AdapterConfig

type AdapterConfig struct {
	ChainName string
	ChainType string
	IP        string
	Port      int
	Query     string
	Listener  EventsListener
}

AdapterConfig is parameters for build an AdapterService

type AdapterController

type AdapterController interface {
	Start() error
	Sync() error
	Stop() error
	Subscribe(listener EventsListener)
}

AdapterController Chain adapter controller interface for adapter pool manager ( adapter.Ports )

type AdapterService

type AdapterService interface {
	AdapterController
	Adapter
}

AdapterService Inner cache type ( AdapterController and Adapter )

Suitable for a variety of different block chain

type Builder

type Builder func(config AdapterConfig) (AdapterService, error)

Builder Create an AdapterService for the specified chain

type EventsListener

type EventsListener func(event *types.Event, adapter Adapter)

EventsListener Listen Tx events from target chain

type Ports

type Ports interface {
	Init()
	RegisterBuilder(chain string, builder Builder) error
	Register(config *AdapterConfig) error
	Count(chainName string) int
	Get(chainName string) (map[string]Adapter, error)
}

Ports Chain adapter pool interface

func GetPortsIncetance

func GetPortsIncetance() Ports

GetPortsIncetance Get Ports singlton instance

type QosAdapter

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

QosAdapter provides adapter for qos chain

func (*QosAdapter) Count

func (a *QosAdapter) Count() (totalNumber int, consensusNumber int)

Count return total number and consensus number of adapters for qos chain

func (*QosAdapter) GetChainName

func (a *QosAdapter) GetChainName() string

GetChainName returns chain's name

func (*QosAdapter) GetIP

func (a *QosAdapter) GetIP() string

GetIP returns chain node's ip

func (*QosAdapter) GetPort

func (a *QosAdapter) GetPort() int

GetPort returns chain node's port

func (*QosAdapter) GetSequence

func (a *QosAdapter) GetSequence() int64

GetSequence returns sequence stored in QosAdapter

func (*QosAdapter) ObtainTx

func (a *QosAdapter) ObtainTx(chain string, sequence int64) (qcp *txs.TxQcp, err error)

ObtainTx search Tx from qos chain

func (*QosAdapter) QuerySequence

func (a *QosAdapter) QuerySequence(chainName string, inout string) (int64, error)

QuerySequence query sequence for the specified chainName and inout ("in" or "out")

func (*QosAdapter) Start

func (a *QosAdapter) Start() error

Start qos adapter service

func (*QosAdapter) Stop

func (a *QosAdapter) Stop() error

Stop qos adapter service

func (*QosAdapter) SubmitTx

func (a *QosAdapter) SubmitTx(chain string, tx *txs.TxQcp) error

SubmitTx submit Tx to qos chain

func (*QosAdapter) Subscribe

func (a *QosAdapter) Subscribe(listener EventsListener)

Subscribe events from qos chain

func (*QosAdapter) Sync

func (a *QosAdapter) Sync() error

Sync status for qos adapter service

Directories

Path Synopsis
sdk
sdk

Jump to

Keyboard shortcuts

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