From c43bd26cf164322bbb08dbbf23ba57867e3e7f07 Mon Sep 17 00:00:00 2001 From: OsauravO Date: Mon, 29 Apr 2024 23:00:51 +0530 Subject: [PATCH] final assignment solution --- main.go | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index 1c710a6..71f1ca3 100644 --- a/main.go +++ b/main.go @@ -314,6 +314,30 @@ func srlzBhead(bh *BlockHeader) []byte { return serlzd } +func isSegWitTransaction(tx *Transaction) bool { + for _, vin := range tx.Vin { + if len(vin.Witness) > 0 { + return true + } + } + return false +} + +func calculateTxID(serializedTx []byte) string { + hash := doubleHash(serializedTx) + reversedHash := rb(hash) + return hex.EncodeToString(reversedHash) +} + +func calculateMerkleRoot(txIDs []string) string { + merkleTree := merkTree(txIDs) + return hex.EncodeToString(merkleTree.Data) +} + +func mineBlock(header *BlockHeader) bool { + return proofOfWork(header) +} + func SegWitSerialize(tx *Transaction) []byte { var serlzd []byte serlzd = append(serlzd, u32ToB(tx.Version)...) @@ -351,30 +375,6 @@ func SegWitSerialize(tx *Transaction) []byte { return serlzd } -func isSegWitTransaction(tx *Transaction) bool { - for _, vin := range tx.Vin { - if len(vin.Witness) > 0 { - return true - } - } - return false -} - -func calculateTxID(serializedTx []byte) string { - hash := doubleHash(serializedTx) - reversedHash := rb(hash) - return hex.EncodeToString(reversedHash) -} - -func calculateMerkleRoot(txIDs []string) string { - merkleTree := merkTree(txIDs) - return hex.EncodeToString(merkleTree.Data) -} - -func mineBlock(header *BlockHeader) bool { - return proofOfWork(header) -} - func writeBlockData(header BlockHeader, coinbaseTx *Transaction, txIDs []string) { outputF, _ := os.Create("output.txt") defer outputF.Close()