common

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: GPL-3.0 Imports: 55 Imported by: 37

Documentation

Index

Constants

View Source
const (
	MaximumEncodingInt = 0xFFFF

	AggregatedSignaturePrefix      = 0xFF01
	AggregatedSignatureSparseMask  = byte(0x01)
	AggregatedSignatureOrdinayMask = 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 (
	TxVersion       = 0x02
	ExtraSizeLimit  = 256
	SliceCountLimit = 256

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

	OutputTypeNodeRemove         = 0xa6
	OutputTypeDomainAccept       = 0xa7
	OutputTypeDomainRemove       = 0xa8
	OutputTypeWithdrawalClaim    = 0xa9
	OutputTypeNodeCancel         = 0xaa
	OutputTypeDomainAssetCustody = 0xab
	OutputTypeDomainAssetRelease = 0xac
	OutputTypeDomainAssetMigrate = 0xad

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

	TransactionTypeNodeRemove   = 0x09
	TransactionTypeDomainAccept = 0x10
	TransactionTypeDomainRemove = 0x11
	TransactionTypeNodeCancel   = 0x12
	TransactionTypeUnknown      = 0xff
)
View Source
const MainNetworkId = "XIN"
View Source
const (
	MintGroupKernelNode = "KERNELNODE"
)
View Source
const Precision = 8
View Source
const (
	SnapshotVersion = 1
)

Variables

View Source
var (
	CompressionVersionZero   = []byte{0, 0, 0, 0}
	CompressionVersionLatest = CompressionVersionZero
)
View Source
var (
	XINAssetId crypto.Hash
)
View Source
var ZstdEmbed []byte

Functions

func Compress added in v0.12.1

func Compress(b []byte) []byte

func CompressMsgpackMarshalPanic added in v0.2.7

func CompressMsgpackMarshalPanic(val interface{}) []byte

func Decompress added in v0.12.1

func Decompress(b []byte) []byte

func DecompressMsgpackUnmarshal added in v0.2.7

func DecompressMsgpackUnmarshal(data []byte, val interface{}) error

func MsgpackMarshalPanic

func MsgpackMarshalPanic(val interface{}) []byte

func MsgpackUnmarshal added in v0.1.13

func MsgpackUnmarshal(data []byte, val interface{}) error

func NewZstdDecoder added in v0.12.22

func NewZstdDecoder(ccr int) *zstd.Decoder

func NewZstdEncoder added in v0.12.22

func NewZstdEncoder(ccr int) *zstd.Encoder

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 {
	ChainId  crypto.Hash
	AssetKey string
}

func (*Asset) AssetId added in v0.1.14

func (a *Asset) AssetId() crypto.Hash

func (*Asset) FeeAssetId added in v0.1.14

func (a *Asset) FeeAssetId() crypto.Hash

func (*Asset) Verify added in v0.2.1

func (a *Asset) Verify() 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 (*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) ReadBytes added in v0.12.1

func (dec *Decoder) ReadBytes() ([]byte, 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) 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) ReadUint64 added in v0.12.1

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

type DepositData

type DepositData struct {
	Chain           crypto.Hash
	AssetKey        string
	TransactionHash string
	OutputIndex     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 DeprecatedSnapshot added in v0.5.0

type DeprecatedSnapshot struct {
	NodeId      crypto.Hash
	Transaction crypto.Hash
	References  *RoundLink
	RoundNumber uint64
	Timestamp   uint64
	Signatures  []*crypto.Signature
}

type Domain

type Domain struct {
	Account Address
}

type DomainReader

type DomainReader interface {
	ReadDomains() []Domain
}

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 (*Encoder) EncodeAggregatedSignature added in v0.12.18

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

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) EncodeSignatures added in v0.12.1

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

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)

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) WriteUint64 added in v0.12.1

func (enc *Encoder) WriteUint64(d uint64)

type GenesisHackInput added in v0.1.14

type GenesisHackInput struct {
	Hash    crypto.Hash
	Index   int
	Genesis []byte
	Deposit *DepositData
	Rebate  []byte
	Mint    []byte
}

type GenesisHackTransaction added in v0.1.14

type GenesisHackTransaction struct {
	Version uint8
	Asset   crypto.Hash
	Inputs  []*GenesisHackInput
	Outputs []*Output
	Extra   []byte
}

type GhostChecker

type GhostChecker interface {
	CheckGhost(key crypto.Key) (bool, error)
}

type Input

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

type Integer

type Integer struct {
	// contains filtered or unexported fields
}
var Zero 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) 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) MarshalMsgpack

func (x Integer) MarshalMsgpack() ([]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

func (*Integer) UnmarshalMsgpack

func (x *Integer) UnmarshalMsgpack(data []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
}

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
	ReadTransaction(hash crypto.Hash) (*VersionedTransaction, string, error)
}

type Output

type Output struct {
	Type       uint8
	Amount     Integer
	Keys       []*crypto.Key
	Withdrawal *WithdrawalData `msgpack:",omitempty"`

	// OutputTypeScript fields
	Script Script
	Mask   crypto.Key
}

type RationalNumber added in v0.11.0

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

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
}
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 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 SignedGenesisHackTransaction added in v0.1.14

type SignedGenesisHackTransaction struct {
	GenesisHackTransaction
	Signatures [][]crypto.Signature
}

type SignedTransaction

type SignedTransaction struct {
	Transaction
	AggregatedSignature *AggregatedSignature           `msgpack:"-"`
	SignaturesMap       []map[uint16]*crypto.Signature `msgpack:"-"`
	SignaturesSliceV1   [][]*crypto.Signature          `msgpack:"-"`
}

func (*SignedTransaction) AggregateSign added in v0.12.18

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

func (*SignedTransaction) AsLatestVersion added in v0.4.1

func (tx *SignedTransaction) AsLatestVersion() *VersionedTransaction

func (*SignedTransaction) SignInput

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

func (*SignedTransaction) SignInputV1 added in v0.12.1

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

func (*SignedTransaction) SignRaw

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

func (*SignedTransaction) SignRawV1 added in v0.12.3

func (signed *SignedTransaction) SignRawV1(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 SignedTransactionV1 added in v0.12.0

type SignedTransactionV1 struct {
	Transaction
	SignaturesSliceV1 [][]*crypto.Signature `msgpack:"Signatures"`
}

type Snapshot

type Snapshot struct {
	Version     uint8
	NodeId      crypto.Hash
	Transaction crypto.Hash
	References  *RoundLink
	RoundNumber uint64
	Timestamp   uint64
	Signatures  []*crypto.Signature   `msgpack:",omitempty"`
	Signature   *crypto.CosiSignature `msgpack:",omitempty"`
	Hash        crypto.Hash           `msgpack:"-"`
}

func (*Snapshot) PayloadHash

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

func (*Snapshot) VersionedPayload added in v0.5.0

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

type SnapshotWithTopologicalOrder

type SnapshotWithTopologicalOrder struct {
	Snapshot
	TopologicalOrder uint64
}

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
	Extra   []byte
}

func NewTransaction

func NewTransaction(asset crypto.Hash) *Transaction

func (*Transaction) AddDepositInput

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

func (*Transaction) AddInput

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

func (*Transaction) AddKernelNodeMintInput added in v0.1.1

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

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) error

func (*Transaction) AddScriptOutput

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

func (*Transaction) AsLatestVersion added in v0.1.14

func (tx *Transaction) AsLatestVersion() *VersionedTransaction

func (*Transaction) DepositData added in v0.12.0

func (tx *Transaction) DepositData() *DepositData

func (*Transaction) ViewGhostKey

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

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 int) (*UTXOKeys, error)
}

type UTXOLockReader added in v0.12.18

type UTXOLockReader interface {
	ReadUTXOLock(hash crypto.Hash, index int) (*UTXOWithLock, error)
	CheckDepositInput(deposit *DepositData, tx crypto.Hash) error
	ReadLastMintDistribution(group string) (*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
}

type VersionedTransaction added in v0.1.14

type VersionedTransaction struct {
	SignedTransaction
	BadGenesis *SignedGenesisHackTransaction `msgpack:"-"`
	// contains filtered or unexported fields
}

func DecompressUnmarshalVersionedTransaction added in v0.2.7

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

func UnmarshalVersionedTransaction added in v0.1.14

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

func (*VersionedTransaction) CompressMarshal added in v0.2.7

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

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() []*UTXO

func (*VersionedTransaction) Validate added in v0.1.14

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

type WithdrawalData added in v0.2.0

type WithdrawalData struct {
	Chain    crypto.Hash
	AssetKey string
	Address  string
	Tag      string
}

func (*WithdrawalData) Asset added in v0.2.0

func (w *WithdrawalData) Asset() *Asset

Jump to

Keyboard shortcuts

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