bridgeagg

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OtherError = iota
	NotFoundUnifiedTokenIDError
	InvalidPTokenIDError
	InvalidNetworkIDError
	InvalidStatusError
	InvalidConvertAmountError
	CalRewardError
	ProducerUpdateStateError
	ProcessUpdateStateError
	UnmarshalShieldProofError
	ValidateDoubleShieldProofError
	ShieldProofIsSubmittedError
	ExtractDataFromReceiptError
	InvalidTokenPairError
	CheckVaultUnshieldError
	StoreShieldExtTxError
	CheckBridgeTokenExistedError
	StoreBridgeTokenError
	InsufficientFundsVaultError
	NoValidShieldEventError
)

Variables

View Source
var ErrCodeMessage = map[int]struct {
	Code    int
	Message string
}{
	OtherError:                     {1, "Other error"},
	NotFoundUnifiedTokenIDError:    {1000, "Not found punified token id in network"},
	InvalidPTokenIDError:           {1001, "Invalid ptoken id in punifiedToken"},
	InvalidNetworkIDError:          {1002, "Invalid networkID"},
	InvalidStatusError:             {1003, "Invalid instruction status error"},
	InvalidConvertAmountError:      {1004, "Invalid convert amount"},
	CalRewardError:                 {1005, "Calculate reward error"},
	ProducerUpdateStateError:       {1006, "Beacon producer update state error"},
	ProcessUpdateStateError:        {1007, "Beacon process update state error"},
	UnmarshalShieldProofError:      {1008, "Unmarshal shielding proof error"},
	ValidateDoubleShieldProofError: {1009, "Validate double shielding proof error"},
	ShieldProofIsSubmittedError:    {1010, "Shield proof was submitted"},
	ExtractDataFromReceiptError:    {1011, "Extract data from shielding receipt error"},
	InvalidTokenPairError:          {1012, "Invalid token pair"},
	CheckVaultUnshieldError:        {1013, "Check vaults for new unshielding request error"},
	StoreShieldExtTxError:          {1014, "Store shield external tx error"},
	CheckBridgeTokenExistedError:   {1015, "Check bridge token existed error"},
	StoreBridgeTokenError:          {1016, "Store bridge token error"},
	InsufficientFundsVaultError:    {1017, "Insufficient funds in Vault"},
	NoValidShieldEventError:        {1018, "Shielding receipt contains no valid shield event"},
}
View Source
var Logger = BrideAggLogger{}

Global instant to use

Functions

func CalRewardForRefillVault

func CalRewardForRefillVault(v *statedb.BridgeAggVaultState, shieldAmt uint64) (uint64, error)

func CalUnshieldFeeByBurnAmount

func CalUnshieldFeeByBurnAmount(
	v *statedb.BridgeAggVaultState,
	burningAmt uint64, percentFeeWithDec uint64,
	lockedVaultAmts map[common.Hash]uint64,
) (bool, uint64, map[common.Hash]uint64, error)

func CalUnshieldFeeByReceivedAmount

func CalUnshieldFeeByReceivedAmount(v *statedb.BridgeAggVaultState, receivedAmt uint64, percentFeeWithDec uint64) (bool, uint64, error)

func CalUnshieldFeeByShortageBurnAmount

func CalUnshieldFeeByShortageBurnAmount(burnAmount uint64, percentFeeWithDec uint64) (uint64, error)

calculate actual received amount and actual fee

func CalUnshieldFeeByShortageReceivedAmount

func CalUnshieldFeeByShortageReceivedAmount(receivedAmount uint64, percentFeeWithDec uint64) (uint64, error)

calculate actual received amount and actual fee

func CalculateIncDecimal

func CalculateIncDecimal(decimal, baseDecimal uint8) uint8

func ConvertAmountByDecimal

func ConvertAmountByDecimal(amount *big.Int, decimal uint8, isToUnifiedDecimal bool) (*big.Int, error)

func DecodeBurnForCallConfirmInst

func DecodeBurnForCallConfirmInst(inst []string) ([]byte, error)

DecodeBurnForCallConfirmInst packs the BurnForCall instruction into a byte slice. Instruction layout: [meta(1), shard(1), network(1), extToken(32), extCallAddr(32), amount(32), txID(32), recvToken(32), withdrawAddr(32), redepositAddr(101), extCalldata, beaconHeight(32)].

func GetBridgeTokenIndex

func GetBridgeTokenIndex(sDB *statedb.StateDB) (map[common.Hash]*rawdbv2.BridgeTokenInfo, map[string]bool, error)

func GetExternalTokenIDByIncTokenID

func GetExternalTokenIDByIncTokenID(incTokenID common.Hash, sDB *statedb.StateDB) ([]byte, error)

func GetExternalTokenIDByNetworkID

func GetExternalTokenIDByNetworkID(externalTokenID string, networkID uint8) ([]byte, error)

func GetExternalTokenIDForUnifiedToken

func GetExternalTokenIDForUnifiedToken() []byte

func GetInsertTxHashIssuedFuncByNetworkID

func GetInsertTxHashIssuedFuncByNetworkID(networkID uint8) func(*statedb.StateDB, []byte) error

func GetNetworkIDByPrefix

func GetNetworkIDByPrefix(prefix string) (uint8, error)

func GetTxIDFromBurningConfirmInst

func GetTxIDFromBurningConfirmInst(inst []string) (*common.Hash, error)

func IsBridgeTxHashUsedInBlock

func IsBridgeTxHashUsedInBlock(uniqTx []byte, uniqTxsUsed [][]byte) bool

func UnmarshalEVMShieldProof

func UnmarshalEVMShieldProof(proofBytes []byte, actionData []byte) (*metadataBridge.EVMProof, *types.Receipt, error)

func ValidateDoubleShieldProof

func ValidateDoubleShieldProof(
	uniqTx []byte,
	listTxUsed [][]byte,
	isTxHashIssued func(stateDB *statedb.StateDB, uniqTx []byte) (bool, error),
	stateDB *statedb.StateDB,
) (bool, []byte, error)

Types

type BrideAggLogger

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

func (*BrideAggLogger) Init

func (bridgeAggLogger *BrideAggLogger) Init(logger common.Logger)

type BridgeAggError

type BridgeAggError struct {
	Code    int    // The code to send with reject messages
	Message string // Human readable message of the issue
	Err     error
}

func NewBridgeAggErrorWithValue

func NewBridgeAggErrorWithValue(key int, err error, params ...interface{}) *BridgeAggError

func (BridgeAggError) Error

func (e BridgeAggError) Error() string

Error satisfies the error interface and prints human-readable errors.

type ConvertStatus

type ConvertStatus struct {
	Status                byte   `json:"Status"`
	ConvertPUnifiedAmount uint64 `json:"ConvertPUnifiedAmount"`
	Reward                uint64 `json:"Reward"`
	ErrorCode             int    `json:"ErrorCode,omitempty"`
}

type Manager

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

func InitManager

func InitManager(sDB *statedb.StateDB) (*Manager, error)

func NewManager

func NewManager() *Manager

func NewManagerWithValue

func NewManagerWithValue(state *State) *Manager

func (*Manager) BuildAddTokenInstruction

func (m *Manager) BuildAddTokenInstruction(beaconHeight uint64, sDBs map[int]*statedb.StateDB, ac *metadata.AccumulatedValues, triggeredFeature map[string]uint64) ([][]string, *metadata.AccumulatedValues, error)

func (*Manager) BuildInstructions

func (m *Manager) BuildInstructions(env StateEnvironment) ([][]string, *metadata.AccumulatedValues, error)

func (*Manager) BuildNewUnshieldInstructions

func (m *Manager) BuildNewUnshieldInstructions(stateDB *statedb.StateDB, beaconHeight uint64, unshieldActionForProducers []UnshieldActionForProducer) ([][]string, error)

func (*Manager) Clone

func (m *Manager) Clone() *Manager

func (*Manager) GetDiffState

func (m *Manager) GetDiffState(state *State) (*State, map[common.Hash]bool, error)

func (*Manager) InitBridgeAggParamDefault

func (m *Manager) InitBridgeAggParamDefault() error

func (*Manager) Process

func (m *Manager) Process(insts [][]string, sDB *statedb.StateDB) (map[string]bool, error)

func (*Manager) State

func (m *Manager) State() *State

func (*Manager) UpdateToDB

func (m *Manager) UpdateToDB(sDB *statedb.StateDB, newUnifiedTokens map[common.Hash]bool) error

type ModifyParamStatus

type ModifyParamStatus struct {
	Status               byte   `json:"Status"`
	NewPercentFeeWithDec uint64 `json:"NewPercentFeeWithDec"`
	ErrorCode            int    `json:"ErrorCode,omitempty"`
}

type ShieldStatus

type ShieldStatus struct {
	Status    byte               `json:"Status"`
	Data      []ShieldStatusData `json:"Data,omitempty"`
	ErrorCode int                `json:"ErrorCode,omitempty"`
}

type ShieldStatusData

type ShieldStatusData struct {
	Amount uint64 `json:"Amount"`
	Reward uint64 `json:"Reward"`
}

type State

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

func InitStateFromDB

func InitStateFromDB(sDB *statedb.StateDB) (*State, error)

func NewState

func NewState() *State

func NewStateWithValue

func NewStateWithValue(
	unifiedTokenInfos map[common.Hash]map[common.Hash]*statedb.BridgeAggVaultState,
	waitingUnshieldReqs map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq,
	param *statedb.BridgeAggParamState,
	newWaitingUnshieldReqs map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq,
	deletedWaitingUnshieldReqKeyHashes []common.Hash,
) *State

func (*State) Clone

func (s *State) Clone() *State

func (*State) CloneNewWaitingUnshieldReqs

func (s *State) CloneNewWaitingUnshieldReqs() map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq

func (*State) CloneUnifiedTokenVaults

func (s *State) CloneUnifiedTokenVaults() map[common.Hash]map[common.Hash]*statedb.BridgeAggVaultState

func (*State) CloneVaultsByUnifiedTokenID

func (s *State) CloneVaultsByUnifiedTokenID(unifiedTokenID common.Hash) (map[common.Hash]*statedb.BridgeAggVaultState, error)

func (*State) CloneWaitingUnshieldReqs

func (s *State) CloneWaitingUnshieldReqs() map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq

func (*State) DeletedWaitingUnshieldReqKeyHashes

func (s *State) DeletedWaitingUnshieldReqKeyHashes() []common.Hash

func (*State) GetDiff

func (s *State) GetDiff(preState *State) (*State, map[common.Hash]bool, error)

func (*State) MarshalJSON

func (s *State) MarshalJSON() ([]byte, error)

func (*State) NewWaitingUnshieldReqs

func (s *State) NewWaitingUnshieldReqs() map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq

func (*State) Param

func (s *State) Param() *statedb.BridgeAggParamState

func (*State) UnifiedTokenVaults

func (s *State) UnifiedTokenVaults() map[common.Hash]map[common.Hash]*statedb.BridgeAggVaultState

UnifiedTokenVaults read only function do not write to result of function

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(data []byte) error

func (*State) WaitingUnshieldReqs

func (s *State) WaitingUnshieldReqs() map[common.Hash][]*statedb.BridgeAggWaitingUnshieldReq

WaitingUnshieldReqs read only function do not write to result of function

type StateChange

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

func NewStateChange

func NewStateChange() *StateChange

type StateEnvBuilder

type StateEnvBuilder interface {
	BuildAccumulatedValues(*metadata.AccumulatedValues) StateEnvBuilder
	BuildUnshieldActions([][]string) StateEnvBuilder
	BuildShieldActions([][]string) StateEnvBuilder
	BuildConvertActions([][]string) StateEnvBuilder
	BuildModifyParamActions([][]string) StateEnvBuilder
	BuildStateDBs(map[int]*statedb.StateDB) StateEnvBuilder
	BuildBeaconHeight(uint64) StateEnvBuilder
	Build() StateEnvironment
}

func NewStateEnvBuilder

func NewStateEnvBuilder() StateEnvBuilder

type StateEnvironment

type StateEnvironment interface {
	BeaconHeight() uint64
	AccumulatedValues() *metadata.AccumulatedValues
	UnshieldActions() [][]string
	ShieldActions() [][]string
	ConvertActions() [][]string
	ModifyParamActions() [][]string
	StateDBs() map[int]*statedb.StateDB
}

type TxBuilder

type TxBuilder struct {
}

func (TxBuilder) Build

func (txBuilder TxBuilder) Build(
	metaType int,
	inst []string,
	producerPrivateKey *privacy.PrivateKey,
	shardID byte,
	transactionStateDB *statedb.StateDB,
) (metadata.Transaction, error)

type UnshieldActionForProducer

type UnshieldActionForProducer struct {
	metadataCommon.Action
	ShardID      byte
	BeaconHeight uint64
}

func BuildUnshieldActionForProducerFromInsts

func BuildUnshieldActionForProducerFromInsts(insts [][]string, shardID byte, beaconHeight uint64) []UnshieldActionForProducer

type UnshieldStatus

type UnshieldStatus struct {
	Status    byte                 `json:"Status"`
	Data      []UnshieldStatusData `json:"Data,omitempty"`
	ErrorCode int                  `json:"ErrorCode,omitempty"`
}

type UnshieldStatusData

type UnshieldStatusData struct {
	ReceivedAmount uint64 `json:"ReceivedAmount"`
	Fee            uint64 `json:"Fee"`
}

type VaultChange

type VaultChange struct {
	IsChanged bool
}

func NewVaultChange

func NewVaultChange() *VaultChange

Jump to

Keyboard shortcuts

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