common

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

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BNBSymbol     = Symbol("BNB")
	RuneA1FSymbol = Symbol("RUNE-A1F")
	RuneB1ASymbol = Symbol("RUNE-B1A")
)
View Source
const (
	BNBTicker  = Ticker("BNB")
	RuneTicker = Ticker("RUNE")
	// TODO these are not tickers, they are symbols, delete them
	RuneA1FTicker = Ticker("RUNE-A1F")
	RuneB1ATicker = Ticker("RUNE-B1A")
)
View Source
const NoSigningAlgo = keys.SigningAlgo("")
View Source
const One = 100000000

One is useful type so we don't need to type 8 zero all the time

Variables

View Source
var (
	BNBAsset     = Asset{BNBChain, "BNB", "BNB"}
	BTCAsset     = Asset{BTCChain, "BTC", "BTC"}
	RuneA1FAsset = Asset{BNBChain, "RUNE-A1F", "RUNE"} // testnet
	RuneB1AAsset = Asset{BNBChain, "RUNE-B1A", "RUNE"} // mainnet
)
View Source
var (
	BNBChain   = Chain("BNB")
	ETHChain   = Chain("ETH")
	BTCChain   = Chain("BTC")
	THORChain  = Chain("THOR")
	EmptyChain = Chain("")
)
View Source
var BlankTxID = TxID("0000000000000000000000000000000000000000000000000000000000000000")
View Source
var NoCoin = Coin{}

Functions

func AmountToUint

func AmountToUint(amount Amount) sdk.Uint

func ConvertAndEncode

func ConvertAndEncode(hrp string, data []byte) (string, error)

ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32

func FloatToDec

func FloatToDec(input float64) sdk.Dec

func FloatToUint

func FloatToUint(input float64) sdk.Uint

func FloatToUintAndMultipleOne

func FloatToUintAndMultipleOne(input float64) sdk.Uint

func IntToInt64

func IntToInt64(input sdk.Int) int64

func IntToUint64

func IntToUint64(input sdk.Int) uint64

func IsBNB

func IsBNB(ticker Ticker) bool

func IsBNBChain

func IsBNBChain(c Chain) bool

func IsBNBSymbol

func IsBNBSymbol(s Symbol) bool

func IsRune

func IsRune(ticker Ticker) bool

func IsRuneSymbol

func IsRuneSymbol(s Symbol) bool

func RandStringBytesMask

func RandStringBytesMask(n int) string

RandStringBytesMask generate random string used for test purpose

func UintToFloat64

func UintToFloat64(input sdk.Uint) float64

UintToFloat64

func UintToUint64

func UintToUint64(input sdk.Uint) uint64

UintToUint64

Types

type Address

type Address string
var NoAddress Address = Address("")
var RagnarokAddr Address = Address("Ragnarok")

func NewAddress

func NewAddress(address string) (Address, error)

NewAddress create a new Address Sample: bnb1lejrrtta9cgr49fuh7ktu3sddhe0ff7wenlpn6

func (Address) Equals

func (addr Address) Equals(addr2 Address) bool

func (Address) IsChain

func (addr Address) IsChain(chain Chain) bool

func (Address) IsEmpty

func (addr Address) IsEmpty() bool

func (Address) String

func (addr Address) String() string

type Amount

type Amount string
var ZeroAmount Amount = Amount("0")

func NewAmount

func NewAmount(amount string) (Amount, error)

func NewAmountFromFloat

func NewAmountFromFloat(f float64) Amount

func UintToAmount

func UintToAmount(input sdk.Uint) Amount

func (Amount) Equals

func (a Amount) Equals(a2 Amount) bool

func (Amount) Float64

func (a Amount) Float64() float64

func (Amount) GreaterThen

func (a Amount) GreaterThen(f float64) bool

func (Amount) IsEmpty

func (a Amount) IsEmpty() bool

func (Amount) IsNegative

func (a Amount) IsNegative() bool

func (Amount) IsZero

func (a Amount) IsZero() bool

func (Amount) LessThen

func (a Amount) LessThen(f float64) bool

func (Amount) Minus

func (a Amount) Minus(a2 Amount) Amount

func (Amount) Plus

func (a Amount) Plus(a2 Amount) Amount

func (Amount) String

func (a Amount) String() string

type Asset

type Asset struct {
	Chain  Chain  `json:"chain"`
	Symbol Symbol `json:"symbol"`
	Ticker Ticker `json:"ticker"`
}

func NewAsset

func NewAsset(input string) (Asset, error)

func RuneAsset

func RuneAsset() Asset

func (Asset) Equals

func (a Asset) Equals(a2 Asset) bool

func (Asset) IsBNB

func (a Asset) IsBNB() bool

func (Asset) IsEmpty

func (a Asset) IsEmpty() bool

func (Asset) IsRune

func (a Asset) IsRune() bool

func (Asset) String

func (a Asset) String() string

type Chain

type Chain string

Chain is the

func NewChain

func NewChain(chain string) (Chain, error)

NewChain create a new Chain and default the siging_algo to Secp256k1

func (Chain) AddressPrefix

func (c Chain) AddressPrefix(cn ChainNetwork) string

AddressPrefix return the address prefix used by the given network (testnet/mainnet)

func (Chain) Equals

func (c Chain) Equals(c2 Chain) bool

func (Chain) GetSigningAlgo

func (c Chain) GetSigningAlgo() keys.SigningAlgo

func (Chain) IsEmpty

func (c Chain) IsEmpty() bool

IsEmpty is to determinate whether the chain is empty

func (Chain) String

func (c Chain) String() string

type ChainNetwork

type ChainNetwork uint8

ChainNetwork is to indicate which chain environment we are working with

const (
	// TestNetwork for test
	TestNet ChainNetwork = iota
	// ProdNetwork for main net
	MainNet
)

func GetCurrentChainNetwork

func GetCurrentChainNetwork() ChainNetwork

GetCurrentChainNetwork determinate what kind of network currently it is working with

type ChainPoolInfo

type ChainPoolInfo struct {
	Chain       Chain   `json:"chain"`
	PubKey      PubKey  `json:"pub_key"`
	PoolAddress Address `json:"pool_address"`
}

ChainPoolInfo represent the pool address specific for a chain

var EmptyChainPoolInfo ChainPoolInfo

EmptyChainPoolInfo everything is empty

func NewChainPoolInfo

func NewChainPoolInfo(chain Chain, pubKey PubKey) (ChainPoolInfo, error)

NewChainPoolInfo create a new instance of ChainPoolInfo

func (ChainPoolInfo) IsEmpty

func (cpi ChainPoolInfo) IsEmpty() bool

IsEmpty whether the struct is empty

type Chains

type Chains []Chain

type Coin

type Coin struct {
	Asset  Asset    `json:"asset"`
	Amount sdk.Uint `json:"amount"`
}

func NewCoin

func NewCoin(asset Asset, amount sdk.Uint) Coin

NewCoin return a new instance of Coin

func (Coin) Equals

func (c Coin) Equals(cc Coin) bool

func (Coin) IsEmpty

func (c Coin) IsEmpty() bool

func (Coin) IsValid

func (c Coin) IsValid() error

func (Coin) String

func (c Coin) String() string

type Coins

type Coins []Coin

func (Coins) Contains

func (cs Coins) Contains(c Coin) bool

Contains check whether the given coin is in the list

func (Coins) IsValid

func (cs Coins) IsValid() error

func (Coins) String

func (cs Coins) String() string

type Duration

type Duration struct {
	time.Duration
}

Duration embedded time.Duration so we could use string to represent duration in json file for example ,1s ,1h , 5m etc

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshal the duration to json string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON convert the json value back to time.Duration

type PoolPubKey

type PoolPubKey struct {
	Chain   Chain   `json:"chain"`
	SeqNo   uint64  `json:"seq_no"`
	PubKey  PubKey  `json:"pub_key"`
	Address Address `json:"address"`
}

PoolPubKey is the pub key only related to a specific chain

func NewPoolPubKey

func NewPoolPubKey(chain Chain, seqNo uint64, pubkey PubKey) (*PoolPubKey, error)

NewPoolPubKey create a new instance of PoolPubKey

func (*PoolPubKey) Equals

func (ppk *PoolPubKey) Equals(ppk1 *PoolPubKey) bool

Equals compare two PoolPubKey to determinate whether they are representing the same address

func (PoolPubKey) GetAddress

func (ppk PoolPubKey) GetAddress() (Address, error)

func (*PoolPubKey) GetSeqNo

func (ppk *PoolPubKey) GetSeqNo() uint64

GetSeqNo

func (PoolPubKey) IsEmpty

func (ppk PoolPubKey) IsEmpty() bool

IsEmpty check whether the given pool pub key is empty

func (PoolPubKey) String

func (ppk PoolPubKey) String() string

Stringer implementation

type PoolPubKeys

type PoolPubKeys []*PoolPubKey

PoolPubKeys

var EmptyPoolPubKeys PoolPubKeys

EmptyPoolPubKeys

func (PoolPubKeys) GetByChain

func (poolPubKeys PoolPubKeys) GetByChain(c Chain) *PoolPubKey

GetByChain get PoolPubKey by chain,

func (PoolPubKeys) IsEmpty

func (poolPubKeys PoolPubKeys) IsEmpty() bool

IsEmpty when there is no item in the list

func (PoolPubKeys) String

func (poolPubKeys PoolPubKeys) String() string

Stringer implementation

func (PoolPubKeys) TryAddKey

func (poolPubKeys PoolPubKeys) TryAddKey(k *PoolPubKey) PoolPubKeys

TryAddKey trying to add the given pool pubkey into the list,if it already exist ,then we just return the list

func (PoolPubKeys) TryRemoveKey

func (poolPubKeys PoolPubKeys) TryRemoveKey(k *PoolPubKey) PoolPubKeys

TryRemoveKey trying to remove the given key from the list

type PubKey

type PubKey string

PubKey used in statechain, it should be bech32 encoded string thus it will be something like thorpub1addwnpepqt7qug8vk9r3saw8n4r803ydj2g3dqwx0mvq5akhnze86fc536xcy2cr8a2 thorpub1addwnpepqdqvd4r84lq9m54m5kk9sf4k6kdgavvch723pcgadulxd6ey9u70kgjgrwl

var EmptyPubKey PubKey

EmptyPubKey

func NewPubKey

func NewPubKey(key string) (PubKey, error)

NewPubKey create a new instance of PubKey key is bech32 encoded string

func NewPubKeyFromCrypto

func NewPubKeyFromCrypto(pk crypto.PubKey) (PubKey, error)

NewPubKeyFromCrypto

func (PubKey) Equals

func (pubKey PubKey) Equals(pubKey1 PubKey) bool

Equals check whether two are the same

func (PubKey) GetAddress

func (pubKey PubKey) GetAddress(chain Chain) (Address, error)

GetAddress will return an address for the given chain

func (PubKey) GetThorAddress

func (pubKey PubKey) GetThorAddress() (sdk.AccAddress, error)

func (PubKey) IsEmpty

func (pubKey PubKey) IsEmpty() bool

IsEmpty to check whether it is empty

func (PubKey) MarshalJSON

func (pubKey PubKey) MarshalJSON() ([]byte, error)

MarshalJSON to Marshals to JSON using Bech32

func (PubKey) String

func (pubKey PubKey) String() string

String stringer implementation

func (*PubKey) UnmarshalJSON

func (pubKey *PubKey) UnmarshalJSON(data []byte) error

UnmarshalJSON to Unmarshal from JSON assuming Bech32 encoding

type PubKeys

type PubKeys struct {
	Secp256k1 PubKey `json:"secp256k1"`
	Ed25519   PubKey `json:"ed25519"`
}

PubKeys contains two pub keys , secp256k1 and ed25519

var EmptyPubKeys PubKeys

EmptyPubKeys

func NewPubKeys

func NewPubKeys(secp256k1, ed25519 PubKey) PubKeys

NewPubKeys create a new instance of PubKeys , which contains two keys

func (PubKeys) Equals

func (pks PubKeys) Equals(pks1 PubKeys) bool

Equals check whether two PubKeys are the same

func (PubKeys) GetAddress

func (pks PubKeys) GetAddress(chain Chain) (Address, error)

GetAddress

func (PubKeys) IsEmpty

func (pks PubKeys) IsEmpty() bool

IsEmpty will determinate whether PubKeys is an empty

func (PubKeys) String

func (pks PubKeys) String() string

String implement fmt.Stinger

type Symbol

type Symbol string

func NewSymbol

func NewSymbol(input string) (Symbol, error)

func (Symbol) Equals

func (s Symbol) Equals(s2 Symbol) bool

func (Symbol) IsEmpty

func (s Symbol) IsEmpty() bool

func (Symbol) String

func (s Symbol) String() string

func (Symbol) Ticker

func (s Symbol) Ticker() Ticker

type Ticker

type Ticker string

func NewTicker

func NewTicker(ticker string) (Ticker, error)

func (Ticker) Equals

func (t Ticker) Equals(t2 Ticker) bool

func (Ticker) IsEmpty

func (t Ticker) IsEmpty() bool

func (Ticker) String

func (t Ticker) String() string

type Tickers

type Tickers []Ticker

type Tx

type Tx struct {
	ID          TxID    `json:"id"`
	Chain       Chain   `json:"chain"`
	FromAddress Address `json:"from_address"`
	ToAddress   Address `json:"to_address"`
	Coins       Coins   `json:"coins"`
	Memo        string  `json:"memo"`
}

func GetRagnarokTx

func GetRagnarokTx(chain Chain) Tx

func NewTx

func NewTx(txID TxID, from Address, to Address, coins Coins, memo string) Tx

func (Tx) IsEmpty

func (tx Tx) IsEmpty() bool

func (Tx) IsValid

func (tx Tx) IsValid() error

type TxID

type TxID string

func NewTxID

func NewTxID(hash string) (TxID, error)

func (TxID) Equals

func (tx TxID) Equals(tx2 TxID) bool

func (TxID) IsEmpty

func (tx TxID) IsEmpty() bool

func (TxID) String

func (tx TxID) String() string

type TxIDs

type TxIDs []TxID

type Txs

type Txs []Tx

Jump to

Keyboard shortcuts

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