Skip to content

Commit cd407af

Browse files
authored
core/rawdb: add HasCode, HasTrieNode and use them where possible ethereum#24454 (XinFinOrg#1211)
1 parent 7464f0a commit cd407af

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

core/rawdb/accessors_state.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte {
4747
if len(data) != 0 {
4848
return data
4949
}
50-
data, _ = db.Get(hash[:])
50+
data, _ = db.Get(hash.Bytes())
5151
return data
5252
}
5353

@@ -59,6 +59,18 @@ func ReadCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) []byte {
5959
return data
6060
}
6161

62+
// HasCode checks if the contract code corresponding to the
63+
// provided code hash is present in the db.
64+
func HasCode(db ethdb.KeyValueReader, hash common.Hash) bool {
65+
// Try with the prefixed code scheme first, if not then try with legacy
66+
// scheme.
67+
if ok := HasCodeWithPrefix(db, hash); ok {
68+
return true
69+
}
70+
ok, _ := db.Has(hash.Bytes())
71+
return ok
72+
}
73+
6274
// HasCodeWithPrefix checks if the contract code corresponding to the
6375
// provided code hash is present in the db. This function will only check
6476
// presence using the prefix-scheme.

0 commit comments

Comments
 (0)