blockchain

package
v0.0.0-...-bc1f52c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BlockChain []Block
)

Functions

func IsBlockValid

func IsBlockValid(newBlock, oldBlock Block) bool

IsBlockValid make sure block is valid by checking index, and comparing the hash of the previous block.

func IsValid

func IsValid(_ []Block) bool

IsValid test if the block is valid. @todo parse all blockChain

func NextID

func NextID(index *big.Int) *big.Int

NextID increment to current ID.

Types

type Block

type Block struct {
	Index        *big.Int
	Validation   Validation
	Timestamp    int64
	Transactions []*Transaction
	Hash         []byte
	PrevHash     []byte
	// Nœud racine du hachage de réception
	ReceiptHash []byte
	// Nœud racine du hachage de transaction
	TransactionHashRoot []byte
	Difficulty          int
	// Code à usage unique choisi au hasard pour transmettre le mot de passe en toute sécurité et empêcher les attaques par rejeu
	Nonce string
	// Il détermine combien de transactions peuvent être stockées dans un bloc en fonction de la somme de gaz
	// Par exemple, lorsque la limite de gaz du bloc est de 100 et que nous avons des transactions dont les limites
	// de gaz sont de 50, 50 et 10. Block ne peut stocker que les deux premières transactions (les 50)
	// mais pas la dernière (10).
	GasLimit  int
	GasUsed   int
	ExtraData []interface{}
}

func AddBlock

func AddBlock(lastHash []byte, index *big.Int, coinBase *Transaction) Block

AddBlock create a new block using previous block's hash.

func Genesis

func Genesis(coinBase *Transaction) *Block

Genesis create the initial blockchain.

func GetLastBlock

func GetLastBlock() Block

GetLastBlock return the last block in blockchain.

type Transaction

type Transaction struct {
	ID      []byte
	Inputs  []TxInput
	Outputs []TxOutput
	// le nonce dans la transaction est un nonce de compte qui représente un ordre de transaction qu'un compte crée.
	Timestamp int64
}

func (*Transaction) IsCoinBase

func (tx *Transaction) IsCoinBase() bool

func (*Transaction) SetID

func (tx *Transaction) SetID()

type TxInput

type TxInput struct {
	// ID will find the Transaction that a specific output is inside of
	ID []byte
	// Out will be the index of the specific output we found within a transaction.
	// For example if a transaction has 4 outputs, we can use this "out" field to specify which output we are looking for
	Out int
	// This would be a script that adds data to an outputs' PubKey
	// however for this tutorial the Sig will be indentical to the PubKey.
	Sig        []byte
	PubKey     []byte
	SchnorrKey []byte
}

Important to note that each output is Indivisible. Vous ne pouvez pas "faire de changement" avec n'importe quelle sortie. Si la valeur est 10, afin de donner 5 à quelqu'un, nous devons faire deux sorties de cinq pièces. TxInput is represntative of a reference to a previous TxOutput

func (*TxInput) CanUnlock

func (in *TxInput) CanUnlock(data []byte) bool

type TxOutput

type TxOutput struct {
	// Value would be representative of the amount of coins in a transaction
	Value *big.Int
	// La Pubkey est nécessaire pour "déverrouiller" toutes les pièces dans une sortie. Cela indique que VOUS êtes celui qui l'a envoyé.
	// Vous êtes identifiable par votre PubKey
	// PubKey dans cette itération sera très simple, mais dans une application réelle, il s'agit d'un algorithme plus complexe
	PubKey []byte
}

TxOutput represents a transaction in the blockchain For Example, I sent you 5 coins. Value would == 5, and it would have my unique PubKey

func (*TxOutput) CanBeUnlocked

func (out *TxOutput) CanBeUnlocked(data []byte) bool

type Validation

type Validation struct {
	Total   int
	Refused int
	Ok      int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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