Skip to content

Commit 37566cb

Browse files
authored
refactor: replace []byte(fmt.Sprintf) with fmt.Appendf (#5158)
Signed-off-by: socialsister <seekseat@qq.com>
1 parent b850a6a commit 37566cb

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/bigint/bigint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (i *BigInt) MarshalJSON() ([]byte, error) {
1919
return []byte("null"), nil
2020
}
2121

22-
return []byte(fmt.Sprintf(`"%s"`, i.String())), nil
22+
return fmt.Appendf(nil, `"%s"`, i.String()), nil
2323
}
2424

2525
func (i *BigInt) UnmarshalJSON(b []byte) error {

pkg/crypto/eip712/typeddata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func EncodeForSigning(typedData *TypedData) ([]byte, error) {
2929
return nil, err
3030
}
3131

32-
rawData := []byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)))
32+
rawData := fmt.Appendf(nil, "\x19\x01%s%s", string(domainSeparator), string(typedDataHash))
3333
return rawData, nil
3434
}
3535

pkg/crypto/signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Signer interface {
3636

3737
// addEthereumPrefix adds the ethereum prefix to the data.
3838
func addEthereumPrefix(data []byte) []byte {
39-
return []byte(fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data))
39+
return fmt.Appendf(nil, "\x19Ethereum Signed Message:\n%d%s", len(data), data)
4040
}
4141

4242
// hashWithEthereumPrefix returns the hash that should be signed for the given data.

pkg/log/formatter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type substr string
2222
type point struct{ x, y int }
2323

2424
func (p point) MarshalText() ([]byte, error) {
25-
return []byte(fmt.Sprintf("(%d, %d)", p.x, p.y)), nil
25+
return fmt.Appendf(nil, "(%d, %d)", p.x, p.y), nil
2626
}
2727

2828
// pointErr implements encoding.TextMarshaler but returns an error.

pkg/storageincentives/proof_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ func TestMakeInclusionProofsRegression(t *testing.T) {
6969
// generate chunks that will be used as sample
7070
sampleChunks := make([]swarm.Chunk, 0, sampleSize)
7171
for i := 0; i < sampleSize; i++ {
72-
ch, err := cac.New([]byte(fmt.Sprintf("Unstoppable data! Chunk #%d", i+1)))
72+
ch, err := cac.New(fmt.Appendf(nil, "Unstoppable data! Chunk #%d", i+1))
7373
if err != nil {
7474
t.Fatal(err)
7575
}
7676

7777
if i%2 == 0 {
78-
id, err := crypto.LegacyKeccak256([]byte(fmt.Sprintf("ID #%d", i+1)))
78+
id, err := crypto.LegacyKeccak256(fmt.Appendf(nil, "ID #%d", i+1))
7979
if err != nil {
8080
t.Fatal(err)
8181
}

0 commit comments

Comments
 (0)