Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertAndEncode(hrp string, data []byte) (string, error)
- func CosmosPrivateKeyToTMPrivateKey(privateKey cryptotypes.PrivKey) crypto.PrivKey
- func Decrypt(data []byte, passphrase string) ([]byte, error)
- func Encrypt(data []byte, passphrase string) ([]byte, error)
- func GetSafeShare(part, total, allocation cosmos.Uint) cosmos.Uint
- func GetUncappedShare(part, total, allocation cosmos.Uint) (share cosmos.Uint)
- func RandStringBytesMask(n int) string
- func SafeSub(input1, input2 cosmos.Uint) cosmos.Uint
- func Sign(buf []byte) ([]byte, []byte, error)
- func SignBase64(buf []byte) (string, string, error)
- type Account
- type Address
- func (addr Address) AccAddress() (cosmos.AccAddress, error)
- func (addr Address) Equals(addr2 Address) bool
- func (addr Address) GetChain() Chain
- func (addr Address) GetNetwork(ver semver.Version, chain Chain) ChainNetwork
- func (addr Address) IsChain(chain Chain) bool
- func (addr Address) IsEmpty() bool
- func (addr Address) IsNoop() bool
- func (addr Address) IsValidBCHAddress() bool
- func (addr Address) String() string
- type Chain
- func (c Chain) AddressPrefix(cn ChainNetwork) string
- func (c Chain) Equals(c2 Chain) bool
- func (c Chain) GetGasAsset() Asset
- func (c Chain) GetGasAssetDecimal() int64
- func (c Chain) GetGasUnits() string
- func (c Chain) GetSigningAlgo() SigningAlgo
- func (c Chain) IsBNB() bool
- func (c Chain) IsEVM() bool
- func (c Chain) IsEmpty() bool
- func (c Chain) IsTHORChain() bool
- func (c Chain) IsValidAddress(addr Address) bool
- func (c Chain) String() string
- func (c Chain) Validate() error
- type ChainNetwork
- type ChainPoolInfo
- type Chains
- type Coins
- func (cs Coins) Add(coin Coin) Coins
- func (cs Coins) Adds(coins Coins) Coins
- func (cs Coins) Contains(c Coin) bool
- func (cs Coins) Distinct() Coins
- func (cs Coins) Equals(cs2 Coins) bool
- func (cs Coins) EqualsEx(cs2 Coins) bool
- func (cs Coins) GetCoin(asset Asset) Coin
- func (cs Coins) HasNoneNativeRune() bool
- func (cs Coins) HasSynthetic() bool
- func (cs Coins) IsEmpty() bool
- func (cs Coins) Native() (cosmos.Coins, error)
- func (cs Coins) NoneEmpty() Coins
- func (cs Coins) String() string
- func (cs Coins) Valid() error
- type Duration
- type Gas
- type NodeRelay
- type NodeRelayMsg
- type PubKey
- func (pubKey PubKey) EVMPubkeyToAddress() (Address, error)
- func (pubKey PubKey) Equals(pubKey1 PubKey) bool
- func (pubKey PubKey) GetAddress(chain Chain) (Address, error)
- func (pubKey PubKey) GetThorAddress() (cosmos.AccAddress, error)
- func (pubKey PubKey) IsEmpty() bool
- func (pubKey PubKey) MarshalJSON() ([]byte, error)
- func (pubKey PubKey) String() string
- func (pubKey *PubKey) UnmarshalJSON(data []byte) error
- type PubKeys
- type SigningAlgo
- type Symbol
- type Ticker
- type Tickers
- type TxID
- type TxIDs
- type Txs
Constants ¶
const ( NoAddress = Address("") NoopAddress = Address("noop") )
const ( // BNBSymbol BNB BNBSymbol = Symbol("BNB") // Rune67CSymbol RUNE on binance testnet Rune67CSymbol = Symbol("RUNE-67C") // RuneB1ASymbol RUNE on binance mainnet RuneB1ASymbol = Symbol("RUNE-B1A") )
const ( // BNBTicker BNB BNBTicker = Ticker("BNB") // RuneTicker RUNE RuneTicker = Ticker("RUNE") )
const One = 100000000
One is useful type so THORNode doesn't need to manage 8 zeroes all the time
const THORChainDecimals = 8
THORChainDecimals indicate the number of decimal points used in THORChain
Variables ¶
var ( // EmptyAsset empty asset, not valid EmptyAsset = Asset{Chain: EmptyChain, Symbol: "", Ticker: "", Synth: false} // LUNAAsset LUNA LUNAAsset = Asset{Chain: TERRAChain, Symbol: "LUNA", Ticker: "LUNA", Synth: false} // ATOMAsset ATOM ATOMAsset = Asset{Chain: GAIAChain, Symbol: "ATOM", Ticker: "ATOM", Synth: false} // BNBAsset BNB BNBAsset = Asset{Chain: BNBChain, Symbol: "BNB", Ticker: "BNB", Synth: false} // BTCAsset BTC BTCAsset = Asset{Chain: BTCChain, Symbol: "BTC", Ticker: "BTC", Synth: false} // LTCAsset BTC LTCAsset = Asset{Chain: LTCChain, Symbol: "LTC", Ticker: "LTC", Synth: false} // BCHAsset BCH BCHAsset = Asset{Chain: BCHChain, Symbol: "BCH", Ticker: "BCH", Synth: false} // DOGEAsset DOGE DOGEAsset = Asset{Chain: DOGEChain, Symbol: "DOGE", Ticker: "DOGE", Synth: false} // ETHAsset ETH ETHAsset = Asset{Chain: ETHChain, Symbol: "ETH", Ticker: "ETH", Synth: false} // AVAXAsset AVAX AVAXAsset = Asset{Chain: AVAXChain, Symbol: "AVAX", Ticker: "AVAX", Synth: false} // Rune67CAsset RUNE on Binance test net Rune67CAsset = Asset{Chain: BNBChain, Symbol: "RUNE-67C", Ticker: "RUNE", Synth: false} // testnet asset on binance ganges // RuneB1AAsset RUNE on Binance main net RuneB1AAsset = Asset{Chain: BNBChain, Symbol: "RUNE-B1A", Ticker: "RUNE", Synth: false} // mainnet // RuneNative RUNE on thorchain RuneNative = Asset{Chain: THORChain, Symbol: "RUNE", Ticker: "RUNE", Synth: false} RuneERC20Asset = Asset{Chain: ETHChain, Symbol: "RUNE-0x3155ba85d5f96b2d030a4966af206230e46849cb", Ticker: "RUNE", Synth: false} RuneERC20TestnetAsset = Asset{Chain: ETHChain, Symbol: "RUNE-0xd601c6A3a36721320573885A8d8420746dA3d7A0", Ticker: "RUNE", Synth: false} )
var ( EmptyChain = Chain("") BNBChain = Chain("BNB") ETHChain = Chain("ETH") BTCChain = Chain("BTC") LTCChain = Chain("LTC") BCHChain = Chain("BCH") DOGEChain = Chain("DOGE") THORChain = Chain("THOR") TERRAChain = Chain("TERRA") GAIAChain = Chain("GAIA") AVAXChain = Chain("AVAX") SigningAlgoSecp256k1 = SigningAlgo("secp256k1") SigningAlgoEd25519 = SigningAlgo("ed25519") )
var BNBGasFeeMulti = Gas{ {Asset: BNBAsset, Amount: bnbMultiTxFee}, }
BNBGasFeeMulti gas fee for multi send
var BNBGasFeeSingleton = Gas{ {Asset: BNBAsset, Amount: bnbSingleTxFee}, }
BNBGasFeeSingleton fee charged by Binance for transfer with a single coin
var BlankTxID = TxID("0000000000000000000000000000000000000000000000000000000000000000")
BlankTxID represent blank
var ETHGasFeeTransfer = Gas{ {Asset: ETHAsset, Amount: ethTransferFee}, }
ETHGasFeeTransfer gas fee for ETH
var LatestVersion semver.Version = semver.MustParse("999.0.0")
var NoCoin = Coin{ Asset: EmptyAsset, Amount: cosmos.ZeroUint(), }
NoCoin is empty Coin
Functions ¶
func ConvertAndEncode ¶
ConvertAndEncode converts from a base64 encoded byte string to hex or base32 encoded byte string and then to bech32
func CosmosPrivateKeyToTMPrivateKey ¶ added in v0.41.0
func CosmosPrivateKeyToTMPrivateKey(privateKey cryptotypes.PrivKey) crypto.PrivKey
CosmosPrivateKeyToTMPrivateKey convert cosmos implementation of private key to tendermint private key
func GetSafeShare ¶ added in v0.63.0
GetSafeShare does the same as GetUncappedShare , but GetSafeShare will guarantee the result will not more than total
func GetUncappedShare ¶ added in v1.93.0
GetUncappedShare this method will panic if any of the input parameter can't be convert to cosmos.Dec which shouldn't happen
func RandStringBytesMask ¶
RandStringBytesMask generate random string used for test purpose
func SafeSub ¶
SafeSub subtract input2 from input1, given cosmos.Uint can't be negative , otherwise it will panic thus in this method,when input2 is larger than input 1, it will just return cosmos.ZeroUint
Types ¶
type Address ¶
type Address string
func ConvertToNewBCHAddressFormat ¶ added in v0.54.0
ConvertToNewBCHAddressFormat convert the given BCH to new address format
func ConvertToNewBCHAddressFormatV83 ¶ added in v1.83.0
ConvertToNewBCHAddressFormatV83 convert the given BCH to new address format
func NewAddress ¶
NewAddress create a new Address. Supports Binance, Bitcoin, and Ethereum
func (Address) AccAddress ¶ added in v0.41.0
func (addr Address) AccAddress() (cosmos.AccAddress, error)
func (Address) GetNetwork ¶ added in v0.54.0
func (addr Address) GetNetwork(ver semver.Version, chain Chain) ChainNetwork
func (Address) IsValidBCHAddress ¶ added in v0.54.0
IsValidBCHAddress determinate whether the address is a valid new BCH address format
type Chain ¶
type Chain string
Chain is an alias of string , represent a block chain
func GetEVMChains ¶ added in v1.95.0
func GetEVMChains() []Chain
GetEVMChains returns all "EVM" chains connected to THORChain "EVM" is defined, in thornode's context, as a chain that: - uses 0x as an address prefix - has a "Router" Smart Contract
func (Chain) AddressPrefix ¶
func (c Chain) AddressPrefix(cn ChainNetwork) string
AddressPrefix return the address prefix used by the given network (testnet/mainnet)
func (Chain) GetGasAssetDecimal ¶ added in v0.80.0
GetGasAssetDecimal for the gas asset of given chain , what kind of precision it is using TERRA and GAIA are using 1E6, all other gas asset so far using 1E8 THORChain is using 1E8, if an external chain's gas asset is larger than 1E8, just return cosmos.DefaultCoinDecimals
func (Chain) GetGasUnits ¶ added in v1.97.0
GetGasUnits returns name of the gas unit for each chain
func (Chain) GetSigningAlgo ¶
func (c Chain) GetSigningAlgo() SigningAlgo
GetSigningAlgo get the signing algorithm for the given chain
func (Chain) IsEVM ¶ added in v1.95.0
IsEVM returns true if given chain is an EVM chain. See working definition of an "EVM" chain in the `GetEVMChains` function description
func (Chain) IsTHORChain ¶ added in v0.41.0
func (Chain) IsValidAddress ¶ added in v0.54.0
IsValidAddress make sure the address is correct for the chain And this also make sure testnet doesn't use mainnet address vice versa
type ChainNetwork ¶
type ChainNetwork uint8
ChainNetwork is to indicate which chain environment THORNode are working with
const ( // TestNet network for test TestNet ChainNetwork = iota // MainNet network for main net MainNet // MockNet network for main net MockNet // Stagenet network for stage net StageNet )
func GetCurrentChainNetwork ¶
func GetCurrentChainNetwork() ChainNetwork
GetCurrentChainNetwork determinate what kind of network currently it is working with
func (ChainNetwork) SoftEquals ¶ added in v0.54.0
func (net ChainNetwork) SoftEquals(net2 ChainNetwork) bool
Soft Equals check is mainnet == mainet, or (testnet/mocknet == testnet/mocknet)
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
Chains represent a slice of Chain
type Coins ¶
type Coins []Coin
Coins represent a slice of Coin
func NewCoins ¶ added in v0.41.0
func NewCoins(coins ...Coin) Coins
NewCoins create a new Coins structure
func (Coins) Adds ¶ added in v0.41.0
This overwrites cs by changing its slice-referenced values, so it is recommended to use destination := make(Coins, len(source)) and copy(destination, source) first.
func (Coins) Distinct ¶ added in v0.41.0
Distinct return a new Coins ,which duplicated coins had been removed
func (Coins) Equals ¶
Equals Check if two lists of coins are equal to each other. Order does not matter This method has side effect because it uses sort.Slice on the input parameter which will potentially change the order of cs1 & cs2 Note: quite a few places already using this method , which can't be changed, otherwise it will cause consensus failure on CHAOSNET Deprecated
func (Coins) EqualsEx ¶ added in v0.65.0
EqualsEx Check if two lists of coins are equal to each other. This method will make a copy of cs1 & cs2 , thus the original coins order will not be changed
func (Coins) GetCoin ¶
func (cs Coins) GetCoin(asset Asset) Coin
GetCoin gets a specific coin by asset. Assumes there is only one of this coin in the list.
func (Coins) HasNoneNativeRune ¶ added in v0.41.0
HasNoneNativeRune check whether the coins contains NoneNativeRUNE
At the moment, there are BEP2 RUNE, ERC20 RUNE and Native RUNE
func (Coins) HasSynthetic ¶ added in v0.55.0
HasSynthetic check whether the coins contains synth coin
type Duration ¶
Duration embedded time.Duration so THORNode could use string to represent duration in json file for example ,1s ,1h , 5m etc
func (Duration) MarshalJSON ¶
MarshalJSON marshal the duration to json string
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON convert the json value back to time.Duration
type Gas ¶
type Gas Coins
Gas coins
func CalcBinanceGasPrice ¶
CalcBinanceGasPrice calculate gas price for Binance chain
func GetAVAXGasFee ¶ added in v1.95.0
GetAVAXGasFee return the gas for AVAX
func GetETHGasFee ¶
GetETHGasFee return the gas for ETH
func MakeAVAXGas ¶ added in v1.95.0
MakeAVAXGas return the gas for AVAX
func MakeETHGas ¶
MakeETHGas return the gas for ETH
func (Gas) Add ¶
Add combines two gas objects into one, adding amounts where needed or appending new coins.
func (Gas) Equals ¶
Equals Check if two lists of coins are equal to each other. Order does not matter
type NodeRelay ¶ added in v0.65.0
type NodeRelay struct { Msg NodeRelayMsg `json:"msg"` Signature string `json:"signature"` PubKey string `json:"pubkey"` }
func NewNodeRelay ¶ added in v0.65.0
type NodeRelayMsg ¶ added in v0.65.0
type PubKey ¶
type PubKey string
PubKey used in thorchain, it should be bech32 encoded string thus it will be something like tthorpub1addwnpepqt7qug8vk9r3saw8n4r803ydj2g3dqwx0mvq5akhnze86fc536xcycgtrnv tthorpub1addwnpepqdqvd4r84lq9m54m5kk9sf4k6kdgavvch723pcgadulxd6ey9u70k6zq8qe
var EmptyPubKey PubKey
func NewPubKeyFromCrypto ¶
NewPubKeyFromCrypto
func (PubKey) EVMPubkeyToAddress ¶ added in v1.95.0
EVMPubkeyToAddress converts a pubkey of an EVM chain to the corresponding address
func (PubKey) GetAddress ¶
GetAddress will return an address for the given chain
func (PubKey) GetThorAddress ¶
func (pubKey PubKey) GetThorAddress() (cosmos.AccAddress, error)
func (PubKey) MarshalJSON ¶
MarshalJSON to Marshals to JSON using Bech32
func (*PubKey) UnmarshalJSON ¶
UnmarshalJSON to Unmarshal from JSON assuming Bech32 encoding
type PubKeys ¶
type PubKeys []PubKey
PubKey used in thorchain, it should be bech32 encoded string thus it will be something like tthorpub1addwnpepqt7qug8vk9r3saw8n4r803ydj2g3dqwx0mvq5akhnze86fc536xcycgtrnv tthorpub1addwnpepqdqvd4r84lq9m54m5kk9sf4k6kdgavvch723pcgadulxd6ey9u70k6zq8qe
type SigningAlgo ¶ added in v1.83.0
type SigningAlgo string
type Symbol ¶
type Symbol string
Symbol represent an asset
func (Symbol) IsMiniToken ¶
IsMiniToken is to determine whether it is a mini token on binance chain
type Ticker ¶
type Ticker string
Ticker The trading 'symbol' or shortened name (typically in capital letters) that refer to a coin on a trading platform. For example: BNB
func NewTicker ¶
NewTicker parse the given string as ticker, return error if it is not legitimate ticker