Skip to content
This repository has been archived by the owner on Mar 2, 2023. It is now read-only.

Commit

Permalink
Remove a bunch of fmt.Sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
alokmenghrajani committed Oct 18, 2018
1 parent 041952c commit e96d581
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion accounter/accounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package accounter
import (
"encoding/hex"
"fmt"
"log"
"sync"
"time"

Expand Down Expand Up @@ -199,7 +200,7 @@ func (a *Accounter) balance() uint64 {
balance -= prev.vout[txin.index].value
if prev.vout[txin.index].spentBy != nil {
// sanity check: an output can only be spent by one transaction.
panic(fmt.Sprintf("%s and %s, both spending %s", hash, *prev.vout[txin.index].spentBy, txin.prevHash))
log.Panicf("%s and %s, both spending %s", hash, *prev.vout[txin.index].spentBy, txin.prevHash)
}
prev.vout[txin.index].spentBy = &hash
}
Expand Down
19 changes: 10 additions & 9 deletions backend/btcd_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"fmt"
"log"
"sync"

"github.com/btcsuite/btcd/btcjson"
Expand Down Expand Up @@ -76,7 +77,7 @@ func NewBtcdBackend(hostPort, user, pass string, network utils.Network) (*BtcdBa
return nil, errors.Wrap(err, "GetBlockHash(0) failed")
}
if genesis.String() != utils.GenesisBlock(network) {
return nil, errors.New(fmt.Sprintf("Unexpected genesis block %s != %s", genesis.String(), utils.GenesisBlock(network)))
return nil, errors.Errorf("Unexpected genesis block %s != %s", genesis.String(), utils.GenesisBlock(network))
}

height, err := client.GetBlockCount()
Expand Down Expand Up @@ -161,17 +162,17 @@ func (b *BtcdBackend) processRequests() {
case addr := <-b.addrRequests:
err := b.processAddrRequest(addr)
if err != nil {
panic(fmt.Sprintf("processAddrRequest failed: %+v", err))
log.Panicf("processAddrRequest failed: %+v", err)
}
case tx := <-b.txRequests:
err := b.processTxRequest(tx)
if err != nil {
panic(fmt.Sprintf("processTxRequest failed: %+v", err))
log.Panicf("processTxRequest failed: %+v", err)
}
case block := <-b.blockRequests:
err := b.processBlockRequest(block)
if err != nil {
panic(fmt.Sprintf("processBlockRequest failed: %+v", err))
log.Panicf("processBlockRequest failed: %+v", err)
}
case <-b.doneCh:
break
Expand Down Expand Up @@ -261,21 +262,21 @@ func (b *BtcdBackend) processBlockRequest(height uint32) error {
if jerr, ok := err.(*btcjson.RPCError); ok {
switch jerr.Code {
case btcjson.ErrRPCInvalidAddressOrKey:
return errors.Wrap(err, fmt.Sprintf("blockchain doesn't have block %d", height))
return errors.Wrapf(err, "blockchain doesn't have block %d", height)
}
}
return errors.Wrap(err, fmt.Sprintf("could not fetch block %d", height))
return errors.Wrapf(err, "could not fetch block %d", height)
}

header, err := b.client.GetBlockHeader(hash)
if err != nil {
if jerr, ok := err.(*btcjson.RPCError); ok {
switch jerr.Code {
case btcjson.ErrRPCInvalidAddressOrKey:
return errors.Wrap(err, fmt.Sprintf("blockchain doesn't have block %d", height))
return errors.Wrapf(err, "blockchain doesn't have block %d", height)
}
}
return errors.Wrap(err, fmt.Sprintf("could not fetch block %d", height))
return errors.Wrapf(err, "could not fetch block %d", height)
}

b.blockResponses <- &BlockResponse{
Expand All @@ -297,7 +298,7 @@ func (b *BtcdBackend) cacheTxs(txs []*btcjson.SearchRawTransactionsResult) {

height, err := b.getBlockHeight(tx.BlockHash)
if err != nil {
panic(fmt.Sprintf("error getting block height for hash %s: %s", tx.BlockHash, err.Error()))
log.Panicf("error getting block height for hash %s: %s", tx.BlockHash, err.Error())
}

b.transactionsMu.Lock()
Expand Down
2 changes: 1 addition & 1 deletion backend/electrum_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (eb *ElectrumBackend) cacheTxs(txs []*electrum.Transaction) {
for _, tx := range txs {
height, exists := eb.transactions[tx.Hash]
if exists && (height != int64(tx.Height)) {
panic(fmt.Sprintf("inconsistent cache: %s %d != %d", tx.Hash, height, tx.Height))
log.Panicf("inconsistent cache: %s %d != %d", tx.Hash, height, tx.Height)
}
eb.transactions[tx.Hash] = int64(tx.Height)
}
Expand Down
3 changes: 2 additions & 1 deletion backend/fixture_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"sync"

Expand Down Expand Up @@ -185,7 +186,7 @@ func (b *FixtureBackend) processBlockRequest(height uint32) {
b.blockResponses <- &resp
return
}
panic(fmt.Sprintf("fixture doesn't contain block %d", height))
log.Panicf("fixture doesn't contain block %d", height)
}

func (fb *FixtureBackend) loadFromFile(f *os.File) error {
Expand Down
2 changes: 1 addition & 1 deletion deriver/address_deriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (d *AddressDeriver) multiSigSegwitDerive(change uint32, addressIndex uint32

pubKeyBytes := pubKey.SerializeCompressed()
if len(pubKeyBytes) != 33 {
panic(fmt.Sprintf("expected pubkey length 33, got %d", len(pubKeyBytes)))
log.Panicf("expected pubkey length 33, got %d", len(pubKeyBytes))
}

pubKeysBytes = append(pubKeysBytes, pubKeyBytes)
Expand Down
5 changes: 3 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"log"

"github.com/btcsuite/btcd/chaincfg"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ func XpubToNetwork(xpub string) Network {
case "tpub":
return Testnet
default:
panic(fmt.Sprintf("unknown prefix: %s", xpub))
log.Panicf("unknown prefix: %s", xpub)
}
}

Expand All @@ -64,7 +65,7 @@ func AddressToNetwork(addr string) Network {
case '3':
return Mainnet // script hash
default:
panic(fmt.Sprintf("unknown prefix: %s", addr))
log.Panicf("unknown prefix: %s", addr)
}
}

Expand Down

0 comments on commit e96d581

Please sign in to comment.