Documentation ¶
Index ¶
- Constants
- Variables
- func AddPaddingBigInt(numInt *big.Int, fixedSize int) []byte
- func AppendSliceString(arrayStrings ...[][]string) [][]string
- func B2I(bytes []byte) *big.Int
- func B2ImN(bytes []byte) *big.Int
- func BoolToByte(value bool) byte
- func BytesSToUint16(b []byte) (uint16, error)
- func BytesToInt(bytesArr []byte) int
- func BytesToInt32(b []byte) (int32, error)
- func BytesToUint16(b [2]byte) uint16
- func BytesToUint32(b []byte) (uint32, error)
- func BytesToUint64(b []byte) (uint64, error)
- func CompareStringArray(src []string, dst []string) bool
- func FromHex(s string) []byte
- func GetShardIDFromLastByte(b byte) byte
- func Has0xPrefix(str string) bool
- func Hash4Bls(data []byte) []byte
- func HashB(b []byte) []byte
- func Hex2Bytes(str string) []byte
- func Int32ToBytes(value int32) []byte
- func Int64ToBytes(value int64) []byte
- func IntToBytes(n int) []byte
- func RandBigIntMaxRange(max *big.Int) (*big.Int, error)
- func RandBytes(length int) []byte
- func RandInt() int
- func RandInt64() int64
- func RandIntInterval(L, R int) int
- func RandUint64() uint64
- func SHA256(b []byte) []byte
- func SliceExists(slice interface{}, item interface{}) (bool, error)
- func Uint16ToBytes(v uint16) [2]byte
- func Uint32ToBytes(value uint32) []byte
- func Uint64ToBytes(value uint64) []byte
- type AES
- type Hash
- func (h Hash) Bytes() []byte
- func (hashObj *Hash) Cmp(target *Hash) (int, error)
- func (hashObj *Hash) Decode(dst *Hash, src string) error
- func (hashObj *Hash) Format(f fmt.State, c rune)
- func (hashObj *Hash) GetBytes() []byte
- func (hashObj *Hash) IsEqual(target *Hash) bool
- func (hashObj Hash) MarshalText() ([]byte, error)
- func (hashObj Hash) NewHash(newHash []byte) (*Hash, error)
- func (hashObj Hash) NewHashFromStr(hash string) (*Hash, error)
- func (hashObj *Hash) SetBytes(newHash []byte) error
- func (hashObj Hash) String() string
- func (hashObj *Hash) UnmarshalJSON(data []byte) error
- func (hashObj Hash) UnmarshalText(text []byte) error
Constants ¶
const ( EmptyString = "" ZeroByte = byte(0x00) DateOutputFormat = "2006-01-02T15:04:05.999999" BigIntSize = 32 // bytes CheckSumLen = 4 // bytes AESKeySize = 32 // bytes Int32Size = 4 // bytes Uint32Size = 4 // bytes Uint64Size = 8 // bytes HashSize = 32 // bytes MaxHashStringSize = HashSize * 2 Base58Version = 0 )
for common
const ( // for key size PrivateKeySize = 32 // bytes PublicKeySize = 32 // bytes BLSPublicKeySize = 128 // bytes BriPublicKeySize = 33 // bytes TransmissionKeySize = 32 //bytes ReceivingKeySize = 32 // bytes PaymentAddressSize = 64 // bytes // for signature size // it is used for both privacy and no privacy SigPubKeySize = 32 SigNoPrivacySize = 64 SigPrivacySize = 96 IncPubKeyB58Size = 51 MaxPSMsgSize = 1 << 22 //4Mb )
size data for incognito key and signature
const ( ExitCodeUnknow = iota ExitByOs ExitByLogging ExitCodeForceUpdate )
for exit code
const ( TxNormalType = "n" // normal tx(send and receive coin) TxRewardType = "s" // reward tx TxReturnStakingType = "rs" // TxConversionType = "cv" // Convert 1 - 2 normal tx TxTokenConversionType = "tcv" // Convert 1 - 2 token tx //TxCustomTokenType = "t" // token tx with no supporting privacy TxCustomTokenPrivacyType = "tp" // token tx with supporting privacy )
For all Transaction information
const ( BeaconRole = "beacon" ShardRole = "shard" CommitteeRole = "committee" ProposerRole = "proposer" ValidatorRole = "validator" PendingRole = "pending" SyncingRole = "syncing" //this is for shard case - when beacon tell it is committee, but its state not WaitingRole = "waiting" BlsConsensus = "bls" BridgeConsensus = "dsa" IncKeyType = "inc" )
CONSENSUS
const ( BeaconChainKey = "beacon" ShardChainKey = "shard" )
const ( BeaconChainDataBaseID = -1 BeaconChainDatabaseDirectory = "beacon" ShardChainDatabaseDirectory = "shard" )
const ( REPLACE_IN = 0 REPLACE_OUT = 1 )
const ( AbiJson = `` /* 10558-byte string literal not displayed */ BridgeShardID = 1 EthAddrStr = "0x0000000000000000000000000000000000000000" )
Ethereum Decentralized bridge
const ( BridgeRequestNotFoundStatus = 0 BridgeRequestProcessingStatus = 1 BridgeRequestAcceptedStatus = 2 BridgeRequestRejectedStatus = 3 PDENotFoundStatus = 0 PDEContributionWaitingStatus = 1 PDEContributionAcceptedStatus = 2 PDEContributionRefundStatus = 3 PDEContributionMatchedNReturnedStatus = 4 PDETradeAcceptedStatus = 1 PDETradeRefundStatus = 2 PDECrossPoolTradeAcceptedStatus = 1 PDECrossPoolTradeRefundStatus = 2 PDEWithdrawalAcceptedStatus = 1 PDEWithdrawalRejectedStatus = 2 PDEFeeWithdrawalAcceptedStatus = 1 PDEFeeWithdrawalRejectedStatus = 2 MinTxFeesOnTokenRequirement = 10000000000000 // 10000 prv, this requirement is applied from beacon height 87301 mainnet BeaconBlockHeighMilestoneForMinTxFeesOnTokenRequirement = 87301 // milestone of beacon height, when apply min fee on token requirement //portal PortalCustodianDepositAcceptedStatus = 1 PortalCustodianDepositRefundStatus = 2 PortalReqPTokenAcceptedStatus = 1 PortalReqPTokenRejectedStatus = 2 PortalPortingTxRequestAcceptedStatus = 1 PortalPortingTxRequestRejectedStatus = 3 PortalPortingReqSuccessStatus = 1 PortalPortingReqWaitingStatus = 2 PortalPortingReqExpiredStatus = 3 PortalPortingReqLiquidatedStatus = 4 PortalRedeemReqSuccessStatus = 1 PortalRedeemReqWaitingStatus = 2 PortalRedeemReqMatchedStatus = 3 PortalRedeemReqLiquidatedStatus = 4 PortalRedeemReqCancelledByLiquidationStatus = 5 PortalRedeemRequestTxAcceptedStatus = 1 PortalRedeemRequestTxRejectedStatus = 2 PortalCustodianWithdrawReqAcceptedStatus = 1 PortalCustodianWithdrawReqRejectStatus = 2 PortalReqUnlockCollateralAcceptedStatus = 1 PortalReqUnlockCollateralRejectedStatus = 2 PortalLiquidateCustodianSuccessStatus = 1 PortalLiquidateCustodianFailedStatus = 2 PortalLiquidationTPExchangeRatesSuccessStatus = 1 PortalLiquidationTPExchangeRatesFailedStatus = 2 PortalReqWithdrawRewardAcceptedStatus = 1 PortalReqWithdrawRewardRejectedStatus = 2 PortalRedeemFromLiquidationPoolSuccessStatus = 1 PortalRedeemFromLiquidationPoolRejectedStatus = 2 PortalCustodianTopupSuccessStatus = 1 PortalCustodianTopupRejectedStatus = 2 PortalExpiredPortingReqSuccessStatus = 1 PortalExpiredPortingReqFailedStatus = 2 PortalExchangeRatesAcceptedStatus = 1 PortalExchangeRatesRejectedStatus = 2 PortalReqMatchingRedeemAcceptedStatus = 1 PortalReqMatchingRedeemRejectedStatus = 2 PortalTopUpWaitingPortingSuccessStatus = 1 PortalTopUpWaitingPortingRejectedStatus = 2 PortalCustodianDepositV3AcceptedStatus = 1 PortalCustodianDepositV3RejectedStatus = 2 PortalCustodianWithdrawReqV3AcceptedStatus = 1 PortalCustodianWithdrawReqV3RejectStatus = 2 PortalUnlockOverRateCollateralsAcceptedStatus = 1 PortalUnlockOverRateCollateralsRejectedStatus = 2 )
Bridge, PDE & Portal statuses for RPCs
const ( PDEContributionWaitingChainStatus = "waiting" PDEContributionMatchedChainStatus = "matched" PDEContributionRefundChainStatus = "refund" PDEContributionMatchedNReturnedChainStatus = "matchedNReturned" PDETradeAcceptedChainStatus = "accepted" PDETradeRefundChainStatus = "refund" PDEWithdrawalAcceptedChainStatus = "accepted" PDEWithdrawalRejectedChainStatus = "rejected" PDEFeeWithdrawalAcceptedChainStatus = "accepted" PDEFeeWithdrawalRejectedChainStatus = "rejected" PDEWithdrawalOnFeeAcceptedChainStatus = "onFeeAccepted" PDEWithdrawalOnPoolPairAcceptedChainStatus = "onPoolPairAccepted" PDEWithdrawalWithPRVFeeRejectedChainStatus = "withPRVFeeRejected" PDECrossPoolTradeFeeRefundChainStatus = "xPoolTradeRefundFee" PDECrossPoolTradeSellingTokenRefundChainStatus = "xPoolTradeRefundSellingToken" PDECrossPoolTradeAcceptedChainStatus = "xPoolTradeAccepted" )
PDE statuses for chain
const ( PortalCustodianDepositAcceptedChainStatus = "accepted" PortalCustodianDepositRefundChainStatus = "refund" PortalReqPTokensAcceptedChainStatus = "accepted" PortalReqPTokensRejectedChainStatus = "rejected" PortalPortingRequestAcceptedChainStatus = "accepted" PortalPortingRequestRejectedChainStatus = "rejected" PortalExchangeRatesAcceptedChainStatus = "accepted" PortalExchangeRatesRejectedChainStatus = "rejected" PortalRedeemRequestAcceptedChainStatus = "accepted" PortalRedeemRequestRejectedChainStatus = "rejected" PortalRedeemReqCancelledByLiquidationChainStatus = "cancelled" PortalCustodianWithdrawRequestAcceptedChainStatus = "accepted" PortalCustodianWithdrawRequestRejectedChainStatus = "rejected" PortalReqUnlockCollateralAcceptedChainStatus = "accepted" PortalReqUnlockCollateralRejectedChainStatus = "rejected" PortalLiquidateCustodianSuccessChainStatus = "success" PortalLiquidateCustodianFailedChainStatus = "failed" PortalLiquidateTPExchangeRatesSuccessChainStatus = "success" PortalLiquidateTPExchangeRatesFailedChainStatus = "rejected" PortalReqWithdrawRewardAcceptedChainStatus = "accepted" PortalReqWithdrawRewardRejectedChainStatus = "rejected" PortalRedeemFromLiquidationPoolSuccessChainStatus = "success" PortalRedeemFromLiquidationPoolRejectedChainStatus = "rejected" PortalCustodianTopupSuccessChainStatus = "success" PortalCustodianTopupRejectedChainStatus = "rejected" PortalExpiredWaitingPortingReqSuccessChainStatus = "success" PortalExpiredWaitingPortingReqFailedChainStatus = "failed" PortalReqMatchingRedeemAcceptedChainStatus = "accepted" PortalReqMatchingRedeemRejectedChainStatus = "rejected" PortalPickMoreCustodianRedeemSuccessChainStatus = "success" PortalPickMoreCustodianRedeemFailedChainStatus = "failed" PortalTopUpWaitingPortingSuccessChainStatus = "success" PortalTopUpWaitingPortingRejectedChainStatus = "rejected" // Portal v3 PortalCustodianDepositV3AcceptedChainStatus = "accepted" PortalCustodianDepositV3RejectedChainStatus = "rejected" PortalCustodianWithdrawRequestV3AcceptedChainStatus = "accepted" PortalCustodianWithdrawRequestV3RejectedChainStatus = "rejected" PortalCusUnlockOverRateCollateralsAcceptedChainStatus = "accepted" PortalCusUnlockOverRateCollateralsRejectedChainStatus = "rejected" )
Portal status for chain
const ( RelayingHeaderRejectedChainStatus = "rejected" RelayingHeaderConsideringChainStatus = "considering" )
Relaying header
const ( BurningAddress = "15pABFiJVeh9D5uiQEhQX4SVibGGbdAVipQxBdxkmDqAJaoG1EdFKHBrNfs" BurningAddress2 = "12RxahVABnAVCGP3LGwCn8jkQxgw7z1x14wztHzn455TTVpi1wBq9YGwkRMQg3J4e657AbAnCvYCJSdA9czBUNuCKwGSRQt55Xwz8WA" )
burning addresses
const ( TestnetETHContractAddressStr = "0xE0D5e7217c6C4bc475404b26d763fAD3F14D2b86" Testnet2ETHContractAddressStr = "0x7c7e371D1e25771f2242833C1A354dCE846f3ec8" MainETHContractAddressStr = "0x97875355eF55Ae35613029df8B1C8Cf8f89c9066" )
const ETHChainName = "eth"
const (
HexEmptyRoot = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
)
const PRVIDStr = "0000000000000000000000000000000000000000000000000000000000000004"
const PortalBNBIDStr = "6abd698ea7ddd1f98b1ecaaddab5db0453b8363ff092f0d8d7d4c6b1155fb693"
const PortalBTCIDStr = "ef5947f70ead81a76a53c7c8b7317dd5245510c665d3a13921dc9a581188728b"
Variables ¶
var ( MaxTxSize = uint64(100) // unit KB = 100KB MaxBlockSize = uint64(2000) //unit kilobytes = 2 Megabyte )
var ( PRVCoinID = Hash{4} // To send PRV in custom token PRVCoinName = "PRV" // To send PRV in custom token ConfidentialAssetID = Hash{5} ConfidentialAssetName = "CA" MaxShardNumber = 8 //programmatically config based on networkID )
special token ids (aka. PropertyID in custom token)
var CipherTextIsEmptyErr = errors.New("ciphertext is empty")
var (
EmptyRoot = HexToHash(HexEmptyRoot)
)
var EthContractAddressStr = MainETHContractAddressStr
var InvalidAESKeyErr = errors.New("aes key is invalid")
var InvalidHashSizeErr = errors.New("invalid hash size")
var InvalidMaxHashSizeErr = errors.New("invalid max hash size")
var MinAmountPortalPToken = map[string]uint64{
PortalBTCIDStr: 10,
PortalBNBIDStr: 10,
}
set MinAmountPortalPToken to avoid attacking with amount is less than smallest unit of cryptocurrency such as satoshi in BTC
var NilHashErr = errors.New("input hash is nil")
var PlainTextIsEmptyErr = errors.New("plaintext is empty")
var PortalSupportedIncTokenIDs = []string{ PortalBTCIDStr, PortalBNBIDStr, }
var SupportedTokenID map[string]string
var TIMESLOT = uint64(0) //need to be set when init chain
Functions ¶
func AddPaddingBigInt ¶
AddPaddingBigInt adds padding to big int to it is fixed size and returns bytes array
func AppendSliceString ¶
AppendSliceString is a variadic function, receives some lists of array of strings and appends them to one list of array of strings
func BoolToByte ¶
BoolToByte receives a value in bool and returns a value in byte
func BytesSToUint16 ¶
func BytesToInt ¶
BytesToInt reverts an integer number from 2-byte array
func BytesToInt32 ¶
BytesToInt32 converts little endian 4-byte array to int32 number
func BytesToUint16 ¶
func BytesToUint32 ¶
BytesToUint32 converts big endian 4-byte array to uint32 number
func BytesToUint64 ¶
BytesToUint64 converts little endian 8-byte array to uint64 number
func CompareStringArray ¶
CompareStringArray receives 2 arrays of string and check whether 2 arrays is the same or not
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func GetShardIDFromLastByte ¶
GetShardIDFromLastByte receives a last byte of public key and returns a corresponding shardID
func Has0xPrefix ¶
Has0xPrefix validates str begins with '0x' or '0X'.
func Hash4Bls ¶
Hash4Bls is Hash function for calculate block hash this is different from hash function for calculate transaction hash
func Int32ToBytes ¶
Int32ToBytes converts int32 number to little endian 4-byte array
func Int64ToBytes ¶
Int64ToBytes converts int64 number to little endian 8-byte array
func IntToBytes ¶
IntToBytes converts an integer number to 2-byte array in big endian
func RandBigIntMaxRange ¶
RandBigIntMaxRange generates a big int with maximum value
func RandIntInterval ¶
RandIntInterval returns a random int in range [L; R]
func RandUint64 ¶
func RandUint64() uint64
func SHA256 ¶
SHA256 calculates SHA256-256 hashing of input b and returns the result in bytes array.
func SliceExists ¶
SliceExists receives a slice and a item in interface type checks whether the slice contain the item or not
func Uint16ToBytes ¶
func Uint32ToBytes ¶
Uint32ToBytes converts uint32 number to big endian 4-byte array
func Uint64ToBytes ¶
Uint64ToBytes converts uint64 number to little endian 8-byte array
Types ¶
type Hash ¶
func BytesToHash ¶
func HashArrayOfHashArray ¶
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func Keccak256Hash ¶
Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.
func (*Hash) Cmp ¶
Cmp compare two hashes hash = target : return 0 hash > target : return 1 hash < target : return -1
func (*Hash) Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func (Hash) MarshalText ¶
MarshalText converts hashObj string to bytes array
func (Hash) NewHashFromStr ¶
NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON unmarshal json data to hashObj
func (Hash) UnmarshalText ¶
UnmarshalText reverts bytes array to hashObj