utils

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PathVarChain             = "Chain"
	PathVarRecipientChain    = "RecipientChain"
	PathVarContract          = "Contract"
	PathVarCosmosAddress     = "CosmosAddress"
	PathVarCounter           = "Counter"
	PathVarAmount            = "Amount"
	PathVarLinkedAddress     = "LinkedAddress"
	PathVarEthereumAddress   = "EthereumAddress"
	PathVarTxID              = "TxID"
	PathVarCommandID         = "CommandID"
	PathVarBatchedCommandsID = "BatchedCommandsID"
	PathVarKeyRole           = "KeyRole"
	PathVarTxType            = "txType"
	PathVarKeyID             = "KeyID"
	PathVarSigID             = "SigID"
	PathVarOutpoint          = "Outpoint"
	PathvarSymbol            = "Symbol"
	PathVarAsset             = "Asset"
)

routes

Variables

View Source
var (
	ErrInvalidLengthThreshold        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowThreshold          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupThreshold = fmt.Errorf("proto: unexpected end of group")
)

Functions

func CloseLogError

func CloseLogError(iter sdk.Iterator, logger log.Logger)

CloseLogError closes the given iterator and logs if an error is returned

func ExtractReqSender

func ExtractReqSender(w http.ResponseWriter, req rest.BaseReq) (sdk.AccAddress, bool)

ExtractReqSender extracts the sender address from an SDK base request

func IndexOf

func IndexOf(strs []string, str string) int

IndexOf returns the index of str in the slice; -1 if not found

func NewNOPLogger

func NewNOPLogger() log.Logger

NewNOPLogger returns a logger that doesn't do anything.

func RegisterQueryHandlerFn

func RegisterQueryHandlerFn(r *mux.Router, moduleRoute string) func(http.HandlerFunc, string, ...string)

RegisterQueryHandlerFn returns a function to register query routes with the given router

func RegisterTxHandlerFn

func RegisterTxHandlerFn(r *mux.Router, moduleRoute string) func(http.HandlerFunc, string, ...string)

RegisterTxHandlerFn returns a function to register rest routes with the given router

func ValidateQueueState added in v0.9.0

func ValidateQueueState(state map[string]codec.ProtoMarshaler) error

ValidateQueueState checks if the keys of the given map have the correct format to be imported as queue state. The expected format is {block height}_{[a-zA-Z0-9]+}

Types

type BackOff

type BackOff func(currentRetryCount int) time.Duration

BackOff computes the next back-off duration

func ExponentialBackOff

func ExponentialBackOff(minTimeout time.Duration) BackOff

ExponentialBackOff computes an exponential back-off

func LinearBackOff

func LinearBackOff(minTimeout time.Duration) BackOff

LinearBackOff computes a linear back-off

type BlockHeightKVQueue

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

BlockHeightKVQueue is a queue that orders items with the block height at which the items are enqueued; the order of items that are enqueued at the same block height is deterministically based on their actual key in the KVStore

func NewBlockHeightKVQueue

func NewBlockHeightKVQueue(name string, store KVStore, blockHeight int64, logger log.Logger) BlockHeightKVQueue

NewBlockHeightKVQueue is the constructor of BlockHeightKVQueue

func (BlockHeightKVQueue) Dequeue

func (q BlockHeightKVQueue) Dequeue(value codec.ProtoMarshaler, filter ...func(value codec.ProtoMarshaler) bool) bool

Dequeue pops the bottom of the queue and unmarshals it into the given object, and return true if anything in the queue is found and the value passes the optional filter function

func (BlockHeightKVQueue) Enqueue

func (q BlockHeightKVQueue) Enqueue(key Key, value codec.ProtoMarshaler)

Enqueue pushes the given value onto the top of the queue and stores the value at given key

func (BlockHeightKVQueue) ImportState added in v0.9.0

func (q BlockHeightKVQueue) ImportState(state map[string]codec.ProtoMarshaler)

ImportState should only be used to populate state at genesis. Panics if the given state is invalid

func (BlockHeightKVQueue) IsEmpty

func (q BlockHeightKVQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty; otherwise, false

func (BlockHeightKVQueue) Keys added in v0.10.0

func (q BlockHeightKVQueue) Keys() []Key

Keys returns a list with the keys for the values still enqueued

func (BlockHeightKVQueue) WithBlockHeight

func (q BlockHeightKVQueue) WithBlockHeight(blockHeight int64) BlockHeightKVQueue

WithBlockHeight returns a queue with the given block height

type Iterator

type Iterator interface {
	sdk.Iterator
	UnmarshalValue(marshaler codec.ProtoMarshaler)
	GetKey() Key
}

Iterator is an easier and safer to use sdk.Iterator extension

type KVQueue

type KVQueue interface {
	Enqueue(key Key, value codec.ProtoMarshaler)
	Dequeue(value codec.ProtoMarshaler, filter ...func(value codec.ProtoMarshaler) bool) bool
	IsEmpty() bool

	//TODO: convert to iterator
	Keys() []Key
}

KVQueue represents a queue built with the KVStore

type KVStore

type KVStore struct {
	sdk.KVStore
	// contains filtered or unexported fields
}

KVStore is a wrapper around the cosmos-sdk KVStore to provide more safety regarding key management and better ease-of-use

func NewNormalizedStore

func NewNormalizedStore(store sdk.KVStore, cdc codec.BinaryCodec) KVStore

NewNormalizedStore returns a new KVStore

func (KVStore) Delete

func (store KVStore) Delete(key Key)

Delete deletes the value stored under the given key, if it exists

func (KVStore) Get

func (store KVStore) Get(key Key, value codec.ProtoMarshaler) bool

Get unmarshals the raw bytes stored under the given key into the value object. Returns true if the key exists.

func (KVStore) GetRaw

func (store KVStore) GetRaw(key Key) []byte

GetRaw returns the raw bytes stored under the given key. Returns nil with key does not exist.

func (KVStore) Has

func (store KVStore) Has(key Key) bool

Has returns true if the key exists.

func (KVStore) Iterator

func (store KVStore) Iterator(prefix Key) Iterator

Iterator returns an Iterator that can handle a structured Key

func (KVStore) Set

func (store KVStore) Set(key Key, value codec.ProtoMarshaler)

Set marshals the value and stores it under the given key

func (KVStore) SetRaw

func (store KVStore) SetRaw(key Key, value []byte)

SetRaw stores the value under the given key

type Key

type Key interface {
	// AsKey returns the byte representation of the key. If given, uses a delimiter string to separate prefixes
	AsKey(delimiter ...string) []byte
	Prepend(prefix Key) Key
	Append(key Key) Key
	Equals(key Key) bool
}

Key represents a store key to interact with the KVStore

type NOPLogger

type NOPLogger struct{}

NOPLogger is a logger that doesn't do anything

func (NOPLogger) Debug

func (NOPLogger) Debug(string, ...interface{})

Debug does nothing

func (NOPLogger) Error

func (NOPLogger) Error(string, ...interface{})

Error does nothing

func (NOPLogger) Info

func (NOPLogger) Info(string, ...interface{})

Info does nothing

func (*NOPLogger) With

func (l *NOPLogger) With(...interface{}) log.Logger

With does nothing

type Nonce added in v0.9.0

type Nonce [sha256.Size]byte

Nonce defines a 32 byte array representing a deterministically-generated nonce

func GetNonce added in v0.9.0

func GetNonce(hash tmbytes.HexBytes, gasMeter sdk.GasMeter) Nonce

GetNonce deterministically calculates a nonce using a hash and gas meter

type SequenceKVQueue

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

SequenceKVQueue is a queue that orders items with the sequence number at which the items are enqueued;

func NewSequenceKVQueue

func NewSequenceKVQueue(prefixStore KVStore, maxSize uint64, logger log.Logger) SequenceKVQueue

NewSequenceKVQueue is the constructor of SequenceKVQueue. The prefixStore should isolate the namespace of the queue

func (*SequenceKVQueue) Dequeue

func (q *SequenceKVQueue) Dequeue(n uint64, value codec.ProtoMarshaler) bool

Dequeue pops the nth value off and unmarshals it into the given object, returns false if n is out of range n is 0-based

func (*SequenceKVQueue) Enqueue

func (q *SequenceKVQueue) Enqueue(value codec.ProtoMarshaler) error

Enqueue pushes the given value onto the top of the queue and stores the value at given key. Returns queue position and status

func (SequenceKVQueue) Peek

func (q SequenceKVQueue) Peek(n uint64, value codec.ProtoMarshaler) bool

Peek unmarshals the value into the given object at the given index and returns its sequence number, returns false if n is out of range n is 0-based

func (SequenceKVQueue) Size

func (q SequenceKVQueue) Size() uint64

Size returns the given current size of the queue

type StringKey

type StringKey interface {
	Key
	AppendStr(key string, stringTransformations ...func(string) string) StringKey
	PrependStr(key string, stringTransformations ...func(string) string) StringKey
}

StringKey extends the Key interface for simplified appending and prepending

func KeyFromBz

func KeyFromBz(k []byte) StringKey

KeyFromBz returns a structured key

func KeyFromStr

func KeyFromStr(k string, stringTransformations ...func(string) string) StringKey

KeyFromStr applies the optional string transformations to the given key in sequence and returns a structured key

func LowerCaseKey

func LowerCaseKey(k string) StringKey

LowerCaseKey returns a key with the input converted to lower case

type Threshold

type Threshold struct {
	// split threshold into Numerator and denominator to avoid floating point
	// errors down the line
	Numerator   int64 `protobuf:"varint,1,opt,name=numerator,proto3" json:"numerator,omitempty"`
	Denominator int64 `protobuf:"varint,2,opt,name=denominator,proto3" json:"denominator,omitempty"`
}
var OneThreshold Threshold = NewThreshold(1, 1)

OneThreshold is a threshold that equals to 1

var ZeroThreshold Threshold = NewThreshold(0, 1)

ZeroThreshold is a threshold that equals to 0

func NewThreshold

func NewThreshold(numerator, denominator int64) Threshold

NewThreshold is the constructor for Threshold

func (*Threshold) Descriptor

func (*Threshold) Descriptor() ([]byte, []int)

func (Threshold) GT

func (m Threshold) GT(t Threshold) bool

GT returns true if and only if threshold is greater than the given one

func (Threshold) GTE

func (m Threshold) GTE(t Threshold) bool

GTE returns true if and only if threshold is greater than or equal to the given one

func (Threshold) IsMet

func (m Threshold) IsMet(share sdk.Int, total sdk.Int) bool

IsMet returns true if share > threshold * total

func (Threshold) LT

func (m Threshold) LT(t Threshold) bool

LT returns true if and only if threshold is less than the given one

func (Threshold) LTE

func (m Threshold) LTE(t Threshold) bool

LTE returns true if and only if threshold is less than or equal to the given one

func (*Threshold) Marshal

func (m *Threshold) Marshal() (dAtA []byte, err error)

func (*Threshold) MarshalTo

func (m *Threshold) MarshalTo(dAtA []byte) (int, error)

func (*Threshold) MarshalToSizedBuffer

func (m *Threshold) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Threshold) ProtoMessage

func (*Threshold) ProtoMessage()

func (*Threshold) Reset

func (m *Threshold) Reset()

func (Threshold) SimpleString

func (m Threshold) SimpleString() string

SimpleString returns a simple string representation of the threshold

func (*Threshold) Size

func (m *Threshold) Size() (n int)

func (*Threshold) String

func (m *Threshold) String() string

func (*Threshold) Unmarshal

func (m *Threshold) Unmarshal(dAtA []byte) error

func (Threshold) Validate

func (m Threshold) Validate() error

Validate returns an error if threshold is invalid

func (*Threshold) XXX_DiscardUnknown

func (m *Threshold) XXX_DiscardUnknown()

func (*Threshold) XXX_Marshal

func (m *Threshold) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Threshold) XXX_Merge

func (m *Threshold) XXX_Merge(src proto.Message)

func (*Threshold) XXX_Size

func (m *Threshold) XXX_Size() int

func (*Threshold) XXX_Unmarshal

func (m *Threshold) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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