Documentation
¶
Index ¶
- Constants
- func PanicHandle(err error)
- func ReturnHandle(err error) error
- func ToHex(number int64) []byte
- type Block
- type BlockChain
- func (chain *BlockChain) AddBlock(transactions []*Transaction)
- func (chain *BlockChain) FindSpendableOutputs(publicKeyHash []byte, amount int) (int, map[string][]int)
- func (chain *BlockChain) FindTransaction(ID []byte) (Transaction, error)
- func (chain *BlockChain) FindUnspentTransactions(publicKeyHash []byte) []Transaction
- func (chain *BlockChain) FindUnspentTransactionsOutputs(publicKeyHash []byte) []TxOutput
- func (chain *BlockChain) Iterator() *ChainIterator
- func (chain *BlockChain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
- func (chain *BlockChain) VerifyTransaction(tx *Transaction) bool
- type ChainIterator
- type ProofOfWork
- type Transaction
- func (tx *Transaction) Hash() []byte
- func (tx *Transaction) IsCoinBase() bool
- func (tx *Transaction) Serialize() []byte
- func (tx *Transaction) SetID()
- func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, previousTXs map[string]Transaction)
- func (tx Transaction) String() string
- func (tx *Transaction) TrimmedCopy() Transaction
- func (tx *Transaction) Verify(previousTXs map[string]Transaction) bool
- type TxInput
- type TxOutput
- type TxOutputs
- type UTXO
Constants ¶
const Difficulty = 18
Difficulty constant representing the diffuculty of finding the nonce
Variables ¶
This section is empty.
Functions ¶
func ReturnHandle ¶ added in v0.0.2
ReturnHandle to return throw errors
Types ¶
type Block ¶
type Block struct { Hash []byte Transactions []*Transaction PreviousHash []byte Nonce int }
Block structure for the Block type in the blockchain
func CreateBlock ¶
func CreateBlock(txns []*Transaction, previousHash []byte) *Block
CreateBlock to create a block in the blockchain
func Deserialize ¶
Deserialize to deserialize the output from BadgerDB
func Genesis ¶
func Genesis(coinbase *Transaction) *Block
Genesis to create the genesis block in the blockchain
func (*Block) HashTransactions ¶
HashTransactions to hash the transactions in the block
type BlockChain ¶
BlockChain structure for the BlockChain type in the blockchain
func ContinueBlockChain ¶
func ContinueBlockChain(address string) *BlockChain
ContinueBlockChain to continue blockchain validation
func InitBlockChain ¶
func InitBlockChain(address string) *BlockChain
InitBlockChain to initialize the BlockChain
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(transactions []*Transaction)
AddBlock to add a block to the existing BlockChain
func (*BlockChain) FindSpendableOutputs ¶
func (chain *BlockChain) FindSpendableOutputs(publicKeyHash []byte, amount int) (int, map[string][]int)
FindSpendableOutputs to find spendable outputs in the BlockChain
func (*BlockChain) FindTransaction ¶ added in v0.0.2
func (chain *BlockChain) FindTransaction(ID []byte) (Transaction, error)
FindTransaction to find a transaction by ID in the list of transactions in the blocks
func (*BlockChain) FindUnspentTransactions ¶
func (chain *BlockChain) FindUnspentTransactions(publicKeyHash []byte) []Transaction
FindUnspentTransactions to find unspent transactions in the blockchain
func (*BlockChain) FindUnspentTransactionsOutputs ¶
func (chain *BlockChain) FindUnspentTransactionsOutputs(publicKeyHash []byte) []TxOutput
FindUnspentTransactionsOutputs to find unspent transaction outputs in the blockchain
func (*BlockChain) Iterator ¶
func (chain *BlockChain) Iterator() *ChainIterator
Iterator to initialise a Iterator over badgerDB
func (*BlockChain) SignTransaction ¶ added in v0.0.2
func (chain *BlockChain) SignTransaction(tx *Transaction, privateKey ecdsa.PrivateKey)
SignTransaction to sign the transaction that is added to a block
func (*BlockChain) VerifyTransaction ¶ added in v0.0.2
func (chain *BlockChain) VerifyTransaction(tx *Transaction) bool
VerifyTransaction to verify the transactions in a block
type ChainIterator ¶
ChainIterator structure to iterate the Blocks in badger.DB
func (*ChainIterator) Next ¶
func (iterator *ChainIterator) Next() *Block
Next to navigate to the next Block in badgerDB
type ProofOfWork ¶
ProofOfWork structure for the proof of work in mining
func NewProof ¶
func NewProof(block *Block) *ProofOfWork
NewProof to create a new ProofOfWork to mine the Block
func (*ProofOfWork) InitData ¶
func (proofOfWork *ProofOfWork) InitData(nonce int) []byte
InitData to initialize the data in the Block
func (*ProofOfWork) Run ¶
func (proofOfWork *ProofOfWork) Run() (int, []byte)
Run to run the computation for the BlockChain
func (*ProofOfWork) Validate ¶
func (proofOfWork *ProofOfWork) Validate() bool
Validate for validation of the ProofOfWork
type Transaction ¶
Transaction structure for the Transaction type in the blockchain
func CoinBaseTx ¶
func CoinBaseTx(to, data string) *Transaction
CoinBaseTx for the coin base transaction
func NewTransaction ¶
func NewTransaction(from, to string, amount int, blockchain *BlockChain) *Transaction
NewTransaction for creating a new Transaction in the BlockChain
func (*Transaction) Hash ¶ added in v0.0.2
func (tx *Transaction) Hash() []byte
Hash to create a new hash for the given transaction
func (*Transaction) IsCoinBase ¶
func (tx *Transaction) IsCoinBase() bool
IsCoinBase to check for CoinBase Transaction
func (*Transaction) Serialize ¶ added in v0.0.2
func (tx *Transaction) Serialize() []byte
Serialize to serialize the transaction
func (*Transaction) Sign ¶ added in v0.0.2
func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, previousTXs map[string]Transaction)
Sign to sign the transation block to enable chaining
func (Transaction) String ¶ added in v0.0.2
func (tx Transaction) String() string
String to output transaction based output
func (*Transaction) TrimmedCopy ¶ added in v0.0.2
func (tx *Transaction) TrimmedCopy() Transaction
TrimmedCopy to create a trimmed copy of the entire transaction
func (*Transaction) Verify ¶ added in v0.0.2
func (tx *Transaction) Verify(previousTXs map[string]Transaction) bool
Verify to verify the signature of the signed transactions
type TxOutput ¶
TxOutput structure for Output for the BlockChainw
func NewTxOutput ¶ added in v0.0.2
NewTxOutput to create a new transaction output for the new transaction that is created by every spend
func (*TxOutput) IsLockedWithKey ¶ added in v0.0.2
IsLockedWithKey to verify that the transaction is locked with only the users public key
type TxOutputs ¶ added in v0.0.2
type TxOutputs struct {
Outputs []TxOutput
}
TxOutputs structure for Transaction Outputs for the Transaction Listing
func DeserializeOutputs ¶ added in v0.0.2
DeserializeOutputs to deserialize the TxOutputs from badger.DB
func (*TxOutputs) SerializeOutputs ¶ added in v0.0.2
SerializeOutputs to serialize the TxOutputs for badger.DB