common: delete StringToAddress, StringToHash (#16436)
* common: delete StringToAddress, StringToHash These functions are confusing because they don't parse hex, but use the bytes of the string. This change removes them, replacing all uses of StringToAddress(s) by BytesToAddress([]byte(s)). * eth/filters: remove incorrect use of common.BytesToAddress
This commit is contained in:
parent
149f706fde
commit
c7ab3e5544
@ -84,8 +84,8 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
debugLogger *vm.StructLogger
|
debugLogger *vm.StructLogger
|
||||||
statedb *state.StateDB
|
statedb *state.StateDB
|
||||||
chainConfig *params.ChainConfig
|
chainConfig *params.ChainConfig
|
||||||
sender = common.StringToAddress("sender")
|
sender = common.BytesToAddress([]byte("sender"))
|
||||||
receiver = common.StringToAddress("receiver")
|
receiver = common.BytesToAddress([]byte("receiver"))
|
||||||
)
|
)
|
||||||
if ctx.GlobalBool(MachineFlag.Name) {
|
if ctx.GlobalBool(MachineFlag.Name) {
|
||||||
tracer = NewJSONLogger(logconfig, os.Stdout)
|
tracer = NewJSONLogger(logconfig, os.Stdout)
|
||||||
|
@ -45,7 +45,6 @@ func BytesToHash(b []byte) Hash {
|
|||||||
h.SetBytes(b)
|
h.SetBytes(b)
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
func StringToHash(s string) Hash { return BytesToHash([]byte(s)) }
|
|
||||||
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
|
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
|
||||||
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
|
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
|
||||||
|
|
||||||
@ -143,7 +142,6 @@ func BytesToAddress(b []byte) Address {
|
|||||||
a.SetBytes(b)
|
a.SetBytes(b)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
func StringToAddress(s string) Address { return BytesToAddress([]byte(s)) }
|
|
||||||
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
|
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
|
||||||
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
|
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
|||||||
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db))
|
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db))
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
address = common.StringToAddress("contract")
|
address = common.BytesToAddress([]byte("contract"))
|
||||||
vmenv = NewEnv(cfg)
|
vmenv = NewEnv(cfg)
|
||||||
sender = vm.AccountRef(cfg.Origin)
|
sender = vm.AccountRef(cfg.Origin)
|
||||||
)
|
)
|
||||||
@ -113,7 +113,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
|||||||
// Call the code with the given configuration.
|
// Call the code with the given configuration.
|
||||||
ret, _, err := vmenv.Call(
|
ret, _, err := vmenv.Call(
|
||||||
sender,
|
sender,
|
||||||
common.StringToAddress("contract"),
|
common.BytesToAddress([]byte("contract")),
|
||||||
input,
|
input,
|
||||||
cfg.GasLimit,
|
cfg.GasLimit,
|
||||||
cfg.Value,
|
cfg.Value,
|
||||||
|
@ -29,8 +29,8 @@ func TestUnmarshalJSONNewFilterArgs(t *testing.T) {
|
|||||||
var (
|
var (
|
||||||
fromBlock rpc.BlockNumber = 0x123435
|
fromBlock rpc.BlockNumber = 0x123435
|
||||||
toBlock rpc.BlockNumber = 0xabcdef
|
toBlock rpc.BlockNumber = 0xabcdef
|
||||||
address0 = common.StringToAddress("70c87d191324e6712a591f304b4eedef6ad9bb9d")
|
address0 = common.HexToAddress("70c87d191324e6712a591f304b4eedef6ad9bb9d")
|
||||||
address1 = common.StringToAddress("9b2055d370f73ec7d8a03e965129118dc8f5bf83")
|
address1 = common.HexToAddress("9b2055d370f73ec7d8a03e965129118dc8f5bf83")
|
||||||
topic0 = common.HexToHash("3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1ca")
|
topic0 = common.HexToHash("3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1ca")
|
||||||
topic1 = common.HexToHash("9084a792d2f8b16a62b882fd56f7860c07bf5fa91dd8a2ae7e809e5180fef0b3")
|
topic1 = common.HexToHash("9084a792d2f8b16a62b882fd56f7860c07bf5fa91dd8a2ae7e809e5180fef0b3")
|
||||||
topic2 = common.HexToHash("6ccae1c4af4152f460ff510e573399795dfab5dcf1fa60d1f33ac8fdc1e480ce")
|
topic2 = common.HexToHash("6ccae1c4af4152f460ff510e573399795dfab5dcf1fa60d1f33ac8fdc1e480ce")
|
||||||
|
Loading…
Reference in New Issue
Block a user