If you want to read only purpose of functions, pls skip this boring introduction
In brief. My idea was to finally answer "What the hell is even this blockchain is?".
Don't understand something. Build it.
So, my goofy plan was:
1. Read A LOT OF DOCS
2. Write simple, but functionally complete blockchain in golang
3. Look for exaplme in Geth(go etherium); ask a team-lead; read repo again
4. Re-write it all with patterns
5. Write tests
6. Write fixes after tests
7. Be happy with my work (never happen)
My next step is to make a blog page with Next.Js with complete overview for the entire project, but for now let it stay in the way it is
InitBlockchain(address, nodeId)
: Create initial blockchain with genesis blockContinueBlockchain(nodeId)
: Restore existing blockchainMineBlock(transaction)
: Create and add new block with transactionsVerifyTransaction(t *Transaction)
: Validate transaction integrityFindUniqueTransaction(address)
: Retrieve transactions for specific addressGetBestHeightAndLastHash()
: Get current blockchain height and last block hash
CreateBlock(txs, prevHash, height)
: Generate new block with transactionsCreateGenesis(coinbase)
: Create initial genesis blockHashTransactions()
: Generate Merkle root for block's transactionsSerialize()
: Convert block to byte arrayDeserializeBlock(data)
: Reconstruct block from byte array
NewTransaction(wallet, to, amount, UTXO)
: Create new transactionSign(privateKey, prevTransactions)
: Sign transaction with private keyVerify(prevTransactions)
: Validate transaction signaturesIsCoinbase()
: Check if transaction is a coinbase (mining reward)CoinbaseTx(to, data)
: Create coinbase transaction for mining rewards
Reindex()
: Rebuild UTXO setUpdate(block)
: Update UTXO set after new blockFindSpendableOutputs(pubKeyHash, amount)
: Find unspent outputs for transactionCountUnspentOuts()
: Count total unspent transaction outputs
NewProof(block)
: Create proof of work for blockRun()
: Mine block by finding valid nonceValidate()
: Check if block's proof of work is valid
Initializes a `Wallets` instance, loads wallet data from a file associated with the given `nodeId`, and returns the instance.
Creates a new wallet with a unique private/public key pair, generates an address, and adds the wallet to the `Wallets` collection. Returns the generated address.
Retrieves a wallet from the `Wallets` collection using its address as the key.
Returns a list of all wallet addresses stored in the `Wallets` collection.
Loads wallet data from a file associated with the given `nodeId`. If the file doesn't exist, it returns an error.
Saves the current `Wallets` collection to a file associated with the given `nodeId`.
Generates a wallet address by applying a series of hashing algorithms (SHA-256 and RIPEMD-160) and encoding the result with Base58. Includes a version byte and a checksum.
Generates a new key pair for a wallet. Uses the P256 elliptic curve to create a private key and derives the public key from it.
Generates a public key hash by applying SHA-256 and RIPEMD-160 hashing algorithms to the provided public key.
Computes a checksum for a given payload by applying SHA-256 twice and returning the first 4 bytes of the result.
Validates a wallet address by verifying its checksum and ensuring it matches the hash of the public key.
Creates a new `Wallet` by generating a private/public key pair and initializing a `Wallet` instance with these keys.
Beyond good website that i wish i found earlier: