Skip to content

Commit c4b7fdd

Browse files
ryanschneidergballet
authored andcommitted
eth, internal/web3ext: add optional first and last arguments to the admin_exportChain RPC. (#20107)
1 parent 275cd49 commit c4b7fdd

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎eth/api.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,16 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI {
166166
return &PrivateAdminAPI{eth: eth}
167167
}
168168

169-
// ExportChain exports the current blockchain into a local file.
170-
func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
169+
// ExportChain exports the current blockchain into a local file,
170+
// or a range of blocks if first and last are non-nil
171+
func (api *PrivateAdminAPI) ExportChain(file string, first *uint64, last *uint64) (bool, error) {
172+
if first == nil && last != nil {
173+
return false, errors.New("last cannot be specified without first")
174+
}
175+
if first != nil && last == nil {
176+
head := api.eth.BlockChain().CurrentHeader().Number.Uint64()
177+
last = &head
178+
}
171179
if _, err := os.Stat(file); err == nil {
172180
// File already exists. Allowing overwrite could be a DoS vecotor,
173181
// since the 'file' may point to arbitrary paths on the drive
@@ -187,7 +195,11 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
187195
}
188196

189197
// Export the blockchain
190-
if err := api.eth.BlockChain().Export(writer); err != nil {
198+
if first != nil {
199+
if err := api.eth.BlockChain().ExportN(writer, *first, *last); err != nil {
200+
return false, err
201+
}
202+
} else if err := api.eth.BlockChain().Export(writer); err != nil {
191203
return false, err
192204
}
193205
return true, nil

‎internal/web3ext/web3ext.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ web3._extend({
172172
new web3._extend.Method({
173173
name: 'exportChain',
174174
call: 'admin_exportChain',
175-
params: 1,
176-
inputFormatter: [null]
175+
params: 3,
176+
inputFormatter: [null, null, null]
177177
}),
178178
new web3._extend.Method({
179179
name: 'importChain',

0 commit comments

Comments
 (0)