types

package
v0.0.0-...-a53bfeb Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

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.

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 (
	ActionTxActionIPO uint8 = iota
	ActionTxActionDestroy
	ActionTxActionSPO
	ActionRequestDomainName
)
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")

	ErrTxNotExist = errors.New("transaction not exist")

	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 ActionData

type ActionData interface {
	marshaller.IMarshaller
	String() string
}

type ActionTx

type ActionTx struct {
	TxBase
	Action     uint8
	From       ogTypes.Address
	ActionData ActionData
	// contains filtered or unexported fields
}

func RandomActionTx

func RandomActionTx() *ActionTx

func SampleActionTx

func SampleActionTx() *ActionTx

func (*ActionTx) CheckActionIsValid

func (t *ActionTx) CheckActionIsValid() bool

func (*ActionTx) Compare

func (t *ActionTx) Compare(tx Txi) bool

func (*ActionTx) Dump

func (t *ActionTx) Dump() string

func (*ActionTx) GetBase

func (t *ActionTx) GetBase() *TxBase

func (*ActionTx) GetConfirm

func (t *ActionTx) GetConfirm() time.Duration

func (*ActionTx) GetSender

func (t *ActionTx) GetSender() ogTypes.Address

func (*ActionTx) MarshalMsg

func (c *ActionTx) MarshalMsg() ([]byte, error)

func (*ActionTx) MsgSize

func (c *ActionTx) MsgSize() int

func (*ActionTx) Sender

func (t *ActionTx) Sender() ogTypes.Address

func (*ActionTx) SetSender

func (c *ActionTx) SetSender(addr ogTypes.Address)

func (*ActionTx) Setconfirm

func (t *ActionTx) Setconfirm()

func (*ActionTx) SignatureTargets

func (t *ActionTx) SignatureTargets() []byte

func (*ActionTx) String

func (t *ActionTx) String() string

func (*ActionTx) UnmarshalMsg

func (c *ActionTx) UnmarshalMsg(b []byte) ([]byte, error)

type BinaryWriter

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

func NewBinaryWriter

func NewBinaryWriter() *BinaryWriter

func (*BinaryWriter) Bytes

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

get bytes

func (*BinaryWriter) Write

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

type BlsSigSet

type BlsSigSet struct {
	PublicKey    []byte
	BlsSignature []byte
}

type DestroyOffering

type DestroyOffering struct {
	TokenId int32 `json:"token_id"`
}

func NewDestroyOffering

func NewDestroyOffering(tokenId int32) *DestroyOffering

func (*DestroyOffering) MarshalMsg

func (d *DestroyOffering) MarshalMsg() ([]byte, error)

func (*DestroyOffering) MsgSize

func (d *DestroyOffering) MsgSize() int

func (*DestroyOffering) String

func (d *DestroyOffering) String() string

func (*DestroyOffering) UnmarshalMsg

func (d *DestroyOffering) UnmarshalMsg(b []byte) ([]byte, error)

type InitialOffering

type InitialOffering struct {
	Value     *math.BigInt `json:"value"`
	EnableSPO bool         `json:"enable_spo"` //if enableSPO is false  , no Secondary Public Issues.
	TokenName string       `json:"token_name"`
}

func NewInitialOffering

func NewInitialOffering(value *math.BigInt, enableSPO bool, tokenName string) *InitialOffering

func (*InitialOffering) MarshalMsg

func (p *InitialOffering) MarshalMsg() ([]byte, error)

func (*InitialOffering) MsgSize

func (p *InitialOffering) MsgSize() int

func (InitialOffering) String

func (p InitialOffering) String() string

func (*InitialOffering) UnmarshalMsg

func (p *InitialOffering) UnmarshalMsg(b []byte) ([]byte, error)

type PublicKey

type PublicKey []byte

func (*PublicKey) DecodeMsg

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

DecodeMsg implements msgp.Decodable

func (PublicKey) EncodeMsg

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

EncodeMsg implements msgp.Encodable

func (PublicKey) MarshalJson

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

func (PublicKey) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (PublicKey) Msgsize

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

func (z PublicKey) String() string

func (*PublicKey) UnmarshalMsg

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

UnmarshalMsg implements msgp.Unmarshaler

type RequestDomain

type RequestDomain struct {
	DomainName string
}

func (RequestDomain) String

func (r RequestDomain) String() string

type SecondaryOffering

type SecondaryOffering struct {
	TokenId int32        `json:"token_id"` //for Secondary Public Issues
	Value   *math.BigInt `json:"value"`
}

func NewSecondaryOffering

func NewSecondaryOffering(tokenId int32, value *math.BigInt) *SecondaryOffering

func (*SecondaryOffering) MarshalMsg

func (so *SecondaryOffering) MarshalMsg() ([]byte, error)

func (*SecondaryOffering) MsgSize

func (so *SecondaryOffering) MsgSize() int

func (SecondaryOffering) String

func (so SecondaryOffering) String() string

func (*SecondaryOffering) UnmarshalMsg

func (so *SecondaryOffering) UnmarshalMsg(b []byte) ([]byte, error)

type Sequencer

type Sequencer struct {
	// TODO: need more states in sequencer to differentiate multiple chains
	TxBase
	Issuer         og_types.Address
	BlsJointSig    hexutil.Bytes
	BlsJointPubKey hexutil.Bytes
	StateRoot      og_types.Hash
	Proposing      bool `msg:"-"` // is the sequencer is proposal ,did't commit yet ,use this flag to avoid bls sig verification failed
}

func RandomSequencer

func RandomSequencer() *Sequencer

func SampleSequencer

func SampleSequencer() *Sequencer

func (*Sequencer) Compare

func (t *Sequencer) Compare(tx Txi) bool

func (*Sequencer) Dump

func (t *Sequencer) Dump() string

func (*Sequencer) GetBase

func (t *Sequencer) GetBase() *TxBase

func (*Sequencer) GetConfirmSeqHash

func (s *Sequencer) GetConfirmSeqHash() og_types.Hash

func (*Sequencer) GetHead

func (t *Sequencer) GetHead() *SequencerHeader

func (*Sequencer) GetParentSeqHash

func (s *Sequencer) GetParentSeqHash() og_types.Hash

func (*Sequencer) GetSender

func (t *Sequencer) GetSender() og_types.Address

func (*Sequencer) MarshalMsg

func (s *Sequencer) MarshalMsg() ([]byte, error)

* Marshaller part

func (*Sequencer) MsgSize

func (s *Sequencer) MsgSize() int

func (*Sequencer) Number

func (t *Sequencer) Number() uint64

func (*Sequencer) Parents

func (t *Sequencer) Parents() []og_types.Hash

func (*Sequencer) PrevBlock

func (s *Sequencer) PrevBlock() og_types.Hash

func (*Sequencer) Sender

func (t *Sequencer) Sender() og_types.Address

func (*Sequencer) SetSender

func (t *Sequencer) SetSender(addr og_types.Address)

func (*Sequencer) SignatureTargets

func (t *Sequencer) SignatureTargets() []byte

func (*Sequencer) String

func (t *Sequencer) String() string

func (*Sequencer) ToJsonMsg

func (s *Sequencer) ToJsonMsg() SequencerMsg

func (*Sequencer) ToSmallCaseJson

func (s *Sequencer) ToSmallCaseJson() ([]byte, error)

func (*Sequencer) UnmarshalMsg

func (s *Sequencer) UnmarshalMsg(b []byte) ([]byte, error)

type SequencerHeader

type SequencerHeader struct {
	Hash   og_types.Hash
	Height uint64
}

func NewSequencerHead

func NewSequencerHead(hash og_types.Hash, height uint64) *SequencerHeader

func (*SequencerHeader) DecodeMsg

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

DecodeMsg implements msgp.Decodable

func (*SequencerHeader) EncodeMsg

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

EncodeMsg implements msgp.Encodable

func (*SequencerHeader) Equal

func (s *SequencerHeader) Equal(h *SequencerHeader) bool

func (*SequencerHeader) GetHash

func (s *SequencerHeader) GetHash() og_types.Hash

func (*SequencerHeader) GetHeight

func (s *SequencerHeader) GetHeight() uint64

func (*SequencerHeader) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*SequencerHeader) Msgsize

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

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

func (*SequencerHeader) SequencerId

func (s *SequencerHeader) SequencerId() uint64

func (*SequencerHeader) String

func (s *SequencerHeader) String() string

func (*SequencerHeader) StringFull

func (s *SequencerHeader) StringFull() string

func (*SequencerHeader) UnmarshalMsg

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

UnmarshalMsg implements msgp.Unmarshaler

type SequencerHeaders

type SequencerHeaders []*SequencerHeader

func (*SequencerHeaders) DecodeMsg

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

DecodeMsg implements msgp.Decodable

func (SequencerHeaders) EncodeMsg

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

EncodeMsg implements msgp.Encodable

func (SequencerHeaders) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (SequencerHeaders) Msgsize

func (z SequencerHeaders) Msgsize() (s int)

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

func (SequencerHeaders) String

func (h SequencerHeaders) String() string

func (*SequencerHeaders) UnmarshalMsg

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

UnmarshalMsg implements msgp.Unmarshaler

type SequencerJson

type SequencerJson struct {
	TxBaseJson
	Issuer         og_types.Address `json:"issuer"`
	BlsJointSig    hexutil.Bytes    `json:"bls_joint_sig"`
	BlsJointPubKey hexutil.Bytes    `json:"bls_joint_pub_key"`
	Proposing      bool             `msg:"-",json:"-"`
}

type SequencerMsg

type SequencerMsg struct {
	Type           int      `json:"type"`
	Hash           string   `json:"hash"`
	Parents        []string `json:"parents"`
	Issuer         string   `json:"issuer"`
	Nonce          uint64   `json:"nonce"`
	Height         uint64   `json:"height"`
	Weight         uint64   `json:"weight"`
	BlsJointSig    string   `json:"bls_joint_sig"`
	BlsJointPubKey string   `json:"bls_joint_pub_key"`
}

type Sequencers

type Sequencers []*Sequencer

func (Sequencers) String

func (s Sequencers) String() string

func (Sequencers) ToHeaders

func (s Sequencers) ToHeaders() SequencerHeaders

type TransactionMsg

type TransactionMsg struct {
	Type    int      `json:"type"`
	Hash    string   `json:"hash"`
	Parents []string `json:"parents"`
	From    string   `json:"from"`
	To      string   `json:"to"`
	Nonce   uint64   `json:"nonce"`
	Value   string   `json:"value"`
	Weight  uint64   `json:"weight"`
}

type Tx

type Tx struct {
	TxBase
	From    og_types.Address
	To      og_types.Address
	Value   *math.BigInt
	TokenId int32
	Data    []byte
	// contains filtered or unexported fields
}

func RandomTx

func RandomTx() *Tx

func SampleTx

func SampleTx() *Tx

func (*Tx) Compare

func (t *Tx) Compare(tx Txi) bool

func (*Tx) Dump

func (t *Tx) Dump() string

func (*Tx) GetBase

func (t *Tx) GetBase() *TxBase

func (*Tx) GetConfirm

func (t *Tx) GetConfirm() time.Duration

func (*Tx) GetSender

func (t *Tx) GetSender() og_types.Address

func (*Tx) GetValue

func (t *Tx) GetValue() *math.BigInt

func (*Tx) MarshalMsg

func (t *Tx) MarshalMsg() ([]byte, error)

func (*Tx) MsgSize

func (t *Tx) MsgSize() int

func (*Tx) Parents

func (t *Tx) Parents() []og_types.Hash

func (*Tx) Sender

func (t *Tx) Sender() og_types.Address

func (*Tx) SetSender

func (t *Tx) SetSender(addr og_types.Address)

func (*Tx) Setconfirm

func (t *Tx) Setconfirm()

func (*Tx) SignatureTargets

func (t *Tx) SignatureTargets() []byte

func (*Tx) String

func (t *Tx) String() string

func (*Tx) ToJsonMsg

func (t *Tx) ToJsonMsg() TransactionMsg

func (*Tx) UnmarshalMsg

func (t *Tx) UnmarshalMsg(b []byte) ([]byte, error)

type TxBase

type TxBase struct {
	Type         TxBaseType
	Hash         og_types.Hash
	ParentsHash  []og_types.Hash
	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 og_types.Hash)

func (*TxBase) CalcTxHash

func (t *TxBase) CalcTxHash() (hash og_types.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) GetHeight

func (t *TxBase) GetHeight() uint64

func (*TxBase) GetNonce

func (t *TxBase) GetNonce() uint64

func (*TxBase) GetTxHash

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

func (*TxBase) GetType

func (t *TxBase) GetType() TxBaseType

func (*TxBase) GetVersion

func (t *TxBase) GetVersion() byte

func (*TxBase) GetWeight

func (t *TxBase) GetWeight() uint64

func (*TxBase) InValid

func (t *TxBase) InValid() bool

func (*TxBase) IsVerified

func (t *TxBase) IsVerified() verifiedType

func (*TxBase) MarshalMsg

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

func (*TxBase) MsgSize

func (t *TxBase) MsgSize() int

func (*TxBase) Parents

func (t *TxBase) Parents() []og_types.Hash

func (*TxBase) SetHash

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

func (*TxBase) SetInValid

func (t *TxBase) SetInValid(b bool)

func (*TxBase) SetVerified

func (t *TxBase) SetVerified(v verifiedType)

func (*TxBase) String

func (t *TxBase) String() string

func (*TxBase) ToSmallCase

func (t *TxBase) ToSmallCase() *TxBaseJson

func (*TxBase) ToSmallCaseJson

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

func (*TxBase) UnmarshalMsg

func (t *TxBase) UnmarshalMsg(b []byte) ([]byte, error)

type TxBaseJson

type TxBaseJson struct {
	Type         TxBaseType      `json:"type"`
	Hash         og_types.Hash   `json:"hash"`
	ParentsHash  []og_types.Hash `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
}

type TxBaseType

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

add tx types here

func (TxBaseType) String

func (t TxBaseType) String() string

type Txi

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

	SetInValid(b bool)
	InValid() bool

	// implemented by each tx type
	GetBase() *TxBase
	Sender() og_types.Address
	GetSender() og_types.Address
	SetSender(addr og_types.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.

	GetVersion() byte

	marshaller.IMarshaller
}

type Txis

type Txis []Txi

func (Txis) Len

func (t Txis) Len() int

func (Txis) Less

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

func (Txis) String

func (t Txis) String() string

func (Txis) Swap

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

type Txs

type Txs []*Tx

func (Txs) String

func (t Txs) String() string

Jump to

Keyboard shortcuts

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