common

package
v1.0.1-beta.0...-9a7f616 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 10 Imported by: 0

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
	IncDAORewardRequestMeta      = 42

	WithDrawRewardRequestMeta  = 44
	WithDrawRewardResponseMeta = 45

	//staking
	ShardStakingMeta    = 63
	StopAutoStakingMeta = 127
	BeaconStakingMeta   = 64
	UnStakingMeta       = 210

	// 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

	// 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

	// 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

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

	InitTokenRequestMeta  = 244
	InitTokenResponseMeta = 245

	IssuingBSCRequestMeta  = 250
	IssuingBSCResponseMeta = 251
	BurningPBSCRequestMeta = 252
	BurningBSCConfirmMeta  = 253

	BurningPBSCForDepositToSCRequestMeta = 326
	BurningPBSCConfirmForDepositToSCMeta = 152

	IssuingPLGRequestMeta               = 327
	IssuingPLGResponseMeta              = 328
	BurningPLGRequestMeta               = 329
	BurningPLGConfirmMeta               = 153 // incognito mode for bsc
	BurningPLGForDepositToSCRequestMeta = 330
	BurningPLGConfirmForDepositToSCMeta = 154

	IssuingFantomRequestMeta               = 331
	IssuingFantomResponseMeta              = 332
	BurningFantomRequestMeta               = 333
	BurningFantomConfirmMeta               = 155
	BurningFantomForDepositToSCRequestMeta = 334
	BurningFantomConfirmForDepositToSCMeta = 156

	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
	EVMConfirmationBlocks = 15
)
View Source
const (
	NoAction = iota
	MetaRequestBeaconMintTxs
	MetaRequestShardMintTxs
)

Variables

View Source
var AcceptedWithdrawRewardRequestVersion = []int{0, 1}

Functions

func AssertPaymentAddressAndTxVersion

func AssertPaymentAddressAndTxVersion(paymentAddress interface{}, version int8) (key.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 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 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 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

Types

type MetaInfo

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

type Metadata

type Metadata interface {
	// GetType returns the type of a Metadata
	GetType() int

	// Sign signs the metadata with the provided private key.
	Sign(*key.PrivateKey, Transaction) error

	// Hash calculates the hash of a metadata.
	Hash() *common.Hash

	// HashWithoutSig calculates the hash of a metadata without including its sig.
	HashWithoutSig() *common.Hash

	// CalculateSize returns the size of a metadata in bytes.
	CalculateSize() uint64
}

Metadata is an interface describing all common methods of a metadata. A Metadata is a special piece of information enclosed with a transaction to indicate additional purpose of the transaction.

type MetadataBase

type MetadataBase struct {
	Type int
}

MetadataBase is the base field for a Metadata.

func NewMetadataBase

func NewMetadataBase(thisType int) *MetadataBase

NewMetadataBase creates a new MetadataBase with the given metadata type.

func (*MetadataBase) CalculateSize

func (mb *MetadataBase) CalculateSize() uint64

CalculateSize returns the size of a metadata in bytes.

func (MetadataBase) GetType

func (mb MetadataBase) GetType() int

GetType returns the type of a metadata.

func (MetadataBase) Hash

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

Hash calculates the hash of a metadata.

func (MetadataBase) HashWithoutSig

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

HashWithoutSig calculates the hash of a metadata without including its sig.

func (*MetadataBase) Sign

func (mb *MetadataBase) Sign(_ *key.PrivateKey, _ Transaction) error

Sign does nothing.

type MetadataBaseWithSignature

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

MetadataBaseWithSignature is the base field for a Metadata that requires authenticity (i.e, has a signature).

func NewMetadataBaseWithSignature

func NewMetadataBaseWithSignature(thisType int) *MetadataBaseWithSignature

NewMetadataBaseWithSignature creates a new MetadataBaseWithSignature with the given metadata type.

func (*MetadataBaseWithSignature) Sign

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

Sign signs a Metadata using the provided private key.

type OTADeclaration

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

type Transaction

type Transaction interface {
	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)

	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

	CheckTxVersion(int8) bool
	IsSalaryTx() bool
	IsPrivacy() bool

	Init(interface{}) error
}

Transaction is an interface describing all common methods of a transaction.

Jump to

Keyboard shortcuts

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