Documentation ¶
Index ¶
- Constants
- Variables
- func DeriveSha(list DerivableList) common.Hash
- type AllTxs
- type Block
- func (b *Block) Body() *Body
- func (b *Block) DecodeRLP(s *rlp.Stream) error
- func (b *Block) EncodeRLP(w io.Writer) error
- func (b *Block) GetHeader() *Header
- func (b *Block) GetLevel() uint64
- func (b *Block) GetTxs() *Transactions
- func (b *Block) GetUniqueInterlink() []uint64
- func (b *Block) GetUpdatedInterlink() [InterlinkLength]uint64
- func (b *Block) Hash() common.Hash
- func (b *Block) Header() *Header
- func (b *Block) InsertTx(tx *Transaction)
- func (b *Block) Number() uint64
- func (b *Block) PrintBlock()
- func (b *Block) PrintTxs()
- func (b *Block) Size() common.StorageSize
- func (b *Block) Transactions() Transactions
- func (b *Block) ValidateBlock() error
- type Body
- type DerivableList
- type Header
- type Transaction
- func (tx *Transaction) GetHash() common.Hash
- func (tx *Transaction) GetPostBalanceSum() uint64
- func (tx *Transaction) GetPostState(key *ecdsa.PublicKey) *state.Account
- func (tx *Transaction) GetPostStateByAddress(key []byte) *state.Account
- func (tx *Transaction) GetPrevBalanceSum() uint64
- func (tx *Transaction) Nonce() []uint64
- func (tx *Transaction) Participants() []*ecdsa.PublicKey
- func (tx *Transaction) PostStates() []*state.Account
- func (tx *Transaction) PrevTxHashes() []*common.Hash
- func (tx *Transaction) PrintTx()
- func (tx *Transaction) Sign(priv *ecdsa.PrivateKey) error
- func (tx *Transaction) ValidateTx() error
- func (tx *Transaction) VerifySignature() error
- type Transactions
- type Txdata
Constants ¶
const (
InterlinkLength = uint64(10)
)
Variables ¶
var ( EmptyRootHash = DeriveSha(Transactions{}) EmptyUncleHash = rlpHash([]*Header(nil)) )
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") )
var ErrInvalidSig = errors.New("this tx has invalid signature")
var ErrInvalidSigKey = errors.New("this private key's owner is not participants of tx")
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
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func NewBlock ¶
func NewBlock(header *Header, txs []*Transaction) *Block
func (*Block) GetTxs ¶
func (b *Block) GetTxs() *Transactions
func (*Block) GetUniqueInterlink ¶
func (*Block) GetUpdatedInterlink ¶
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) InsertTx ¶
func (b *Block) InsertTx(tx *Transaction)
func (*Block) PrintBlock ¶
func (b *Block) PrintBlock()
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 ¶
block validation function for iot node
type Body ¶
type Body struct {
Transactions []*Transaction
}
type DerivableList ¶
type Header ¶
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 (*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 UnmarshalJSON ¶
func UnmarshalJSON(txbuf []byte) *Transaction
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