database

package
v0.0.0-...-491cd9a Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountID AccountID
	Nonce     uint64
	Balance   uint64
}

Account represents information stored in the database for an individual account.

type AccountID

type AccountID string

AccountID represents an account id that is used to sign transactions and is associated with transactions on the blockchain.

func ToAccountID

func ToAccountID(hex string) (AccountID, error)

ToAccountID converts a hex-encoded string to an account and validates the hex-encoded string is formatted correctly.

func (AccountID) IsAccountID

func (a AccountID) IsAccountID() bool

IsAccountID verifies whether the underlying data represents a valid hex-encoded account.

type Block

type Block struct {
	Header     BlockHeader
	MerkleTree *merkle.Tree[BlockTx]
}

Block represents a group of transactions batched together.

type BlockData

type BlockData struct {
	Hash   string      `json:"hash"`
	Header BlockHeader `json:"block"`
	Trans  []BlockTx   `json:"trans"`
}

BlockData represents what can be serialized to disk and over the network.

type BlockHeader

type BlockHeader struct {
	Number        uint64    `json:"number"`
	PrevBlockHash string    `json:"prev_block_hash"`
	TimeStamp     uint64    `json:"timestamp"`
	BeneficiaryID AccountID `json:"beneficiary"`
	Difficulty    uint16    `json:"difficulty"`
	MiningReward  uint64    `json:"mining_reward"`
	StateRoot     string    `json:"state_root"`
	TransRoot     string    `json:"trans_root"`
	Nonce         uint64    `json:"nonce"`
}

BlockHeader represents common information required for each block.

type BlockTx

type BlockTx struct {
	SignedTx
	TimeStamp uint64 `json:"timestamp"` // Ethereum: The time the transaction was received.
	GasPrice  uint64 `json:"gas_price"` // Ethereum: The price of one unit of gas to be paid for fees.
	GasUnits  uint64 `json:"gas_units"` // Ethereum: The number of units of gas used for this transaction.
}

BlockTx represents the transaction as it's recorded inside a block. This includes a timestamp and gas fees.

func NewBlockTx

func NewBlockTx(signedTx SignedTx, gasPrice uint64, unitsOfGas uint64) BlockTx

NewBlockTx constructs a new block transaction.

func (BlockTx) Equals

func (tx BlockTx) Equals(otherTx BlockTx) bool

Equals implements the markle Hashable interface for providing an equality check between two block transactions. If the nonce and signatures are the same, the two blocks are the same.

func (BlockTx) Hash

func (tx BlockTx) Hash() ([]byte, error)

Hash implements the markle Hashable interface for providing a hash of a block transaction.

type Database

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

Database manages data related to accounts who have transacted on the blockchain.

type SignedTx

type SignedTx struct {
	Tx
	V *big.Int `json:"v"` // Ethereum: Recovery identifier, either 29 or 30 with sophiaID.
	R *big.Int `json:"r"` // Ethereum: First coordinate of the ECDSA signature.
	S *big.Int `json:"s"` // Ethereum: Second coordinate of the ECDSA signature.
}

SignedTx is a signed version of the transaction. This is how clients like a wallet provide transactions for inclusion into the blockchain.

func (SignedTx) FromAccount

func (tx SignedTx) FromAccount() (AccountID, error)

FromAccount extracts the account id that signed the transaction.

func (SignedTx) SignatureString

func (tx SignedTx) SignatureString() string

SignatureString returns the signature as a string.

func (SignedTx) String

func (tx SignedTx) String() string

String implements the fmt.Stringer interface for logging.

func (SignedTx) Validate

func (tx SignedTx) Validate() error

Validate verifies the transaction has a proper signature that conforms to our standards and is associated with the data claimed to be signed. It also checks the format of the account.

type Tx

type Tx struct {
	ChainID uint16    `json:"chain_id"` // Ethereum: The chain id that is listed in the genesis file.
	Nonce   uint64    `json:"nonce"`    // Ethereum: Unique id for the transaction supplied by the user.
	ToID    AccountID `json:"to"`       // Ethereum: Account receiving the benefit of the transaction.
	Value   uint64    `json:"value"`    // Ethereum: Monetary value received from this transaction.
	Tip     uint64    `json:"tip"`      // Ethereum: Tip offered by the sender as an incentive to mine this transaction.
	Data    []byte    `json:"data"`     // Ethereum: Extra data related to the transaction.
}

Tx is the transactional information between two parties.

func NewTx

func NewTx(chainID uint16, nonce uint64, toID AccountID, value uint64, tip uint64, data []byte) (Tx, error)

NewTx constructs a new transaction.

func (Tx) Sign

func (tx Tx) Sign(privateKey *ecdsa.PrivateKey) (SignedTx, error)

Sign uses the specified private key to sign the transaction.

Jump to

Keyboard shortcuts

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