Commit c4b7fdd2 authored by Ryan Schneider's avatar Ryan Schneider Committed by Guillaume Ballet

eth, internal/web3ext: add optional first and last arguments to the ...

eth, internal/web3ext: add optional first and last arguments to the  `admin_exportChain` RPC. (#20107)
parent 275cd498
...@@ -166,8 +166,16 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI { ...@@ -166,8 +166,16 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI {
return &PrivateAdminAPI{eth: eth} return &PrivateAdminAPI{eth: eth}
} }
// ExportChain exports the current blockchain into a local file. // ExportChain exports the current blockchain into a local file,
func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { // or a range of blocks if first and last are non-nil
func (api *PrivateAdminAPI) ExportChain(file string, first *uint64, last *uint64) (bool, error) {
if first == nil && last != nil {
return false, errors.New("last cannot be specified without first")
}
if first != nil && last == nil {
head := api.eth.BlockChain().CurrentHeader().Number.Uint64()
last = &head
}
if _, err := os.Stat(file); err == nil { if _, err := os.Stat(file); err == nil {
// File already exists. Allowing overwrite could be a DoS vecotor, // File already exists. Allowing overwrite could be a DoS vecotor,
// since the 'file' may point to arbitrary paths on the drive // since the 'file' may point to arbitrary paths on the drive
...@@ -187,7 +195,11 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { ...@@ -187,7 +195,11 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
} }
// Export the blockchain // Export the blockchain
if err := api.eth.BlockChain().Export(writer); err != nil { if first != nil {
if err := api.eth.BlockChain().ExportN(writer, *first, *last); err != nil {
return false, err
}
} else if err := api.eth.BlockChain().Export(writer); err != nil {
return false, err return false, err
} }
return true, nil return true, nil
......
...@@ -172,8 +172,8 @@ web3._extend({ ...@@ -172,8 +172,8 @@ web3._extend({
new web3._extend.Method({ new web3._extend.Method({
name: 'exportChain', name: 'exportChain',
call: 'admin_exportChain', call: 'admin_exportChain',
params: 1, params: 3,
inputFormatter: [null] inputFormatter: [null, null, null]
}), }),
new web3._extend.Method({ new web3._extend.Method({
name: 'importChain', name: 'importChain',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment