types

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 11 Imported by: 43

Documentation

Index

Constants

View Source
const (
	MaxPrecision = 8
	MinPrecision = 0
)
View Source
const (
	// BlockVersion is the version of block.
	BlockVersion uint32 = 0

	// GenesisNonce is the nonce of genesis block.
	GenesisNonce uint32 = 3194347904

	// MaxBlockSize is the maximum size of a block.
	MaxBlockSize = 8000000

	// MaxBlockHeaderSize is the maximum number of bytes allowed per block header.
	MaxBlockHeaderSize uint32 = 2000000

	// MaxTxPerBlock is the maximum transactions can be included in
	// a block.
	MaxTxPerBlock = 100000
)
View Source
const (
	RechargeToSideChainPayloadVersion0 byte = 0x00
	RechargeToSideChainPayloadVersion1 byte = 0x01
)
View Source
const (
	// MaxProgramCodeSize is the maximum allowed length of program code.
	MaxProgramCodeSize = 10000

	// MaxProgramParamSize is the maximum allowed length of program parameter.
	MaxProgramParamSize = MaxProgramCodeSize * 2
)
View Source
const (
	// MaxPayloadDataSize is the maximum allowed length of payload data.
	MaxPayloadDataSize = 1024 * 1024 // 1MB
)
View Source
const PayloadCoinBaseVersion byte = 0x04
View Source
const RecordPayloadVersion byte = 0x00

Variables

View Source
var DeserializeOutput = func(output *Output, r io.Reader) error {
	err := output.AssetID.Deserialize(r)
	if err != nil {
		return err
	}

	err = output.Value.Deserialize(r)
	if err != nil {
		return err
	}

	temp, err := common.ReadUint32(r)
	if err != nil {
		return err
	}
	output.OutputLock = uint32(temp)

	err = output.ProgramHash.Deserialize(r)
	if err != nil {
		return err
	}

	return nil
}
View Source
var GetDataContainer = func(programHash *common.Uint168, tx *Transaction) interfaces.IDataContainer {
	return tx
}
View Source
var GetPayloadByTxType = func(txType TxType) (Payload, error) {
	var p Payload
	switch txType {
	case CoinBase:
		p = new(PayloadCoinBase)
	case RegisterAsset:
		p = new(PayloadRegisterAsset)
	case TransferAsset:
		p = new(PayloadTransferAsset)
	case Record:
		p = new(PayloadRecord)
	case RechargeToSideChain:
		p = new(PayloadRechargeToSideChain)
	case TransferCrossChainAsset:
		p = new(PayloadTransferCrossChainAsset)
	default:
		return nil, errors.New("[Transaction], invalid transaction type.")
	}
	return p, nil
}
View Source
var SerializeOutput = func(output *Output, w io.Writer) error {
	err := output.AssetID.Serialize(w)
	if err != nil {
		return err
	}

	err = output.Value.Serialize(w)
	if err != nil {
		return err
	}

	common.WriteUint32(w, output.OutputLock)

	err = output.ProgramHash.Serialize(w)
	if err != nil {
		return err
	}

	return nil
}
View Source
var TxTypeStr = func(txType TxType) string {
	s, ok := ttStrings[txType]
	if ok {
		return s
	}
	return fmt.Sprintf("TxType%d", txType)
}

Functions

func GetSystemAssetId

func GetSystemAssetId() common.Uint256

func IsValidAttributeType

func IsValidAttributeType(usage AttributeUsage) bool

Types

type Asset

type Asset struct {
	Name        string
	Description string
	Precision   byte
	AssetType   AssetType
	RecordType  AssetRecordType
}

registered asset will be assigned to contract address

func (*Asset) Deserialize

func (a *Asset) Deserialize(r io.Reader) error

Deserialize is the implement of SignableData interface.

func (*Asset) Hash

func (a *Asset) Hash() common.Uint256

func (*Asset) Serialize

func (a *Asset) Serialize(w io.Writer) error

Serialize is the implement of SignableData interface.

type AssetRecordType

type AssetRecordType byte
const (
	Unspent AssetRecordType = 0x00
	Balance AssetRecordType = 0x01
)

type AssetType

type AssetType byte

AssetType

const (
	Token AssetType = 0x00
	Share AssetType = 0x01
)

type Attribute

type Attribute struct {
	Usage AttributeUsage
	Data  []byte
}

func NewAttribute

func NewAttribute(u AttributeUsage, d []byte) Attribute

func (*Attribute) Deserialize

func (a *Attribute) Deserialize(r io.Reader) error

func (*Attribute) Serialize

func (a *Attribute) Serialize(w io.Writer) error

func (Attribute) String

func (a Attribute) String() string

type AttributeUsage

type AttributeUsage byte
const (
	Nonce          AttributeUsage = 0x00
	Script         AttributeUsage = 0x20
	Memo           AttributeUsage = 0x81
	Description    AttributeUsage = 0x90
	DescriptionUrl AttributeUsage = 0x91
)

func (AttributeUsage) Name

func (u AttributeUsage) Name() string

type BaseHeader added in v0.1.6

type BaseHeader struct {
	Version    uint32
	Previous   common.Uint256
	MerkleRoot common.Uint256
	Timestamp  uint32
	Bits       uint32
	Nonce      uint32
	Height     uint32
}

func (*BaseHeader) Deserialize added in v0.1.6

func (header *BaseHeader) Deserialize(r io.Reader) error

func (*BaseHeader) Serialize added in v0.1.6

func (header *BaseHeader) Serialize(w io.Writer) error

type Block

type Block struct {
	interfaces.Header

	Transactions []*Transaction
}

func NewBlock added in v0.1.5

func NewBlock() *Block

func (*Block) Deserialize

func (b *Block) Deserialize(r io.Reader) error

func (*Block) FromTrimmedData

func (b *Block) FromTrimmedData(r io.Reader) error

func (*Block) GetSize

func (b *Block) GetSize() int

func (*Block) Hash

func (b *Block) Hash() common.Uint256

func (*Block) Serialize

func (b *Block) Serialize(w io.Writer) error

func (*Block) Trim

func (b *Block) Trim(w io.Writer) error
type Header struct {
	Base       BaseHeader
	SideAuxPow auxpow.SideAuxPow
}

func (*Header) Deserialize

func (header *Header) Deserialize(r io.Reader) error

func (*Header) GetAuxPow added in v0.1.5

func (header *Header) GetAuxPow() *auxpow.SideAuxPow

func (*Header) GetBits added in v0.1.5

func (header *Header) GetBits() uint32

func (*Header) GetHeaderSize added in v0.1.8

func (header *Header) GetHeaderSize() int

func (*Header) GetHeight added in v0.1.5

func (header *Header) GetHeight() uint32

func (*Header) GetMerkleRoot added in v0.1.5

func (header *Header) GetMerkleRoot() common.Uint256

func (*Header) GetNonce added in v0.1.5

func (header *Header) GetNonce() uint32

func (*Header) GetPrevious added in v0.1.5

func (header *Header) GetPrevious() common.Uint256

func (*Header) GetTimeStamp added in v0.1.5

func (header *Header) GetTimeStamp() uint32

func (*Header) GetVersion added in v0.1.5

func (header *Header) GetVersion() uint32

func (*Header) Hash

func (header *Header) Hash() common.Uint256

func (*Header) Serialize

func (header *Header) Serialize(w io.Writer) error

func (*Header) SetAuxPow added in v0.1.5

func (header *Header) SetAuxPow(sideAuxPow *auxpow.SideAuxPow)

func (*Header) SetBits added in v0.1.5

func (header *Header) SetBits(bits uint32)

func (*Header) SetHeight added in v0.1.5

func (header *Header) SetHeight(height uint32)

func (*Header) SetMerkleRoot added in v0.1.5

func (header *Header) SetMerkleRoot(root common.Uint256)

func (*Header) SetNonce added in v0.1.5

func (header *Header) SetNonce(nonce uint32)

func (*Header) SetPrevious added in v0.1.5

func (header *Header) SetPrevious(previous common.Uint256)

func (*Header) SetTimeStamp added in v0.1.5

func (header *Header) SetTimeStamp(timestamp uint32)

func (*Header) SetVersion added in v0.1.5

func (header *Header) SetVersion(version uint32)

type Input

type Input struct {
	// Reference outpoint of this input
	Previous OutPoint

	// Sequence number
	Sequence uint32
}

func (*Input) Deserialize

func (i *Input) Deserialize(r io.Reader) error

func (*Input) IsEqual

func (i *Input) IsEqual(o Input) bool

func (*Input) ReferKey

func (i *Input) ReferKey() string

func (*Input) Serialize

func (i *Input) Serialize(w io.Writer) error

func (Input) String

func (i Input) String() string

type OutPoint

type OutPoint struct {
	TxID  common.Uint256
	Index uint16
}

func NewOutPoint

func NewOutPoint(txId common.Uint256, index uint16) *OutPoint

func OutPointFromBytes

func OutPointFromBytes(value []byte) (*OutPoint, error)

func (*OutPoint) Bytes

func (o *OutPoint) Bytes() []byte

func (*OutPoint) Deserialize

func (o *OutPoint) Deserialize(r io.Reader) error

func (*OutPoint) IsEqual

func (o *OutPoint) IsEqual(t OutPoint) bool

func (*OutPoint) Serialize

func (o *OutPoint) Serialize(w io.Writer) error

type Output

type Output struct {
	AssetID     common.Uint256
	Value       common.Fixed64
	TokenValue  big.Int
	OutputLock  uint32
	ProgramHash common.Uint168
}

func (*Output) Deserialize

func (o *Output) Deserialize(r io.Reader) error

func (*Output) Serialize

func (o *Output) Serialize(w io.Writer) error

func (Output) String

func (o Output) String() string

type Payload

type Payload interface {
	//  Get payload data
	Data(version byte) []byte

	//Serialize payload data
	Serialize(w io.Writer, version byte) error

	Deserialize(r io.Reader, version byte) error
}

Payload define the func for loading the payload data base on payload type which have different struture

type PayloadCoinBase

type PayloadCoinBase struct {
	CoinbaseData []byte
}

func (*PayloadCoinBase) Data

func (a *PayloadCoinBase) Data(version byte) []byte

func (*PayloadCoinBase) Deserialize

func (a *PayloadCoinBase) Deserialize(r io.Reader, version byte) error

func (*PayloadCoinBase) Serialize

func (a *PayloadCoinBase) Serialize(w io.Writer, version byte) error

type PayloadRechargeToSideChain

type PayloadRechargeToSideChain struct {
	MerkleProof              []byte
	MainChainTransaction     []byte
	MainChainTransactionHash common.Uint256
}

func (*PayloadRechargeToSideChain) Data

func (t *PayloadRechargeToSideChain) Data(version byte) []byte

func (*PayloadRechargeToSideChain) Deserialize

func (t *PayloadRechargeToSideChain) Deserialize(r io.Reader, version byte) error

func (*PayloadRechargeToSideChain) GetMainchainTxHash

func (t *PayloadRechargeToSideChain) GetMainchainTxHash(payloadVersion byte) (*common.Uint256, error)

func (*PayloadRechargeToSideChain) Serialize

func (t *PayloadRechargeToSideChain) Serialize(w io.Writer, version byte) error

type PayloadRecord

type PayloadRecord struct {
	RecordType string
	RecordData []byte
}

func (*PayloadRecord) Data

func (a *PayloadRecord) Data(version byte) []byte

func (*PayloadRecord) Deserialize

func (a *PayloadRecord) Deserialize(r io.Reader, version byte) error

Deserialize is the implement of SignableData interface.

func (*PayloadRecord) Serialize

func (a *PayloadRecord) Serialize(w io.Writer, version byte) error

Serialize is the implement of SignableData interface.

type PayloadRegisterAsset

type PayloadRegisterAsset struct {
	Asset      Asset
	Amount     common.Fixed64
	Controller common.Uint168
}

func (*PayloadRegisterAsset) Data

func (a *PayloadRegisterAsset) Data(version byte) []byte

func (*PayloadRegisterAsset) Deserialize

func (a *PayloadRegisterAsset) Deserialize(r io.Reader, version byte) error

func (*PayloadRegisterAsset) Serialize

func (a *PayloadRegisterAsset) Serialize(w io.Writer, version byte) error

type PayloadTransferAsset

type PayloadTransferAsset struct{}

func (*PayloadTransferAsset) Data

func (a *PayloadTransferAsset) Data(version byte) []byte

func (*PayloadTransferAsset) Deserialize

func (a *PayloadTransferAsset) Deserialize(r io.Reader, version byte) error

func (*PayloadTransferAsset) Serialize

func (a *PayloadTransferAsset) Serialize(w io.Writer, version byte) error

type PayloadTransferCrossChainAsset

type PayloadTransferCrossChainAsset struct {
	CrossChainAddresses []string
	OutputIndexes       []uint64
	CrossChainAmounts   []common.Fixed64
}

func (*PayloadTransferCrossChainAsset) Data

func (a *PayloadTransferCrossChainAsset) Data(version byte) []byte

func (*PayloadTransferCrossChainAsset) Deserialize

func (a *PayloadTransferCrossChainAsset) Deserialize(r io.Reader, version byte) error

func (*PayloadTransferCrossChainAsset) Serialize

func (a *PayloadTransferCrossChainAsset) Serialize(w io.Writer, version byte) error

type Program

type Program struct {
	//the contract program code,which will be run on VM or specific envrionment
	Code []byte

	//the program code's parameter
	Parameter []byte
}

func (*Program) Deserialize

func (p *Program) Deserialize(w io.Reader) error

Deserialize the Program

func (*Program) Serialize

func (p *Program) Serialize(w io.Writer) error

Serialize the Program

func (Program) String

func (p Program) String() string

type Transaction

type Transaction struct {
	TxType         TxType
	PayloadVersion byte
	Payload        Payload
	Attributes     []*Attribute
	Inputs         []*Input
	Outputs        []*Output
	LockTime       uint32
	Programs       []*Program
	Fee            common.Fixed64
	FeePerKB       common.Fixed64
	// contains filtered or unexported fields
}

func NewTrimmedTx

func NewTrimmedTx(hash common.Uint256) *Transaction

func (*Transaction) Deserialize

func (tx *Transaction) Deserialize(r io.Reader) error

deserialize the Transaction

func (*Transaction) DeserializeUnsigned

func (tx *Transaction) DeserializeUnsigned(r io.Reader) error

func (*Transaction) GetData

func (tx *Transaction) GetData() []byte

VM IDataContainer interface

func (*Transaction) GetSize

func (tx *Transaction) GetSize() int

func (*Transaction) Hash

func (tx *Transaction) Hash() common.Uint256

func (*Transaction) IsCoinBaseTx

func (tx *Transaction) IsCoinBaseTx() bool

func (*Transaction) IsRechargeToSideChainTx

func (tx *Transaction) IsRechargeToSideChainTx() bool

func (*Transaction) IsRegisterAssetTx

func (tx *Transaction) IsRegisterAssetTx() bool

func (*Transaction) IsSideChainPowTx

func (tx *Transaction) IsSideChainPowTx() bool

func (*Transaction) IsTransferCrossChainAssetTx

func (tx *Transaction) IsTransferCrossChainAssetTx() bool

func (*Transaction) Serialize

func (tx *Transaction) Serialize(w io.Writer) error

Serialize the Transaction

func (*Transaction) SerializeUnsigned

func (tx *Transaction) SerializeUnsigned(w io.Writer) error

Serialize the Transaction data without contracts

func (*Transaction) String

func (tx *Transaction) String() string

type TxType

type TxType byte

for different transaction types with different payload format and transaction process methods

const (
	CoinBase                TxType = 0x00
	RegisterAsset           TxType = 0x01
	TransferAsset           TxType = 0x02
	Record                  TxType = 0x03
	Deploy                  TxType = 0x04
	SideChainPow            TxType = 0x05
	RechargeToSideChain     TxType = 0x06
	WithdrawFromSideChain   TxType = 0x07
	TransferCrossChainAsset TxType = 0x08
	Invoke                  TxType = 0xF0

	InvalidTransactionSize = -1
)

func (TxType) String

func (tt TxType) String() string

type UTXO

type UTXO struct {
	TxId  common.Uint256
	Index uint32
	Value common.Fixed64
}

func (*UTXO) Deserialize

func (u *UTXO) Deserialize(r io.Reader) error

func (*UTXO) Serialize

func (u *UTXO) Serialize(w io.Writer) error

Jump to

Keyboard shortcuts

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