common

package
v0.18.14 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 20 Imported by: 37

Documentation

Index

Constants

View Source
const (
	MinimumEncodingVersion = 0x1
	MaximumEncodingInt     = 0xFFFF

	AggregatedSignaturePrefix       = 0xFF01
	AggregatedSignatureSparseMask   = byte(0x01)
	AggregatedSignatureOrdinaryMask = byte(0x00)
)
View Source
const (
	NodeStatePledging  = "PLEDGING"
	NodeStateAccepted  = "ACCEPTED"
	NodeStateRemoved   = "REMOVED"
	NodeStateCancelled = "CANCELLED"
)
View Source
const (
	Operator0   = 0x00
	Operator64  = 0x40
	OperatorSum = 0xfe
	OperatorCmp = 0xff
)
View Source
const (
	TxVersionHashSignature = 0x05

	ExtraSizeGeneralLimit    = 256
	ExtraSizeStorageStep     = 1024
	ExtraSizeStorageCapacity = 1024 * 1024 * 4
	ExtraStoragePriceStep    = "0.0001"
	SliceCountLimit          = 256
	ReferencesCountLimit     = 2

	OutputTypeScript           = 0x00
	OutputTypeWithdrawalSubmit = 0xa1
	OutputTypeNodePledge       = 0xa3
	OutputTypeNodeAccept       = 0xa4

	OutputTypeNodeRemove           = 0xa6
	OutputTypeWithdrawalClaim      = 0xa9
	OutputTypeNodeCancel           = 0xaa
	OutputTypeCustodianUpdateNodes = 0xb1
	OutputTypeCustodianSlashNodes  = 0xb2

	TransactionTypeScript           = 0x00
	TransactionTypeMint             = 0x01
	TransactionTypeDeposit          = 0x02
	TransactionTypeWithdrawalSubmit = 0x03
	TransactionTypeWithdrawalClaim  = 0x05
	TransactionTypeNodePledge       = 0x06
	TransactionTypeNodeAccept       = 0x07

	TransactionTypeNodeRemove           = 0x09
	TransactionTypeNodeCancel           = 0x12
	TransactionTypeCustodianUpdateNodes = 0x13
	TransactionTypeCustodianSlashNodes  = 0x14
	TransactionTypeUnknown              = 0xff
)
View Source
const MainAddressPrefix = "XIN"
View Source
const Precision = 8
View Source
const (
	SnapshotVersionCommonEncoding = 2
)

Variables

View Source
var (
	XINAssetId          = crypto.Sha256Hash([]byte("c94ac88f-4671-3976-b60a-09064f1811e8"))
	BitcoinAssetId      = crypto.Sha256Hash([]byte("c6d0c728-2624-429b-8e0d-d9d19b6592fa"))
	EthereumAssetId     = crypto.Sha256Hash([]byte("43d61dcd-e413-450d-80b8-101d5e903357"))
	BOXAssetId          = crypto.Sha256Hash([]byte("f5ef6b5d-cc5a-3d90-b2c0-a2fd386e7a3c"))
	MOBAssetId          = crypto.Sha256Hash([]byte("eea900a8-b327-488c-8d8d-1428702fe240"))
	USDTEthereumAssetId = crypto.Sha256Hash([]byte("4d8c508b-91c5-375b-92b0-ee702ed2dac5"))
	USDTTronAssetId     = crypto.Sha256Hash([]byte("b91e18ff-a9ae-3dc7-8679-e935d9a4b34b"))
	PandoUSDAssetId     = crypto.Sha256Hash([]byte("31d2ea9c-95eb-3355-b65b-ba096853bc18"))
	USDCAssetId         = crypto.Sha256Hash([]byte("9b180ab6-6abe-3dc0-a13f-04169eb34bfa"))
	EOSAssetId          = crypto.Sha256Hash([]byte("6cfe566e-4aad-470b-8c9a-2fd35b49c68d"))
	SOLAssetId          = crypto.Sha256Hash([]byte("64692c23-8971-4cf4-84a7-4dd1271dd887"))
	UNIAssetId          = crypto.Sha256Hash([]byte("a31e847e-ca87-3162-b4d1-322bc552e831"))
	DOGEAssetId         = crypto.Sha256Hash([]byte("6770a1e5-6086-44d5-b60f-545f9d9e8ffd"))

	XINAsset = &Asset{Chain: EthereumAssetId, AssetKey: "0xa974c709cfb4566686553a20790685a47aceaa33"}
)
View Source
var (
	KernelNodePledgeAmount = NewInteger(13439)
)
View Source
var OneRat = NewInteger(1).Ration(NewInteger(1))
View Source
var Zero = NewInteger(0)

Functions

func ComputeRoundHash added in v0.17.7

func ComputeRoundHash(nodeId crypto.Hash, number uint64, snapshots []*Snapshot) (uint64, uint64, crypto.Hash)

func EncodeCustodianNode added in v0.16.0

func EncodeCustodianNode(custodian, payee *Address, signerSpend, payeeSpend, custodianSpend *crypto.Key, networkId crypto.Hash) []byte

Types

type Address

type Address struct {
	PrivateSpendKey crypto.Key
	PrivateViewKey  crypto.Key
	PublicSpendKey  crypto.Key
	PublicViewKey   crypto.Key
}

func NewAddressFromSeed

func NewAddressFromSeed(seed []byte) Address

func NewAddressFromString

func NewAddressFromString(s string) (Address, error)

func (Address) Hash

func (a Address) Hash() crypto.Hash

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

type AggregatedSignature added in v0.12.18

type AggregatedSignature struct {
	Signers   []int
	Signature crypto.Signature
}

type Asset added in v0.1.14

type Asset struct {
	Chain    crypto.Hash
	AssetKey string
}

func (*Asset) Verify added in v0.2.1

func (a *Asset) Verify() error

type AssetReader added in v0.17.0

type AssetReader interface {
	ReadAssetWithBalance(id crypto.Hash) (*Asset, Integer, error)
}

type CustodianNode added in v0.16.0

type CustodianNode struct {
	Custodian Address
	Payee     Address
	Extra     []byte
}

type CustodianReader added in v0.16.0

type CustodianReader interface {
	ReadCustodian(ts uint64) (*CustodianUpdateRequest, error)
}

type CustodianUpdateRequest added in v0.16.0

type CustodianUpdateRequest struct {
	Custodian   *Address
	Nodes       []*CustodianNode
	Signature   *crypto.Signature
	Transaction crypto.Hash
	Timestamp   uint64
}

func ParseCustodianUpdateNodesExtra added in v0.16.0

func ParseCustodianUpdateNodesExtra(extra []byte, genesis bool) (*CustodianUpdateRequest, error)

type Decoder added in v0.12.1

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

func NewDecoder added in v0.12.1

func NewDecoder(b []byte) *Decoder

func NewMinimumDecoder added in v0.14.0

func NewMinimumDecoder(b []byte) (*Decoder, error)

func (*Decoder) DecodeSnapshotWithTopo added in v0.14.0

func (dec *Decoder) DecodeSnapshotWithTopo() (*SnapshotWithTopologicalOrder, error)

func (*Decoder) DecodeTransaction added in v0.12.1

func (dec *Decoder) DecodeTransaction() (*SignedTransaction, error)

func (*Decoder) Read added in v0.12.1

func (dec *Decoder) Read(b []byte) error

func (*Decoder) ReadAggregatedSignature added in v0.12.18

func (dec *Decoder) ReadAggregatedSignature() (*AggregatedSignature, error)

func (*Decoder) ReadByte added in v0.14.19

func (dec *Decoder) ReadByte() (byte, error)

func (*Decoder) ReadBytes added in v0.12.1

func (dec *Decoder) ReadBytes() ([]byte, error)

func (*Decoder) ReadCosiSignature added in v0.14.0

func (dec *Decoder) ReadCosiSignature() (*crypto.CosiSignature, error)

func (*Decoder) ReadInput added in v0.12.1

func (dec *Decoder) ReadInput() (*Input, error)

func (*Decoder) ReadInt added in v0.12.1

func (dec *Decoder) ReadInt() (int, error)

func (*Decoder) ReadInteger added in v0.12.1

func (dec *Decoder) ReadInteger() (Integer, error)

func (*Decoder) ReadMagic added in v0.12.1

func (dec *Decoder) ReadMagic() (bool, error)

func (*Decoder) ReadOutput added in v0.12.1

func (dec *Decoder) ReadOutput() (*Output, error)

func (*Decoder) ReadRoundReferences added in v0.15.0

func (dec *Decoder) ReadRoundReferences() (*RoundLink, error)

func (*Decoder) ReadSignatures added in v0.12.1

func (dec *Decoder) ReadSignatures() (map[uint16]*crypto.Signature, error)

func (*Decoder) ReadUint16 added in v0.12.1

func (dec *Decoder) ReadUint16() (uint16, error)

func (*Decoder) ReadUint32 added in v0.15.0

func (dec *Decoder) ReadUint32() (uint32, error)

func (*Decoder) ReadUint64 added in v0.12.1

func (dec *Decoder) ReadUint64() (uint64, error)

type DepositData

type DepositData struct {
	Chain       crypto.Hash
	AssetKey    string
	Transaction string
	Index       uint64
	Amount      Integer
}

func (*DepositData) Asset added in v0.1.14

func (d *DepositData) Asset() *Asset

func (*DepositData) UniqueKey added in v0.1.4

func (d *DepositData) UniqueKey() crypto.Hash

type Encoder added in v0.12.1

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

func NewEncoder added in v0.12.1

func NewEncoder() *Encoder

func NewMinimumEncoder added in v0.14.0

func NewMinimumEncoder() *Encoder

func (*Encoder) Bytes added in v0.13.10

func (enc *Encoder) Bytes() []byte

func (*Encoder) EncodeAggregatedSignature added in v0.12.18

func (enc *Encoder) EncodeAggregatedSignature(js *AggregatedSignature)

func (*Encoder) EncodeCosiSignature added in v0.14.0

func (enc *Encoder) EncodeCosiSignature(s *crypto.CosiSignature)

func (*Encoder) EncodeInput added in v0.12.1

func (enc *Encoder) EncodeInput(in *Input)

func (*Encoder) EncodeOutput added in v0.12.1

func (enc *Encoder) EncodeOutput(o *Output)

func (*Encoder) EncodeRoundReferences added in v0.15.0

func (enc *Encoder) EncodeRoundReferences(r *RoundLink)

func (*Encoder) EncodeSignatures added in v0.12.1

func (enc *Encoder) EncodeSignatures(sm map[uint16]*crypto.Signature)

func (*Encoder) EncodeSnapshotPayload added in v0.14.0

func (enc *Encoder) EncodeSnapshotPayload(s *Snapshot) []byte

func (*Encoder) EncodeSnapshotWithTopo added in v0.14.0

func (enc *Encoder) EncodeSnapshotWithTopo(s *SnapshotWithTopologicalOrder) []byte

func (*Encoder) EncodeTransaction added in v0.12.1

func (enc *Encoder) EncodeTransaction(signed *SignedTransaction) []byte

func (*Encoder) Write added in v0.12.1

func (enc *Encoder) Write(b []byte)

func (*Encoder) WriteByte added in v0.12.18

func (enc *Encoder) WriteByte(b byte) error

func (*Encoder) WriteInt added in v0.12.1

func (enc *Encoder) WriteInt(d int)

func (*Encoder) WriteInteger added in v0.12.1

func (enc *Encoder) WriteInteger(d Integer)

func (*Encoder) WriteUint16 added in v0.12.1

func (enc *Encoder) WriteUint16(d uint16)

func (*Encoder) WriteUint32 added in v0.15.0

func (enc *Encoder) WriteUint32(d uint32)

func (*Encoder) WriteUint64 added in v0.12.1

func (enc *Encoder) WriteUint64(d uint64)

type Genesis added in v0.17.7

type Genesis struct {
	Epoch int64 `json:"epoch"`
	Nodes []*struct {
		Signer    *Address `json:"signer"`
		Payee     *Address `json:"payee"`
		Custodian *Address `json:"custodian"`
		Balance   Integer  `json:"balance"`
	} `json:"nodes"`
	Custodian *Address `json:"custodian"`
}

func ReadGenesis added in v0.17.7

func ReadGenesis(path string) (*Genesis, error)

func (*Genesis) BuildSnapshots added in v0.17.7

func (gns *Genesis) BuildSnapshots() ([]*Round, []*SnapshotWithTopologicalOrder, []*VersionedTransaction, error)

func (*Genesis) EpochTimestamp added in v0.17.7

func (gns *Genesis) EpochTimestamp() uint64

func (*Genesis) NetworkId added in v0.17.7

func (gns *Genesis) NetworkId() crypto.Hash

type GhostLocker added in v0.16.0

type GhostLocker interface {
	LockGhostKeys(keys []*crypto.Key, tx crypto.Hash, fork bool) error
}

type Input

type Input struct {
	Hash    crypto.Hash
	Index   uint
	Genesis []byte
	Deposit *DepositData
	Mint    *MintData
}

type Integer

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

func GetAssetCapacity added in v0.17.1

func GetAssetCapacity(id crypto.Hash) Integer

func NewInteger

func NewInteger(x uint64) (v Integer)

func NewIntegerFromString

func NewIntegerFromString(x string) (v Integer)

func (Integer) Add

func (x Integer) Add(y Integer) (v Integer)

func (Integer) Cmp

func (x Integer) Cmp(y Integer) int

func (Integer) Count added in v0.15.0

func (x Integer) Count(y Integer) uint64

func (Integer) Div added in v0.1.1

func (x Integer) Div(y int) (v Integer)

func (Integer) MarshalJSON

func (x Integer) MarshalJSON() ([]byte, error)

func (Integer) Mul added in v0.1.1

func (x Integer) Mul(y int) (v Integer)

func (Integer) Ration added in v0.11.0

func (x Integer) Ration(y Integer) (v RationalNumber)

func (Integer) Sign

func (x Integer) Sign() int

func (Integer) String

func (x Integer) String() string

func (Integer) Sub

func (x Integer) Sub(y Integer) (v Integer)

func (*Integer) UnmarshalJSON

func (x *Integer) UnmarshalJSON(b []byte) error

type MintData added in v0.1.1

type MintData struct {
	Group  string
	Batch  uint64
	Amount Integer
}

func (*MintData) Distribute added in v0.1.1

func (m *MintData) Distribute(tx crypto.Hash) *MintDistribution

type MintDistribution added in v0.1.1

type MintDistribution struct {
	MintData
	Transaction crypto.Hash
}

func UnmarshalMintDistribution added in v0.14.0

func UnmarshalMintDistribution(b []byte) (*MintDistribution, error)

func (*MintDistribution) Marshal added in v0.14.0

func (m *MintDistribution) Marshal() []byte

type Node

type Node struct {
	Signer      Address
	Payee       Address
	State       string
	Transaction crypto.Hash
	Timestamp   uint64
}

func (*Node) IdForNetwork added in v0.5.2

func (n *Node) IdForNetwork(networkId crypto.Hash) crypto.Hash

type NodeReader

type NodeReader interface {
	ReadAllNodes(offset uint64, withState bool) []*Node
}

type Output

type Output struct {
	Type   uint8
	Amount Integer

	Keys   []*crypto.Key
	Mask   crypto.Key
	Script Script

	Withdrawal *WithdrawalData
}

type RationalNumber added in v0.11.0

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

func (RationalNumber) Cmp added in v0.11.0

func (RationalNumber) Product added in v0.11.0

func (r RationalNumber) Product(x Integer) (v Integer)

type Round

type Round struct {
	Hash       crypto.Hash
	NodeId     crypto.Hash
	Number     uint64
	Timestamp  uint64
	References *RoundLink
}

func UnmarshalRound added in v0.14.0

func UnmarshalRound(b []byte) (*Round, error)

func (*Round) Marshal added in v0.14.0

func (r *Round) Marshal() []byte
type RoundLink struct {
	Self     crypto.Hash
	External crypto.Hash
}

func (*RoundLink) Copy added in v0.9.1

func (m *RoundLink) Copy() *RoundLink

func (*RoundLink) Equal

func (m *RoundLink) Equal(n *RoundLink) bool

type RoundSpace added in v0.14.0

type RoundSpace struct {
	NodeId   crypto.Hash
	Batch    uint64
	Round    uint64
	Duration uint64
}

type Script

type Script []uint8

func NewThresholdScript added in v0.1.1

func NewThresholdScript(threshold uint8) Script

func (Script) MarshalJSON

func (s Script) MarshalJSON() ([]byte, error)

func (Script) String

func (s Script) String() string

func (*Script) UnmarshalJSON

func (s *Script) UnmarshalJSON(b []byte) error

func (Script) Validate

func (s Script) Validate(sum int) error

func (Script) VerifyFormat

func (s Script) VerifyFormat() error

type SignedTransaction

type SignedTransaction struct {
	Transaction
	AggregatedSignature *AggregatedSignature
	SignaturesMap       []map[uint16]*crypto.Signature
}

func (*SignedTransaction) AggregateSign added in v0.12.18

func (signed *SignedTransaction) AggregateSign(reader UTXOKeysReader, accounts [][]*Address, seed []byte) error

func (*SignedTransaction) AsVersioned added in v0.14.0

func (tx *SignedTransaction) AsVersioned() *VersionedTransaction

func (*SignedTransaction) GetExtraLimit added in v0.17.5

func (tx *SignedTransaction) GetExtraLimit() int

func (*SignedTransaction) SignInput

func (signed *SignedTransaction) SignInput(reader UTXOKeysReader, index int, accounts []*Address) error

func (*SignedTransaction) SignRaw

func (signed *SignedTransaction) SignRaw(key crypto.Key) error

func (*SignedTransaction) SignUTXO added in v0.5.10

func (signed *SignedTransaction) SignUTXO(utxo *UTXO, accounts []*Address) error

func (*SignedTransaction) TransactionType added in v0.2.0

func (tx *SignedTransaction) TransactionType() uint8

type Snapshot

type Snapshot struct {
	Version      uint8
	NodeId       crypto.Hash
	References   *RoundLink
	RoundNumber  uint64
	Timestamp    uint64
	Signature    *crypto.CosiSignature
	Hash         crypto.Hash
	Transactions []crypto.Hash
}

func (*Snapshot) AddSoleTransaction added in v0.14.0

func (s *Snapshot) AddSoleTransaction(tx crypto.Hash)

func (*Snapshot) PayloadHash

func (s *Snapshot) PayloadHash() crypto.Hash

func (*Snapshot) SoleTransaction added in v0.14.0

func (s *Snapshot) SoleTransaction() crypto.Hash

func (*Snapshot) VersionedMarshal added in v0.14.0

func (s *Snapshot) VersionedMarshal() []byte

type SnapshotWithTopologicalOrder

type SnapshotWithTopologicalOrder struct {
	*Snapshot
	TopologicalOrder uint64
}

func UnmarshalVersionedSnapshot added in v0.14.0

func UnmarshalVersionedSnapshot(b []byte) (*SnapshotWithTopologicalOrder, error)

func (*SnapshotWithTopologicalOrder) VersionedMarshal added in v0.14.0

func (s *SnapshotWithTopologicalOrder) VersionedMarshal() []byte

type SnapshotWork added in v0.11.7

type SnapshotWork struct {
	Hash      crypto.Hash
	Timestamp uint64
	Signers   []crypto.Hash
}

type Transaction

type Transaction struct {
	Version    uint8
	Asset      crypto.Hash
	Inputs     []*Input
	Outputs    []*Output
	References []crypto.Hash
	Extra      []byte
}

func NewTransactionV5 added in v0.17.0

func NewTransactionV5(asset crypto.Hash) *Transaction

func (*Transaction) AddDepositInput

func (tx *Transaction) AddDepositInput(data *DepositData)

func (*Transaction) AddInput

func (tx *Transaction) AddInput(hash crypto.Hash, index uint)

func (*Transaction) AddOutputWithType added in v0.2.0

func (tx *Transaction) AddOutputWithType(ot uint8, accounts []*Address, s Script, amount Integer, seed []byte)

func (*Transaction) AddRandomScriptOutput added in v0.2.0

func (tx *Transaction) AddRandomScriptOutput(accounts []*Address, s Script, amount Integer)

func (*Transaction) AddScriptOutput

func (tx *Transaction) AddScriptOutput(accounts []*Address, s Script, amount Integer, seed []byte)

func (*Transaction) AddUniversalMintInput added in v0.16.0

func (tx *Transaction) AddUniversalMintInput(batch uint64, amount Integer)

func (*Transaction) AsVersioned added in v0.14.0

func (tx *Transaction) AsVersioned() *VersionedTransaction

func (*Transaction) DepositData added in v0.12.0

func (tx *Transaction) DepositData() *DepositData

func (*Transaction) NodeTransactionExtraAsSigner added in v0.17.5

func (tx *Transaction) NodeTransactionExtraAsSigner() *Address

func (*Transaction) ViewGhostKey

func (tx *Transaction) ViewGhostKey(a *crypto.Key) []*Output

type TransactionReader added in v0.17.1

type TransactionReader interface {
	ReadTransaction(hash crypto.Hash) (*VersionedTransaction, string, error)
}

type UTXO

type UTXO struct {
	Input
	Output
	Asset crypto.Hash
}

type UTXOKeys added in v0.12.18

type UTXOKeys struct {
	Mask crypto.Key
	Keys []*crypto.Key
}

type UTXOKeysReader added in v0.12.18

type UTXOKeysReader interface {
	ReadUTXOKeys(hash crypto.Hash, index uint) (*UTXOKeys, error)
}

type UTXOLockReader added in v0.12.18

type UTXOLockReader interface {
	ReadUTXOLock(hash crypto.Hash, index uint) (*UTXOWithLock, error)
	ReadDepositLock(deposit *DepositData) (crypto.Hash, error)
	ReadLastMintDistribution(batch uint64) (*MintDistribution, error)
}

type UTXOLocker

type UTXOLocker interface {
	LockUTXOs(inputs []*Input, tx crypto.Hash, fork bool) error
	LockDepositInput(deposit *DepositData, tx crypto.Hash, fork bool) error
	LockMintInput(mint *MintData, tx crypto.Hash, fork bool) error
}

type UTXOWithLock

type UTXOWithLock struct {
	UTXO
	LockHash crypto.Hash
}

func UnmarshalUTXO added in v0.14.0

func UnmarshalUTXO(b []byte) (*UTXOWithLock, error)

func (*UTXOWithLock) Marshal added in v0.14.0

func (out *UTXOWithLock) Marshal() []byte

type VersionedTransaction added in v0.1.14

type VersionedTransaction struct {
	SignedTransaction
	// contains filtered or unexported fields
}

func UnmarshalVersionedTransaction added in v0.1.14

func UnmarshalVersionedTransaction(val []byte) (*VersionedTransaction, error)

func (*VersionedTransaction) LockInputs added in v0.1.14

func (tx *VersionedTransaction) LockInputs(locker UTXOLocker, fork bool) error

func (*VersionedTransaction) Marshal added in v0.1.14

func (ver *VersionedTransaction) Marshal() []byte

func (*VersionedTransaction) PayloadHash added in v0.1.14

func (ver *VersionedTransaction) PayloadHash() crypto.Hash

func (*VersionedTransaction) PayloadMarshal added in v0.1.14

func (ver *VersionedTransaction) PayloadMarshal() []byte

func (*VersionedTransaction) UnspentOutputs added in v0.1.14

func (tx *VersionedTransaction) UnspentOutputs() []*UTXOWithLock

func (*VersionedTransaction) Validate added in v0.1.14

func (ver *VersionedTransaction) Validate(store DataStore, snapTime uint64, fork bool) error

type WithdrawalData added in v0.2.0

type WithdrawalData struct {
	Address string
	Tag     string
}

Jump to

Keyboard shortcuts

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