fix serialization issues

This commit is contained in:
whyrusleeping 2019-07-18 12:12:30 -07:00
parent 38a5bcd659
commit 3f0c7f37f9
4 changed files with 44 additions and 1 deletions

View File

@ -71,6 +71,9 @@ func (bi *BigInt) UnmarshalJSON(b []byte) error {
i, ok := big.NewInt(0).SetString(s, 10)
if !ok {
if string(s) == "<nil>" {
return nil
}
return fmt.Errorf("failed to parse bigint string")
}

36
chain/types_test.go Normal file
View File

@ -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)
}
}

View File

@ -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),

View File

@ -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