From 3f0c7f37f9e1cf98e6d71c495624a1277d67d623 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 18 Jul 2019 12:12:30 -0700 Subject: [PATCH] fix serialization issues --- chain/types/bigint.go | 3 +++ chain/types_test.go | 36 ++++++++++++++++++++++++++++++++++++ cli/createminer.go | 1 + node/api.go | 5 ++++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 chain/types_test.go diff --git a/chain/types/bigint.go b/chain/types/bigint.go index ae2efc470..5e5b54dc5 100644 --- a/chain/types/bigint.go +++ b/chain/types/bigint.go @@ -71,6 +71,9 @@ func (bi *BigInt) UnmarshalJSON(b []byte) error { i, ok := big.NewInt(0).SetString(s, 10) if !ok { + if string(s) == "" { + return nil + } return fmt.Errorf("failed to parse bigint string") } diff --git a/chain/types_test.go b/chain/types_test.go new file mode 100644 index 000000000..99bbb8212 --- /dev/null +++ b/chain/types_test.go @@ -0,0 +1,36 @@ +package chain + +import ( + "encoding/json" + "testing" + + "github.com/filecoin-project/go-lotus/chain/address" + "github.com/filecoin-project/go-lotus/chain/types" +) + +func TestSignedMessageJsonRoundtrip(t *testing.T) { + to, _ := address.NewIDAddress(5234623) + from, _ := address.NewIDAddress(603911192) + smsg := &SignedMessage{ + Message: types.Message{ + To: to, + From: from, + Params: []byte("some bytes, idk"), + Method: 1235126, + Value: types.NewInt(123123), + GasPrice: types.NewInt(1234), + GasLimit: types.NewInt(9992969384), + Nonce: 123123, + }, + } + + out, err := json.Marshal(smsg) + if err != nil { + t.Fatal(err) + } + + var osmsg SignedMessage + if err := json.Unmarshal(out, &osmsg); err != nil { + t.Fatal(err) + } +} diff --git a/cli/createminer.go b/cli/createminer.go index e3fff1691..f22931627 100644 --- a/cli/createminer.go +++ b/cli/createminer.go @@ -78,6 +78,7 @@ var createMinerCmd = &cli.Command{ From: addr, Method: 1, // TODO: constants pls Params: params, + Value: types.NewInt(0), Nonce: nonce, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), diff --git a/node/api.go b/node/api.go index dca8a1d94..ee0954ee6 100644 --- a/node/api.go +++ b/node/api.go @@ -141,7 +141,10 @@ func (a *API) WalletSign(ctx context.Context, k address.Address, msg []byte) (*c } func (a *API) WalletDefaultAddress(ctx context.Context) (address.Address, error) { - addrs := a.Wallet.ListAddrs() + addrs, err := a.Wallet.ListAddrs() + if err != nil { + return address.Undef, err + } // TODO: store a default address in the config or 'wallet' portion of the repo return addrs[0], nil