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

Commit 685a5f1

Browse files
Remove a bunch of fmt.Sprintf
1 parent e9e10cc commit 685a5f1

6 files changed

Lines changed: 18 additions & 15 deletions

File tree

accounter/accounter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package accounter
33
import (
44
"encoding/hex"
55
"fmt"
6+
"log"
67
"sync"
78
"time"
89

@@ -199,7 +200,7 @@ func (a *Accounter) balance() uint64 {
199200
balance -= prev.vout[txin.index].value
200201
if prev.vout[txin.index].spentBy != nil {
201202
// sanity check: an output can only be spent by one transaction.
202-
panic(fmt.Sprintf("%s and %s, both spending %s", hash, *prev.vout[txin.index].spentBy, txin.prevHash))
203+
log.Panicf("%s and %s, both spending %s", hash, *prev.vout[txin.index].spentBy, txin.prevHash)
203204
}
204205
prev.vout[txin.index].spentBy = &hash
205206
}

backend/btcd_backend.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package backend
22

33
import (
44
"fmt"
5+
"log"
56
"sync"
67

78
"github.com/btcsuite/btcd/btcjson"
@@ -76,7 +77,7 @@ func NewBtcdBackend(host, port, user, pass string, network utils.Network) (*Btcd
7677
return nil, errors.Wrap(err, "GetBlockHash(0) failed")
7778
}
7879
if genesis.String() != utils.GenesisBlock(network) {
79-
return nil, errors.New(fmt.Sprintf("Unexpected genesis block %s != %s", genesis.String(), utils.GenesisBlock(network)))
80+
return nil, errors.Errorf("Unexpected genesis block %s != %s", genesis.String(), utils.GenesisBlock(network))
8081
}
8182

8283
height, err := client.GetBlockCount()
@@ -161,17 +162,17 @@ func (b *BtcdBackend) processRequests() {
161162
case addr := <-b.addrRequests:
162163
err := b.processAddrRequest(addr)
163164
if err != nil {
164-
panic(fmt.Sprintf("processAddrRequest failed: %+v", err))
165+
log.Panicf("processAddrRequest failed: %+v", err)
165166
}
166167
case tx := <-b.txRequests:
167168
err := b.processTxRequest(tx)
168169
if err != nil {
169-
panic(fmt.Sprintf("processTxRequest failed: %+v", err))
170+
log.Panicf("processTxRequest failed: %+v", err)
170171
}
171172
case block := <-b.blockRequests:
172173
err := b.processBlockRequest(block)
173174
if err != nil {
174-
panic(fmt.Sprintf("processBlockRequest failed: %+v", err))
175+
log.Panicf("processBlockRequest failed: %+v", err)
175176
}
176177
case <-b.doneCh:
177178
break
@@ -261,21 +262,21 @@ func (b *BtcdBackend) processBlockRequest(height uint32) error {
261262
if jerr, ok := err.(*btcjson.RPCError); ok {
262263
switch jerr.Code {
263264
case btcjson.ErrRPCInvalidAddressOrKey:
264-
return errors.Wrap(err, fmt.Sprintf("blockchain doesn't have block %d", height))
265+
return errors.Wrapf(err, "blockchain doesn't have block %d", height)
265266
}
266267
}
267-
return errors.Wrap(err, fmt.Sprintf("could not fetch block %d", height))
268+
return errors.Wrapf(err, "could not fetch block %d", height)
268269
}
269270

270271
header, err := b.client.GetBlockHeader(hash)
271272
if err != nil {
272273
if jerr, ok := err.(*btcjson.RPCError); ok {
273274
switch jerr.Code {
274275
case btcjson.ErrRPCInvalidAddressOrKey:
275-
return errors.Wrap(err, fmt.Sprintf("blockchain doesn't have block %d", height))
276+
return errors.Wrapf(err, "blockchain doesn't have block %d", height)
276277
}
277278
}
278-
return errors.Wrap(err, fmt.Sprintf("could not fetch block %d", height))
279+
return errors.Wrapf(err, "could not fetch block %d", height)
279280
}
280281

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

298299
height, err := b.getBlockHeight(tx.BlockHash)
299300
if err != nil {
300-
panic(fmt.Sprintf("error getting block height for hash %s: %s", tx.BlockHash, err.Error()))
301+
log.Panicf("error getting block height for hash %s: %s", tx.BlockHash, err.Error())
301302
}
302303

303304
b.transactionsMu.Lock()

backend/electrum/blockchain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package electrum
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"strings"
78
"sync/atomic"
89
"time"
@@ -157,7 +158,7 @@ func NewNode(addr, port string, network utils.Network) (*Node, error) {
157158
}
158159
t, err = NewSSLTransport(fmt.Sprintf("%s:%s", a, p))
159160
} else {
160-
panic(fmt.Sprintf("port (%s) must start with t or s", port))
161+
log.Panicf("port (%s) must start with t or s", port)
161162
}
162163

163164
if err != nil {

backend/electrum_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (eb *ElectrumBackend) cacheTxs(txs []*electrum.Transaction) {
443443
for _, tx := range txs {
444444
height, exists := eb.transactions[tx.Hash]
445445
if exists && (height != int64(tx.Height)) {
446-
panic(fmt.Sprintf("inconsistent cache: %s %d != %d", tx.Hash, height, tx.Height))
446+
log.Panicf("inconsistent cache: %s %d != %d", tx.Hash, height, tx.Height)
447447
}
448448
eb.transactions[tx.Hash] = int64(tx.Height)
449449
}

backend/fixture_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package backend
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"io/ioutil"
6+
"log"
77
"os"
88
"sync"
99

@@ -185,7 +185,7 @@ func (b *FixtureBackend) processBlockRequest(height uint32) {
185185
b.blockResponses <- &resp
186186
return
187187
}
188-
panic(fmt.Sprintf("fixture doesn't contain block %d", height))
188+
log.Panicf("fixture doesn't contain block %d", height)
189189
}
190190

191191
func (fb *FixtureBackend) loadFromFile(f *os.File) error {

deriver/address_deriver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (d *AddressDeriver) multiSigSegwitDerive(change uint32, addressIndex uint32
156156

157157
pubKeyBytes := pubKey.SerializeCompressed()
158158
if len(pubKeyBytes) != 33 {
159-
panic(fmt.Sprintf("expected pubkey length 33, got %d", len(pubKeyBytes)))
159+
log.Panicf("expected pubkey length 33, got %d", len(pubKeyBytes))
160160
}
161161

162162
pubKeysBytes = append(pubKeysBytes, pubKeyBytes)

0 commit comments

Comments
 (0)