common

package
v0.0.0-...-11d313d Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewBlock_A                   = "NewBlock"
	NewChannel_A                 = "NewChannel"
	CloseChannel_A               = "CloseChannel"
	NodeRegMethodsConsolidated_A = "NodeRegMethodsConsolidated"
)
View Source
const (
	Iter int = iota
	Len
)
View Source
const NetworkTimeout = 3 * time.Second

Variables

View Source
var (
	LogDebug   *log.Logger = log.New(os.Stderr, "Debug ", log.LstdFlags)
	LogTrace   *log.Logger = log.New(os.Stderr, "Trace ", log.LstdFlags)
	LogInfo    *log.Logger = log.New(os.Stderr, "Info ", log.LstdFlags)
	LogWarning *log.Logger = log.New(os.Stderr, "Warning ", log.LstdFlags)
	LogError   *log.Logger = log.New(os.Stderr, "Error ", log.LstdFlags)
)
View Source
var (
	MethodSignatures = []string{
		"LogNodeIDRegistered(bytes)",
		"LogNodeIDUnregistered(bytes)",
		"LogNodeIDUpdated(bytes)",
		"LogChannelOpened(bytes32)",
		"LogChannelClosed(bytes32)",
		"LogChannelSlashed(bytes32)",
		"LogParameterTuned()"}
	// methodSignatures
	LogNodeIDRegistered   = MethodSignatures[0]
	LogNodeIDUnregistered = MethodSignatures[1]
	LogNodeIDUpdated      = MethodSignatures[2]
	LogChannelOpened      = MethodSignatures[3]
	LogChannelClosed      = MethodSignatures[4]
	LogChannelSlashed     = MethodSignatures[5]
	LogParameterTuned     = MethodSignatures[6]
	// topics
	LogNodeIDRegisteredTopic   = Topic(LogNodeIDRegistered)
	LogNodeIDUnregisteredTopic = Topic(LogNodeIDUnregistered)
	LogNodeIDUpdatedTopic      = Topic(LogNodeIDUpdated)
	LogChannelOpenedTopic      = Topic(LogChannelOpened)
	LogChannelClosedTopic      = Topic(LogChannelClosed)
	LogChannelSlashedTopic     = Topic(LogChannelSlashed)
	LogParameterTunedTopic     = Topic(LogParameterTuned)
)
View Source
var Filenames = struct {
	sync.RWMutex
	M map[string]*SafeFilename
}{M: make(map[string]*SafeFilename)}
View Source
var NodeRegMethods = []string{"RegisterNodeID(bytes)",
	"UpdateNodeID(bytes)",
	LogNodeIDRegistered,
	LogNodeIDUpdated}
View Source
var NodeUnregMethods = []string{"UnregisterNodeID(bytes)",
	LogNodeIDUnregistered}

Functions

func Abort

func Abort(err error)

Abort does nothing if err is nil, otherwise logs the error and exits

func Append

func Append(list ...interface{}) (b []byte)

func B32ToHex

func B32ToHex(b [32]byte) (h string)

func B32ToString

func B32ToString(b [32]byte) (s string)

func BreakSlice

func BreakSlice(slc interface{}) <-chan interface{}

func CompareHashAsSlice

func CompareHashAsSlice(a, b []byte) (cmp int)

func CompareHex

func CompareHex(aHex, bHex string) (cmp int)

func CreateFile

func CreateFile(fullPath string) (*os.File, error)

func DefaultToExecutable

func DefaultToExecutable(path string) string

Default to executable returns full path. If input path is relative, it will considered relative to the the folder of the executable

func DirExists

func DirExists(path string) (tf bool)

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the size the files in a folder and subfolders in bytes

func FileExists

func FileExists(path string) bool

func FileSize

func FileSize(path string) int64

func FileSizeString

func FileSizeString(fullPath string) string

func Hex2Uint64

func Hex2Uint64(hexString string) (ret uint64)

func HexString2B20

func HexString2B20(hexString string) (ret [20]byte)

func HexString2Slice

func HexString2Slice(hexString string) (ret []byte)

func InitLogging

func InitLogging(filePath string)

InitLogging initializes a rotating logger. This should be done once by the executable filePath is the full path of the log file

func IsFullPath

func IsFullPath(path string) bool

func IsNodeReg

func IsNodeReg(method string) (tf bool)

func IsNodeRegOrUnreg

func IsNodeRegOrUnreg(method string) (tf bool)

func IsNodeUnreg

func IsNodeUnreg(method string) (tf bool)

func IsPendingTx

func IsPendingTx(method string) (tf bool)

func Join

func Join(dir, subpath string) string

func Joins

func Joins(folders ...string) (res string)

func MakeFolders

func MakeFolders(folders []string) (err error)

func NAgo

func NAgo(currentHex string, n uint64) (nAgoHex string, er error)

func NAgoUint64

func NAgoUint64(currentHex string, n uint64) (nAgo uint64, er error)

func NewRandUint32

func NewRandUint32() (r uint32)

func RandomlySortSlice

func RandomlySortSlice(slc interface{}) (r []interface{})

currently supports []peer.ID and []int

func RemoveDir

func RemoveDir(path string) (er error)

func SafeFileDelete

func SafeFileDelete(fullPath string) (er error)

func SafeFileRead

func SafeFileRead(fullPath string) (data []byte, er error)

func SafeFileWrite

func SafeFileWrite(fullPath string, data []byte) (er error)

func SafeReadDir

func SafeReadDir(fullPath string) (ret []os.FileInfo, er error)

func SameECDSAPrivateKey

func SameECDSAPrivateKey(k1, k2 *ecdsa.PrivateKey) (same bool)

func SameEllipticCurve

func SameEllipticCurve(c1, c2 elliptic.Curve) (same bool)

func SameSlice

func SameSlice(s1, s2 []byte) (same bool)

func SetLoggingLevel

func SetLoggingLevel(level LoggingLevel)

func SetLoggingLevelFromName

func SetLoggingLevelFromName(level string)

func Slice2B20

func Slice2B20(slc []byte) (b20 [20]byte)

func Slice2B32

func Slice2B32(slc []byte) (b32 [32]byte)

func Slice2BigInt

func Slice2BigInt(slc []byte) (b *big.Int)

func Slice2Hex

func Slice2Hex(sl []byte) (hex string)

func Slice2Uint32

func Slice2Uint32(b []byte) (r uint32)

func String2B32

func String2B32(str string) (b32 [32]byte)

func Topic

func Topic(methodSignature string) (hex string)

func Uint64ToHex

func Uint64ToHex(u uint64) (ret string)

func Uint64sToHexs

func Uint64sToHexs(u []uint64) (ret []string)

func UniqueStringSlice

func UniqueStringSlice(list ...interface{}) (s []string)

func UnlockFile

func UnlockFile(ptr *SafeFilename)

Types

type Alerts

type Alerts struct {
	sync.RWMutex
	Name2Chan map[string]*ChanString
}

func G_Alerts

func G_Alerts() (a *Alerts)

func NewAlertsHub

func NewAlertsHub() (a *Alerts)

func (*Alerts) Init

func (a *Alerts) Init()

func (*Alerts) NewSubscription

func (a *Alerts) NewSubscription(chanName string) (subCH <-chan string, er error)

func (*Alerts) SendAlert

func (a *Alerts) SendAlert(chanName string, data string)

type BytesOrErr

type BytesOrErr struct {
	B   []byte
	Err error
}

type BytesOrErrCH

type BytesOrErrCH struct {
	CH        (chan *BytesOrErr)
	Cache     []byte
	CachePtrs []int // 1 for iter, 2 for len
}

func (*BytesOrErrCH) Init

func (b *BytesOrErrCH) Init()

func (BytesOrErrCH) Read

func (b BytesOrErrCH) Read(p []byte) (i int, er error)

type Chan

type Chan interface {
	NewSubscription()
}

type ChanString

type ChanString struct {
	sync.RWMutex
	CH            (chan string)
	Subscriptions [](chan string)
}

func (*ChanString) Init

func (c *ChanString) Init(CH chan string)

func (*ChanString) NewSubscription

func (c *ChanString) NewSubscription() <-chan string

this is effectively creates a fanout on ChanString.CH

type ChannelData

type ChannelData struct {
	ChannelID string `json:"channel_id"`
}

type DoublyLinkedList

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

func (*DoublyLinkedList) AddElt

func (dll *DoublyLinkedList) AddElt(number uint64)

func (*DoublyLinkedList) DelEltsLessThan

func (dll *DoublyLinkedList) DelEltsLessThan(bound uint64)

func (*DoublyLinkedList) GetAll

func (dll *DoublyLinkedList) GetAll() (ret []uint64)

func (*DoublyLinkedList) GetAllHex

func (dll *DoublyLinkedList) GetAllHex() (ret []string)

func (*DoublyLinkedList) GetNumsLessThan

func (dll *DoublyLinkedList) GetNumsLessThan(bound uint64) (ret []uint64)

type Elt

type Elt struct {
	PrevElt *Elt
	Number  uint64
	NextElt *Elt
}

func (*Elt) Set

func (e *Elt) Set(number uint64)

func (*Elt) SetNext

func (e *Elt) SetNext(n *Elt)

func (*Elt) SetPrev

func (e *Elt) SetPrev(p *Elt)

type Flag

type Flag byte
const (
	Ok Flag = iota
	Warning
	Danger
	Suspended
)

func (Flag) RaiseFlag

func (a Flag) RaiseFlag() (raisedFlag Flag)

type LoggingLevel

type LoggingLevel int
const (
	LogLevelUnknown LoggingLevel = iota
	LogLevelTrace
	LogLevelDebug
	LogLevelInfo
	LogLevelWarning
	LogLevelError
)

func GetLoggingLevel

func GetLoggingLevel() LoggingLevel

type NYUP

type NYUP byte // No,Yes,Unknown,Probably
const (
	Unknown NYUP = iota
	Probably
	Y
	ProbablyNot
	N
)

func MaxNYUP

func MaxNYUP(a, b NYUP) (r NYUP)

func (*NYUP) Affirmative

func (n *NYUP) Affirmative() (tf bool)

func (*NYUP) String

func (n *NYUP) String() (s string)

type NodeID

type NodeID string

type NodeOrChannel

type NodeOrChannel byte
const (
	Node_T NodeOrChannel = iota
	Channel_T
)

type OnOff

type OnOff byte
const (
	Off OnOff = iota
	On
)

type QuickSearch

type QuickSearch struct {
	sync.RWMutex
	M map[string]bool
}

simple yet common struct

func NewNodeRegMethods

func NewNodeRegMethods() (q *QuickSearch)

func NewNodeUnregMethods

func NewNodeUnregMethods() (q *QuickSearch)

func NewQuickSearch

func NewQuickSearch() (q *QuickSearch)

type RedeemSolutionInput

type RedeemSolutionInput struct {
	ChannelID [32]byte
	Soln      [32]byte
	TOS       TickOrStop
}

encodings

func (*RedeemSolutionInput) ChannelData

func (r *RedeemSolutionInput) ChannelData() (c *ChannelData)

structs conversions

type SafeFilename

type SafeFilename struct {
	sync.RWMutex
}

func LockFile

func LockFile(fullPath string) (ptr *SafeFilename)

type Slice

type Slice []byte

func (Slice) Hex

func (s Slice) Hex() (hex string)

func (Slice) RedeemSolutionInput

func (s Slice) RedeemSolutionInput() (r *RedeemSolutionInput)

type Takee

type Takee struct {
	Left int
}

func NewTakee

func NewTakee(num int) (t *Takee)

func (*Takee) TakeMin

func (t *Takee) TakeMin(other int) (taken int, left *Takee)

type TickOrStop

type TickOrStop byte
const (
	Tick TickOrStop = iota
	Stop
	BothTOS
)

func B1ToTickOrStop

func B1ToTickOrStop(b [1]byte) (t TickOrStop)

func (*TickOrStop) String

func (tos *TickOrStop) String() (s string)

type TxByHashResult

type TxByHashResult struct {
	BlockHash        string `json:blockHash`
	BlockNumber      string `json:blockNumber`
	From             string `json:from`
	Gas              string `json:gas`
	GasPrice         string `json:gasPrice`
	Hash             string `json:hash`
	Input            string `json:input`
	Nonce            string `json:nonce`
	R                string `json:r`
	S                string `json:s`
	To               string `json:to`
	TransactionIndex string `json:transactionIndex`
	V                string `json:v`
	Value            string `json:value`
}

Jump to

Keyboard shortcuts

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