types

package
v0.0.0-...-820de1c Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

Package types contains types like structs and interfaces that are commonly used in go-chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address string

Address of an wallet that is derived from the publicKey.

type Balance

type Balance uint64

Balance of an wallet.

type Block

type Block struct {
	Timestamp    int64         `json:"timestamp"`
	LastHash     string        `json:"lastHash"`
	Hash         string        `json:"hash"`
	Transactions []Transaction `json:"transactions"`
	Difficulty   uint64        `json:"difficulty"`
	Nonce        int           `json:"nonce"`
}

Block is chained with other Blocks (lastHash) to form the blockchain.

func (Block) String

func (b Block) String() string

type Input

type Input struct {
	Address Address `json:"address"`
	Amount  uint64  `json:"amount"`
}

Input defines how much value an address receives.

type Output

type Output struct {
	Address Address `json:"address"`
	Amount  uint64  `json:"amount"`
}

Output defines how much value an address sends.

type Signature

type Signature struct {
	R *big.Int `json:"r"`
	S *big.Int `json:"s"`
}

Signature is composed of a pair of integers that is the result of the Sign function.

type Signer

type Signer interface {
	Sign([]byte) (Signature, error)
}

Signer can take a []byte hash and sign it to verify it's validity.

type Transaction

type Transaction struct {
	ID        uuid.UUID `json:"id"`
	Input     Input     `json:"input"`
	Outputs   []Output  `json:"outputs"`
	Signature Signature `json:"signature"`
}

Transaction gets created and signed by an account. Will be added to a "Block" by miners.

func (Transaction) Hash

func (t Transaction) Hash() ([]byte, error)

Hash returns a sha256 string based on the given transaction.

func (Transaction) IsValid

func (t Transaction) IsValid() bool

IsValid returns "true" if transaction is valid

func (Transaction) String

func (t Transaction) String() string

type Wallet

type Wallet struct {
	Address    Address          `json:"address"`
	PublicKey  ecdsa.PublicKey  `json:"publicKey"`
	PrivateKey ecdsa.PrivateKey `json:"privateKey"`
	Balance    Balance          `json:"balance"`
}

Wallet represents a single user/client wallet in the go-chain.

func (Wallet) Sign

func (w Wallet) Sign(h []byte) (Signature, error)

Sign uses the private key of the wallet to cryptographically sign the given hashed value.

func (Wallet) String

func (w Wallet) String() string

Jump to

Keyboard shortcuts

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