Skip to content

Commit 2697e44

Browse files
authored
all: change format 0x%x to %#x (ethereum#25221)
1 parent 953a29f commit 2697e44

File tree

25 files changed

+39
-39
lines changed

25 files changed

+39
-39
lines changed

accounts/scwallet/securechannel.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (s *SecureChannelSession) mutuallyAuthenticate() error {
178178
return err
179179
}
180180
if response.Sw1 != 0x90 || response.Sw2 != 0x00 {
181-
return fmt.Errorf("got unexpected response from MUTUALLY_AUTHENTICATE: 0x%x%x", response.Sw1, response.Sw2)
181+
return fmt.Errorf("got unexpected response from MUTUALLY_AUTHENTICATE: %#x%x", response.Sw1, response.Sw2)
182182
}
183183

184184
if len(response.Data) != scSecretLength {
@@ -261,7 +261,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
261261
rapdu.deserialize(plainData)
262262

263263
if rapdu.Sw1 != sw1Ok {
264-
return nil, fmt.Errorf("unexpected response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", cla, ins, rapdu.Sw1, rapdu.Sw2)
264+
return nil, fmt.Errorf("unexpected response status Cla=%#x, Ins=%#x, Sw=%#x%x", cla, ins, rapdu.Sw1, rapdu.Sw2)
265265
}
266266

267267
return rapdu, nil

accounts/scwallet/wallet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func transmit(card *pcsc.Card, command *commandAPDU) (*responseAPDU, error) {
167167
}
168168

169169
if response.Sw1 != sw1Ok {
170-
return nil, fmt.Errorf("unexpected insecure response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", command.Cla, command.Ins, response.Sw1, response.Sw2)
170+
return nil, fmt.Errorf("unexpected insecure response status Cla=%#x, Ins=%#x, Sw=%#x%x", command.Cla, command.Ins, response.Sw1, response.Sw2)
171171
}
172172

173173
return response, nil

cmd/devp2p/internal/ethtest/snap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,10 @@ func (s *Suite) snapGetAccountRange(t *utesting.T, tc *accRangeTest) error {
496496
}
497497
if len(hashes) > 0 {
498498
if exp, got := tc.expFirst, res.Accounts[0].Hash; exp != got {
499-
return fmt.Errorf("expected first account 0x%x, got 0x%x", exp, got)
499+
return fmt.Errorf("expected first account %#x, got %#x", exp, got)
500500
}
501501
if exp, got := tc.expLast, res.Accounts[len(res.Accounts)-1].Hash; exp != got {
502-
return fmt.Errorf("expected last account 0x%x, got 0x%x", exp, got)
502+
return fmt.Errorf("expected last account %#x, got %#x", exp, got)
503503
}
504504
}
505505
// Reconstruct a partial trie from the response and verify it

cmd/evm/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ allocated bytes: %d
309309
`, initialGas-leftOverGas, stats.time, stats.allocs, stats.bytesAllocated)
310310
}
311311
if tracer == nil {
312-
fmt.Printf("0x%x\n", output)
312+
fmt.Printf("%#x\n", output)
313313
if err != nil {
314314
fmt.Printf(" error: %v\n", err)
315315
}

cmd/geth/dbcmd.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ func checkStateContent(ctx *cli.Context) error {
337337
hasher.Read(got)
338338
if !bytes.Equal(k, got) {
339339
errs++
340-
fmt.Printf("Error at 0x%x\n", k)
341-
fmt.Printf(" Hash: 0x%x\n", got)
342-
fmt.Printf(" Data: 0x%x\n", v)
340+
fmt.Printf("Error at %#x\n", k)
341+
fmt.Printf(" Hash: %#x\n", got)
342+
fmt.Printf(" Data: %#x\n", v)
343343
}
344344
if time.Since(lastLog) > 8*time.Second {
345345
log.Info("Iterating the database", "at", fmt.Sprintf("%#x", k), "elapsed", common.PrettyDuration(time.Since(startTime)))
@@ -716,7 +716,7 @@ func showMetaData(ctx *cli.Context) error {
716716
if val == nil {
717717
return "<nil>"
718718
}
719-
return fmt.Sprintf("%d (0x%x)", *val, *val)
719+
return fmt.Sprintf("%d (%#x)", *val, *val)
720720
}
721721
data := [][]string{
722722
{"databaseVersion", pp(rawdb.ReadDatabaseVersion(db))},
@@ -726,15 +726,15 @@ func showMetaData(ctx *cli.Context) error {
726726
if b := rawdb.ReadHeadBlock(db); b != nil {
727727
data = append(data, []string{"headBlock.Hash", fmt.Sprintf("%v", b.Hash())})
728728
data = append(data, []string{"headBlock.Root", fmt.Sprintf("%v", b.Root())})
729-
data = append(data, []string{"headBlock.Number", fmt.Sprintf("%d (0x%x)", b.Number(), b.Number())})
729+
data = append(data, []string{"headBlock.Number", fmt.Sprintf("%d (%#x)", b.Number(), b.Number())})
730730
}
731731
if b := rawdb.ReadSkeletonSyncStatus(db); b != nil {
732732
data = append(data, []string{"SkeletonSyncStatus", string(b)})
733733
}
734734
if h := rawdb.ReadHeadHeader(db); h != nil {
735735
data = append(data, []string{"headHeader.Hash", fmt.Sprintf("%v", h.Hash())})
736736
data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)})
737-
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (0x%x)", h.Number, h.Number)})
737+
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (%#x)", h.Number, h.Number)})
738738
}
739739
data = append(data, [][]string{{"frozen", fmt.Sprintf("%d items", ancients)},
740740
{"lastPivotNumber", pp(rawdb.ReadLastPivotNumber(db))},

cmd/rlpdump/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func main() {
8383
if err != nil {
8484
die(err)
8585
}
86-
fmt.Printf("0x%x\n", data)
86+
fmt.Printf("%#x\n", data)
8787
return
8888
} else {
8989
err := rlpToText(r, out)

cmd/rlpdump/rlpdump_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestRoundtrip(t *testing.T) {
4343
t.Errorf("test %d: error %v", i, err)
4444
continue
4545
}
46-
have := fmt.Sprintf("0x%x", rlpBytes)
46+
have := fmt.Sprintf("%#x", rlpBytes)
4747
if have != want {
4848
t.Errorf("test %d: have\n%v\nwant:\n%v\n", i, have, want)
4949
}

consensus/misc/forks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
3535
// If the homestead reprice hash is set, validate it
3636
if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number) == 0 {
3737
if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() {
38-
return fmt.Errorf("homestead gas reprice fork: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash)
38+
return fmt.Errorf("homestead gas reprice fork: have %#x, want %#x", header.Hash(), config.EIP150Hash)
3939
}
4040
}
4141
// All ok, return

core/asm/asm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func PrintDisassembled(code string) error {
109109
it := NewInstructionIterator(script)
110110
for it.Next() {
111111
if it.Arg() != nil && 0 < len(it.Arg()) {
112-
fmt.Printf("%05x: %v 0x%x\n", it.PC(), it.Op(), it.Arg())
112+
fmt.Printf("%05x: %v %#x\n", it.PC(), it.Op(), it.Arg())
113113
} else {
114114
fmt.Printf("%05x: %v\n", it.PC(), it.Op())
115115
}
@@ -124,7 +124,7 @@ func Disassemble(script []byte) ([]string, error) {
124124
it := NewInstructionIterator(script)
125125
for it.Next() {
126126
if it.Arg() != nil && 0 < len(it.Arg()) {
127-
instrs = append(instrs, fmt.Sprintf("%05x: %v 0x%x\n", it.PC(), it.Op(), it.Arg()))
127+
instrs = append(instrs, fmt.Sprintf("%05x: %v %#x\n", it.PC(), it.Op(), it.Arg()))
128128
} else {
129129
instrs = append(instrs, fmt.Sprintf("%05x: %v\n", it.PC(), it.Op()))
130130
}

core/blockchain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
23422342
Chain config: %v
23432343
23442344
Number: %v
2345-
Hash: 0x%x
2345+
Hash: %#x
23462346
%v
23472347
23482348
Error: %v

core/types/hashing_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func printList(l types.DerivableList) {
197197
for i := 0; i < l.Len(); i++ {
198198
var buf bytes.Buffer
199199
l.EncodeIndex(i, &buf)
200-
fmt.Printf("\"0x%x\",\n", buf.Bytes())
200+
fmt.Printf("\"%#x\",\n", buf.Bytes())
201201
}
202202
fmt.Printf("},\n")
203203
}

core/vm/jump_table.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type JumpTable [256]*operation
6363
func validate(jt JumpTable) JumpTable {
6464
for i, op := range jt {
6565
if op == nil {
66-
panic(fmt.Sprintf("op 0x%x is not set", i))
66+
panic(fmt.Sprintf("op %#x is not set", i))
6767
}
6868
// The interpreter has an assumption that if the memorySize function is
6969
// set, then the dynamicGas function is also set. This is a somewhat

core/vm/opcodes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ var opCodeToString = map[OpCode]string{
392392
func (op OpCode) String() string {
393393
str := opCodeToString[op]
394394
if len(str) == 0 {
395-
return fmt.Sprintf("opcode 0x%x not defined", int(op))
395+
return fmt.Sprintf("opcode %#x not defined", int(op))
396396
}
397397

398398
return str

core/vm/runtime/runtime_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,15 @@ func TestEip2929Cases(t *testing.T) {
503503
it := asm.NewInstructionIterator(code)
504504
for it.Next() {
505505
if it.Arg() != nil && 0 < len(it.Arg()) {
506-
instrs = append(instrs, fmt.Sprintf("%v 0x%x", it.Op(), it.Arg()))
506+
instrs = append(instrs, fmt.Sprintf("%v %#x", it.Op(), it.Arg()))
507507
} else {
508508
instrs = append(instrs, fmt.Sprintf("%v", it.Op()))
509509
}
510510
}
511511
ops := strings.Join(instrs, ", ")
512512
fmt.Printf("### Case %d\n\n", id)
513513
id++
514-
fmt.Printf("%v\n\nBytecode: \n```\n0x%x\n```\nOperations: \n```\n%v\n```\n\n",
514+
fmt.Printf("%v\n\nBytecode: \n```\n%#x\n```\nOperations: \n```\n%v\n```\n\n",
515515
comment,
516516
code, ops)
517517
Execute(code, nil, &Config{

eth/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
316316
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
317317
blockRlp = err.Error() // Hacky, but hey, it works
318318
} else {
319-
blockRlp = fmt.Sprintf("0x%x", rlpBytes)
319+
blockRlp = fmt.Sprintf("%#x", rlpBytes)
320320
}
321321
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil {
322322
blockJSON = map[string]interface{}{"error": err.Error()}

eth/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestStorageRangeAt(t *testing.T) {
213213
t.Error(err)
214214
}
215215
if !reflect.DeepEqual(result, test.want) {
216-
t.Fatalf("wrong result for range 0x%x.., limit %d:\ngot %s\nwant %s",
216+
t.Fatalf("wrong result for range %#x.., limit %d:\ngot %s\nwant %s",
217217
test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want))
218218
}
219219
}

eth/filters/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestUnmarshalJSONNewFilterArgs(t *testing.T) {
5656

5757
// from, to block number
5858
var test1 FilterCriteria
59-
vector := fmt.Sprintf(`{"fromBlock":"0x%x","toBlock":"0x%x"}`, fromBlock, toBlock)
59+
vector := fmt.Sprintf(`{"fromBlock":"%#x","toBlock":"%#x"}`, fromBlock, toBlock)
6060
if err := json.Unmarshal([]byte(vector), &test1); err != nil {
6161
t.Fatal(err)
6262
}

eth/tracers/logger/logger.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
224224
l.output = output
225225
l.err = err
226226
if l.cfg.Debug {
227-
fmt.Printf("0x%x\n", output)
227+
fmt.Printf("%#x\n", output)
228228
if err != nil {
229229
fmt.Printf(" error: %v\n", err)
230230
}
@@ -346,11 +346,11 @@ func NewMarkdownLogger(cfg *Config, writer io.Writer) *mdLogger {
346346
func (t *mdLogger) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
347347
t.env = env
348348
if !create {
349-
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n",
349+
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
350350
from.String(), to.String(),
351351
input, gas, value)
352352
} else {
353-
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n",
353+
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
354354
from.String(), to.String(),
355355
input, gas, value)
356356
}
@@ -387,7 +387,7 @@ func (t *mdLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope
387387
}
388388

389389
func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) {
390-
fmt.Fprintf(t.out, "\nOutput: `0x%x`\nConsumed gas: `%d`\nError: `%v`\n",
390+
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
391391
output, gasUsed, err)
392392
}
393393

internal/ethapi/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ func (api *DebugAPI) SeedHash(ctx context.Context, number uint64) (string, error
19501950
if block == nil {
19511951
return "", fmt.Errorf("block #%d not found", number)
19521952
}
1953-
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil
1953+
return fmt.Sprintf("%#x", ethash.SeedHash(number)), nil
19541954
}
19551955

19561956
// ChaindbProperty returns leveldb properties of the key-value database.

mobile/types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (n *Nonce) GetBytes() []byte {
5555

5656
// GetHex retrieves the hex string representation of the block nonce.
5757
func (n *Nonce) GetHex() string {
58-
return fmt.Sprintf("0x%x", n.nonce[:])
58+
return fmt.Sprintf("%#x", n.nonce[:])
5959
}
6060

6161
// String returns a printable representation of the nonce.
@@ -75,7 +75,7 @@ func (b *Bloom) GetBytes() []byte {
7575

7676
// GetHex retrieves the hex string representation of the bloom filter.
7777
func (b *Bloom) GetHex() string {
78-
return fmt.Sprintf("0x%x", b.bloom[:])
78+
return fmt.Sprintf("%#x", b.bloom[:])
7979
}
8080

8181
// String returns a printable representation of the bloom filter.

signer/core/apitypes/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
659659
if b, err := parseInteger(encType, encValue); err != nil {
660660
return "", err
661661
} else {
662-
return fmt.Sprintf("%d (0x%x)", b, b), nil
662+
return fmt.Sprintf("%d (%#x)", b, b), nil
663663
}
664664
}
665665
return "", fmt.Errorf("unhandled type %v", encType)

signer/core/signed_data.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
129129
{
130130
Name: "Full message for signing",
131131
Typ: "hexdata",
132-
Value: fmt.Sprintf("0x%x", msg),
132+
Value: fmt.Sprintf("%#x", msg),
133133
},
134134
}
135135
req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Messages: messages, Hash: sighash}
@@ -161,7 +161,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
161161
{
162162
Name: "Clique header",
163163
Typ: "clique",
164-
Value: fmt.Sprintf("clique header %d [0x%x]", header.Number, header.Hash()),
164+
Value: fmt.Sprintf("clique header %d [%#x]", header.Number, header.Hash()),
165165
},
166166
}
167167
// Clique uses V on the form 0 or 1

tests/fuzzers/stacktrie/trie_fuzzer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (f *fuzzer) fuzz() int {
185185
sort.Sort(vals)
186186
for _, kv := range vals {
187187
if f.debugging {
188-
fmt.Printf("{\"0x%x\" , \"0x%x\"} // stacktrie.Update\n", kv.k, kv.v)
188+
fmt.Printf("{\"%#x\" , \"%#x\"} // stacktrie.Update\n", kv.k, kv.v)
189189
}
190190
trieB.Update(kv.k, kv.v)
191191
}

tests/fuzzers/trie/trie-fuzzer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func runRandTest(rt randTest) error {
159159
v := tr.Get(step.key)
160160
want := values[string(step.key)]
161161
if string(v) != want {
162-
rt[i].err = fmt.Errorf("mismatch for key 0x%x, got 0x%x want 0x%x", step.key, v, want)
162+
rt[i].err = fmt.Errorf("mismatch for key %#x, got %#x want %#x", step.key, v, want)
163163
}
164164
case opCommit:
165165
_, _, rt[i].err = tr.Commit(nil)

trie/trie_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func runRandTest(rt randTest) bool {
432432
v := tr.Get(step.key)
433433
want := values[string(step.key)]
434434
if string(v) != want {
435-
rt[i].err = fmt.Errorf("mismatch for key 0x%x, got 0x%x want 0x%x", step.key, v, want)
435+
rt[i].err = fmt.Errorf("mismatch for key %#x, got %#x want %#x", step.key, v, want)
436436
}
437437
case opCommit:
438438
_, _, rt[i].err = tr.Commit(nil)

0 commit comments

Comments
 (0)