core

package
v0.0.0-...-77fbf23 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenesisHashTxInput = HashBytes([]byte("genesis"))

Functions

func CalculatePoW

func CalculatePoW(data PoWData, difficulty uint64) (uint64, error)

CalculatePoW calculates the nonce for the given data in order to fit in the current Proof of Work difficulty

func CheckBlockPoW

func CheckBlockPoW(block *Block, difficulty uint64) bool

func CheckPoW

func CheckPoW(hash Hash, difficulty uint64) bool

CheckPoW verifies the PoW difficulty of a Hash

func CheckTx

func CheckTx(tx *Tx) bool

CheckTx checks if the transaction is consistent

func NewKey

func NewKey() (*ecdsa.PrivateKey, error)

func PackPubK

func PackPubK(pubK *ecdsa.PublicKey) []byte

func Uint64FromBytes

func Uint64FromBytes(b []byte) uint64

func Uint64ToBytes

func Uint64ToBytes(u uint64) []byte

func UnpackPubK

func UnpackPubK(b []byte) *ecdsa.PublicKey

func VerifySignature

func VerifySignature(pubK *ecdsa.PublicKey, m []byte, sig Signature) bool

Types

type Address

type Address [32]byte

Address is the type data for addresses

func AddressFromPrivK

func AddressFromPrivK(privK *ecdsa.PrivateKey) Address

func AddressFromPubK

func AddressFromPubK(pubK *ecdsa.PublicKey) Address

func (Address) String

func (addr Address) String() string

type Block

type Block struct {
	Height    uint64
	PrevHash  Hash
	Txs       []Tx
	Miner     Address
	MinerPubK *ecdsa.PublicKey // tmp meanwhile no ecrecover function
	Timestamp time.Time
	Nonce     uint64
	Hash      Hash
	Signature []byte
}

Block holds the data structure for the block

func BlockFromBytes

func BlockFromBytes(b []byte) (*Block, error)

func (Block) Bytes

func (blk Block) Bytes() []byte

Bytes outputs a byte array containing the data of the Block

func (*Block) CalculateHash

func (block *Block) CalculateHash()

func (*Block) CalculatePoW

func (block *Block) CalculatePoW(difficulty uint64) error

func (Block) Copy

func (block Block) Copy() *Block

func (*Block) GetNonce

func (blk *Block) GetNonce() uint64

func (*Block) IncrementNonce

func (blk *Block) IncrementNonce()

func (Block) Print

func (block Block) Print()

for testing

type Blockchain

type Blockchain struct {
	Id         []byte // Id allows to have multiple blockchains
	Difficulty uint64
	Genesis    Hash
	LastBlock  *Block

	PoA PoA
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(database *db.Db, dif uint64) *Blockchain

func NewPoABlockchain

func NewPoABlockchain(database *db.Db, authNodes []*ecdsa.PublicKey) *Blockchain

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(block *Block) error

func (*Blockchain) GetBalance

func (bc *Blockchain) GetBalance(pubK *ecdsa.PublicKey) (uint64, error)

func (*Blockchain) GetBlock

func (bc *Blockchain) GetBlock(hash Hash) (*Block, error)

func (*Blockchain) GetHeight

func (bc *Blockchain) GetHeight() uint64

func (*Blockchain) GetLastBlock

func (bc *Blockchain) GetLastBlock() *Block

func (*Blockchain) GetPrevBlock

func (bc *Blockchain) GetPrevBlock(hash Hash) (*Block, error)

func (*Blockchain) UpdateWalletsWithNewTx

func (bc *Blockchain) UpdateWalletsWithNewTx(tx *Tx) error

func (*Blockchain) VerifyBlock

func (bc *Blockchain) VerifyBlock(block *Block) bool

type Hash

type Hash [32]byte

Hash is the type for a hash data packet

func HashBytes

func HashBytes(b []byte) Hash

HashBytes performs a hash over a given byte array

func (*Hash) IsZero

func (h *Hash) IsZero() bool

IsZero returns true if the Hash is empty (all zeroes)

func (*Hash) String

func (h *Hash) String() string

type Input

type Input struct {
	TxId  Hash
	Vout  int // index of the output from the TxId
	Value uint64
}

type Output

type Output struct {
	Value uint64
}

type PoA

type PoA struct {
	AuthMiners []*ecdsa.PublicKey
}

type PoWData

type PoWData interface {
	Bytes() []byte
	GetNonce() uint64
	IncrementNonce()
}

PoWData is the interface for the data that have the Nonce parameter to calculate the Proof-of-Work

type Signature

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

func Sign

func Sign(privK *ecdsa.PrivateKey, m []byte) (*Signature, error)

func SignatureFromBytes

func SignatureFromBytes(b []byte) (*Signature, error)

func (*Signature) Bytes

func (sig *Signature) Bytes() []byte

type Tx

type Tx struct {
	TxId       Hash
	From       *ecdsa.PublicKey
	To         *ecdsa.PublicKey
	InputCount uint64
	Inputs     []Input
	Outputs    []Output
	Signature  []byte
}

Tx holds the data structure of a transaction

func NewTx

func NewTx(from, to *ecdsa.PublicKey, in []Input, out []Output) *Tx

func (*Tx) Bytes

func (tx *Tx) Bytes() []byte

func (*Tx) CalculateTxId

func (tx *Tx) CalculateTxId()

Jump to

Keyboard shortcuts

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