all: change format `0x%x` to `%#x` (#25221)

pull/25230/head
Seungbae.yu 2 years ago committed by GitHub
parent 953a29f5fd
commit 2697e44d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      accounts/scwallet/securechannel.go
  2. 2
      accounts/scwallet/wallet.go
  3. 4
      cmd/devp2p/internal/ethtest/snap.go
  4. 2
      cmd/evm/runner.go
  5. 12
      cmd/geth/dbcmd.go
  6. 2
      cmd/rlpdump/main.go
  7. 2
      cmd/rlpdump/rlpdump_test.go
  8. 2
      consensus/misc/forks.go
  9. 4
      core/asm/asm.go
  10. 2
      core/blockchain.go
  11. 2
      core/types/hashing_test.go
  12. 2
      core/vm/jump_table.go
  13. 2
      core/vm/opcodes.go
  14. 4
      core/vm/runtime/runtime_test.go
  15. 2
      eth/api.go
  16. 2
      eth/api_test.go
  17. 2
      eth/filters/api_test.go
  18. 8
      eth/tracers/logger/logger.go
  19. 2
      internal/ethapi/api.go
  20. 4
      mobile/types.go
  21. 2
      signer/core/apitypes/types.go
  22. 4
      signer/core/signed_data.go
  23. 2
      tests/fuzzers/stacktrie/trie_fuzzer.go
  24. 2
      tests/fuzzers/trie/trie-fuzzer.go
  25. 2
      trie/trie_test.go

@ -178,7 +178,7 @@ func (s *SecureChannelSession) mutuallyAuthenticate() error {
return err return err
} }
if response.Sw1 != 0x90 || response.Sw2 != 0x00 { if response.Sw1 != 0x90 || response.Sw2 != 0x00 {
return fmt.Errorf("got unexpected response from MUTUALLY_AUTHENTICATE: 0x%x%x", response.Sw1, response.Sw2) return fmt.Errorf("got unexpected response from MUTUALLY_AUTHENTICATE: %#x%x", response.Sw1, response.Sw2)
} }
if len(response.Data) != scSecretLength { if len(response.Data) != scSecretLength {
@ -261,7 +261,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
rapdu.deserialize(plainData) rapdu.deserialize(plainData)
if rapdu.Sw1 != sw1Ok { if rapdu.Sw1 != sw1Ok {
return nil, fmt.Errorf("unexpected response status Cla=0x%x, Ins=0x%x, Sw=0x%x%x", cla, ins, rapdu.Sw1, rapdu.Sw2) return nil, fmt.Errorf("unexpected response status Cla=%#x, Ins=%#x, Sw=%#x%x", cla, ins, rapdu.Sw1, rapdu.Sw2)
} }
return rapdu, nil return rapdu, nil

@ -167,7 +167,7 @@ func transmit(card *pcsc.Card, command *commandAPDU) (*responseAPDU, error) {
} }
if response.Sw1 != sw1Ok { if response.Sw1 != sw1Ok {
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) return nil, fmt.Errorf("unexpected insecure response status Cla=%#x, Ins=%#x, Sw=%#x%x", command.Cla, command.Ins, response.Sw1, response.Sw2)
} }
return response, nil return response, nil

@ -496,10 +496,10 @@ func (s *Suite) snapGetAccountRange(t *utesting.T, tc *accRangeTest) error {
} }
if len(hashes) > 0 { if len(hashes) > 0 {
if exp, got := tc.expFirst, res.Accounts[0].Hash; exp != got { if exp, got := tc.expFirst, res.Accounts[0].Hash; exp != got {
return fmt.Errorf("expected first account 0x%x, got 0x%x", exp, got) return fmt.Errorf("expected first account %#x, got %#x", exp, got)
} }
if exp, got := tc.expLast, res.Accounts[len(res.Accounts)-1].Hash; exp != got { if exp, got := tc.expLast, res.Accounts[len(res.Accounts)-1].Hash; exp != got {
return fmt.Errorf("expected last account 0x%x, got 0x%x", exp, got) return fmt.Errorf("expected last account %#x, got %#x", exp, got)
} }
} }
// Reconstruct a partial trie from the response and verify it // Reconstruct a partial trie from the response and verify it

@ -309,7 +309,7 @@ allocated bytes: %d
`, initialGas-leftOverGas, stats.time, stats.allocs, stats.bytesAllocated) `, initialGas-leftOverGas, stats.time, stats.allocs, stats.bytesAllocated)
} }
if tracer == nil { if tracer == nil {
fmt.Printf("0x%x\n", output) fmt.Printf("%#x\n", output)
if err != nil { if err != nil {
fmt.Printf(" error: %v\n", err) fmt.Printf(" error: %v\n", err)
} }

@ -337,9 +337,9 @@ func checkStateContent(ctx *cli.Context) error {
hasher.Read(got) hasher.Read(got)
if !bytes.Equal(k, got) { if !bytes.Equal(k, got) {
errs++ errs++
fmt.Printf("Error at 0x%x\n", k) fmt.Printf("Error at %#x\n", k)
fmt.Printf(" Hash: 0x%x\n", got) fmt.Printf(" Hash: %#x\n", got)
fmt.Printf(" Data: 0x%x\n", v) fmt.Printf(" Data: %#x\n", v)
} }
if time.Since(lastLog) > 8*time.Second { if time.Since(lastLog) > 8*time.Second {
log.Info("Iterating the database", "at", fmt.Sprintf("%#x", k), "elapsed", common.PrettyDuration(time.Since(startTime))) 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 {
if val == nil { if val == nil {
return "<nil>" return "<nil>"
} }
return fmt.Sprintf("%d (0x%x)", *val, *val) return fmt.Sprintf("%d (%#x)", *val, *val)
} }
data := [][]string{ data := [][]string{
{"databaseVersion", pp(rawdb.ReadDatabaseVersion(db))}, {"databaseVersion", pp(rawdb.ReadDatabaseVersion(db))},
@ -726,7 +726,7 @@ func showMetaData(ctx *cli.Context) error {
if b := rawdb.ReadHeadBlock(db); b != nil { if b := rawdb.ReadHeadBlock(db); b != nil {
data = append(data, []string{"headBlock.Hash", fmt.Sprintf("%v", b.Hash())}) data = append(data, []string{"headBlock.Hash", fmt.Sprintf("%v", b.Hash())})
data = append(data, []string{"headBlock.Root", fmt.Sprintf("%v", b.Root())}) data = append(data, []string{"headBlock.Root", fmt.Sprintf("%v", b.Root())})
data = append(data, []string{"headBlock.Number", fmt.Sprintf("%d (0x%x)", b.Number(), b.Number())}) data = append(data, []string{"headBlock.Number", fmt.Sprintf("%d (%#x)", b.Number(), b.Number())})
} }
if b := rawdb.ReadSkeletonSyncStatus(db); b != nil { if b := rawdb.ReadSkeletonSyncStatus(db); b != nil {
data = append(data, []string{"SkeletonSyncStatus", string(b)}) data = append(data, []string{"SkeletonSyncStatus", string(b)})
@ -734,7 +734,7 @@ func showMetaData(ctx *cli.Context) error {
if h := rawdb.ReadHeadHeader(db); h != nil { if h := rawdb.ReadHeadHeader(db); h != nil {
data = append(data, []string{"headHeader.Hash", fmt.Sprintf("%v", h.Hash())}) data = append(data, []string{"headHeader.Hash", fmt.Sprintf("%v", h.Hash())})
data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)}) data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)})
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (0x%x)", h.Number, h.Number)}) data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (%#x)", h.Number, h.Number)})
} }
data = append(data, [][]string{{"frozen", fmt.Sprintf("%d items", ancients)}, data = append(data, [][]string{{"frozen", fmt.Sprintf("%d items", ancients)},
{"lastPivotNumber", pp(rawdb.ReadLastPivotNumber(db))}, {"lastPivotNumber", pp(rawdb.ReadLastPivotNumber(db))},

@ -83,7 +83,7 @@ func main() {
if err != nil { if err != nil {
die(err) die(err)
} }
fmt.Printf("0x%x\n", data) fmt.Printf("%#x\n", data)
return return
} else { } else {
err := rlpToText(r, out) err := rlpToText(r, out)

@ -43,7 +43,7 @@ func TestRoundtrip(t *testing.T) {
t.Errorf("test %d: error %v", i, err) t.Errorf("test %d: error %v", i, err)
continue continue
} }
have := fmt.Sprintf("0x%x", rlpBytes) have := fmt.Sprintf("%#x", rlpBytes)
if have != want { if have != want {
t.Errorf("test %d: have\n%v\nwant:\n%v\n", i, have, want) t.Errorf("test %d: have\n%v\nwant:\n%v\n", i, have, want)
} }

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

@ -109,7 +109,7 @@ func PrintDisassembled(code string) error {
it := NewInstructionIterator(script) it := NewInstructionIterator(script)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
fmt.Printf("%05x: %v 0x%x\n", it.PC(), it.Op(), it.Arg()) fmt.Printf("%05x: %v %#x\n", it.PC(), it.Op(), it.Arg())
} else { } else {
fmt.Printf("%05x: %v\n", it.PC(), it.Op()) fmt.Printf("%05x: %v\n", it.PC(), it.Op())
} }
@ -124,7 +124,7 @@ func Disassemble(script []byte) ([]string, error) {
it := NewInstructionIterator(script) it := NewInstructionIterator(script)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
instrs = append(instrs, fmt.Sprintf("%05x: %v 0x%x\n", it.PC(), it.Op(), it.Arg())) instrs = append(instrs, fmt.Sprintf("%05x: %v %#x\n", it.PC(), it.Op(), it.Arg()))
} else { } else {
instrs = append(instrs, fmt.Sprintf("%05x: %v\n", it.PC(), it.Op())) instrs = append(instrs, fmt.Sprintf("%05x: %v\n", it.PC(), it.Op()))
} }

@ -2342,7 +2342,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
Chain config: %v Chain config: %v
Number: %v Number: %v
Hash: 0x%x Hash: %#x
%v %v
Error: %v Error: %v

@ -197,7 +197,7 @@ func printList(l types.DerivableList) {
for i := 0; i < l.Len(); i++ { for i := 0; i < l.Len(); i++ {
var buf bytes.Buffer var buf bytes.Buffer
l.EncodeIndex(i, &buf) l.EncodeIndex(i, &buf)
fmt.Printf("\"0x%x\",\n", buf.Bytes()) fmt.Printf("\"%#x\",\n", buf.Bytes())
} }
fmt.Printf("},\n") fmt.Printf("},\n")
} }

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

@ -392,7 +392,7 @@ var opCodeToString = map[OpCode]string{
func (op OpCode) String() string { func (op OpCode) String() string {
str := opCodeToString[op] str := opCodeToString[op]
if len(str) == 0 { if len(str) == 0 {
return fmt.Sprintf("opcode 0x%x not defined", int(op)) return fmt.Sprintf("opcode %#x not defined", int(op))
} }
return str return str

@ -503,7 +503,7 @@ func TestEip2929Cases(t *testing.T) {
it := asm.NewInstructionIterator(code) it := asm.NewInstructionIterator(code)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
instrs = append(instrs, fmt.Sprintf("%v 0x%x", it.Op(), it.Arg())) instrs = append(instrs, fmt.Sprintf("%v %#x", it.Op(), it.Arg()))
} else { } else {
instrs = append(instrs, fmt.Sprintf("%v", it.Op())) instrs = append(instrs, fmt.Sprintf("%v", it.Op()))
} }
@ -511,7 +511,7 @@ func TestEip2929Cases(t *testing.T) {
ops := strings.Join(instrs, ", ") ops := strings.Join(instrs, ", ")
fmt.Printf("### Case %d\n\n", id) fmt.Printf("### Case %d\n\n", id)
id++ id++
fmt.Printf("%v\n\nBytecode: \n```\n0x%x\n```\nOperations: \n```\n%v\n```\n\n", fmt.Printf("%v\n\nBytecode: \n```\n%#x\n```\nOperations: \n```\n%v\n```\n\n",
comment, comment,
code, ops) code, ops)
Execute(code, nil, &Config{ Execute(code, nil, &Config{

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

@ -213,7 +213,7 @@ func TestStorageRangeAt(t *testing.T) {
t.Error(err) t.Error(err)
} }
if !reflect.DeepEqual(result, test.want) { if !reflect.DeepEqual(result, test.want) {
t.Fatalf("wrong result for range 0x%x.., limit %d:\ngot %s\nwant %s", t.Fatalf("wrong result for range %#x.., limit %d:\ngot %s\nwant %s",
test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want)) test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want))
} }
} }

@ -56,7 +56,7 @@ func TestUnmarshalJSONNewFilterArgs(t *testing.T) {
// from, to block number // from, to block number
var test1 FilterCriteria var test1 FilterCriteria
vector := fmt.Sprintf(`{"fromBlock":"0x%x","toBlock":"0x%x"}`, fromBlock, toBlock) vector := fmt.Sprintf(`{"fromBlock":"%#x","toBlock":"%#x"}`, fromBlock, toBlock)
if err := json.Unmarshal([]byte(vector), &test1); err != nil { if err := json.Unmarshal([]byte(vector), &test1); err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -224,7 +224,7 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
l.output = output l.output = output
l.err = err l.err = err
if l.cfg.Debug { if l.cfg.Debug {
fmt.Printf("0x%x\n", output) fmt.Printf("%#x\n", output)
if err != nil { if err != nil {
fmt.Printf(" error: %v\n", err) fmt.Printf(" error: %v\n", err)
} }
@ -346,11 +346,11 @@ func NewMarkdownLogger(cfg *Config, writer io.Writer) *mdLogger {
func (t *mdLogger) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { func (t *mdLogger) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
t.env = env t.env = env
if !create { if !create {
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n", fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
from.String(), to.String(), from.String(), to.String(),
input, gas, value) input, gas, value)
} else { } else {
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n", fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
from.String(), to.String(), from.String(), to.String(),
input, gas, value) input, gas, value)
} }
@ -387,7 +387,7 @@ func (t *mdLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope
} }
func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) { func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) {
fmt.Fprintf(t.out, "\nOutput: `0x%x`\nConsumed gas: `%d`\nError: `%v`\n", fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
output, gasUsed, err) output, gasUsed, err)
} }

@ -1950,7 +1950,7 @@ func (api *DebugAPI) SeedHash(ctx context.Context, number uint64) (string, error
if block == nil { if block == nil {
return "", fmt.Errorf("block #%d not found", number) return "", fmt.Errorf("block #%d not found", number)
} }
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil return fmt.Sprintf("%#x", ethash.SeedHash(number)), nil
} }
// ChaindbProperty returns leveldb properties of the key-value database. // ChaindbProperty returns leveldb properties of the key-value database.

@ -55,7 +55,7 @@ func (n *Nonce) GetBytes() []byte {
// GetHex retrieves the hex string representation of the block nonce. // GetHex retrieves the hex string representation of the block nonce.
func (n *Nonce) GetHex() string { func (n *Nonce) GetHex() string {
return fmt.Sprintf("0x%x", n.nonce[:]) return fmt.Sprintf("%#x", n.nonce[:])
} }
// String returns a printable representation of the nonce. // String returns a printable representation of the nonce.
@ -75,7 +75,7 @@ func (b *Bloom) GetBytes() []byte {
// GetHex retrieves the hex string representation of the bloom filter. // GetHex retrieves the hex string representation of the bloom filter.
func (b *Bloom) GetHex() string { func (b *Bloom) GetHex() string {
return fmt.Sprintf("0x%x", b.bloom[:]) return fmt.Sprintf("%#x", b.bloom[:])
} }
// String returns a printable representation of the bloom filter. // String returns a printable representation of the bloom filter.

@ -659,7 +659,7 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
if b, err := parseInteger(encType, encValue); err != nil { if b, err := parseInteger(encType, encValue); err != nil {
return "", err return "", err
} else { } else {
return fmt.Sprintf("%d (0x%x)", b, b), nil return fmt.Sprintf("%d (%#x)", b, b), nil
} }
} }
return "", fmt.Errorf("unhandled type %v", encType) return "", fmt.Errorf("unhandled type %v", encType)

@ -129,7 +129,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
{ {
Name: "Full message for signing", Name: "Full message for signing",
Typ: "hexdata", Typ: "hexdata",
Value: fmt.Sprintf("0x%x", msg), Value: fmt.Sprintf("%#x", msg),
}, },
} }
req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Messages: messages, Hash: sighash} req = &SignDataRequest{ContentType: mediaType, Rawdata: []byte(msg), Messages: messages, Hash: sighash}
@ -161,7 +161,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
{ {
Name: "Clique header", Name: "Clique header",
Typ: "clique", Typ: "clique",
Value: fmt.Sprintf("clique header %d [0x%x]", header.Number, header.Hash()), Value: fmt.Sprintf("clique header %d [%#x]", header.Number, header.Hash()),
}, },
} }
// Clique uses V on the form 0 or 1 // Clique uses V on the form 0 or 1

@ -185,7 +185,7 @@ func (f *fuzzer) fuzz() int {
sort.Sort(vals) sort.Sort(vals)
for _, kv := range vals { for _, kv := range vals {
if f.debugging { if f.debugging {
fmt.Printf("{\"0x%x\" , \"0x%x\"} // stacktrie.Update\n", kv.k, kv.v) fmt.Printf("{\"%#x\" , \"%#x\"} // stacktrie.Update\n", kv.k, kv.v)
} }
trieB.Update(kv.k, kv.v) trieB.Update(kv.k, kv.v)
} }

@ -159,7 +159,7 @@ func runRandTest(rt randTest) error {
v := tr.Get(step.key) v := tr.Get(step.key)
want := values[string(step.key)] want := values[string(step.key)]
if string(v) != want { if string(v) != want {
rt[i].err = fmt.Errorf("mismatch for key 0x%x, got 0x%x want 0x%x", step.key, v, want) rt[i].err = fmt.Errorf("mismatch for key %#x, got %#x want %#x", step.key, v, want)
} }
case opCommit: case opCommit:
_, _, rt[i].err = tr.Commit(nil) _, _, rt[i].err = tr.Commit(nil)

@ -432,7 +432,7 @@ func runRandTest(rt randTest) bool {
v := tr.Get(step.key) v := tr.Get(step.key)
want := values[string(step.key)] want := values[string(step.key)]
if string(v) != want { if string(v) != want {
rt[i].err = fmt.Errorf("mismatch for key 0x%x, got 0x%x want 0x%x", step.key, v, want) rt[i].err = fmt.Errorf("mismatch for key %#x, got %#x want %#x", step.key, v, want)
} }
case opCommit: case opCommit:
_, _, rt[i].err = tr.Commit(nil) _, _, rt[i].err = tr.Commit(nil)

Loading…
Cancel
Save