types

package
v0.0.0-...-dd5a67f Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InterlinkLength = uint64(10)
)

Variables

View Source
var (
	EmptyRootHash  = DeriveSha(Transactions{})
	EmptyUncleHash = rlpHash([]*Header(nil))
)
View Source
var (
	// incorrect block's number (current_block_number + 1 != insert_block's_number)
	ErrDiffFieldLength = errors.New("tx has different field array length")

	ErrInvalidPostStates = errors.New("tx's PostStates's Account is not same with tx's Participants")

	ErrInvalidPrevTxHashes = errors.New("Account in tx's PrevTxHashes is not match with Participants")
)
View Source
var ErrInvalidSig = errors.New("this tx has invalid signature")
View Source
var ErrInvalidSigKey = errors.New("this private key's owner is not participants of tx")
View Source
var ErrNoFields = errors.New("there are not filled fields in tx")

Functions

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

Types

type AllTxs

type AllTxs map[common.Hash]*Transaction

temporary type. transaction will be saved in db

func (AllTxs) Print

func (txs AllTxs) Print()

type Block

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

func NewBlock

func NewBlock(header *Header, txs []*Transaction) *Block

func (*Block) Body

func (b *Block) Body() *Body

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(s *rlp.Stream) error

DecodeRLP decodes the Ethereum

func (*Block) EncodeRLP

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

EncodeRLP serializes b into the Ethereum RLP block format.

func (*Block) GetHeader

func (b *Block) GetHeader() *Header

func (*Block) GetLevel

func (b *Block) GetLevel() uint64

func (*Block) GetTxs

func (b *Block) GetTxs() *Transactions
func (b *Block) GetUniqueInterlink() []uint64
func (b *Block) GetUpdatedInterlink() [InterlinkLength]uint64

GetUpdatedInterlink returns interlink that contains this block too to compare with next block's interlink should be current_block.GetUpdatedInterlink() == next_block.header.Interlink Also, this function can be used when you fill newly mined block's interlink new_mined_block.header.Interlink = current_block.GetUpdatedInterlink()

func (*Block) Hash

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

block's hash is same with header's hash

func (*Block) Header

func (b *Block) Header() *Header

func (*Block) InsertTx

func (b *Block) InsertTx(tx *Transaction)

func (*Block) Number

func (b *Block) Number() uint64

func (*Block) PrintBlock

func (b *Block) PrintBlock()

func (*Block) PrintTxs

func (b *Block) PrintTxs()

func (*Block) Size

func (b *Block) Size() common.StorageSize

Size returns the true RLP encoded storage size of the block, either by encoding and returning it, or returning a previsouly cached value.

func (*Block) Transactions

func (b *Block) Transactions() Transactions

func (*Block) ValidateBlock

func (b *Block) ValidateBlock() error

block validation function for iot node

type Body

type Body struct {
	Transactions []*Transaction
}

func (*Body) PrintBody

func (b *Body) PrintBody()

type DerivableList

type DerivableList interface {
	Len() int
	GetRlp(i int) []byte
}
type Header struct {
	ParentHash common.Hash             `json:"parentHash"` // previous block's hash
	Coinbase   common.Address          `json:"miner"`
	Root       common.Hash             `json:"stateRoot"`
	TxHash     common.Hash             `json:"transactionsRoot"`
	Number     uint64                  `json:"number"` // (Number == Height) A scalar value equal to the number of ancestor blocks. The genesis block has a number of zero
	Time       uint64                  `json:"timestamp"`
	Nonce      uint64                  `json:"nonce"`
	InterLink  [InterlinkLength]uint64 `json:"interlink"`  // list of block's level
	Difficulty uint64                  `json:"difficulty"` // no difficulty change, so set global Difficulty
}

func CopyHeader

func CopyHeader(header *Header) *Header

func NewHeader

func NewHeader(parentHash common.Hash, miner common.Address, stateRoot common.Hash, txHash common.Hash, difficulty uint64, number uint64, time uint64, nonce uint64) *Header

func (*Header) Hash

func (h *Header) Hash() common.Hash

func (*Header) PrintHeader

func (h *Header) PrintHeader()

type Transaction

type Transaction struct {
	Data Txdata      `json:"d"`
	Hash common.Hash `json:"h"`

	// signature values of participants
	Signature_R []*big.Int `json:"r"`
	Signature_S []*big.Int `json:"s"`
}

func MakeTestSignedTx

func MakeTestSignedTx(participantsNum int, s state.Accounts) *Transaction

make random signed tx for test

func MakeTestTx

func MakeTestTx(participantsNum int, s state.Accounts) *Transaction

make random tx for test

func NewTransaction

func NewTransaction(participants []*ecdsa.PublicKey, postStates []*state.Account, prevTxHashes []*common.Hash) *Transaction

func UnmarshalJSON

func UnmarshalJSON(txbuf []byte) *Transaction

func (*Transaction) GetHash

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

hashing txdata of tx

func (*Transaction) GetPostBalanceSum

func (tx *Transaction) GetPostBalanceSum() uint64

func (*Transaction) GetPostState

func (tx *Transaction) GetPostState(key *ecdsa.PublicKey) *state.Account

Get specific user's post state using public key

func (*Transaction) GetPostStateByAddress

func (tx *Transaction) GetPostStateByAddress(key []byte) *state.Account

Get specific user's post state using address

func (*Transaction) GetPrevBalanceSum

func (tx *Transaction) GetPrevBalanceSum() uint64

func (*Transaction) Nonce

func (tx *Transaction) Nonce() []uint64

func (*Transaction) Participants

func (tx *Transaction) Participants() []*ecdsa.PublicKey

func (*Transaction) PostStates

func (tx *Transaction) PostStates() []*state.Account

func (*Transaction) PrevTxHashes

func (tx *Transaction) PrevTxHashes() []*common.Hash

func (*Transaction) PrintTx

func (tx *Transaction) PrintTx()

func (*Transaction) Sign

func (tx *Transaction) Sign(priv *ecdsa.PrivateKey) error

func (*Transaction) ValidateTx

func (tx *Transaction) ValidateTx() error

tx validation function for iot node

func (*Transaction) VerifySignature

func (tx *Transaction) VerifySignature() error

verify that this signed tx has all correct participants' signature

type Transactions

type Transactions []*Transaction

Transactions is a Transaction slice type for basic sorting

func (Transactions) GetRlp

func (s Transactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (Transactions) Hash

func (txs Transactions) Hash() common.Hash

hashing all transactions in txs (temporary) TODO: this hash value should be root value of tx's merkle tree

func (*Transactions) Insert

func (txs *Transactions) Insert(tx *Transaction)

insert tx into txs

func (Transactions) Len

func (s Transactions) Len() int

Len returns the length of s.

type Txdata

type Txdata struct {
	// new version fields
	Participants []*ecdsa.PublicKey `json:"participants"`
	PostStates   []*state.Account   `json:"poststates"`
	PrevTxHashes []*common.Hash     `json:"prevtxhashes"`
}

simple implementation

func (*Txdata) GetHashedBytes

func (data *Txdata) GetHashedBytes() []byte

get hashed txdata's byte array

Jump to

Keyboard shortcuts

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