Skip to content

Commit

Permalink
remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
humblenginr committed Apr 15, 2024
1 parent 2b5a122 commit c24a33d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/mining/merkle_tree.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mining

import (
"fmt"
"math/bits"

"github.com/humblenginr/btc-miner/transaction"
Expand Down Expand Up @@ -120,7 +119,6 @@ func (s *rollingMerkleTreeStore) calcMerkleRoot(adds []*transaction.Transaction,
s.add(zeroHash)
case witness:
s.add([32]byte(adds[i].WitnessHash()))
fmt.Printf("Witness Hash: %x", adds[i].WitnessHash())
default:
s.add([32]byte(adds[i].TxHash()))
}
Expand Down
4 changes: 1 addition & 3 deletions src/mining/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func GetCandidateBlock(txns []*txn.Transaction, hasWitness bool) Block {
}

func MineBlock(candidateBlock Block, outputFilePath string) error {
nonce := findNonce(&candidateBlock)
fmt.Printf("Found nonce: %d", nonce)
findNonce(&candidateBlock)
err := candidateBlock.WriteToFile(outputFilePath)
if err != nil {
return err
Expand All @@ -89,7 +88,6 @@ func findNonce(candidateBlock *Block) uint32 {
// hash the block header
err := header.Serialize(w)
if err != nil {
fmt.Printf("WARN: Could not serialize block header: %v", err)
// else this might go in infinity loop
panic(err)
}
Expand Down
5 changes: 0 additions & 5 deletions src/txnpicker/picker.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package txnpicker

import (
"fmt"

txn "github.com/humblenginr/btc-miner/transaction"
"github.com/humblenginr/btc-miner/utils"
)

type TransactionsPicker struct {
Expand Down Expand Up @@ -32,8 +29,6 @@ func (tp *TransactionsPicker) PickUsingPQ() []*txn.Transaction {
tx := txn.Transaction(item.(Item))
weight := tx.GetWeight()
fee := tx.GetFees()
fmt.Printf("Weight of the transaction: %d\n", weight)
fmt.Printf("Txid: %x\n", utils.ReverseBytes(tx.TxHash()))
if((weight+ totalWeight < tp.MaxTotalWeight) && (fee + totalFee < tp.MaxFees)) {
txns = append(txns, &tx)
totalWeight += weight
Expand Down
10 changes: 2 additions & 8 deletions src/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ func validateP2TR( tx transaction.Transaction, trIdx int ) bool {
// 1. Parse public key and signature
pk, sig, hashtype, err := schnorr.ParseSigAndPubkey(pubkey, sigBytes)
if err != nil {
fmt.Println("Cannot parse signatuer and pub key: "+ err.Error())
// fmt.Println("Cannot parse signatuer and pub key: "+ err.Error())
return false
}
// 2. Calculate signature hash
sighash, err := sighash.CalcTaprootSignatureHash(&sighashes, hashtype,&tx, trIdx, nil, annexBytes)
if err != nil {
fmt.Println("Cannot calculate signature hash : "+ err.Error())
// fmt.Println("Cannot calculate signature hash : "+ err.Error())
return false
}
// 3. Verify signature
Expand All @@ -121,7 +121,6 @@ func validateP2TR( tx transaction.Transaction, trIdx int ) bool {
if(s[33] != 0xac) {
// fmt.Printf("Witness script: %x\n", s)
// fmt.Printf("WARN: Skipping the transaction input since it's witness script is unrecognisable: %s\n", txIn)
fmt.Printf("Expected 0xac, got: %x\n", s[33])
return false
}
// remove annex from the witness array, if found
Expand All @@ -134,23 +133,19 @@ func validateP2TR( tx transaction.Transaction, trIdx int ) bool {
q, _ := hex.DecodeString(txIn.PrevOut.ScriptPubKey[4:])
err = VerifyTaprootLeafCommitment(c,q,s)
if err != nil {
fmt.Printf("INFO: Invalid taproot leaf commitment: %e\n", err)
return false
}
if(ScriptHasOpSuccess(s)) {
fmt.Printf("INFO: Witness script has OpSuccess\n")
return true
}
// parse the witness script
if(!checkScriptParses(s)){
fmt.Printf("INFO: Could not parse witness script\n")
return false
}
// parse sig and pk
sigBytes, _ := hex.DecodeString(witness[0])
pk, sig, hashtype, err := schnorr.ParseSigAndPubkey(s[1:33], sigBytes)
if err != nil {
fmt.Println("Cannot parse signatuer and pub key: "+ err.Error())
return false
}
// calculate sighash
Expand All @@ -159,7 +154,6 @@ func validateP2TR( tx transaction.Transaction, trIdx int ) bool {

sighash, err := sighash.CalcTaprootSignatureHash(&sighashes, hashtype,&tx, trIdx,utils.ReverseBytes(tapLeafHash[:]), annexBytes)
if err != nil {
fmt.Println("Cannot calculate signature hash : "+ err.Error())
}
// fmt.Printf("Schnorr Sighash: %x\n", sighash)
serializedPubkey := schnorr.SerializePubKey(pk)
Expand Down

0 comments on commit c24a33d

Please sign in to comment.