common

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: 22 Imported by: 5

Documentation

Index

Constants

View Source
const (
	InvalidMeta = 1

	IssuingRequestMeta     = 24
	IssuingResponseMeta    = 25
	ContractingRequestMeta = 26
	IssuingETHRequestMeta  = 80
	IssuingETHResponseMeta = 81

	ShardBlockReward = 36

	ShardBlockSalaryResponseMeta = 38
	BeaconRewardRequestMeta      = 39
	BeaconSalaryResponseMeta     = 40
	ReturnStakingMeta            = 41
	ReturnBeaconStakingMeta      = 46
	MintDelegationRewardMeta     = 47
	IncDAORewardRequestMeta      = 42

	WithDrawRewardRequestMeta  = 44
	WithDrawRewardResponseMeta = 45

	WithdrawDelegationRewardRequestMeta = 48

	// staking
	ShardStakingMeta    = 63
	StopAutoStakingMeta = 127
	BeaconStakingMeta   = 64
	UnStakingMeta       = 210
	AddStakingMeta      = 360
	ReDelegateMeta      = 361

	// Incognito -> Ethereum bridge
	BeaconSwapConfirmMeta = 70
	BridgeSwapConfirmMeta = 71
	BurningRequestMeta    = 27
	BurningRequestMetaV2  = 240
	BurningConfirmMeta    = 72
	BurningConfirmMetaV2  = 241

	// pde
	PDEContributionMeta                   = 90
	PDETradeRequestMeta                   = 91
	PDETradeResponseMeta                  = 92
	PDEWithdrawalRequestMeta              = 93
	PDEWithdrawalResponseMeta             = 94
	PDEContributionResponseMeta           = 95
	PDEPRVRequiredContributionRequestMeta = 204
	PDECrossPoolTradeRequestMeta          = 205
	PDECrossPoolTradeResponseMeta         = 206
	PDEFeeWithdrawalRequestMeta           = 207
	PDEFeeWithdrawalResponseMeta          = 208
	PDETradingFeesDistributionMeta        = 209

	// portal
	PortalCustodianDepositMeta                  = 100
	PortalRequestPortingMeta                    = 101
	PortalUserRequestPTokenMeta                 = 102
	PortalCustodianDepositResponseMeta          = 103
	PortalUserRequestPTokenResponseMeta         = 104
	PortalExchangeRatesMeta                     = 105
	PortalRedeemRequestMeta                     = 106
	PortalRedeemRequestResponseMeta             = 107
	PortalRequestUnlockCollateralMeta           = 108
	PortalCustodianWithdrawRequestMeta          = 110
	PortalCustodianWithdrawResponseMeta         = 111
	PortalLiquidateCustodianMeta                = 112
	PortalLiquidateCustodianResponseMeta        = 113
	PortalLiquidateTPExchangeRatesMeta          = 114
	PortalExpiredWaitingPortingReqMeta          = 116
	PortalRewardMeta                            = 117
	PortalRequestWithdrawRewardMeta             = 118
	PortalRequestWithdrawRewardResponseMeta     = 119
	PortalRedeemFromLiquidationPoolMeta         = 120
	PortalRedeemFromLiquidationPoolResponseMeta = 121
	PortalCustodianTopupMeta                    = 122
	PortalCustodianTopupResponseMeta            = 123
	PortalTotalRewardCustodianMeta              = 124
	PortalPortingResponseMeta                   = 125
	PortalReqMatchingRedeemMeta                 = 126
	PortalPickMoreCustodianForRedeemMeta        = 128
	PortalCustodianTopupMetaV2                  = 129
	PortalCustodianTopupResponseMetaV2          = 130

	// Portal v3
	PortalCustodianDepositMetaV3                  = 131
	PortalCustodianWithdrawRequestMetaV3          = 132
	PortalRewardMetaV3                            = 133
	PortalRequestUnlockCollateralMetaV3           = 134
	PortalLiquidateCustodianMetaV3                = 135
	PortalLiquidateByRatesMetaV3                  = 136
	PortalRedeemFromLiquidationPoolMetaV3         = 137
	PortalRedeemFromLiquidationPoolResponseMetaV3 = 138
	PortalCustodianTopupMetaV3                    = 139
	PortalTopUpWaitingPortingRequestMetaV3        = 140
	PortalRequestPortingMetaV3                    = 141
	PortalRedeemRequestMetaV3                     = 142
	PortalUnlockOverRateCollateralsMeta           = 143

	// Incognito => Ethereum's SC for portal
	PortalCustodianWithdrawConfirmMetaV3         = 170
	PortalRedeemFromLiquidationPoolConfirmMetaV3 = 171
	PortalLiquidateRunAwayCustodianConfirmMetaV3 = 172

	// Note: don't use this metadata type for others
	PortalResetPortalDBMeta = 199

	// relaying
	RelayingBNBHeaderMeta = 200
	RelayingBTCHeaderMeta = 201

	PortalTopUpWaitingPortingRequestMeta  = 202
	PortalTopUpWaitingPortingResponseMeta = 203

	// incognito mode for smart contract
	BurningForDepositToSCRequestMeta   = 96
	BurningForDepositToSCRequestMetaV2 = 242
	BurningConfirmForDepositToSCMeta   = 97
	BurningConfirmForDepositToSCMetaV2 = 243

	InitTokenRequestMeta  = 244
	InitTokenResponseMeta = 245

	// incognito mode for bsc
	IssuingBSCRequestMeta  = 250
	IssuingBSCResponseMeta = 251
	BurningPBSCRequestMeta = 252
	BurningBSCConfirmMeta  = 253

	// PORTAL V4
	PortalV4ShieldingRequestMeta      = 260
	PortalV4ShieldingResponseMeta     = 261
	PortalV4UnshieldingRequestMeta    = 262
	PortalV4UnshieldingResponseMeta   = 263
	PortalV4UnshieldBatchingMeta      = 264
	PortalV4FeeReplacementRequestMeta = 265
	PortalV4SubmitConfirmedTxMeta     = 266
	PortalV4ConvertVaultRequestMeta   = 267

	// erc20/bep20 for prv token
	IssuingPRVERC20RequestMeta  = 270
	IssuingPRVERC20ResponseMeta = 271
	IssuingPRVBEP20RequestMeta  = 272
	IssuingPRVBEP20ResponseMeta = 273
	BurningPRVERC20RequestMeta  = 274
	BurningPRVERC20ConfirmMeta  = 150
	BurningPRVBEP20RequestMeta  = 275
	BurningPRVBEP20ConfirmMeta  = 151

	// pDEX v3
	Pdexv3ModifyParamsMeta                  = 280
	Pdexv3AddLiquidityRequestMeta           = 281
	Pdexv3AddLiquidityResponseMeta          = 282
	Pdexv3WithdrawLiquidityRequestMeta      = 283
	Pdexv3WithdrawLiquidityResponseMeta     = 284
	Pdexv3TradeRequestMeta                  = 285
	Pdexv3TradeResponseMeta                 = 286
	Pdexv3AddOrderRequestMeta               = 287
	Pdexv3AddOrderResponseMeta              = 288
	Pdexv3WithdrawOrderRequestMeta          = 289
	Pdexv3WithdrawOrderResponseMeta         = 290
	Pdexv3UserMintNftRequestMeta            = 291
	Pdexv3UserMintNftResponseMeta           = 292
	Pdexv3MintNftRequestMeta                = 293
	Pdexv3MintNftResponseMeta               = 294
	Pdexv3StakingRequestMeta                = 295
	Pdexv3StakingResponseMeta               = 296
	Pdexv3UnstakingRequestMeta              = 297
	Pdexv3UnstakingResponseMeta             = 298
	Pdexv3WithdrawLPFeeRequestMeta          = 299
	Pdexv3WithdrawLPFeeResponseMeta         = 300
	Pdexv3WithdrawProtocolFeeRequestMeta    = 301
	Pdexv3WithdrawProtocolFeeResponseMeta   = 302
	Pdexv3MintPDEXGenesisMeta               = 303
	Pdexv3MintBlockRewardMeta               = 304
	Pdexv3DistributeStakingRewardMeta       = 305
	Pdexv3WithdrawStakingRewardRequestMeta  = 306
	Pdexv3WithdrawStakingRewardResponseMeta = 307
	Pdexv3DistributeMiningOrderRewardMeta   = 308

	// pBSC
	BurningPBSCForDepositToSCRequestMeta = 326
	BurningPBSCConfirmForDepositToSCMeta = 152

	// incognito mode for polygon
	IssuingPLGRequestMeta  = 327
	IssuingPLGResponseMeta = 328
	BurningPLGRequestMeta  = 329
	BurningPLGConfirmMeta  = 153

	// pPLG ( Polygon )
	BurningPLGForDepositToSCRequestMeta = 330
	BurningPLGConfirmForDepositToSCMeta = 154

	// incognito mode for Fantom
	IssuingFantomRequestMeta  = 331
	IssuingFantomResponseMeta = 332
	BurningFantomRequestMeta  = 333
	BurningFantomConfirmMeta  = 155

	// pFantom ( Fantom )
	BurningFantomForDepositToSCRequestMeta = 334
	BurningFantomConfirmForDepositToSCMeta = 156

	// bridgeagg
	BridgeAggModifyParamMeta                        = 340
	BridgeAggConvertTokenToUnifiedTokenRequestMeta  = 341
	BridgeAggConvertTokenToUnifiedTokenResponseMeta = 342
	IssuingUnifiedTokenRequestMeta                  = 343
	IssuingUnifiedTokenResponseMeta                 = 344
	BurningUnifiedTokenRequestMeta                  = 345
	BurningUnifiedTokenResponseMeta                 = 346
	BridgeAggAddTokenMeta                           = 347

	BurnForCallConfirmMeta      = 158
	BurnForCallRequestMeta      = 348
	BurnForCallResponseMeta     = 349
	IssuingReshieldResponseMeta = 350

	// incognito mode for Aurora
	IssuingAuroraRequestMeta  = 351
	IssuingAuroraResponseMeta = 352
	BurningAuroraRequestMeta  = 353
	BurningAuroraConfirmMeta  = 159

	// incognito mode for Avalanche
	IssuingAvaxRequestMeta  = 354
	IssuingAvaxResponseMeta = 355
	BurningAvaxRequestMeta  = 356
	BurningAvaxConfirmMeta  = 160

	// pAurora ( Aurora )
	BurningAuroraForDepositToSCRequestMeta = 357
	BurningAuroraConfirmForDepositToSCMeta = 161

	// pAVAX ( avalanche )
	BurningAvaxForDepositToSCRequestMeta = 358
	BurningAvaxConfirmForDepositToSCMeta = 162

	// incognito mode for Near
	IssuingNearRequestMeta  = 335
	IssuingNearResponseMeta = 336
	BurningNearRequestMeta  = 337
	BurningNearConfirmMeta  = 163

	// pdao feature
	BurningPRVRequestMeta        = 338
	BurningPRVRequestConfirmMeta = 164

	InscribeRequestMeta  = 363
	InscribeResponseMeta = 364
)
View Source
const (
	AllShards  = -1
	BeaconOnly = -2
)

Special rules for shardID: stored as 2nd param of instruction of BeaconBlock

View Source
const (
	StopAutoStakingAmount    = 0
	ReDelegateFee            = 0
	EVMConfirmationBlocks    = 15 // update to 32 when eth merge
	PLGConfirmationBlocks    = 128
	FantomConfirmationBlocks = 5
	AuroraConfirmationBlocks = 5
	AvaxConfirmationBlocks   = 15
	NearConfirmationBlocks   = 5
)
View Source
const (
	ExternalAddressLen         = 20
	BurnForCallMinBlockVersion = 10 // ADJUST_BLOCKTIME_VERSION
)
View Source
const (
	UnexpectedError = iota

	IssuingEvmRequestDecodeInstructionError
	IssuingEvmRequestUnmarshalJsonError
	IssuingEvmRequestNewIssuingEVMRequestFromMapError
	IssuingEvmRequestValidateTxWithBlockChainError
	IssuingEvmRequestValidateSanityDataError
	IssuingEvmRequestBuildReqActionsError
	IssuingEvmRequestVerifyProofAndParseReceipt

	IssuingRequestDecodeInstructionError
	IssuingRequestUnmarshalJsonError
	IssuingRequestNewIssuingRequestFromMapEror
	IssuingRequestValidateTxWithBlockChainError
	IssuingRequestValidateSanityDataError
	IssuingRequestBuildReqActionsError
	IssuingRequestVerifyProofAndParseReceipt

	BeaconBlockRewardNewBeaconBlockRewardInfoFromStrError
	BeaconBlockRewardBuildInstructionForBeaconBlockRewardError

	StopAutoStakingRequestNotInCommitteeListError
	StopAutoStakingRequestGetStakingTransactionError
	StopAutoStakingRequestStakingTransactionNotFoundError
	StopAutoStakingRequestInvalidTransactionSenderError
	StopAutoStakingRequestNoAutoStakingAvaiableError
	StopAutoStakingRequestTypeAssertionError
	StopAutoStakingRequestAlreadyStopError

	WrongIncognitoDAOPaymentAddressError

	// pde
	PDEWithdrawalRequestFromMapError
	CouldNotGetExchangeRateError
	RejectInvalidFee
	PDEFeeWithdrawalRequestFromMapError
	PDECouldNotGenerateHashFromStringError
	PDEInvalidMetadataValueError
	PDENotBurningTxError
	PDEInvalidTxTypeError
	PDETxWrongVersionError

	// pDex v3
	Pdexv3ModifyParamsValidateSanityDataError
	Pdexv3WithdrawLPFeeValidateSanityDataError
	Pdexv3WithdrawProtocolFeeValidateSanityDataError
	Pdexv3WithdrawStakingRewardValidateSanityDataError

	// portal
	PortalRequestPTokenParamError
	PortalRedeemRequestParamError
	PortalRedeemLiquidateExchangeRatesParamError

	// Unstake
	UnStakingRequestNotInCommitteeListError
	UnStakingRequestGetStakerInfoError
	UnStakingRequestNotFoundStakerInfoError
	UnStakingRequestStakingTransactionNotFoundError
	UnStakingRequestInvalidTransactionSenderError
	UnStakingRequestNoAutoStakingAvaiableError
	UnStakingRequestTypeAssertionError
	UnStakingRequestAlreadyStopError
	UnStakingRequestInvalidFormatRequestKey
	UnstakingRequestAlreadyUnstake

	// eth utils
	VerifyProofAndParseReceiptError

	// init privacy custom token
	InitTokenRequestDecodeInstructionError
	InitTokenRequestUnmarshalJsonError
	InitTokenRequestNewInitPTokenRequestFromMapError
	InitTokenRequestValidateTxWithBlockChainError
	InitTokenRequestValidateSanityDataError
	InitTokenRequestBuildReqActionsError

	InitTokenResponseValidateSanityDataError

	// portal v3
	PortalCustodianDepositV3ValidateWithBCError
	PortalCustodianDepositV3ValidateSanityDataError
	NewPortalCustodianDepositV3MetaFromMapError
	PortalUnlockOverRateCollateralsError

	// portal v4
	PortalV4ShieldRequestValidateSanityDataError
	PortalV4UnshieldRequestValidateSanityDataError
	PortalV4FeeReplacementRequestMetaError
	PortalV4SubmitConfirmedTxRequestMetaError
	PortalV4ConvertVaultRequestMetaError

	// relaying header
	RelayingHeaderMetaError

	// bridge agg
	BridgeAggModifyParamValidateSanityDataError
	BridgeAggConvertRequestValidateSanityDataError
	BridgeAggShieldValidateSanityDataError
	BridgeAggUnshieldValidateSanityDataError

	// near bridge
	IssuingWasmRequestDecodeInstructionError
	IssuingWasmRequestUnmarshalJsonError
	IssuingWasmRequestNewIssuingWasmRequestFromMapError
	IssuingWasmRequestValidateTxWithBlockChainError
	IssuingWasmRequestValidateSanityDataError
	IssuingWasmRequestBuildReqActionsError
	IssuingWasmRequestVerifyProofAndParseReceipt

	ConsensusMetadataTypeAssertionError
	ConsensusMetadataInvalidTransactionSenderError
	AddStakingNotInCommitteeListError
	AddStakingCommitteeNotFoundError

	ReDelegateNotInCommitteeListError
	ReDelegateCommitteeNotFoundError
	ReDelegateInvalidTxError
)
View Source
const (
	NoAction = iota
	MetaRequestBeaconMintTxs
	MetaRequestShardMintTxs
)
View Source
const (
	SpecifiedTxType1 = 1 // only defined min fee per tx, use default min fee per KB
	SpecifiedTxType2 = 2 // BOTH min fee per tx and min fee per KB are defined
)

Variables

View Source
var AcceptedWithdrawRewardRequestVersion = []int{0, 1}
View Source
var ErrCodeMessage = map[int]struct {
	Code    int
	Message string
}{
	UnexpectedError: {-1, "Unexpected error"},

	IssuingEvmRequestDecodeInstructionError:           {-1001, "Can not decode instruction"},
	IssuingEvmRequestUnmarshalJsonError:               {-1002, "Can not unmarshall json"},
	IssuingEvmRequestNewIssuingEVMRequestFromMapError: {-1003, "Can no new issuing evm request from map"},
	IssuingEvmRequestValidateTxWithBlockChainError:    {-1004, "Validate tx with block chain error"},
	IssuingEvmRequestValidateSanityDataError:          {-1005, "Validate sanity data error"},
	IssuingEvmRequestBuildReqActionsError:             {-1006, "Build request action error"},
	IssuingEvmRequestVerifyProofAndParseReceipt:       {-1007, "Verify proof and parse receipt"},

	IssuingRequestDecodeInstructionError:        {-2001, "Can not decode instruction"},
	IssuingRequestUnmarshalJsonError:            {-2002, "Can not unmarshall json"},
	IssuingRequestNewIssuingRequestFromMapEror:  {-2003, "Can no new issuing eth request from map"},
	IssuingRequestValidateTxWithBlockChainError: {-2004, "Validate tx with block chain error"},
	IssuingRequestValidateSanityDataError:       {-2005, "Validate sanity data error"},
	IssuingRequestBuildReqActionsError:          {-2006, "Build request action error"},
	IssuingRequestVerifyProofAndParseReceipt:    {-2007, "Verify proof and parse receipt"},

	BeaconBlockRewardNewBeaconBlockRewardInfoFromStrError:      {-3000, "Can not new beacon block reward from string"},
	BeaconBlockRewardBuildInstructionForBeaconBlockRewardError: {-3001, "Can not build instruction for beacon block reward"},

	StopAutoStakingRequestNotInCommitteeListError:         {-4000, "Stop Auto-Staking Request Not In Committee List Error"},
	StopAutoStakingRequestStakingTransactionNotFoundError: {-4001, "Stop Auto-Staking Request Staking Transaction Not Found Error"},
	StopAutoStakingRequestInvalidTransactionSenderError:   {-4002, "Stop Auto-Staking Request Invalid Transaction Sender Error"},
	StopAutoStakingRequestNoAutoStakingAvaiableError:      {-4003, "Stop Auto-Staking Request No Auto Staking Avaliable Error"},
	StopAutoStakingRequestTypeAssertionError:              {-4004, "Stop Auto-Staking Request Type Assertion Error"},
	StopAutoStakingRequestAlreadyStopError:                {-4005, "Stop Auto Staking Request Already Stop Error"},
	StopAutoStakingRequestGetStakingTransactionError:      {-4006, "Stop Auto Staking Request Get Staking Transaction Error"},
	UnStakingRequestNotInCommitteeListError:               {-4100, "Unstaking Request Not In Committee List Error"},
	UnStakingRequestGetStakerInfoError:                    {-4101, "Unstaking Request Get Staker Info Error"},
	UnStakingRequestNotFoundStakerInfoError:               {-4102, "Unstaking Request Not Found Staker Info Error"},
	UnStakingRequestStakingTransactionNotFoundError:       {-4103, "Unstaking Request Staking Transaction Not Found Error"},
	UnStakingRequestInvalidTransactionSenderError:         {-4104, "Unstaking Request Invalid Transaction Sender Error"},
	UnStakingRequestNoAutoStakingAvaiableError:            {-4105, "UnStaking Request No Auto Staking Available Error"},
	UnStakingRequestTypeAssertionError:                    {-4106, "UnStaking Request Type Assertion Error"},
	UnStakingRequestAlreadyStopError:                      {-4107, "UnStaking Request Already Stop Error"},
	UnStakingRequestInvalidFormatRequestKey:               {-4108, "Unstaking Request Key Is Invalid Format"},
	UnstakingRequestAlreadyUnstake:                        {-4109, "Public Key Has Been Already Unstaked"},

	ReDelegateNotInCommitteeListError: {-4110, "Delegate not in committee list"},
	ReDelegateCommitteeNotFoundError:  {-4111, "Delegate committee not found"},
	ReDelegateInvalidTxError:          {-4112, "Delegate invalid tx"},

	WrongIncognitoDAOPaymentAddressError: {-5001, "Invalid dev account"},

	PDEWithdrawalRequestFromMapError:       {-6001, "PDE withdrawal request Error"},
	CouldNotGetExchangeRateError:           {-6002, "Could not get the exchange rate error"},
	RejectInvalidFee:                       {-6003, "Reject invalid fee"},
	PDECouldNotGenerateHashFromStringError: {-6003, "Could not generate hash from string"},
	PDEInvalidMetadataValueError:           {-6004, "Invalid metadata value"},
	PDENotBurningTxError:                   {-6004, "Tx is not a burning tx"},
	PDEInvalidTxTypeError:                  {-6005, "Invalid tx type"},
	PDETxWrongVersionError:                 {-6006, "Invalid tx version"},

	PortalRequestPTokenParamError:                {-7001, "Portal request ptoken param error"},
	PortalRedeemRequestParamError:                {-7002, "Portal redeem request param error"},
	PortalRedeemLiquidateExchangeRatesParamError: {-7003, "Portal redeem liquidate exchange rates param error"},

	VerifyProofAndParseReceiptError: {-8001, "Verify proof and parse receipt eth error"},

	InitTokenRequestDecodeInstructionError:           {-8002, "Cannot decode instruction"},
	InitTokenRequestUnmarshalJsonError:               {-8003, "Cannot unmarshall json"},
	InitTokenRequestNewInitPTokenRequestFromMapError: {-8004, "Cannot new InitPToken eth request from map"},
	InitTokenRequestValidateTxWithBlockChainError:    {-8005, "Validate tx with block chain error"},
	InitTokenRequestValidateSanityDataError:          {-8006, "Validate sanity data error"},
	InitTokenRequestBuildReqActionsError:             {-8007, "Build request action error"},

	InitTokenResponseValidateSanityDataError: {-8008, "Validate sanity data error"},

	PortalCustodianDepositV3ValidateWithBCError:     {-9001, "Validate with blockchain tx portal custodian deposit v3 error"},
	PortalCustodianDepositV3ValidateSanityDataError: {-9002, "Validate sanity data tx portal custodian deposit v3 error"},
	NewPortalCustodianDepositV3MetaFromMapError:     {-9003, "New portal custodian deposit v3 metadata from map error"},
	PortalUnlockOverRateCollateralsError:            {-9004, "Validate with blockchain tx portal custodian unlock over rate v3 error"},

	PortalV4ShieldRequestValidateSanityDataError:   {-10001, "Validate sanity data portal v4 shielding request error"},
	PortalV4UnshieldRequestValidateSanityDataError: {-10002, "Validate sanity data portal v4 unshielding request error"},
	PortalV4FeeReplacementRequestMetaError:         {-10003, "Portal batch unshield request metadata error"},
	PortalV4SubmitConfirmedTxRequestMetaError:      {-10004, "Portal submit external confirmed tx metadata error"},
	PortalV4ConvertVaultRequestMetaError:           {-10005, "Portal convert vault tx metadata error"},

	RelayingHeaderMetaError: {-11005, " relaying header metadata error"},

	BridgeAggModifyParamValidateSanityDataError:    {-12000, "Modify list token validate sanity error"},
	BridgeAggConvertRequestValidateSanityDataError: {-12001, "Convert request sanity error"},
	BridgeAggShieldValidateSanityDataError:         {-12002, "Shield request sanity error"},
	BridgeAggUnshieldValidateSanityDataError:       {-12003, "Unshield request sanity error"},

	IssuingWasmRequestDecodeInstructionError:            {-1301, "Can not decode instruction"},
	IssuingWasmRequestUnmarshalJsonError:                {-1302, "Can not unmarshall json"},
	IssuingWasmRequestNewIssuingWasmRequestFromMapError: {-1303, "Can no new issuing wasm request from map"},
	IssuingWasmRequestValidateTxWithBlockChainError:     {-1304, "Validate tx with block chain error"},
	IssuingWasmRequestValidateSanityDataError:           {-1305, "Validate sanity data error"},
	IssuingWasmRequestBuildReqActionsError:              {-1306, "Build request action error"},
	IssuingWasmRequestVerifyProofAndParseReceipt:        {-1307, "Verify proof and parse receipt"},

	ConsensusMetadataTypeAssertionError:            {-4120, "ConsensusMetadata Type Assertion Error"},
	ConsensusMetadataInvalidTransactionSenderError: {-4121, "ConsensusMetadata Invalid Transaction Sender Error"},
	AddStakingNotInCommitteeListError:              {-4122, "AddStaking Not In Committee List Error"},
	AddStakingCommitteeNotFoundError:               {-4123, "AddStaking Committee Not Found Error"},
}
View Source
var FeatureFlagWithMetaTypes = map[string][]int{
	common.PortalRelayingFlag: portalRelayingMetaTypes,
	common.PortalV3Flag:       portalMetaTypesV3,
	common.PortalV4Flag:       portalV4MetaTypes,
}

NOTE: add new records when add new feature flags

View Source
var Logger = MetaDataLogger{}

Global instant to use

Functions

func AssertPaymentAddressAndTxVersion

func AssertPaymentAddressAndTxVersion(paymentAddress interface{}, version int8) (privacy.PaymentAddress, error)

Checks if a string payment address is supported by the underlying transaction.

TODO: try another approach since the function itself is too complicated.

func CalculateSize

func CalculateSize(meta Metadata) uint64

func CheckIncognitoAddress

func CheckIncognitoAddress(address, txRandom string) (bool, error, int)

func ConvertNativeTokenToPrivacyToken

func ConvertNativeTokenToPrivacyToken(
	nativeTokenAmount uint64,
	tokenID *common.Hash,
	beaconHeight int64,
	stateDB *statedb.StateDB,
) (float64, error)

return error if there is no exchange rate between native token and privacy token beaconHeight = -1: get the latest beacon height

func ConvertPrivacyTokenToNativeToken

func ConvertPrivacyTokenToNativeToken(
	privacyTokenAmount uint64,
	tokenID *common.Hash,
	beaconHeight int64,
	stateDB *statedb.StateDB,
) (float64, error)

return error if there is no exchange rate between native token and privacy token beaconHeight = -1: get the latest beacon height

func GenTokenIDFromRequest

func GenTokenIDFromRequest(txHash string, shardID byte) *common.Hash

genTokenID generates a (deterministically) random tokenID for the request transaction. From now on, users cannot generate their own tokenID. The generated tokenID is calculated as the hash of the following components:

  • The Tx hash
  • The shardID at which the request is sent

func GetLimitOfMeta

func GetLimitOfMeta(metaType int) int

func GetMetaAction

func GetMetaAction(metaType int) int

func GetSpecifiedFeeTxType

func GetSpecifiedFeeTxType(metaType int) int

func HasBridgeInstructions

func HasBridgeInstructions(instructions [][]string) bool

func HasInputNoOutput

func HasInputNoOutput(metaType int) bool

func HasPortalInstructions

func HasPortalInstructions(instructions [][]string) bool

func IsAvailableMetaInTxType

func IsAvailableMetaInTxType(metaType int, txType string) bool

func IsBridgeAggUnshieldMetaType

func IsBridgeAggUnshieldMetaType(metadataType int) bool

NOTE: append new bridge agg unshield metadata type

func IsBridgeUnshieldMetaType

func IsBridgeUnshieldMetaType(metadataType int) bool

NOTE: append new bridge unshield metadata type

func IsPDETx

func IsPDETx(metadata Metadata) bool

func IsPDEType

func IsPDEType(metadataType int) bool

func IsPdexv3Tx

func IsPdexv3Tx(metadata Metadata) bool

func IsPdexv3Type

func IsPdexv3Type(metadataType int) bool

func IsPortalMetaTypeV3

func IsPortalMetaTypeV3(metaType int) bool

func IsPortalMetaTypeV4

func IsPortalMetaTypeV4(metaType int) bool

func IsPortalRelayingMetaType

func IsPortalRelayingMetaType(metaType int) bool

func NoInputHasOutput

func NoInputHasOutput(metaType int) bool

func NoInputNoOutput

func NoInputNoOutput(metaType int) bool

func ValidatePortalExternalAddress

func ValidatePortalExternalAddress(chainName string, tokenID string, address string) (bool, error)

Validate portal external addresses for collateral tokens (ETH/ERC20)

Types

type AccumulatedValues

type AccumulatedValues struct {
	UniqETHTxsUsed    [][]byte
	UniqBSCTxsUsed    [][]byte
	UniqPRVEVMTxsUsed [][]byte
	UniqPLGTxsUsed    [][]byte
	UniqFTMTxsUsed    [][]byte
	UniqNEARTxsUsed   [][]byte
	UniqAURORATxsUsed [][]byte
	UniqAVAXTxsUsed   [][]byte
	DBridgeTokenPair  map[string][]byte
	CBridgeTokens     []*common.Hash
	InitTokens        []*common.Hash
}

func (AccumulatedValues) CanProcessCIncToken

func (ac AccumulatedValues) CanProcessCIncToken(
	incTokenID common.Hash,
) bool

func (AccumulatedValues) CanProcessTokenInit

func (ac AccumulatedValues) CanProcessTokenInit(
	pTokenID common.Hash,
) bool

func (AccumulatedValues) CanProcessTokenPair

func (ac AccumulatedValues) CanProcessTokenPair(
	externalTokenID []byte,
	incTokenID common.Hash,
) (bool, error)

func (*AccumulatedValues) Clone

func (ac *AccumulatedValues) Clone() *AccumulatedValues

func (*AccumulatedValues) UpdateUniqTxsUsed

func (ac *AccumulatedValues) UpdateUniqTxsUsed(networkID uint8, uniqTxsUsed [][]byte) (*AccumulatedValues, error)

type Action

type Action struct {
	Meta      Metadata    `json:"Meta"`
	TxReqID   common.Hash `json:"TxReqID"`
	ExtraData [][]byte    `json:"ExtraData,omitempty"`
}

func NewAction

func NewAction() *Action

func NewActionWithValue

func NewActionWithValue(
	meta Metadata, txReqID common.Hash, extraData [][]byte,
) *Action

func (*Action) FromString

func (a *Action) FromString(source string) error

func (*Action) StringSlice

func (a *Action) StringSlice(metaType int) ([]string, error)

type BeaconViewRetriever

type BeaconViewRetriever interface {
	GetHeight() uint64
	GetAllStakers() (map[byte][]incognitokey.CommitteePublicKey, map[byte][]incognitokey.CommitteePublicKey, map[byte][]incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey, []incognitokey.CommitteePublicKey)
	GetAllCommitteeValidatorCandidateFlattenListFromDatabase() ([]string, error)
	GetAutoStakingList() map[string]bool
	// GetAllBridgeTokens() ([]common.Hash, error)
	GetBeaconFeatureStateDB() *statedb.StateDB
	GetBeaconRewardStateDB() *statedb.StateDB
	GetBeaconSlashStateDB() *statedb.StateDB
	GetStakerInfo(string) (*statedb.StakerInfo, bool, error)
	GetBeaconStakerInfo(stakerPubkey string) (*statedb.BeaconStakerInfo, bool, error)
	GetShardCommitteeFlattenList() []string
	GetShardPendingFlattenList() []string
	GetBeaconConsensusStateDB() *statedb.StateDB
	CandidateWaitingForNextRandom() []incognitokey.CommitteePublicKey
	GetCandidateShardWaitingForCurrentRandom() []incognitokey.CommitteePublicKey
	IsValidNftID(incdb.Database, interface{}, string) error
	IsValidPoolPairID(incdb.Database, interface{}, string) error
	IsValidMintNftRequireAmount(incdb.Database, interface{}, uint64) error
	IsValidPdexv3StakingPool(incdb.Database, interface{}, string) error
	IsValidPdexv3UnstakingAmount(incdb.Database, interface{}, string, string, uint64) error
	IsValidPdexv3ShareAmount(incdb.Database, interface{}, string, string, uint64) error
	BlockHash() common.Hash
	GetBeaconLocking() []incognitokey.CommitteePublicKey
}

type ChainRetriever

type ChainRetriever interface {
	GetCentralizedWebsitePaymentAddress(uint64) string
	GetBurningAddress(blockHeight uint64) string
	GetTransactionByHash(common.Hash) (byte, common.Hash, uint64, int, Transaction, error)
	ListPrivacyTokenAndBridgeTokenAndPRVByShardID(byte) ([]common.Hash, error)
	GetBNBChainID() string
	GetBTCChainID() string
	GetBTCHeaderChain() *btcrelaying.BlockChain
	GetBTCChainParams() *chaincfg.Params
	GetShardStakingTx(shardID byte, beaconHeight uint64) (map[string]string, error)
	IsAfterNewZKPCheckPoint(beaconHeight uint64) bool
	IsAfterPrivacyV2CheckPoint(beaconHeight uint64) bool
	IsAfterPdexv3CheckPoint(beaconHeight uint64) bool
	GetPortalFeederAddress(beaconHeight uint64) string
	IsSupportedTokenCollateralV3(beaconHeight uint64, externalTokenID string) bool
	GetPortalETHContractAddrStr(beaconHeight uint64) string
	GetLatestBNBBlkHeight() (int64, error)
	GetBNBDataHash(blockHeight int64) ([]byte, error)
	CheckBlockTimeIsReached(recentBeaconHeight, beaconHeight, recentShardHeight, shardHeight uint64, duration time.Duration) bool
	IsPortalExchangeRateToken(beaconHeight uint64, tokenIDStr string) bool
	GetMinAmountPortalToken(tokenIDStr string, beaconHeight uint64, version uint) (uint64, error)
	IsPortalToken(beaconHeight uint64, tokenIDStr string, version uint) (bool, error)
	IsValidPortalRemoteAddress(tokenIDStr string, remoteAddr string, beaconHeight uint64, version uint) (bool, error)
	ValidatePortalRemoteAddresses(remoteAddresses map[string]string, beaconHeight uint64, version uint) (bool, error)
	IsEnableFeature(featureFlag string, epoch uint64) bool
	GetPortalV4MinUnshieldAmount(tokenIDStr string, beaconHeight uint64) uint64
	GetPortalV4GeneralMultiSigAddress(tokenIDStr string, beaconHeight uint64) string
	GetPortalReplacementAddress(beaconHeight uint64) string
	CheckBlockTimeIsReachedByBeaconHeight(recentBeaconHeight, beaconHeight uint64, duration time.Duration) bool
	GetPortalV4MultipleTokenAmount(tokenIDStr string, beaconHeight uint64) uint64
	GetFinalBeaconHeight() uint64
	GetPdexv3Cached(common.Hash) interface{}
	GetBeaconChainDatabase() incdb.Database
	GetDelegationRewardAmount(stateDB *statedb.StateDB, pk key.PublicKey) (uint64, error)
}

type Instruction

type Instruction struct {
	MetaType int    `json:"MetaType"`
	Status   string `json:"Status"`
	ShardID  byte   `json:"ShardID"`
	Content  string `json:"Content,omitempty"`
}

func NewInstruction

func NewInstruction() *Instruction

func NewInstructionWithValue

func NewInstructionWithValue(
	metaType int, status string, shardID byte, content string,
) *Instruction

func (*Instruction) FromStringSlice

func (i *Instruction) FromStringSlice(source []string) error

func (*Instruction) StringSlice

func (i *Instruction) StringSlice() []string

func (*Instruction) StringSliceWithRejectContent

func (i *Instruction) StringSliceWithRejectContent(rejectContent *RejectContent) ([]string, error)

type MempoolRetriever

type MempoolRetriever interface {
	GetSerialNumbersHashH() map[common.Hash][]common.Hash
	GetTxsInMem() map[common.Hash]TxDesc
	GetOTAHashH() map[common.Hash][]common.Hash
}

Interface for mempool which is used in metadata

type MetaDataLogger

type MetaDataLogger struct {
	Log common.Logger
}

func (*MetaDataLogger) Init

func (metricLogger *MetaDataLogger) Init(inst common.Logger)

type MetaInfo

type MetaInfo struct {
	HasInput   bool
	HasOutput  bool
	TxType     map[string]interface{}
	MetaAction int
}

type Metadata

type Metadata interface {
	GetType() int
	Sign(*privacy.PrivateKey, Transaction) error
	VerifyMetadataSignature([]byte, Transaction) (bool, error)
	Hash() *common.Hash
	HashWithoutSig() *common.Hash
	CheckTransactionFee(Transaction, uint64, uint64, int64, *statedb.StateDB) bool
	ValidateTxWithBlockChain(tx Transaction, chainRetriever ChainRetriever, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever, shardID byte, transactionStateDB *statedb.StateDB) (bool, error)
	ValidateSanityData(chainRetriever ChainRetriever, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever, beaconHeight uint64, tx Transaction) (bool, bool, error)
	ValidateMetadataByItself() bool
	BuildReqActions(tx Transaction, chainRetriever ChainRetriever, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever, shardID byte, shardHeight uint64) ([][]string, error)
	CalculateSize() uint64
	VerifyMinerCreatedTxBeforeGettingInBlock(mintData *MintData, shardID byte, tx Transaction, chainRetriever ChainRetriever, ac *AccumulatedValues, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever) (bool, error)
	IsMinerCreatedMetaType() bool
	SetSharedRandom([]byte)
}

Interface for all types of metadata in tx

type MetadataBase

type MetadataBase struct {
	Type int
}

func NewMetadataBase

func NewMetadataBase(thisType int) *MetadataBase

func (*MetadataBase) BuildReqActions

func (mb *MetadataBase) BuildReqActions(tx Transaction, chainRetriever ChainRetriever, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever, shardID byte, shardHeight uint64) ([][]string, error)

func (*MetadataBase) CalculateSize

func (mb *MetadataBase) CalculateSize() uint64

func (MetadataBase) CheckTransactionFee

func (mb MetadataBase) CheckTransactionFee(tx Transaction, minFeePerKbTx uint64, minFeePerTx uint64, beaconHeight int64, stateDB *statedb.StateDB) bool

func (MetadataBase) GetType

func (mb MetadataBase) GetType() int

func (MetadataBase) Hash

func (mb MetadataBase) Hash() *common.Hash

func (MetadataBase) HashWithoutSig

func (mb MetadataBase) HashWithoutSig() *common.Hash

func (MetadataBase) IsMinerCreatedMetaType

func (mb MetadataBase) IsMinerCreatedMetaType() bool

func (*MetadataBase) Process

func (mb *MetadataBase) Process() error

func (*MetadataBase) SetSharedRandom

func (mb *MetadataBase) SetSharedRandom(_ []byte)

func (*MetadataBase) Sign

func (mb *MetadataBase) Sign(privateKey *privacy.PrivateKey, tx Transaction) error

func (*MetadataBase) Validate

func (mb *MetadataBase) Validate() error

func (*MetadataBase) VerifyMetadataSignature

func (mb *MetadataBase) VerifyMetadataSignature(publicKey []byte, tx Transaction) (bool, error)

func (MetadataBase) VerifyMinerCreatedTxBeforeGettingInBlock

func (mb MetadataBase) VerifyMinerCreatedTxBeforeGettingInBlock(mintData *MintData, shardID byte, tx Transaction, chainRetriever ChainRetriever, ac *AccumulatedValues, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever) (bool, error)

type MetadataBaseWithSignature

type MetadataBaseWithSignature struct {
	MetadataBase
	Sig []byte `json:"Sig,omitempty"`
}

func NewMetadataBaseWithSignature

func NewMetadataBaseWithSignature(thisType int) *MetadataBaseWithSignature

func (*MetadataBaseWithSignature) Sign

func (mbs *MetadataBaseWithSignature) Sign(privateKey *privacy.PrivateKey, tx Transaction) error

func (*MetadataBaseWithSignature) VerifyMetadataSignature

func (mbs *MetadataBaseWithSignature) VerifyMetadataSignature(publicKey []byte, tx Transaction) (bool, error)

type MetadataTxError

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

func NewMetadataTxError

func NewMetadataTxError(key int, err error, params ...interface{}) *MetadataTxError

func (MetadataTxError) Error

func (e MetadataTxError) Error() string

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

type MintData

type MintData struct {
	ReturnStaking  map[string]bool
	WithdrawReward map[string]bool
	Txs            []Transaction
	TxsUsed        []int
	Insts          [][]string
	InstsUsed      []int
}

type OTADeclaration

type OTADeclaration struct {
	PublicKey [32]byte
	TokenID   common.Hash
}

type RejectContent

type RejectContent struct {
	TxReqID   common.Hash `json:"TxReqID"`
	ErrorCode int         `json:"ErrorCode,omitempty"`
	Data      []byte      `json:"Data,omitempty"`
}

func NewRejectContent

func NewRejectContent() *RejectContent

func NewRejectContentWithValue

func NewRejectContentWithValue(txReqID common.Hash, errorCode int, data []byte) *RejectContent

func (*RejectContent) FromString

func (r *RejectContent) FromString(source string) error

func (*RejectContent) String

func (r *RejectContent) String() (string, error)

type ShardViewRetriever

type ShardViewRetriever interface {
	GetEpoch() uint64
	GetBeaconHeight() uint64
	GetShardID() byte
	GetStakingTx() map[string]string
	ListShardPrivacyTokenAndPRV() []common.Hash
	GetShardRewardStateDB() *statedb.StateDB
	GetCopiedFeatureStateDB() *statedb.StateDB
	GetCopiedTransactionStateDB() *statedb.StateDB
	GetHeight() uint64
	GetBlockVersion() int
	GetTriggeredFeature() map[string]uint64
	GetShardCommittee() []incognitokey.CommitteePublicKey
	GetShardPendingValidator() []incognitokey.CommitteePublicKey
}

type Transaction

type Transaction interface {
	// GET/SET FUNCTION
	GetVersion() int8
	SetVersion(int8)
	GetMetadataType() int
	GetType() string
	SetType(string)
	GetLockTime() int64
	SetLockTime(int64)
	GetSenderAddrLastByte() byte
	SetGetSenderAddrLastByte(byte)
	GetTxFee() uint64
	SetTxFee(uint64)
	GetTxFeeToken() uint64
	GetInfo() []byte
	SetInfo([]byte)
	GetSigPubKey() []byte
	SetSigPubKey([]byte)
	GetSig() []byte
	SetSig([]byte)
	GetProof() privacy.Proof
	SetProof(privacy.Proof)
	GetTokenID() *common.Hash
	GetMetadata() Metadata
	SetMetadata(Metadata)

	// =================== FUNCTIONS THAT GET STUFF AND REQUIRE SOME CODING ===================
	GetTxActualSize() uint64
	GetReceivers() ([][]byte, []uint64)
	GetTransferData() (bool, []byte, uint64, *common.Hash)
	GetReceiverData() ([]coin.Coin, error)
	GetTxMintData() (bool, coin.Coin, *common.Hash, error)
	GetTxBurnData() (bool, coin.Coin, *common.Hash, error)
	GetTxFullBurnData() (bool, coin.Coin, coin.Coin, *common.Hash, error)
	ListOTAHashH() []common.Hash
	ListSerialNumbersHashH() []common.Hash
	String() string
	Hash() *common.Hash
	HashWithoutMetadataSig() *common.Hash
	CalculateTxValue() uint64

	// =================== FUNCTION THAT CHECK STUFFS  ===================
	CheckTxVersion(int8) bool
	IsSalaryTx() bool
	IsPrivacy() bool
	IsCoinsBurning(ChainRetriever, ShardViewRetriever, BeaconViewRetriever, uint64) bool

	// =================== FUNCTIONS THAT VALIDATE STUFFS ===================
	ValidateTxSalary(*statedb.StateDB) (bool, error)
	ValidateTxWithCurrentMempool(MempoolRetriever) error
	ValidateSanityData(ChainRetriever, ShardViewRetriever, BeaconViewRetriever, uint64) (bool, error)

	ValidateTxWithBlockChain(chainRetriever ChainRetriever, shardViewRetriever ShardViewRetriever, beaconViewRetriever BeaconViewRetriever, shardID byte, stateDB *statedb.StateDB) error
	ValidateDoubleSpendWithBlockchain(byte, *statedb.StateDB, *common.Hash) error
	ValidateTxByItself(map[string]bool, *statedb.StateDB, *statedb.StateDB, ChainRetriever, byte, ShardViewRetriever, BeaconViewRetriever) (bool, error)
	ValidateType() bool
	ValidateTransaction(map[string]bool, *statedb.StateDB, *statedb.StateDB, byte, *common.Hash) (bool, []privacy.Proof, error)
	VerifyMinerCreatedTxBeforeGettingInBlock(*MintData, byte, ChainRetriever, *AccumulatedValues, ShardViewRetriever, BeaconViewRetriever) (bool, error)

	// Init Transaction, the input should be params such as: TxPrivacyInitParams
	Init(interface{}) error
	// Verify the init function above, which verify zero knowledge proof and signatures
	Verify(map[string]bool, *statedb.StateDB, *statedb.StateDB, byte, *common.Hash) (bool, error)

	GetValidationEnv() ValidationEnviroment
	SetValidationEnv(ValidationEnviroment)
	UnmarshalJSON(data []byte) error

	// VerifySigTx() (bool, error)
	ValidateSanityDataByItSelf() (bool, error)
	ValidateTxCorrectness(db *statedb.StateDB) (bool, error)
	LoadData(db *statedb.StateDB) error
	CheckData(db *statedb.StateDB) error
	ValidateSanityDataWithBlockchain(
		chainRetriever ChainRetriever,
		shardViewRetriever ShardViewRetriever,
		beaconViewRetriever BeaconViewRetriever,
		beaconHeight uint64,
	) (
		bool,
		error,
	)
}

Interface for all type of transaction

type TxDesc

type TxDesc struct {
	// Tx is the transaction associated with the entry.
	Tx Transaction

	// Height is the best block's height when the entry was added to the the source pool.
	Height uint64

	// Fee is the total fee the transaction associated with the entry pays.
	Fee uint64

	// FeeToken is the total token fee the transaction associated with the entry pays.
	// FeeToken is zero if tx is PRV transaction
	FeeToken uint64

	// FeePerKB is the fee the transaction pays in coin per 1000 bytes.
	FeePerKB int32
}

This is tx struct which is really saved in tx mempool

type ValidationEnviroment

type ValidationEnviroment interface {
	IsPrivacy() bool
	IsConfimed() bool
	TxType() string
	TxAction() int
	ShardID() int
	ShardHeight() uint64
	BeaconHeight() uint64
	ConfirmedTime() int64
	Version() int
	SigPubKey() []byte
	HasCA() bool
	TokenID() common.Hash
	DBData() [][]byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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