types

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: ISC Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerLength = 53
	MaxName    = 100
)

Variables

View Source
var CoinBase = arry.StringToAddress("coinbase")

Functions

func CalculateFee

func CalculateFee(msgs []types.IMessage) uint64

func EncodeRlpBlocks

func EncodeRlpBlocks(rlpBlocks []*RlpBlock) ([]byte, error)

func EncodeRlpMessages

func EncodeRlpMessages(msgs []*RlpMessage) []byte

func MsgRoot

func MsgRoot(msgs []types.IMessage) arry.Hash

func RlpBlocksToBlocks

func RlpBlocksToBlocks(rlpBlocks []*RlpBlock) []types.IBlock

func Verify

func Verify(hash arry.Hash, signScript types.ISignature) bool

Verify signature by hash and signature result

func VerifySigner

func VerifySigner(network string, signer arry.Address, pubKey []byte) bool

Verify whether the signers are consistent through the public key

Types

type Account

type Account struct {
	Address    arry.Address `json:"address"`
	Nonce      uint64       `json:"nonce"`
	Tokens     Tokens       `json:"tokens"`
	Confirmed  uint64       `json:"confirmed"`
	JournalIn  *journalIn   `json:"-"`
	JournalOut *journalOut  `json:"-"`
}

func DecodeAccount

func DecodeAccount(bytes []byte) (*Account, error)

func NewAccount

func NewAccount() *Account

func (*Account) Bytes

func (a *Account) Bytes() []byte

func (*Account) Check

func (a *Account) Check(msg types.IMessage, strict bool) error

func (*Account) EaterMessage

func (a *Account) EaterMessage(msg types.IMessage, height uint64) error

func (*Account) Exist

func (a *Account) Exist() bool

func (*Account) FromMessage

func (a *Account) FromMessage(msg types.IMessage, height uint64) error

func (*Account) GetAddress

func (a *Account) GetAddress() arry.Address

func (*Account) GetBalance

func (a *Account) GetBalance(tokenAddr arry.Address) uint64

func (*Account) NeedUpdate

func (a *Account) NeedUpdate() bool

func (*Account) ToMessage

func (a *Account) ToMessage(msg types.IMessage, height uint64) error

func (*Account) UpdateLocked

func (a *Account) UpdateLocked(confirmed uint64) error

Update through the account transfer log information

type Block

type Block struct {
	*Header
	*Body
}

func (*Block) Add

func (b *Block) Add(message types.IMessage)

func (*Block) BlockBody

func (b *Block) BlockBody() types.IBody

func (*Block) BlockHeader

func (b *Block) BlockHeader() types.IHeader

func (*Block) CheckMsgRoot

func (b *Block) CheckMsgRoot() bool

func (*Block) GetMsgIndexs

func (b *Block) GetMsgIndexs() map[arry.Hash]*MsgIndex

func (*Block) Hash

func (b *Block) Hash() arry.Hash

func (*Block) Height

func (b *Block) Height() uint64

func (*Block) MsgRoot

func (b *Block) MsgRoot() arry.Hash

func (*Block) Msgs

func (b *Block) Msgs() []types.IMessage

func (*Block) SetHash

func (b *Block) SetHash()

func (*Block) Sign

func (b *Block) Sign(key *secp256k1.PrivateKey) error

func (*Block) Signer

func (b *Block) Signer() arry.Address

func (*Block) Time

func (b *Block) Time() int64

func (*Block) ToRlpBlock

func (b *Block) ToRlpBlock() types.IRlpBlock

func (*Block) ToRlpHeader

func (b *Block) ToRlpHeader() types.IRlpHeader

type Blocks

type Blocks []*Block

func (Blocks) Blocks

func (b Blocks) Blocks() []*Block

type Body

type Body struct {
	Messages
}

func (*Body) Msgs

func (b *Body) Msgs() []types.IMessage

func (*Body) ToRlpBody

func (b *Body) ToRlpBody() *RlpBody

type CancelBody

type CancelBody struct {
}

func (*CancelBody) CheckBody

func (c *CancelBody) CheckBody(from arry.Address) error

func (*CancelBody) MsgAmount

func (c *CancelBody) MsgAmount() uint64

func (*CancelBody) MsgTo

func (c *CancelBody) MsgTo() arry.Address

func (*CancelBody) MsgToken

func (c *CancelBody) MsgToken() arry.Address

type CandidateBody

type CandidateBody struct {
	Peer Peer
}

func RpcCandidateBodyToBody

func RpcCandidateBodyToBody(rpcBody *RpcCandidateBody) (*CandidateBody, error)

func (*CandidateBody) CheckBody

func (c *CandidateBody) CheckBody(from arry.Address) error

func (*CandidateBody) MsgAmount

func (c *CandidateBody) MsgAmount() uint64

func (*CandidateBody) MsgTo

func (c *CandidateBody) MsgTo() arry.Address

func (*CandidateBody) MsgToken

func (c *CandidateBody) MsgToken() arry.Address

type Candidates

type Candidates struct {
	Members []*Member
}

func NewCandidates

func NewCandidates() *Candidates

func (*Candidates) Get

func (c *Candidates) Get(i int) types.ICandidate

func (*Candidates) GetPreHash

func (c *Candidates) GetPreHash() arry.Hash

func (*Candidates) Len

func (c *Candidates) Len() int

func (*Candidates) List

func (c *Candidates) List() []types.ICandidate

func (*Candidates) Remove

func (c *Candidates) Remove(reMem *Member)

func (*Candidates) Set

func (c *Candidates) Set(newMem *Member)
type Header struct {
	Version   uint32
	Hash      arry.Hash
	PreHash   arry.Hash
	MsgRoot   arry.Hash
	ActRoot   arry.Hash
	DPosRoot  arry.Hash
	TokenRoot arry.Hash
	Height    uint64
	Time      uint64
	Cycle     uint64
	Signer    arry.Address
	Signature *Signature
}

func DecodeHeader

func DecodeHeader(bytes []byte) (*Header, error)

func NewHeader

func NewHeader(preHash, msgRoot, actRoot, dPosRoot, tokenRoot arry.Hash, height uint64,
	blockTime uint64, signer arry.Address) *Header

func (*Header) Bytes

func (h *Header) Bytes() []byte

func (*Header) GetActRoot

func (h *Header) GetActRoot() arry.Hash

func (*Header) GetCycle

func (h *Header) GetCycle() uint64

func (*Header) GetDPosRoot

func (h *Header) GetDPosRoot() arry.Hash

func (*Header) GetHash

func (h *Header) GetHash() arry.Hash

func (*Header) GetHeight

func (h *Header) GetHeight() uint64

func (*Header) GetMsgRoot

func (h *Header) GetMsgRoot() arry.Hash

func (*Header) GetPreHash

func (h *Header) GetPreHash() arry.Hash

func (*Header) GetSignature

func (h *Header) GetSignature() types.ISignature

func (*Header) GetSigner

func (h *Header) GetSigner() arry.Address

func (*Header) GetTime

func (h *Header) GetTime() uint64

func (*Header) GetTokenRoot

func (h *Header) GetTokenRoot() arry.Hash

func (*Header) SetHash

func (h *Header) SetHash()

func (*Header) Sign

func (h *Header) Sign(key *secp256k1.PrivateKey) error

func (*Header) ToRlpHeader

func (h *Header) ToRlpHeader() types.IRlpHeader

type IRpcMessageBody

type IRpcMessageBody interface {
}

type InAmount

type InAmount struct {
	TokenAddress string
	Amount       uint64
	Height       uint64
}

type InList

type InList []*InAmount

func (*InList) Get

func (o *InList) Get(height uint64, tokenAddr string) (*InAmount, bool)

func (*InList) Remove

func (o *InList) Remove(height uint64, TokenAddress string) *InAmount

func (*InList) Set

func (o *InList) Set(outAmount *InAmount)

type Member

type Member struct {
	Signer   arry.Address
	PeerId   string
	Weight   uint64
	MntCount uint32
	Voters   []arry.Address
}

func DecodeMember

func DecodeMember(bytes []byte) (*Member, error)

func (*Member) Bytes

func (m *Member) Bytes() []byte

func (*Member) GetPeerId

func (m *Member) GetPeerId() string

func (*Member) GetSinger

func (m *Member) GetSinger() arry.Address

type Message

type Message struct {
	Header *MsgHeader
	Body   types.IMessageBody
}

func RpcMsgToMsg

func RpcMsgToMsg(rpcMsg *RpcMessage) (*Message, error)

func (*Message) Bytes

func (m *Message) Bytes() []byte

func (*Message) Check

func (m *Message) Check() error

func (*Message) CheckCoinBase

func (m *Message) CheckCoinBase(fee uint64, coinbase uint64) error

func (*Message) Fee

func (m *Message) Fee() uint64

func (*Message) From

func (m *Message) From() arry.Address

func (*Message) Hash

func (m *Message) Hash() arry.Hash

func (*Message) IsCoinBase

func (m *Message) IsCoinBase() bool

func (*Message) MsgAmount

func (m *Message) MsgAmount() uint64

func (*Message) MsgBody

func (m *Message) MsgBody() types.IMessageBody

func (*Message) MsgTo

func (m *Message) MsgTo() arry.Address

func (*Message) Nonce

func (m *Message) Nonce() uint64

func (*Message) PublicKey

func (m *Message) PublicKey() string

func (*Message) SetHash

func (m *Message) SetHash() error

func (*Message) SignMessage

func (m *Message) SignMessage(key *secp256k1.PrivateKey) error

func (*Message) SignMsg

func (m *Message) SignMsg(key *secp256k1.PrivateKey) error

func (*Message) Signature

func (m *Message) Signature() string

func (*Message) Time

func (m *Message) Time() uint64

func (*Message) ToRlp

func (m *Message) ToRlp() types.IRlpMessage

func (*Message) Type

func (m *Message) Type() int

type MessageType

type MessageType uint8
const (
	Transaction MessageType = iota
	Token
	Candidate
	Cancel
	Vote
)

type Messages

type Messages []types.IMessage

func (Messages) Count

func (m Messages) Count() int

func (Messages) MsgList

func (m Messages) MsgList() []types.IMessage

type MsgHeader

type MsgHeader struct {
	Type      MessageType
	Hash      arry.Hash
	From      arry.Address
	Nonce     uint64
	Fee       uint64
	Time      uint64
	Signature *Signature
}

func (*MsgHeader) Check

func (m *MsgHeader) Check() error

type MsgIndex

type MsgIndex struct {
	MsgRoot arry.Hash
	Index   uint32
	Height  uint64
}

func DecodeTxIndex

func DecodeTxIndex(bytes []byte) (*MsgIndex, error)

func (*MsgIndex) Bytes

func (t *MsgIndex) Bytes() []byte

func (*MsgIndex) GetHeight

func (t *MsgIndex) GetHeight() uint64

type Peer

type Peer [PeerLength]byte

func (Peer) Bytes

func (p Peer) Bytes() []byte

func (Peer) String

func (p Peer) String() string

type Record

type Record struct {
	Height   uint64
	MsgHash  arry.Hash
	Receiver arry.Address
	Time     uint64
	Amount   uint64
}

type RecordList

type RecordList []*Record

func (*RecordList) Get

func (r *RecordList) Get(height uint64) (*Record, bool)

func (*RecordList) Len

func (r *RecordList) Len() int

func (*RecordList) Remove

func (r *RecordList) Remove(height uint64)

func (*RecordList) Set

func (r *RecordList) Set(newRecord *Record)

type RlpBlock

type RlpBlock struct {
	RlpHeader *Header
	RlpBody   *RlpBody
}

func DecodeRlpBlock

func DecodeRlpBlock(bytes []byte) (*RlpBlock, error)

func DecodeRlpBlocks

func DecodeRlpBlocks(bytes []byte) ([]*RlpBlock, error)

func (*RlpBlock) Bytes

func (r *RlpBlock) Bytes() []byte

func (*RlpBlock) ToBlock

func (r *RlpBlock) ToBlock() types.IBlock

type RlpBody

type RlpBody struct {
	Msgs []*RlpMessage
}

func (*RlpBody) MsgList

func (r *RlpBody) MsgList() []*RlpMessage

func (*RlpBody) ToBody

func (r *RlpBody) ToBody() *Body

type RlpHeader

type RlpHeader Header

func DecodeRlpHeader

func DecodeRlpHeader(bytes []byte) (*RlpHeader, error)

func (*RlpHeader) Bytes

func (r *RlpHeader) Bytes() []byte

type RlpMessage

type RlpMessage struct {
	MsgHeader *MsgHeader
	MsgBody   []byte
}

func DecodeMessage

func DecodeMessage(bytes []byte) (*RlpMessage, error)

func DecodeRlpMessages

func DecodeRlpMessages(bytes []byte) ([]*RlpMessage, error)

func (*RlpMessage) Bytes

func (r *RlpMessage) Bytes() []byte

func (*RlpMessage) ToMessage

func (r *RlpMessage) ToMessage() types.IMessage

type RpcCancelBody

type RpcCancelBody struct {
}

type RpcCandidateBody

type RpcCandidateBody struct {
	PeerId string `json:"peerid"`
}

func (*RpcCandidateBody) PeerIdBytes

func (r *RpcCandidateBody) PeerIdBytes() []byte

type RpcMessage

type RpcMessage struct {
	MsgHeader *RpcMessageHeader `json:"msgheader"`
	MsgBody   IRpcMessageBody   `json:"msgbody"`
}

func MsgToRpcMsg

func MsgToRpcMsg(msg types.IMessage) (*RpcMessage, error)

type RpcMessageHeader

type RpcMessageHeader struct {
	MsgHash   string        `json:"msghash"`
	Type      MessageType   `json:"type"`
	From      string        `json:"from"`
	Nonce     uint64        `json:"nonce"`
	Fee       uint64        `json:"fee"`
	Time      uint64        `json:"time"`
	Signature *RpcSignature `json:"signscript"`
}

type RpcMessageWithHeight

type RpcMessageWithHeight struct {
	MsgHeader *RpcMessageHeader `json:"msgheader"`
	MsgBody   IRpcMessageBody   `json:"msgbody"`
	Height    uint64            `json:"height"`
	Confirmed bool              `json:"confirmed"`
}

type RpcSignature

type RpcSignature struct {
	Signature string `json:"signature"`
	PubKey    string `json:"pubkey"`
}

type RpcTokenBody

type RpcTokenBody struct {
	Address        string `json:"address"`
	Receiver       string `json:"receiver"`
	Name           string `json:"name"`
	Shorthand      string `json:"shorthand"`
	Amount         uint64 `json:"amount"`
	IncreaseIssues bool   `json:"allowedincrease"`
}

type RpcTransactionBody

type RpcTransactionBody struct {
	Token  string `json:"token"`
	To     string `json:"to"`
	Amount uint64 `json:"amount"`
}

func (*RpcTransactionBody) GetTo

func (r *RpcTransactionBody) GetTo() []byte

type RpcVoteBody

type RpcVoteBody struct {
	To string `json:"to"`
}

type Signature

type Signature struct {
	Bytes  []byte `json:"bytes"`
	PubKey []byte `json:"pubkey"`
}

Signature information, including the result of the signature and the public key.

func RpcSignatureToSignature

func RpcSignatureToSignature(rpcSignScript *RpcSignature) (*Signature, error)

func Sign

func Sign(key *secp256k1.PrivateKey, hash arry.Hash) (*Signature, error)

Sign the hash with the private key

func (*Signature) PubKeyString

func (s *Signature) PubKeyString() string

func (*Signature) PubicKey

func (s *Signature) PubicKey() []byte

func (*Signature) SignatureBytes

func (s *Signature) SignatureBytes() []byte

func (*Signature) SignatureString

func (s *Signature) SignatureString() string

type SortableCandidates

type SortableCandidates []*Member

func (SortableCandidates) Len

func (p SortableCandidates) Len() int

func (SortableCandidates) Less

func (p SortableCandidates) Less(i, j int) bool

func (SortableCandidates) Swap

func (p SortableCandidates) Swap(i, j int)

type Supers

type Supers struct {
	Candidates []*Member
	PreHash    arry.Hash
}

Super nodes

func NewSupers

func NewSupers() *Supers

func (*Supers) Get

func (s *Supers) Get(i int) types.ICandidate

func (*Supers) GetPreHash

func (s *Supers) GetPreHash() arry.Hash

func (*Supers) Len

func (s *Supers) Len() int

func (*Supers) List

func (s *Supers) List() []types.ICandidate

type TokenAccount

type TokenAccount struct {
	Address   string `json:"address"`
	Balance   uint64 `json:"balance"`
	LockedIn  uint64 `json:"locked"`
	LockedOut uint64 `json:"-"`
}

type TokenBody

type TokenBody struct {
	TokenAddress   arry.Address
	Receiver       arry.Address
	Name           string
	Shorthand      string
	IncreaseIssues bool
	Amount         uint64
}

func RpcTokenBodyToBody

func RpcTokenBodyToBody(rpcBody *RpcTokenBody) (*TokenBody, error)

func (*TokenBody) CheckBody

func (t *TokenBody) CheckBody(from arry.Address) error

func (*TokenBody) MsgAmount

func (t *TokenBody) MsgAmount() uint64

func (*TokenBody) MsgTo

func (t *TokenBody) MsgTo() arry.Address

func (*TokenBody) MsgToken

func (t *TokenBody) MsgToken() arry.Address

type TokenRecord

type TokenRecord struct {
	Address        arry.Address
	Sender         arry.Address
	Name           string
	Shorthand      string
	IncreaseIssues bool
	Records        *RecordList
}

token structure, issuing a contract with the same name is equivalent to reissuing the pass

func DecodeToken

func DecodeToken(bytes []byte) (*TokenRecord, error)

func NewToken

func NewToken() *TokenRecord

func (*TokenRecord) Bytes

func (t *TokenRecord) Bytes() []byte

func (*TokenRecord) Check

func (t *TokenRecord) Check(msg types.IMessage) error

func (*TokenRecord) FallBack

func (t *TokenRecord) FallBack(height uint64) error

func (*TokenRecord) IncreaseRecord

func (t *TokenRecord) IncreaseRecord(record *Record)

func (*TokenRecord) IsExist

func (t *TokenRecord) IsExist(msgHash arry.Hash) bool

type Tokens

type Tokens []*TokenAccount

List of secondary accounts

func (*Tokens) Get

func (t *Tokens) Get(contract string) (*TokenAccount, bool)

func (*Tokens) Set

func (t *Tokens) Set(newCoin *TokenAccount)

type TransactionBody

type TransactionBody struct {
	TokenAddress arry.Address
	Receiver     arry.Address
	Amount       uint64
}

func RpcTransactionBodyToBody

func RpcTransactionBodyToBody(rpcBody *RpcTransactionBody) (*TransactionBody, error)

func (*TransactionBody) CheckBody

func (t *TransactionBody) CheckBody(from arry.Address) error

func (*TransactionBody) MsgAmount

func (t *TransactionBody) MsgAmount() uint64

func (*TransactionBody) MsgTo

func (t *TransactionBody) MsgTo() arry.Address

func (*TransactionBody) MsgToken

func (t *TransactionBody) MsgToken() arry.Address

type TxOutList

type TxOutList []*txOut

func (*TxOutList) Get

func (t *TxOutList) Get(height uint64) (*txOut, bool)

func (*TxOutList) Remove

func (t *TxOutList) Remove(height uint64)

func (*TxOutList) Set

func (t *TxOutList) Set(txIn *txOut)

type VoteBody

type VoteBody struct {
	To arry.Address
}

func RpcVoteBodyToBody

func RpcVoteBodyToBody(rpcBody *RpcVoteBody) (*VoteBody, error)

func (*VoteBody) CheckBody

func (v *VoteBody) CheckBody(from arry.Address) error

func (*VoteBody) MsgAmount

func (v *VoteBody) MsgAmount() uint64

func (*VoteBody) MsgTo

func (v *VoteBody) MsgTo() arry.Address

func (*VoteBody) MsgToken

func (v *VoteBody) MsgToken() arry.Address

Jump to

Keyboard shortcuts

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