common

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeStatePledging  = "PLEDGING"
	NodeStateAccepted  = "ACCEPTED"
	NodeStateDeparting = "DEPARTING"
)
View Source
const (
	Operator0   = 0x00
	Operator64  = 0x40
	OperatorSum = 0xfe
	OperatorCmp = 0xff
)
View Source
const (
	TxVersion      = 0x01
	ExtraSizeLimit = 256

	OutputTypeScript           = 0x00
	OutputTypeWithdrawalSubmit = 0xa1
	OutputTypeWithdrawalFuel   = 0xa2
	OutputTypeNodePledge       = 0xa3
	OutputTypeNodeAccept       = 0xa4
	OutputTypeNodeDepart       = 0xa5
	OutputTypeNodeRemove       = 0xa6
	OutputTypeDomainAccept     = 0xa7
	OutputTypeDomainRemove     = 0xa8
	OutputTypeWithdrawalClaim  = 0xa9

	TransactionTypeScript           = 0x00
	TransactionTypeMint             = 0x01
	TransactionTypeDeposit          = 0x02
	TransactionTypeWithdrawalSubmit = 0x03
	TransactionTypeWithdrawalFuel   = 0x04
	TransactionTypeWithdrawalClaim  = 0x05
	TransactionTypeNodePledge       = 0x06
	TransactionTypeNodeAccept       = 0x07
	TransactionTypeNodeDepart       = 0x08
	TransactionTypeNodeRemove       = 0x09
	TransactionTypeDomainAccept     = 0x10
	TransactionTypeDomainRemove     = 0x11
	TransactionTypeUnknown          = 0xff
)
View Source
const MainNetworkId = "XIN"
View Source
const (
	MintGroupKernelNode = "KERNELNODE"
)
View Source
const Precision = 8

Variables

View Source
var (
	EthereumChainId crypto.Hash

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

Functions

func CompressMsgpackMarshalPanic

func CompressMsgpackMarshalPanic(val interface{}) []byte

func DecompressMsgpackUnmarshal

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

func MsgpackMarshalPanic

func MsgpackMarshalPanic(val interface{}) []byte

func MsgpackUnmarshal

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

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 Asset

type Asset struct {
	ChainId  crypto.Hash
	AssetKey string
}

func (*Asset) AssetId

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

func (*Asset) FeeAssetId

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

func (*Asset) Verify

func (a *Asset) Verify() error

type DepositData

type DepositData struct {
	Chain           crypto.Hash `json:"chain"`
	AssetKey        string      `json:"asset"`
	TransactionHash string      `json:"transaction"`
	OutputIndex     uint64      `json:"index"`
	Amount          Integer     `json:"amount"`
}

func (*DepositData) Asset

func (d *DepositData) Asset() *Asset

func (*DepositData) UniqueKey

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

type Domain

type Domain struct {
	Account Address
}

type DomainReader

type DomainReader interface {
	ReadDomains() []Domain
}

type GenesisHackInput

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

type GenesisHackTransaction

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  `json:"hash,omitempty"`
	Index   int          `json:"index,omitempty"`
	Genesis []byte       `json:"genesis,omitempty"`
	Deposit *DepositData `json:"deposit,omitempty"`
	Mint    *MintData    `json:"mint,omitempty"`
}

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

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

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

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

type MintData struct {
	Group  string  `json:"group"`
	Batch  uint64  `json:"batch"`
	Amount Integer `json:"amount"`
}

func (*MintData) Distribute

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

type MintDistribution

type MintDistribution struct {
	Group       string      `json:"group"`
	Batch       uint64      `json:"batch"`
	Amount      Integer     `json:"amount"`
	Transaction crypto.Hash `json:"transaction"`
}

type Node

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

type NodeReader

type NodeReader interface {
	ReadConsensusNodes() []*Node
	ReadTransaction(hash crypto.Hash) (*VersionedTransaction, error)
}

type Output

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

	// OutputTypeScript fields
	Script Script     `json:"script,omitempty"`
	Mask   crypto.Key `json:"mask,omitempty"`
}

type Round

type Round struct {
	Hash       crypto.Hash `json:"hash"`
	NodeId     crypto.Hash `json:"node"`
	Number     uint64      `json:"number"`
	Timestamp  uint64      `json:"timestamp"`
	References *RoundLink  `json:"references"`
}
type RoundLink struct {
	Self     crypto.Hash `json:"self"`
	External crypto.Hash `json:"external"`
}

func (*RoundLink) Equal

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

type Script

type Script []uint8

func NewThresholdScript

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

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

type SignedTransaction

type SignedTransaction struct {
	Transaction
	Signatures [][]crypto.Signature `json:"signatures,omitempty"`
}

func (*SignedTransaction) DepositData

func (tx *SignedTransaction) DepositData() *DepositData

func (*SignedTransaction) SignInput

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

func (*SignedTransaction) SignRaw

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

func (*SignedTransaction) TransactionType

func (tx *SignedTransaction) TransactionType() uint8

type Snapshot

type Snapshot struct {
	NodeId      crypto.Hash         `json:"node"`
	Transaction crypto.Hash         `json:"transaction"`
	References  *RoundLink          `json:"references"`
	RoundNumber uint64              `json:"round"`
	Timestamp   uint64              `json:"timestamp"`
	Signatures  []*crypto.Signature `json:"signatures,omitempty"`
	Hash        crypto.Hash         `msgpack:"-"json:"hash"`
}

func (*Snapshot) Payload added in v0.1.0

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

func (*Snapshot) PayloadHash

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

type SnapshotWithTopologicalOrder

type SnapshotWithTopologicalOrder struct {
	Snapshot
	TopologicalOrder uint64 `json:"topology"`
}

type Transaction

type Transaction struct {
	Version uint8       `json:"version"`
	Asset   crypto.Hash `json:"asset"`
	Inputs  []*Input    `json:"inputs"`
	Outputs []*Output   `json:"outputs"`
	Extra   []byte      `json:"extra,omitempty"`
}

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

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

func (*Transaction) AddOutputWithType

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

func (*Transaction) AddRandomScriptOutput

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

func (tx *Transaction) AsLatestVersion() *VersionedTransaction

func (*Transaction) ViewGhostKey

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

type UTXO

type UTXO struct {
	Input
	Output
	Asset crypto.Hash
}

type UTXOLocker

type UTXOLocker interface {
	LockUTXO(hash crypto.Hash, index int, 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 UTXOReader

type UTXOReader interface {
	ReadUTXO(hash crypto.Hash, index int) (*UTXOWithLock, error)
	CheckDepositInput(deposit *DepositData, tx crypto.Hash) error
	ReadLastMintDistribution(group string) (*MintDistribution, error)
}

type UTXOWithLock

type UTXOWithLock struct {
	UTXO
	LockHash crypto.Hash
}

type VersionedTransaction

type VersionedTransaction struct {
	SignedTransaction
	BadGenesis *SignedGenesisHackTransaction
}

func DecompressUnmarshalVersionedTransaction

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

func UnmarshalVersionedTransaction

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

func (*VersionedTransaction) CompressMarshal

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

func (*VersionedTransaction) LockInputs

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

func (*VersionedTransaction) Marshal

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

func (*VersionedTransaction) PayloadHash

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

func (*VersionedTransaction) PayloadMarshal

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

func (*VersionedTransaction) UnspentOutputs

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

func (*VersionedTransaction) Validate

func (ver *VersionedTransaction) Validate(store DataStore) error

type WithdrawalData

type WithdrawalData struct {
	Chain    crypto.Hash `json:"chain"`
	AssetKey string      `json:"asset"`
	Address  string      `json:"address"`
	Tag      string      `json:"tag"`
}

func (*WithdrawalData) Asset

func (w *WithdrawalData) Asset() *Asset

Jump to

Keyboard shortcuts

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