MCPcopy Create free account
hub / github.com/CPChain/chain / ExportChain

Method ExportChain

protocols/cpc/api.go:194–213  ·  view source on GitHub ↗

ExportChain exports the current blockchain into a local file.

(file string)

Source from the content-addressed store, hash-verified

192
193// ExportChain exports the current blockchain into a local file.
194func (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
215func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
216 for _, b := range bs {

Callers

nothing calls this directly

Calls 3

CloseMethod · 0.65
BlockChainMethod · 0.65
ExportMethod · 0.45

Tested by

no test coverage detected