Skip to content

Commit

Permalink
Merge pull request #22 from pred695/testing/room
Browse files Browse the repository at this point in the history
revert
  • Loading branch information
pred695 authored Apr 20, 2024
2 parents 2172272 + a79575c commit eba9b4e
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions Blockchain/mine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package Blockchain

import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"time"
Expand All @@ -20,31 +19,13 @@ var Bh Structs.BlockHeader = Structs.BlockHeader{
Nonce: 0,
}

func GetAllTxid() []string {
var permittedTxIDs []string
dir := "./mempool"
files, _ := os.ReadDir(dir)
for _, file := range files {
txData, err := Utils.JsonData(dir + "/" + file.Name())
Utils.Handle(err)
var tx Structs.Transaction
err = json.Unmarshal([]byte(txData), &tx)
serialized, _ := Utils.SerializeTransaction(&tx)
txID := Utils.ReverseBytes(Utils.To_sha(Utils.To_sha(serialized)))
permittedTxIDs = append(permittedTxIDs, hex.EncodeToString(txID))
}
return permittedTxIDs

}
func MineBlock() {
netReward, TxIDs, _ := Utils.Prioritize()

cbTx := Utils.CreateCoinbase(netReward)
serializedcbTx, _ := Utils.SerializeTransaction(cbTx)
fmt.Printf("CBTX: %x\n", serializedcbTx)
txidsnew := GetAllTxid()
fmt.Println("Length of txids: ", len(txidsnew))
TxIDs = append([]string{hex.EncodeToString(Utils.ReverseBytes(Utils.To_sha(Utils.To_sha(serializedcbTx))))}, GetAllTxid()...)
TxIDs = append([]string{hex.EncodeToString(Utils.ReverseBytes(Utils.To_sha(Utils.To_sha(serializedcbTx))))}, TxIDs...)
mkr := Utils.NewMerkleTree(TxIDs)
Bh.MerkleRoot = hex.EncodeToString(mkr.Data)
cbtxbase := Utils.CalculateBaseSize(cbTx)
Expand Down

0 comments on commit eba9b4e

Please sign in to comment.