Skip to content

Commit

Permalink
final assignment solution
Browse files Browse the repository at this point in the history
  • Loading branch information
OsauravO committed Apr 29, 2024
1 parent 4cac310 commit c43bd26
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c43bd26

Please sign in to comment.