mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-06 06:58:39 +00:00
cmd/geth: add code exporter for db export (#34696)
Adds a 'code' exporter to 'geth db export' that iterates over all contract bytecode entries (CodePrefix + code_hash -> bytecode). Usage: geth --datadir <dir> db export code code.rlp This enables exporting contract bytecode.
This commit is contained in:
parent
ba215fd927
commit
89c1c16a46
1 changed files with 22 additions and 0 deletions
|
|
@ -806,6 +806,24 @@ func (iter *snapshotIterator) Release() {
|
||||||
iter.storage.Release()
|
iter.storage.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type codeIterator struct {
|
||||||
|
iter ethdb.Iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
func (iter *codeIterator) Next() (byte, []byte, []byte, bool) {
|
||||||
|
for iter.iter.Next() {
|
||||||
|
key := iter.iter.Key()
|
||||||
|
if bytes.HasPrefix(key, rawdb.CodePrefix) && len(key) == (len(rawdb.CodePrefix)+common.HashLength) {
|
||||||
|
return utils.OpBatchAdd, key, iter.iter.Value(), true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, nil, nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (iter *codeIterator) Release() {
|
||||||
|
iter.iter.Release()
|
||||||
|
}
|
||||||
|
|
||||||
// chainExporters defines the export scheme for all exportable chain data.
|
// chainExporters defines the export scheme for all exportable chain data.
|
||||||
var chainExporters = map[string]func(db ethdb.Database) utils.ChainDataIterator{
|
var chainExporters = map[string]func(db ethdb.Database) utils.ChainDataIterator{
|
||||||
"preimage": func(db ethdb.Database) utils.ChainDataIterator {
|
"preimage": func(db ethdb.Database) utils.ChainDataIterator {
|
||||||
|
|
@ -817,6 +835,10 @@ var chainExporters = map[string]func(db ethdb.Database) utils.ChainDataIterator{
|
||||||
storage := db.NewIterator(rawdb.SnapshotStoragePrefix, nil)
|
storage := db.NewIterator(rawdb.SnapshotStoragePrefix, nil)
|
||||||
return &snapshotIterator{account: account, storage: storage}
|
return &snapshotIterator{account: account, storage: storage}
|
||||||
},
|
},
|
||||||
|
"code": func(db ethdb.Database) utils.ChainDataIterator {
|
||||||
|
iter := db.NewIterator(rawdb.CodePrefix, nil)
|
||||||
|
return &codeIterator{iter: iter}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportChaindata(ctx *cli.Context) error {
|
func exportChaindata(ctx *cli.Context) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue