types

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	VerifiedNone verifiedType = iota
	VerifiedFormat
	VerifiedGraph
	VerifiedFormatAndGraph
)

Variables

View Source
var (
	ErrDuplicateTx = errors.New("Duplicate tx found in txlookup")

	ErrDuplicateNonce = errors.New("Duplicate tx nonce")

	ErrNonceNotExist = errors.New("Nonce not exist")
)
View Source
var CanRecoverPubFromSig bool

Functions

func ChannelHandler

func ChannelHandler(timer *time.Timer, receiver chan interface{}, data interface{})

Types

type BinaryWriter added in v0.0.2

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

func NewBinaryWriter added in v0.0.2

func NewBinaryWriter() *BinaryWriter

func (*BinaryWriter) Bytes added in v0.0.2

func (s *BinaryWriter) Bytes() []byte

get bytes

func (*BinaryWriter) Write added in v0.0.2

func (s *BinaryWriter) Write(datas ...interface{})

type ConfirmTime

type ConfirmTime struct {
	SeqHeight   uint64 `json:"seq_Height"`
	TxNum       uint64 `json:"tx_num"`
	ConfirmTime string `json:"confirm_time"`
}

func (*ConfirmTime) DecodeMsg

func (z *ConfirmTime) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ConfirmTime) EncodeMsg

func (z ConfirmTime) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ConfirmTime) MarshalMsg

func (z ConfirmTime) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (ConfirmTime) Msgsize

func (z ConfirmTime) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ConfirmTime) UnmarshalMsg

func (z *ConfirmTime) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type PublicKey added in v0.0.2

type PublicKey []byte

func (*PublicKey) DecodeMsg added in v0.0.2

func (z *PublicKey) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (PublicKey) EncodeMsg added in v0.0.2

func (z PublicKey) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (PublicKey) MarshalJson added in v0.0.2

func (b PublicKey) MarshalJson() ([]byte, error)

func (PublicKey) MarshalMsg added in v0.0.2

func (z PublicKey) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (PublicKey) Msgsize added in v0.0.2

func (z PublicKey) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (PublicKey) String added in v0.0.2

func (z PublicKey) String() string

func (*PublicKey) UnmarshalMsg added in v0.0.2

func (z *PublicKey) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type RawTxi

type RawTxi interface {
	GetType() TxBaseType
	GetHeight() uint64
	GetWeight() uint64
	GetTxHash() common.Hash
	GetNonce() uint64
	Parents() common.Hashes // Parents returns the hash of txs that it directly proves.
	SetHash(h common.Hash)
	String() string
	CalcTxHash() common.Hash    // TxHash returns a full tx hash (parents sealed by PoW stage 2)
	CalcMinedHash() common.Hash // NonceHash returns the part that needs to be considered in PoW stage 1.
	CalculateWeight(parents Txis) uint64

	Txi() Txi

	// implemented by msgp
	DecodeMsg(dc *msgp.Reader) (err error)
	EncodeMsg(en *msgp.Writer) (err error)
	MarshalMsg(b []byte) (o []byte, err error)
	UnmarshalMsg(bts []byte) (o []byte, err error)
	Msgsize() (s int)
}

type RawTxis

type RawTxis []RawTxi
func (t Txis) ToRaw() (txs RawTxs, cps RawCampaigns, tcs RawTermChanges, seqs RawSequencers) {
	for _, txi := range t {
		switch tx := txi.(type) {
		case *Tx:
			txs = append(txs, tx.RawTx())
		case *Campaign:
			cps = append(cps, tx.RawCampaign())
		case *TermChange:
			tcs = append(tcs, tx.RawTermChange())
		case *Sequencer:
			seqs = append(seqs, tx.RawSequencer())
		}
	}
	if len(txs) == 0 {
		txs = nil
	}
	if len(cps) == 0 {
		cps = nil
	}
	if len(seqs) == 0 {
		seqs = nil
	}
	return
}

func (*RawTxis) DecodeMsg

func (z *RawTxis) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (RawTxis) EncodeMsg

func (z RawTxis) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (RawTxis) MarshalMsg

func (z RawTxis) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (RawTxis) Msgsize

func (z RawTxis) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*RawTxis) UnmarshalMsg

func (z *RawTxis) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type TxBase

type TxBase struct {
	Type         TxBaseType
	Hash         common.Hash
	ParentsHash  common.Hashes
	AccountNonce uint64
	Height       uint64
	PublicKey    PublicKey //
	Signature    hexutil.Bytes
	MineNonce    uint64
	Weight       uint64

	Version byte
	// contains filtered or unexported fields
}

func (*TxBase) CalcMinedHash

func (t *TxBase) CalcMinedHash() (hash common.Hash)

func (*TxBase) CalcTxHash

func (t *TxBase) CalcTxHash() (hash common.Hash)

func (*TxBase) CalculateWeight

func (t *TxBase) CalculateWeight(parents Txis) uint64

CalculateWeight a core algorithm for tx sorting, a tx's weight must bigger than any of it's parent's weight and bigger than any of it's elder transaction's

func (*TxBase) DecodeMsg

func (z *TxBase) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*TxBase) EncodeMsg

func (z *TxBase) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*TxBase) GetHeight

func (t *TxBase) GetHeight() uint64

func (*TxBase) GetNonce

func (t *TxBase) GetNonce() uint64

func (*TxBase) GetTxHash

func (t *TxBase) GetTxHash() common.Hash

func (*TxBase) GetType

func (t *TxBase) GetType() TxBaseType

func (*TxBase) GetVersion added in v0.0.2

func (t *TxBase) GetVersion() byte

func (*TxBase) GetWeight

func (t *TxBase) GetWeight() uint64

func (*TxBase) InValid

func (t *TxBase) InValid() bool

func (*TxBase) IsVerified added in v0.0.2

func (t *TxBase) IsVerified() verifiedType

func (*TxBase) MarshalMsg

func (z *TxBase) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*TxBase) Msgsize

func (z *TxBase) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*TxBase) Parents

func (t *TxBase) Parents() common.Hashes

func (*TxBase) SetHash

func (t *TxBase) SetHash(hash common.Hash)

func (*TxBase) SetInValid

func (t *TxBase) SetInValid(b bool)

func (*TxBase) SetVerified added in v0.0.2

func (t *TxBase) SetVerified(v verifiedType)

func (*TxBase) String

func (t *TxBase) String() string

func (*TxBase) ToSmallCase added in v0.0.2

func (t *TxBase) ToSmallCase() *TxBaseJson

func (*TxBase) ToSmallCaseJson added in v0.0.2

func (t *TxBase) ToSmallCaseJson() ([]byte, error)

func (*TxBase) UnmarshalMsg

func (z *TxBase) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type TxBaseJson added in v0.0.2

type TxBaseJson struct {
	Type         TxBaseType    `json:"type"`
	Hash         common.Hash   `json:"hash"`
	ParentsHash  common.Hashes `json:"parents_hash"`
	AccountNonce uint64        `json:"account_nonce"`
	Height       uint64        `json:"height"`
	PublicKey    PublicKey     `json:"public_key"`
	Signature    hexutil.Bytes `json:"signature"`
	MineNonce    uint64        `json:"mine_nonce"`
	Weight       uint64        `json:"weight"`

	Version byte `json:"version"`
	// contains filtered or unexported fields
}

func (*TxBaseJson) DecodeMsg added in v0.0.2

func (z *TxBaseJson) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*TxBaseJson) EncodeMsg added in v0.0.2

func (z *TxBaseJson) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*TxBaseJson) MarshalMsg added in v0.0.2

func (z *TxBaseJson) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*TxBaseJson) Msgsize added in v0.0.2

func (z *TxBaseJson) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*TxBaseJson) UnmarshalMsg added in v0.0.2

func (z *TxBaseJson) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type TxBaseType

type TxBaseType uint8
const (
	TxBaseTypeNormal TxBaseType = iota
	TxBaseTypeSequencer
	TxBaseTypeCampaign
	TxBaseTypeTermChange
	TxBaseTypeArchive
	TxBaseAction
)

add tx types here

func (*TxBaseType) DecodeMsg

func (z *TxBaseType) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (TxBaseType) EncodeMsg

func (z TxBaseType) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (TxBaseType) MarshalMsg

func (z TxBaseType) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (TxBaseType) Msgsize

func (z TxBaseType) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (TxBaseType) String

func (t TxBaseType) String() string

func (*TxBaseType) UnmarshalMsg

func (z *TxBaseType) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Txi

type Txi interface {
	// Implemented by TxBase
	GetType() TxBaseType
	GetHeight() uint64
	GetWeight() uint64
	GetTxHash() common.Hash
	GetNonce() uint64
	Parents() common.Hashes // Parents returns the common.Hash of txs that it directly proves.
	SetHash(h common.Hash)
	String() string
	CalcTxHash() common.Hash    // TxHash returns a full tx common.Hash (parents sealed by PoW stage 2)
	CalcMinedHash() common.Hash // NonceHash returns the part that needs to be considered in PoW stage 1.
	CalculateWeight(parents Txis) uint64

	SetInValid(b bool)
	InValid() bool

	// implemented by each tx type
	GetBase() *TxBase
	Sender() common.Address
	GetSender() *common.Address
	SetSender(addr common.Address)
	Dump() string             // For logger dump
	Compare(tx Txi) bool      // Compare compares two txs, return true if they are the same.
	SignatureTargets() []byte // SignatureTargets only returns the parts that needs to be signed by sender.

	RawTxi() RawTxi // compressed txi

	// implemented by msgp
	DecodeMsg(dc *msgp.Reader) (err error)
	EncodeMsg(en *msgp.Writer) (err error)
	MarshalMsg(b []byte) (o []byte, err error)
	UnmarshalMsg(bts []byte) (o []byte, err error)
	Msgsize() (s int)
	GetVersion() byte
	ToSmallCaseJson() ([]byte, error)
	IsVerified() verifiedType
	SetVerified(v verifiedType)
}

type TxiSmallCaseMarshal added in v0.0.2

type TxiSmallCaseMarshal struct {
	Txi Txi
}

func (*TxiSmallCaseMarshal) DecodeMsg added in v0.0.2

func (z *TxiSmallCaseMarshal) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*TxiSmallCaseMarshal) EncodeMsg added in v0.0.2

func (z *TxiSmallCaseMarshal) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*TxiSmallCaseMarshal) MarshalJSON added in v0.0.2

func (t *TxiSmallCaseMarshal) MarshalJSON() ([]byte, error)

func (*TxiSmallCaseMarshal) MarshalMsg added in v0.0.2

func (z *TxiSmallCaseMarshal) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*TxiSmallCaseMarshal) Msgsize added in v0.0.2

func (z *TxiSmallCaseMarshal) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*TxiSmallCaseMarshal) UnmarshalMsg added in v0.0.2

func (z *TxiSmallCaseMarshal) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Txis

type Txis []Txi

func (*Txis) DecodeMsg

func (z *Txis) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Txis) EncodeMsg

func (z Txis) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Txis) Len

func (t Txis) Len() int

func (Txis) Less

func (t Txis) Less(i, j int) bool

func (Txis) MarshalMsg

func (z Txis) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Txis) Msgsize

func (z Txis) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (Txis) RawTxis

func (t Txis) RawTxis() RawTxis

func (Txis) String

func (t Txis) String() string

func (Txis) Swap

func (t Txis) Swap(i, j int)

func (*Txis) UnmarshalMsg

func (z *Txis) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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