# Simple Bitcoin Architecture

By [Untitled](https://paragraph.com/@0xb14101d59de63a177e7b5cd76afcd14ae237a5b7) · 2023-03-30

---

    Block{ hash, previousHash, merkleRoot, data, transactions, timeStamp, nonce}　　　　
       Nonce:随机数，使得hash的前difficulty位是0　　
       mineBlock(int difficulty)　　
    
    Wallet{ privateKey, publicKey, UTXOs}　　
       UTXOs:Unspent Transaction Output, 属于自己且没有被使用的交易输出
        generateKeyPair使用ECC（椭圆曲线算法）生成公私钥
        getBalance
        sendFunds　　
    
    MerkleRoot:
        What: 任一父节点等于左右子节点数据相加后哈希的结果，所以默克尔树有另外一个名字哈希树(Hash tree)
        Use：mine时从transactions里获取merkleRoot: 遍历树
        Function: 打包计算hash Sha256(merkleRoot + previousHash + timeStamp + nonce)　　
    
    Transaction{ transactionId, sender, recipient接收方, value, byte[] signature, inputs, outputs}
       processTransaction  
       verifySignature  
       input.UTXO  
       calculateHash  
       UTXOs.put(output.id,output);  
       UTXOs.remove(input.UTXO.id);　　
    
    signature：使用privateKey对交易双方和value等数据进行签名　　
        使用公钥验证签名　　
        1.只有数字货币的拥有者才能使用；　　
        2.在交易被矿工挖出之前(共识前)交易不会被篡改

---

*Originally published on [Untitled](https://paragraph.com/@0xb14101d59de63a177e7b5cd76afcd14ae237a5b7/simple-bitcoin-architecture)*
