|
@ -1,13 +1,11 @@ |
|
|
package files |
|
|
package files |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
|
|
|
|
|
|
"io/ioutil" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
"github.com/pkg/errors" |
|
|
|
|
|
|
|
|
wire "github.com/tendermint/go-wire" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/lite" |
|
|
"github.com/tendermint/tendermint/lite" |
|
|
liteErr "github.com/tendermint/tendermint/lite/errors" |
|
|
liteErr "github.com/tendermint/tendermint/lite/errors" |
|
|
) |
|
|
) |
|
@ -19,7 +17,7 @@ const ( |
|
|
MaxFullCommitSize = 1024 * 1024 |
|
|
MaxFullCommitSize = 1024 * 1024 |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// SaveFullCommit exports the seed in binary / go-wire style
|
|
|
|
|
|
|
|
|
// SaveFullCommit exports the seed in binary / go-amino style
|
|
|
func SaveFullCommit(fc lite.FullCommit, path string) error { |
|
|
func SaveFullCommit(fc lite.FullCommit, path string) error { |
|
|
f, err := os.Create(path) |
|
|
f, err := os.Create(path) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -27,9 +25,11 @@ func SaveFullCommit(fc lite.FullCommit, path string) error { |
|
|
} |
|
|
} |
|
|
defer f.Close() |
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
var n int |
|
|
|
|
|
wire.WriteBinary(fc, f, &n, &err) |
|
|
|
|
|
return errors.WithStack(err) |
|
|
|
|
|
|
|
|
_, err = cdc.MarshalBinaryWriter(f, fc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// SaveFullCommitJSON exports the seed in a json format
|
|
|
// SaveFullCommitJSON exports the seed in a json format
|
|
@ -39,9 +39,15 @@ func SaveFullCommitJSON(fc lite.FullCommit, path string) error { |
|
|
return errors.WithStack(err) |
|
|
return errors.WithStack(err) |
|
|
} |
|
|
} |
|
|
defer f.Close() |
|
|
defer f.Close() |
|
|
stream := json.NewEncoder(f) |
|
|
|
|
|
err = stream.Encode(fc) |
|
|
|
|
|
return errors.WithStack(err) |
|
|
|
|
|
|
|
|
bz, err := cdc.MarshalJSON(fc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
_, err = f.Write(bz) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// LoadFullCommit loads the full commit from the file system.
|
|
|
// LoadFullCommit loads the full commit from the file system.
|
|
@ -56,9 +62,11 @@ func LoadFullCommit(path string) (lite.FullCommit, error) { |
|
|
} |
|
|
} |
|
|
defer f.Close() |
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
var n int |
|
|
|
|
|
wire.ReadBinaryPtr(&fc, f, MaxFullCommitSize, &n, &err) |
|
|
|
|
|
return fc, errors.WithStack(err) |
|
|
|
|
|
|
|
|
_, err = cdc.UnmarshalBinaryReader(f, &fc, 0) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return fc, errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
return fc, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// LoadFullCommitJSON loads the commit from the file system in JSON format.
|
|
|
// LoadFullCommitJSON loads the commit from the file system in JSON format.
|
|
@ -73,7 +81,13 @@ func LoadFullCommitJSON(path string) (lite.FullCommit, error) { |
|
|
} |
|
|
} |
|
|
defer f.Close() |
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
stream := json.NewDecoder(f) |
|
|
|
|
|
err = stream.Decode(&fc) |
|
|
|
|
|
return fc, errors.WithStack(err) |
|
|
|
|
|
|
|
|
bz, err := ioutil.ReadAll(f) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return fc, errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
err = cdc.UnmarshalJSON(bz, &fc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return fc, errors.WithStack(err) |
|
|
|
|
|
} |
|
|
|
|
|
return fc, nil |
|
|
} |
|
|
} |