types

package
v0.0.0-...-e85cc61 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDataHash

func CalculateDataHash(txx []*Transaction) (hash common.Hash, err error)

func RandomBytes

func RandomBytes(size int) []byte

func RandomHash

func RandomHash() common.Hash

Types

type Account

type Account struct {
	Address common.Address
	Nonce   uint64
	Balance uint64
}

func CreateAccount

func CreateAccount(address common.Address) *Account

func (*Account) AddBalance

func (a *Account) AddBalance(amount uint64)

func (*Account) Decode

func (a *Account) Decode(dec Decoder[*Account]) error

func (*Account) Encode

func (a *Account) Encode(enc Encoder[*Account]) error

func (*Account) SubBalance

func (a *Account) SubBalance(amount uint64) error

func (*Account) Transfer

func (a *Account) Transfer(to *Account, amount uint64) error

type Block

type Block struct {
	*Header

	Transactions []*Transaction
	Signer       PublicKey
	Signature    *Signature

	Extra string
	// Cached version of the header hash
	Hash common.Hash
}

func NewBlock

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

func NewBlockFromPrevHeader

func NewBlockFromPrevHeader(prevHeader *Header, txs []*Transaction) (*Block, error)

func NewRandomBlock

func NewRandomBlock(t *testing.T, height int32, prevBlockHash common.Hash) *Block

func NewRandomBlockWithSignature

func NewRandomBlockWithSignature(t *testing.T, pk PrivateKey, height int32, prevHash common.Hash) *Block

func (*Block) AddTransaction

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

func (*Block) Decode

func (b *Block) Decode(dec Decoder[*Block]) error

func (*Block) Encode

func (b *Block) Encode(enc Encoder[*Block]) error

func (*Block) GetHash

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

func (*Block) Sign

func (b *Block) Sign(privateKey PrivateKey) error

func (*Block) Verify

func (b *Block) Verify() error

type BlockHasher

type BlockHasher struct{}

func (BlockHasher) Hash

func (BlockHasher) Hash(header *Header) common.Hash

type Decoder

type Decoder[T any] interface {
	Decode(T) error
}

type Encoder

type Encoder[T any] interface {
	Encode(T) error
}

type GobAccountDecoder

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

func NewGobAccountDecoder

func NewGobAccountDecoder(r io.Reader) *GobAccountDecoder

func (*GobAccountDecoder) Decode

func (dec *GobAccountDecoder) Decode(a *Account) error

type GobAccountEncoder

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

func NewGobAccountEncoder

func NewGobAccountEncoder(w io.Writer) *GobAccountEncoder

func (*GobAccountEncoder) Encode

func (enc *GobAccountEncoder) Encode(a *Account) error

type GobBlockDecoder

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

func NewGobBlockDecoder

func NewGobBlockDecoder(r io.Reader) *GobBlockDecoder

func (*GobBlockDecoder) Decode

func (dec *GobBlockDecoder) Decode(b *Block) error

type GobBlockEncoder

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

func NewGobBlockEncoder

func NewGobBlockEncoder(w io.Writer) *GobBlockEncoder

func (*GobBlockEncoder) Encode

func (enc *GobBlockEncoder) Encode(b *Block) error

type GobHeaderDecoder

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

func NewGobHeaderDecoder

func NewGobHeaderDecoder(r io.Reader) *GobHeaderDecoder

func (*GobHeaderDecoder) Decode

func (dec *GobHeaderDecoder) Decode(h *Header) error

type GobHeaderEncoder

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

func NewGobHeaderEncoder

func NewGobHeaderEncoder(w io.Writer) *GobHeaderEncoder

func (*GobHeaderEncoder) Encode

func (enc *GobHeaderEncoder) Encode(h *Header) error

type GobPrivateKeyDecoder

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

func NewGobPrivateKeyDecoder

func NewGobPrivateKeyDecoder(r io.Reader) *GobPrivateKeyDecoder

func (*GobPrivateKeyDecoder) Decode

func (dec *GobPrivateKeyDecoder) Decode(key *PrivateKey) error

type GobPrivateKeyEncoder

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

func NewGobPrivateKeyEncoder

func NewGobPrivateKeyEncoder(w io.Writer) *GobPrivateKeyEncoder

func (*GobPrivateKeyEncoder) Encode

func (enc *GobPrivateKeyEncoder) Encode(key *PrivateKey) error

type GobTxDecoder

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

func NewGobTxDecoder

func NewGobTxDecoder(r io.Reader) *GobTxDecoder

func (*GobTxDecoder) Decode

func (e *GobTxDecoder) Decode(tx *Transaction) error

type GobTxEncoder

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

func NewGobTxEncoder

func NewGobTxEncoder(w io.Writer) *GobTxEncoder

func (*GobTxEncoder) Encode

func (e *GobTxEncoder) Encode(tx *Transaction) error

type Hasher

type Hasher[T any] interface {
	Hash(T) common.Hash
}
type Header struct {
	Version       uint32
	DataHash      common.Hash
	PrevBlockHash common.Hash
	Height        int32
	Timestamp     int64
}

func (*Header) Bytes

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

func (*Header) Decode

func (h *Header) Decode(dec Decoder[*Header]) error

func (*Header) Encode

func (h *Header) Encode(enc Encoder[*Header]) error

type PrivateKey

type PrivateKey struct {
	Key       *ecdsa.PrivateKey
	PublicKey PublicKey
}

func CreatePrivateKey

func CreatePrivateKey(hexKey string) (*PrivateKey, error)

func GeneratePrivateKey

func GeneratePrivateKey() *PrivateKey

func NewPrivateKeyFromReader

func NewPrivateKeyFromReader(r io.Reader) *PrivateKey

func (*PrivateKey) Decode

func (k *PrivateKey) Decode(dec Decoder[*PrivateKey]) error

func (*PrivateKey) Encode

func (k *PrivateKey) Encode(enc Encoder[*PrivateKey]) error

func (*PrivateKey) Sign

func (k *PrivateKey) Sign(data []byte) (*Signature, error)

type PublicKey

type PublicKey struct {
	Key *ecdsa.PublicKey
}

func GetPublicKey

func GetPublicKey(xHex string, yHex string) (*PublicKey, error)

func (*PublicKey) Address

func (k *PublicKey) Address() common.Address

func (*PublicKey) String1

func (k *PublicKey) String1() string

type Signature

type Signature struct {
	S *big.Int
	R *big.Int
}

func GetSignature

func GetSignature(rHex string, sHex string) (*Signature, error)

func (*Signature) String

func (sig *Signature) String() string

func (*Signature) Verify

func (sig *Signature) Verify(publicKey PublicKey, data []byte) bool

type Transaction

type Transaction struct {
	Nonce       uint64
	BlockHeight int32
	Timestamp   int64
	From        common.Address
	To          common.Address
	Value       uint64
	Data        []byte
	Signer      PublicKey
	Signature   *Signature

	Hash common.Hash
}

func CreateSignedTransaction

func CreateSignedTransaction(
	nonce uint64,
	from common.Address,
	to common.Address,
	value uint64,
	data []byte,
	signer PublicKey,
	signature *Signature) *Transaction

func CreateTransaction

func CreateTransaction(
	nonce uint64,
	from common.Address,
	to common.Address,
	value uint64,
	data []byte) *Transaction

func NewRandomTransaction

func NewRandomTransaction(privateKey *PrivateKey) *Transaction

NewRandomTransaction return a new random transaction whithout signature.

func NewRandomTransactionWithSignature

func NewRandomTransactionWithSignature(t *testing.T, privateKey *PrivateKey, size int) *Transaction

func (*Transaction) Decode

func (tx *Transaction) Decode(dec Decoder[*Transaction]) error

func (*Transaction) Encode

func (tx *Transaction) Encode(enc Encoder[*Transaction]) error

func (*Transaction) GetHash

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

func (*Transaction) Sign

func (tx *Transaction) Sign(privateKey *PrivateKey) error

func (*Transaction) Verify

func (tx *Transaction) Verify() error

type TxHasher

type TxHasher struct{}

func (TxHasher) Hash

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

Hash will hash the whole bytes of the TX no exception.

Jump to

Keyboard shortcuts

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