cross

package
v3.1.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: ISC Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Entangle Transcation type
	ExpandedTxEntangle_Doge = 0xF0
	ExpandedTxEntangle_Ltc  = 0xF1
	ExpandedTxEntangle_Btc  = 0xF2
	ExpandedTxEntangle_Bsv  = 0xF3
	ExpandedTxEntangle_Bch  = 0xF4
)
View Source
const (
	LhAssetBTC uint32 = 1 << iota
	LhAssetBCH
	LhAssetBSV
	LhAssetLTC
	LhAssetUSDT
	LhAssetDOGE
)

Variables

View Source
var (
	ErrInvalidMsgLen       = errors.New("invalid message length, need 32 bytes")
	ErrInvalidSignatureLen = errors.New("invalid signature length")
	ErrInvalidRecoveryID   = errors.New("invalid signature recovery id")
	ErrInvalidKey          = errors.New("invalid private key")
	ErrInvalidPubkey       = errors.New("invalid public key")
	ErrSignFailed          = errors.New("signing failed")
	ErrRecoverFailed       = errors.New("recovery failed")
	ErrCryptoType          = errors.New("invalid crypto type")
)
View Source
var (
	NoEntangle           = errors.New("no entangle info in transcation")
	NoBeaconRegistration = errors.New("no BeaconRegistration info in transcation")
	NoAddBeaconPledge    = errors.New("no AddBeaconPledge info in transcation")
)
View Source
var (
	ErrInvalidParam       = errors.New("Invalid Param")
	ErrLessThanMin        = errors.New("less than min staking amount for beaconAddress")
	ErrRepeatRegister     = errors.New("repeat register on this address")
	ErrNotRepeatRegister  = errors.New("repeat not register on this address")
	ErrRepeatToAddress    = errors.New("repeat to Address on this register")
	ErrNoRegister         = errors.New("not found the beaconAddress")
	ErrAddressInWhiteList = errors.New("the address in the whitelist")
	ErrNoUserReg          = errors.New("not entangle user in the beaconAddress")
	ErrNoUserAsset        = errors.New("user no entangle asset in the beaconAddress")
	ErrNotEnouthBurn      = errors.New("not enough burn amount in beaconAddress")
	ErrNotMatchUser       = errors.New("cann't find user address")
	ErrBurnProof          = errors.New("burn proof info not match")
	ErrStakingNotEnough   = errors.New("staking not enough")
)
View Source
var (
	MinStakingAmountForBeaconAddress  = new(big.Int).Mul(big.NewInt(1000000), big.NewInt(1e8))
	MaxWhiteListCount                 = 4
	MAXBASEFEE                        = 100000
	MAXFREEQUOTA                      = 100000 // about 30 days
	LimitRedeemHeightForBeaconAddress = 5000
	MaxCoinBase                       = 4
)
View Source
var (
	BucketKey        = []byte("entangle-tx")
	EntangleStateKey = []byte("entanglestate")
)
View Source
var (
	ErrHeightTooClose = errors.New("the block heigth to close for entangling")
)

Functions

func CheckTransactionisBlock

func CheckTransactionisBlock(txhash string, block *rpcclient.DogecoinMsgBlock) bool

func ComputeDiff

func ComputeDiff(params *chaincfg.Params, target *big.Int, address czzutil.Address, eState *EntangleState) *big.Int

func EnoughAmount

func EnoughAmount(reserve int64, items []*EntangleItem, keepInfo *KeepedAmount, fork bool) bool

func GetMaxHeight

func GetMaxHeight(items map[uint32]*EntangleTxInfo) uint64

func Hash

func Hash(es *EntangleState) chainhash.Hash

func IsEntangleTx

func IsEntangleTx(tx *wire.MsgTx) (map[uint32]*EntangleTxInfo, error)

func IsSendToZeroAddress

func IsSendToZeroAddress(PkScript []byte) (bool, error)

func MakeAddress

func MakeAddress(puk ecdsa.PublicKey) (error, czzutil.Address)

func MakeEntangleTx

func MakeEntangleTx(params *chaincfg.Params, inputs []*wire.TxIn, feeRate, inAmount czzutil.Amount,
	changeAddr czzutil.Address, info *EntangleTxInfo) (*wire.MsgTx, error)

func MakeMergeCoinbaseTx

func MakeMergeCoinbaseTx(tx *wire.MsgTx, pool *PoolAddrItem, items []*EntangleItem,
	lastScriptInfo []byte, fork bool) error

func MakeMergerCoinbaseTx2

func MakeMergerCoinbaseTx2(height *big.Int, tx *wire.MsgTx, items []*EntangleItem2, state *EntangleState) error

func OverEntangleAmount

func OverEntangleAmount(tx *wire.MsgTx, pool *PoolAddrItem, items []*EntangleItem,
	lastScriptInfo []byte, fork bool, state *EntangleState) bool

func PreCalcEntangleAmount

func PreCalcEntangleAmount(item *EntangleItem, keepInfo *KeepedAmount, fork bool)

func RecoverPublicFromBytes

func RecoverPublicFromBytes(pub []byte, t ExpandedTxType) (*ecdsa.PublicKey, error)

RecoverPublic returns the public key of the marshal bytes.

func SignEntangleTx

func SignEntangleTx(tx *wire.MsgTx, inputAmount []czzutil.Amount,
	priv *czzec.PrivateKey) error

func SummayPunishedInfos

func SummayPunishedInfos(infos map[uint64]UserTimeOutBurnInfo) map[uint64]LHPunishedItems

func UnmarshalPubkey1

func UnmarshalPubkey1(pub []byte) (*ecdsa.PublicKey, error)

UnmarshalPubkey converts bytes to a secp256k1 public key.

func ValidAssetType

func ValidAssetType(utype uint32) bool

///////////////////////////////////////////////////////////////

func ValidPK

func ValidPK(pk []byte) bool

func VerifyTxsSequence

func VerifyTxsSequence(infos []*EtsInfo) error

Types

type AddBeaconPledge

type AddBeaconPledge struct {
	Address       string   `json:"address"`
	ToAddress     []byte   `json:"to_address"`
	StakingAmount *big.Int `json:"staking_amount"`
}

func AddBeaconPledgeTxFromScript

func AddBeaconPledgeTxFromScript(script []byte) (*AddBeaconPledge, error)

func IsAddBeaconPledgeTx

func IsAddBeaconPledgeTx(tx *wire.MsgTx, params *chaincfg.Params) (*AddBeaconPledge, error)

type BaseAmountUint

type BaseAmountUint struct {
	AssetType uint32   `json:"asset_type"`
	Amount    *big.Int `json:"amount"`
}

type BeaconAddressInfo

type BeaconAddressInfo struct {
	ExchangeID      uint64           `json:"exchange_id"`
	Address         string           `json:"address"`
	ToAddress       []byte           `json:"toAddress"`
	StakingAmount   *big.Int         `json:"staking_amount"`  // in
	EntangleAmount  *big.Int         `json:"entangle_amount"` // out,express by czz,all amount of user's entangle
	EnAssets        []*EnAssetItem   `json:"en_assets"`       // out,the extrinsic asset
	Frees           []*FreeQuotaItem `json:"frees"`           // extrinsic asset
	AssetFlag       uint32           `json:"asset_flag"`
	Fee             uint64           `json:"fee"`
	KeepTime        uint64           `json:"keep_time"` // the time as the block count for finally redeem time
	WhiteList       []*WhiteUnit     `json:"white_list"`
	CoinBaseAddress []string         `json:"CoinBaseAddress"`
}

func BeaconRegistrationTxFromScript

func BeaconRegistrationTxFromScript(script []byte) (*BeaconAddressInfo, error)

Beacon

func IsBeaconRegistrationTx

func IsBeaconRegistrationTx(tx *wire.MsgTx, params *chaincfg.Params) (*BeaconAddressInfo, error)

type BurnInfos

type BurnInfos struct {
	Items      []*BurnItem
	RAllAmount *big.Int // redeem asset for outside asset by burned czz
	BAllAmount *big.Int // all burned asset on czz by the account
}

func (*BurnInfos) GetAllAmountByOrigin

func (b *BurnInfos) GetAllAmountByOrigin() *big.Int

GetAllAmountByOrigin returns all burned amount asset (czz)

func (*BurnInfos) GetAllBurnedAmountByOutside

func (b *BurnInfos) GetAllBurnedAmountByOutside() *big.Int

type BurnItem

type BurnItem struct {
	Amount      *big.Int `json:"amount"`  // czz asset amount
	RAmount     *big.Int `json:"ramount"` // outside asset amount
	Height      uint64   `json:"height"`
	RedeemState byte     `json:"redeem_state"` // 0--init, 1 -- redeem done by BeaconAddress payed,2--punishing,3-- punished
}

type BurnProofInfo

type BurnProofInfo struct {
	LightID uint64
	Height  uint64
	Amount  *big.Int
	Address czzutil.Address
	Atype   uint32
	TxHash  []byte
}

type BurnTxInfo

type BurnTxInfo struct {
	ExTxType ExpandedTxType
	Address  string
	LightID  uint64
	Amount   *big.Int
}

func BurnInfoFromScript

func BurnInfoFromScript(script []byte) (*BurnTxInfo, error)

func IsBurnTx

func IsBurnTx(tx *wire.MsgTx) (*BurnTxInfo, error)

func (*BurnTxInfo) DecodeRLP

func (es *BurnTxInfo) DecodeRLP(s *rlp.Stream) error

func (*BurnTxInfo) EncodeRLP

func (es *BurnTxInfo) EncodeRLP(w io.Writer) error

type CacheEntangleInfo

type CacheEntangleInfo struct {
	DB database.DB
}

func (*CacheEntangleInfo) FetchEntangleUtxoView

func (c *CacheEntangleInfo) FetchEntangleUtxoView(info *EntangleTxInfo) bool

func (*CacheEntangleInfo) LoadEntangleState

func (c *CacheEntangleInfo) LoadEntangleState(height int32, hash chainhash.Hash) *EntangleState

type EnAssetItem

type EnAssetItem BaseAmountUint

type EntangleEntity

type EntangleEntity struct {
	ExchangeID      uint64     `json:"exchange_id"`
	Address         string     `json:"address"`
	AssetType       uint32     `json:"asset_type"`
	Height          *big.Int   `json:"height"`            // newest height for entangle
	OldHeight       *big.Int   `json:"old_height"`        // oldest height for entangle
	EnOutsideAmount *big.Int   `json:"en_outside_amount"` // out asset
	OriginAmount    *big.Int   `json:"origin_amount"`     // origin asset(czz) by entangle in
	MaxRedeem       *big.Int   `json:"max_redeem"`        // out asset
	BurnAmount      *BurnInfos `json:"burn_amount"`
}

/////////////////////////////////////////////////////////////// Address > EntangleEntity

func (*EntangleEntity) GetValidRedeemAmount

func (e *EntangleEntity) GetValidRedeemAmount() *big.Int

the returns maybe negative

type EntangleEntitys

type EntangleEntitys []*EntangleEntity

type EntangleItem

type EntangleItem struct {
	EType ExpandedTxType
	Value *big.Int
	Addr  czzutil.Address
}

func ToEntangleItems

func ToEntangleItems(txs []*czzutil.Tx, addrs map[chainhash.Hash][]*TmpAddressPair) []*EntangleItem

func (*EntangleItem) Clone

func (ii *EntangleItem) Clone() *EntangleItem

type EntangleItem2

type EntangleItem2 struct {
	EType ExpandedTxType
	Value *big.Int
	Addr  czzutil.Address
	BID   uint64
}

func (*EntangleItem2) Clone

func (ii *EntangleItem2) Clone() *EntangleItem2

type EntangleState

type EntangleState struct {
	EnInfos       map[string]*BeaconAddressInfo
	EnEntitys     map[uint64]UserEntangleInfos
	PoolAmount1   *big.Int
	PoolAmount2   *big.Int
	CurExchangeID uint64
}

func NewEntangleState

func NewEntangleState() *EntangleState

func (*EntangleState) AddEntangleItem

func (es *EntangleState) AddEntangleItem(addr string, aType uint32, lightID uint64,
	height, amount *big.Int) (*big.Int, error)

AddEntangleItem add item in the state, keep BeaconAddress have enough amount to entangle,

func (*EntangleState) AddPoolAmount

func (es *EntangleState) AddPoolAmount(amount1, amount2 *big.Int)

func (*EntangleState) AddressInWhiteList

func (es *EntangleState) AddressInWhiteList(addr string, self bool) bool

func (*EntangleState) AppendAmountForBeaconAddress

func (es *EntangleState) AppendAmountForBeaconAddress(addr string, amount *big.Int) error

func (*EntangleState) AppendCoinbase

func (es *EntangleState) AppendCoinbase(addr string, coinbases []string) error

func (*EntangleState) AppendWhiteList

func (es *EntangleState) AppendWhiteList(addr string, wlist []*WhiteUnit) error

func (*EntangleState) BurnAsset

func (es *EntangleState) BurnAsset(addr string, aType uint32, lightID, height uint64,
	amount *big.Int) (*big.Int, error)

BurnAsset user burn the czz asset to exchange the outside asset,the caller keep the burn was true. verify the txid,keep equal amount czz returns the amount czz by user's burnned, took out fee by beaconaddress

func (*EntangleState) DecodeRLP

func (es *EntangleState) DecodeRLP(s *rlp.Stream) error

func (*EntangleState) EncodeRLP

func (es *EntangleState) EncodeRLP(w io.Writer) error

func (*EntangleState) FinishBeaconAddressPunished

func (es *EntangleState) FinishBeaconAddressPunished(eid uint64, amount *big.Int) error

func (*EntangleState) FinishHandleUserBurn

func (es *EntangleState) FinishHandleUserBurn(lightID, height uint64, addr czzutil.Address, atype uint32, amount *big.Int) error

FinishHandleUserBurn the BeaconAddress finish the burn item

func (*EntangleState) GetCoinbase

func (es *EntangleState) GetCoinbase(addr string) []string

func (*EntangleState) LimitStakingAmount

func (es *EntangleState) LimitStakingAmount(eid uint64, atype uint32) *big.Int

Minimum pledge amount = 1 million CZZ + (cumulative cross-chain buying CZZ - cumulative cross-chain selling CZZ) x exchange rate ratio

func (*EntangleState) Load

func (es *EntangleState) Load() error

func (*EntangleState) RegisterBeaconAddress

func (es *EntangleState) RegisterBeaconAddress(addr string, to []byte, amount *big.Int,
	fee, keeptime uint64, assetType uint32, wu []*WhiteUnit, cba []string) error

/////////////////////////////////////////////////////////////// keep staking enough amount asset

func (*EntangleState) Save

func (es *EntangleState) Save() error

func (*EntangleState) SetInitPoolAmount

func (es *EntangleState) SetInitPoolAmount(amount1, amount2 *big.Int)

func (*EntangleState) SubPoolAmount1

func (es *EntangleState) SubPoolAmount1(amount *big.Int)

func (*EntangleState) SubPoolAmount2

func (es *EntangleState) SubPoolAmount2(amount *big.Int)

func (*EntangleState) ToBytes

func (es *EntangleState) ToBytes() []byte

func (*EntangleState) TourAllUserBurnInfo

func (es *EntangleState) TourAllUserBurnInfo(height uint64) map[uint64]UserTimeOutBurnInfo

TourAllUserBurnInfo Tours all user's burned asset and check which is timeout to redeem

func (*EntangleState) UnregisterBeaconAddress

func (es *EntangleState) UnregisterBeaconAddress(addr string) error

UnregisterBeaconAddress need to check all the proves and handle all the user's burn coins

func (*EntangleState) UpdateCfgForBeaconAddress

func (es *EntangleState) UpdateCfgForBeaconAddress(addr string, fee, keeptime uint64, assetType uint32) error

func (*EntangleState) UpdateCoinbase

func (es *EntangleState) UpdateCoinbase(addr, update, newAddr string) error

func (*EntangleState) UpdateQuotaOnBlock

func (es *EntangleState) UpdateQuotaOnBlock(height uint64) error

//////////////////////////////////////////////////////////////////// UpdateQuotaOnBlock called in insertBlock for update user's quota state

func (*EntangleState) UpdateStateToPunished

func (es *EntangleState) UpdateStateToPunished(infos map[uint64]UserTimeOutBurnInfo)

type EntangleTxInfo

type EntangleTxInfo struct {
	ExTxType  ExpandedTxType
	Index     uint32
	Height    uint64
	Amount    *big.Int
	ExtTxHash []byte
}

func EntangleTxFromScript

func EntangleTxFromScript(script []byte) (*EntangleTxInfo, error)

func (*EntangleTxInfo) Parse

func (info *EntangleTxInfo) Parse(data []byte) error

func (*EntangleTxInfo) Serialize

func (info *EntangleTxInfo) Serialize() []byte

type EntangleVerify

type EntangleVerify struct {
	DogeCoinRPC []*rpcclient.Client
	LtcCoinRPC  []*rpcclient.Client
	Cache       *CacheEntangleInfo
	Params      *chaincfg.Params
}

func (*EntangleVerify) VerifyAddBeaconPledgeTx

func (ev *EntangleVerify) VerifyAddBeaconPledgeTx(tx *wire.MsgTx, eState *EntangleState) (*AddBeaconPledge, error)

func (*EntangleVerify) VerifyBeaconRegistrationTx

func (ev *EntangleVerify) VerifyBeaconRegistrationTx(tx *wire.MsgTx, eState *EntangleState) (*BeaconAddressInfo, error)

func (*EntangleVerify) VerifyEntangleTx

func (ev *EntangleVerify) VerifyEntangleTx(tx *wire.MsgTx) ([]*TuplePubIndex, error)

type EtsInfo

type EtsInfo struct {
	FeePerKB int64
	Tx       *wire.MsgTx
}

entangle tx Sequence infomation

type ExpandedTxType

type ExpandedTxType uint8

type FreeQuotaItem

type FreeQuotaItem BaseAmountUint

type KeepedAmount

type KeepedAmount struct {
	Count byte
	Items []KeepedItem
}

func KeepedAmountFromScript

func KeepedAmountFromScript(script []byte) (*KeepedAmount, error)

func (*KeepedAmount) Add

func (info *KeepedAmount) Add(item KeepedItem)

func (*KeepedAmount) GetValue

func (info *KeepedAmount) GetValue(t ExpandedTxType) *big.Int

func (*KeepedAmount) Parse

func (info *KeepedAmount) Parse(data []byte) error

func (*KeepedAmount) Serialize

func (info *KeepedAmount) Serialize() []byte

type KeepedItem

type KeepedItem struct {
	ExTxType ExpandedTxType
	Amount   *big.Int
}

type LHPunishedItem

type LHPunishedItem struct {
	All  *big.Int // czz amount(all user burned item in timeout)
	User string
}

type LHPunishedItems

type LHPunishedItems []*LHPunishedItem

type PoolAddrItem

type PoolAddrItem struct {
	POut   []wire.OutPoint
	Script [][]byte
	Amount []*big.Int
}

type SortStoreBeaconAddress

type SortStoreBeaconAddress []*StoreBeaconAddress

func (SortStoreBeaconAddress) Len

func (vs SortStoreBeaconAddress) Len() int

func (SortStoreBeaconAddress) Less

func (vs SortStoreBeaconAddress) Less(i, j int) bool

func (SortStoreBeaconAddress) Swap

func (vs SortStoreBeaconAddress) Swap(i, j int)

type SortStoreUserInfos

type SortStoreUserInfos []*StoreUserInfos

func (SortStoreUserInfos) Len

func (vs SortStoreUserInfos) Len() int

func (SortStoreUserInfos) Less

func (vs SortStoreUserInfos) Less(i, j int) bool

func (SortStoreUserInfos) Swap

func (vs SortStoreUserInfos) Swap(i, j int)

type SortStoreUserItems

type SortStoreUserItems []*StoreUserItme

func (SortStoreUserItems) Len

func (vs SortStoreUserItems) Len() int

func (SortStoreUserItems) Less

func (vs SortStoreUserItems) Less(i, j int) bool

func (SortStoreUserItems) Swap

func (vs SortStoreUserItems) Swap(i, j int)

type StoreBeaconAddress

type StoreBeaconAddress struct {
	Address string
	Lh      *BeaconAddressInfo
}

type StoreUserInfos

type StoreUserInfos struct {
	EID       uint64
	UserInfos UserEntangleInfos
}

type StoreUserItme

type StoreUserItme struct {
	Addr      string
	UserInfos EntangleEntitys
}

type TimeOutBurnInfo

type TimeOutBurnInfo struct {
	Items     []*BurnItem
	AssetType uint32
}

type TmpAddressPair

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

the tool function for entangle tx

func ToAddressFromEntangle

func ToAddressFromEntangle(tx *czzutil.Tx, ev *EntangleVerify) ([]*TmpAddressPair, error)

type TuplePubIndex

type TuplePubIndex struct {
	EType ExpandedTxType
	Index uint32
	Pub   []byte
}

type TypeTimeOutBurnInfo

type TypeTimeOutBurnInfo []*TimeOutBurnInfo

type UserEntangleInfos

type UserEntangleInfos map[string]EntangleEntitys

func (*UserEntangleInfos) DecodeRLP

func (es *UserEntangleInfos) DecodeRLP(s *rlp.Stream) error

func (*UserEntangleInfos) EncodeRLP

func (es *UserEntangleInfos) EncodeRLP(w io.Writer) error

type UserTimeOutBurnInfo

type UserTimeOutBurnInfo map[string]TypeTimeOutBurnInfo

type WhiteUnit

type WhiteUnit struct {
	AssetType uint32 `json:"asset_type"`
	Pk        []byte `json:"pk"`
}

Jump to

Keyboard shortcuts

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