ExportChain exports the current blockchain into a local file.
(file string)
| 192 | |
| 193 | // ExportChain exports the current blockchain into a local file. |
| 194 | func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) { |
| 195 | // Make sure we can create the file to export into |
| 196 | out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) |
| 197 | if err != nil { |
| 198 | return false, err |
| 199 | } |
| 200 | defer out.Close() |
| 201 | |
| 202 | var writer io.Writer = out |
| 203 | if strings.HasSuffix(file, ".gz") { |
| 204 | writer = gzip.NewWriter(writer) |
| 205 | defer writer.(*gzip.Writer).Close() |
| 206 | } |
| 207 | |
| 208 | // Export the blockchain |
| 209 | if err := api.cpc.BlockChain().Export(writer); err != nil { |
| 210 | return false, err |
| 211 | } |
| 212 | return true, nil |
| 213 | } |
| 214 | |
| 215 | func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool { |
| 216 | for _, b := range bs { |
nothing calls this directly
no test coverage detected