util

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IoMaxSize = 1024
	MaxSize   = 0x02000000
)
View Source
const (
	// SatoshiPerBitcent is the number of satoshi in one bitcoin cent.
	SatoshiPerBitcent = 1e6

	// SatoshiPerBitcoin is the number of satoshi in one bitcoin (1 BTC).
	SatoshiPerBitcoin = 1e8

	// MaxSatoshi is the maximum transaction amount allowed in satoshi.
	MaxSatoshi = 21e6 * SatoshiPerBitcoin

	/*OneMegaByte 1MB */
	OneMegaByte uint64 = 1000000
)
View Source
const (
	COIN     int64 = 100000000
	MaxMoney       = 21000000 * COIN
	// MinFeeRate minimum and Maximum values for tracking feeRates
	MinFeeRate  int64   = 10
	MaxFee      int64   = 1e7
	InfFeeRate  int64   = MaxMoney
	InfPriority float64 = 1e9 * float64(MaxMoney)

	DefaultMinRelayTxFeePerK int64 = 1000

	//FeeSpacing we have to lump transactions into buckets based on feeRate, but we want to be
	// able to give accurate estimates over a large range of potential feeRates.
	// Therefore it makes sense to exponentially space the buckets
	FeeSpacing   float64 = 1.1
	CurrencyUnit         = "BCH"
)
View Source
const (
	// MaxBlockConfirms track confirm delays up to 25 blocks, can't estimate beyond that
	MaxBlockConfirms uint = 25

	// DefaultDecay decay of .998 is a half-life of 346 blocks or about 2.4 days
	DefaultDecay float64 = .998

	// MinSuccessPct require greater than 95% of X feeRate transactions to be confirmed within Y
	// blocks for X to be big enough
	MinSuccessPct float64 = .95

	// SufficientFeeTxs Require an avg of 1 tx in the combined feeRate bucket per block to have stat
	// significance
	SufficientFeeTxs float64 = 1
)
View Source
const (
	Hash256Size       = 32
	MaxHashStringSize = Hash256Size * 2
	Hash160Size       = 20
)

Variables

View Source
var HashOne = Hash{0x0000000000000000000000000000000000000000000000000000000000000001}
View Source
var HashZero = Hash{0x0000000000000000000000000000000000000000000000000000000000000000}

Functions

func DoubleSha256Bytes

func DoubleSha256Bytes(b []byte) []byte

func EncodeVarLenInt

func EncodeVarLenInt(n uint64) []byte

func GetAdjustedTimeSec added in v0.0.5

func GetAdjustedTimeSec() int64

func GetHashBytesFromStr

func GetHashBytesFromStr(src string) (bytes []byte, err error)

func GetRand

func GetRand(nMax uint64) uint64

func GetRandInt

func GetRandInt(nMax int) int

func GetTimeMicroSec added in v0.0.5

func GetTimeMicroSec() int64

func GetTimeOffsetSec added in v0.0.5

func GetTimeOffsetSec() int64

func GetTimeSec added in v0.0.5

func GetTimeSec() int64

func GetUint64FromReder

func GetUint64FromReder(r io.Reader) (uint64, error)

func Hash160

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(sha256(b)).

func InsecureRand32

func InsecureRand32() uint32

InsecureRand32 create a random number in [0 math.MaxUint32]

func InsecureRand64

func InsecureRand64() uint64

func MaxI

func MaxI(a, b int64) int64

func MaxI32

func MaxI32(a, b int32) int32

func MaxU

func MaxU(a, b uint64) uint64

func MaxU32

func MaxU32(a, b uint32) uint32

func MinI

func MinI(a, b int64) int64

func MinI32

func MinI32(a, b int32) int32

func MinU

func MinU(a, b uint64) uint64

func MinU32

func MinU32(a, b uint32) uint32

func RandomUint64

func RandomUint64() (uint64, error)

func ReadElements

func ReadElements(r io.Reader, elements ...interface{}) error

func ReadVarBytes

func ReadVarBytes(r io.Reader, maxAllowed uint64, fieldName string) ([]byte, error)

func ReadVarInt

func ReadVarInt(r io.Reader) (uint64, error)

func ReadVarLenInt

func ReadVarLenInt(r io.Reader) (uint64, error)

func ReadVarString

func ReadVarString(r io.Reader) (string, error)

func Ripemd160

func Ripemd160(buf []byte) []byte

func SetMockTime

func SetMockTime(time int64)

func Sha1

func Sha1(buf []byte) [20]byte

func Sha256Bytes

func Sha256Bytes(b []byte) []byte

func SipHash

func SipHash(k0, k1 uint64, hash []byte) uint64

func SipHashExtra

func SipHashExtra(k0, k1 uint64, hash []byte, extra uint32) uint64

func Swap

func Swap(s *Stack, other *Stack)

func VarIntSerializeSize

func VarIntSerializeSize(val uint64) uint32

func VarLenIntSize

func VarLenIntSize(n uint64) uint

func WriteElements

func WriteElements(w io.Writer, elements ...interface{}) error

func WriteVarBytes

func WriteVarBytes(w io.Writer, bytes []byte) error

func WriteVarInt

func WriteVarInt(w io.Writer, val uint64) error

func WriteVarLenInt

func WriteVarLenInt(w io.Writer, n uint64) error

func WriteVarString

func WriteVarString(w io.Writer, str string) error

Types

type BinaryFreeList

type BinaryFreeList chan []byte
var BinarySerializer BinaryFreeList = make(chan []byte, IoMaxSize)

func (BinaryFreeList) Borrow

func (b BinaryFreeList) Borrow() (buf []byte)

func (BinaryFreeList) PutUint16

func (b BinaryFreeList) PutUint16(w io.Writer, byteOrder binary.ByteOrder, val uint16) error

func (BinaryFreeList) PutUint32

func (b BinaryFreeList) PutUint32(w io.Writer, byteOrder binary.ByteOrder, val uint32) error

func (BinaryFreeList) PutUint64

func (b BinaryFreeList) PutUint64(w io.Writer, byteOrder binary.ByteOrder, val uint64) error

func (BinaryFreeList) PutUint8

func (b BinaryFreeList) PutUint8(w io.Writer, val uint8) error

func (BinaryFreeList) Return

func (b BinaryFreeList) Return(buf []byte)

func (BinaryFreeList) Uint16

func (b BinaryFreeList) Uint16(r io.Reader, byteOrder binary.ByteOrder) (uint16, error)

func (BinaryFreeList) Uint32

func (b BinaryFreeList) Uint32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error)

func (BinaryFreeList) Uint64

func (b BinaryFreeList) Uint64(r io.Reader, byteOrder binary.ByteOrder) (uint64, error)

func (BinaryFreeList) Uint8

func (b BinaryFreeList) Uint8(r io.Reader) (uint8, error)

type FastRandomContext

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

func NewFastRandomContext

func NewFastRandomContext(fDeterministic bool) *FastRandomContext

func (*FastRandomContext) Rand32

func (f *FastRandomContext) Rand32() uint32

type FeeRate

type FeeRate struct {
	SataoshisPerK int64
}

FeeRate : Fee rate in satoshis per kilobyte: Amount / kB

func NewFeeRate

func NewFeeRate(amount int64) *FeeRate

func NewFeeRateWithSize

func NewFeeRateWithSize(feePaid int64, bytes int64) *FeeRate

func Unserialize

func Unserialize(reader io.Reader) (*FeeRate, error)

func (*FeeRate) GetFee

func (feeRate *FeeRate) GetFee(bytes int) int64

GetFee : Return the fee in satoshis for the given size in bytes.

func (*FeeRate) GetFeePerK

func (feeRate *FeeRate) GetFeePerK() int64

GetFeePerK : Return the fee in satoshis for a size of 1000 bytes

func (*FeeRate) Less

func (feeRate *FeeRate) Less(b FeeRate) bool

func (*FeeRate) Serialize

func (feeRate *FeeRate) Serialize(writer io.Writer) error

func (*FeeRate) SerializeSize

func (feeRate *FeeRate) SerializeSize() int

func (*FeeRate) String

func (feeRate *FeeRate) String() string

type Hash

type Hash [Hash256Size]byte

func DoubleSha256Hash

func DoubleSha256Hash(b []byte) Hash

func GetHashFromStr

func GetHashFromStr(hashStr string) (hash *Hash, err error)

func GetRandHash

func GetRandHash() *Hash

func HashFromString

func HashFromString(hexString string) *Hash

func Sha256Hash

func Sha256Hash(b []byte) Hash

func (*Hash) Cmp

func (hash *Hash) Cmp(other *Hash) int

func (*Hash) Decode

func (hash *Hash) Decode(r io.Reader) (int, error)

func (*Hash) Encode

func (hash *Hash) Encode(w io.Writer) (int, error)

func (*Hash) EncodeSize

func (hash *Hash) EncodeSize() uint32

func (*Hash) GetCloneBytes

func (hash *Hash) GetCloneBytes() []byte

func (*Hash) IsEqual

func (hash *Hash) IsEqual(target *Hash) bool

func (*Hash) IsNull

func (hash *Hash) IsNull() bool

func (*Hash) Serialize

func (hash *Hash) Serialize(w io.Writer) (int, error)

func (*Hash) SerializeSize

func (hash *Hash) SerializeSize() uint32

func (Hash) String

func (hash Hash) String() string

func (*Hash) ToBigInt

func (hash *Hash) ToBigInt() *big.Int

func (*Hash) Unserialize

func (hash *Hash) Unserialize(r io.Reader) (int, error)

type MedianTime added in v0.0.4

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

func GetMedianTimeSource added in v0.0.6

func GetMedianTimeSource() *MedianTime

func (*MedianTime) AddTimeSample added in v0.0.4

func (medianTime *MedianTime) AddTimeSample(sourceID string, timeVal time.Time)

type SipHasher

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

func NewSipHasher

func NewSipHasher(k0, k1 uint64) *SipHasher

func (*SipHasher) Finalize

func (sh *SipHasher) Finalize() uint64

func (*SipHasher) Write

func (sh *SipHasher) Write(data []byte) *SipHasher

func (*SipHasher) WriteUint64

func (sh *SipHasher) WriteUint64(data uint64) *SipHasher

type Stack

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

func NewStack

func NewStack() *Stack

func (*Stack) Copy

func (s *Stack) Copy() *Stack

func (*Stack) CountBool

func (s *Stack) CountBool(val bool) int

func (*Stack) Empty

func (s *Stack) Empty() bool

func (*Stack) Equal added in v0.0.3

func (s *Stack) Equal(other *Stack) bool

func (*Stack) Erase

func (s *Stack) Erase(begin int, end int) bool

func (*Stack) Insert

func (s *Stack) Insert(index int, value interface{}) bool

func (*Stack) Pop

func (s *Stack) Pop() interface{}

func (*Stack) Push

func (s *Stack) Push(value interface{})

func (*Stack) RemoveAt

func (s *Stack) RemoveAt(index int) bool

func (*Stack) SetTop

func (s *Stack) SetTop(i int, value interface{}) bool

func (*Stack) Size

func (s *Stack) Size() int

func (*Stack) Swap

func (s *Stack) Swap(i int, j int) bool

func (*Stack) Top

func (s *Stack) Top(i int) interface{}

Directories

Path Synopsis
algorithm
Package base58 provides an API for working with modified base58 and Base58Check encodings.
Package base58 provides an API for working with modified base58 and Base58Check encodings.

Jump to

Keyboard shortcuts

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