blockchain

package
v0.0.0-...-6b24a3f Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TxsQueue struct {
	sync.RWMutex
	Txs []Transaction
}

Functions

func HandleBCmessage

func HandleBCmessage(s core.Server, conn net.Conn)

HandleBCmessage : recive bc messages and answer them

func HashSha256

func HashSha256(tohash []byte) string

HashSha256 : returns the hash of a slice of bytes

func IsBlockValid

func IsBlockValid(newBlock, oldBlock Block) (bool, error)

IsBlockValid : check if block is valid

func ProcessTx

func ProcessTx(Tx Transaction) bool

func ReadyToValidate

func ReadyToValidate(s core.Server, conn net.Conn)

func StdAddListeners

func StdAddListeners(s core.Server)

StdAddListeners : add the standard listeners to the server NEW CONNECTION NEW DOSCONNECTION

func StdBCServer

func StdBCServer(sc core.ServerConfig) core.Server

StdBCServer : create a standard server

func StdReciveMessage

func StdReciveMessage(s core.Server, conn net.Conn) error

StdReciveMessage : Standard function to recive messages

func Validate

func Validate(s core.Server)

Types

type Block

type Block struct {
	Index        int
	Timestamp    string
	Transactions []Transaction
	Hash         string
	PrevHash     string
}

Block : struct of a blockchan block

func GenerateBlock

func GenerateBlock(oldBlock Block, txs []Transaction) (Block, error)

GenerateBlock : generate a new block from an old block and some txs

func GenerateGenesisBlock

func GenerateGenesisBlock() (Block, error)

GenerateGenesisBlock : generate a genesis block

func (*Block) CalculateHash

func (b *Block) CalculateHash() (string, error)

CalculateHash : calcumate has of the block

type Chain

type Chain interface {
	Get() []Block
	GetBlock(int) (Block, error)
	Replace(Chain) bool
	Append(Block) bool
	Lock()
	RLock()
	Unlock()
	RUnlock()
}

Chain type for chain and methods

func NewChain

func NewChain(blocks []Block, dir string) Chain

NewChain : create a new chain

type Transaction

type Transaction struct {
	Hash    string
	NTxsIn  int
	TxsIn   []TxIn
	NTxsOut int
	TxsOut  []TxOut
}

Transaction : struct of a blockchain transaction

type TxIn

type TxIn struct {
	PrevTx    string
	Index     int
	ScriptSig string
}

TxIn : struct for bc transaction input

type TxOut

type TxOut struct {
	Value        int64
	ScriptPubKey string
}

TxOut : struct for bc transaction output

Jump to

Keyboard shortcuts

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