utils

package
v0.0.0-...-8e17a21 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2020 License: GPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReturnCh is chan for returns
	ReturnCh chan string
	// CancelFunc is represents cancel func
	CancelFunc context.CancelFunc
	// DaemonsCount is number of daemons
	DaemonsCount int
)
View Source
var DuplicateBlockError = errors.New("block with that time interval already exists in db")
View Source
var ErrBlockSize = errors.New("Bad block size")
View Source
var TimeError = errors.New("current time before first block")

Functions

func CallMethod

func CallMethod(i interface{}, methodName string) interface{}

CallMethod calls the function by its name

func Caller

func Caller(steps int) string

Caller returns the name of the latest function

func CheckSign

func CheckSign(publicKeys [][]byte, forSign []byte, signs []byte, nodeKeyOrLogin bool) (bool, error)

CheckSign checks the signature

func CopyFileContents

func CopyFileContents(src, dst string) error

CopyFileContents copy files

func CreateDirIfNotExists

func CreateDirIfNotExists(dir string, mode os.FileMode) error

func ErrInfo

func ErrInfo(verr interface{}, additionally ...string) error

ErrInfo formats the error message

func ErrInfoFmt

func ErrInfoFmt(err string, a ...interface{}) error

ErrInfoFmt fomats the error message

func GetCurrentDir

func GetCurrentDir() string

GetCurrentDir returns the current directory

func GetHTTPTextAnswer

func GetHTTPTextAnswer(url string) (string, error)

GetHTTPTextAnswer returns HTTP answer as a string

func GetHostPort

func GetHostPort(h string) string

func GetNodeKeys

func GetNodeKeys() (string, string, error)

GetNodeKeys returns node private key and public key

func GetNodePrivateKey

func GetNodePrivateKey() ([]byte, error)

func GetParent

func GetParent() string

GetParent returns the information where the call of function happened

func IsBanError

func IsBanError(err error) bool

func LockOrDie

func LockOrDie(dir string) *flock.Flock

func MakeDirectory

func MakeDirectory(dir string) error

MakeDirectory makes directory if is not exists

func MerkleTreeRoot

func MerkleTreeRoot(dataArray [][]byte) []byte

MerkleTreeRoot rertun Merkle value

func ShellExecute

func ShellExecute(cmdline string)

ShellExecute runs cmdline

func ShuffleSlice

func ShuffleSlice(slice []string)

func StringInSlice

func StringInSlice(slice []string, v string) bool

func TypeInt

func TypeInt(txType string) int64

TypeInt returns the identifier of the embedded transaction

func UUID

func UUID() string

func WithBan

func WithBan(err error) error

Types

type BanError

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

func (*BanError) Error

func (b *BanError) Error() string

type BlockData

type BlockData struct {
	BlockID           int64
	Time              int64
	EcosystemID       int64
	KeyID             int64
	NodePosition      int64
	Sign              []byte
	Hash              []byte
	RollbacksHash     []byte
	Version           int
	PrivateBlockchain bool
}

BlockData is a structure of the block's header

func ParseBlockHeader

func ParseBlockHeader(buf *bytes.Buffer) (header, prev BlockData, err error)

ParseBlockHeader is parses block header

func (BlockData) ForSha

func (b BlockData) ForSha(prev *BlockData, mrklRoot []byte) string

func (BlockData) ForSign

func (b BlockData) ForSign(prev *BlockData, mrklRoot []byte) string

ForSign from 128 bytes to 512 bytes. Signature of TYPE, BLOCK_ID, PREV_BLOCK_HASH, TIME, WALLET_ID, state_id, MRKL_ROOT

func (BlockData) String

func (b BlockData) String() string

type BlockTimeCalculator

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

BlockTimeCalculator calculating block generation time

func BuildBlockTimeCalculator

func BuildBlockTimeCalculator(transaction *model.DbTransaction) (BlockTimeCalculator, error)

func NewBlockTimeCalculator

func NewBlockTimeCalculator(firstBlockTime time.Time, generationTime, blocksGap time.Duration, nodesCount int64) BlockTimeCalculator

func (*BlockTimeCalculator) SetClock

func (btc *BlockTimeCalculator) SetClock(clock Clock) *BlockTimeCalculator

func (*BlockTimeCalculator) TimeToGenerate

func (btc *BlockTimeCalculator) TimeToGenerate(nodePosition int64) (bool, error)

func (*BlockTimeCalculator) ValidateBlock

func (btc *BlockTimeCalculator) ValidateBlock(nodePosition int64, at time.Time) (bool, error)

type BlockTimeCounter

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

func NewBlockTimeCounter

func NewBlockTimeCounter() *BlockTimeCounter

NewBlockTimeCounter return initialized BlockTimeCounter

func (*BlockTimeCounter) Block

func (btc *BlockTimeCounter) Block(t time.Time) int

Block returns serial block number for time

func (*BlockTimeCounter) BlockForTimeExists

func (btc *BlockTimeCounter) BlockForTimeExists(t time.Time, nodePosition int) (bool, error)

func (*BlockTimeCounter) NextTime

func (btc *BlockTimeCounter) NextTime(t time.Time, nodePosition int) time.Time

NextTime returns next generation time for node position at time

func (*BlockTimeCounter) NodePosition

func (btc *BlockTimeCounter) NodePosition(t time.Time) int

NodePosition returns generating node position for time

func (*BlockTimeCounter) RangesByTime

func (btc *BlockTimeCounter) RangesByTime(t time.Time) (start, end time.Time)

RangesByTime returns start and end of interval by time

func (*BlockTimeCounter) ValidateBlock

func (btc *BlockTimeCounter) ValidateBlock(t time.Time, nodePosition int) bool

ValidateBlock checks conformity between time and nodePosition

type Cert

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

func ParseCert

func ParseCert(b []byte) (c *Cert, err error)

func (*Cert) EqualBytes

func (c *Cert) EqualBytes(bs ...[]byte) bool

func (*Cert) Validate

func (c *Cert) Validate(pem []byte) error

type Clock

type Clock interface {
	Now() time.Time
}

Clock represents interface of clock

type ClockWrapper

type ClockWrapper struct {
}

ClockWrapper represents wrapper of clock

func (*ClockWrapper) Now

func (cw *ClockWrapper) Now() time.Time

Now returns current time

type MockClock

type MockClock struct {
	mock.Mock
}

MockClock is an autogenerated mock type for the Clock type

func (*MockClock) Now

func (_m *MockClock) Now() time.Time

Now provides a mock function with given fields:

type Rand

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

func NewRand

func NewRand(seed int64) *Rand

func (*Rand) BytesSeed

func (r *Rand) BytesSeed(b []byte) *rand.Rand

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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