Skip to content

Commit a4f401e

Browse files
authored
wallet: consider that NewFromString returns Undef address (textileio#391)
* wallet: consider that NewFromString returns Undef address and not error on empty strings Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com> * test fixes Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent 6d8d269 commit a4f401e

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

api/client/ffs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"context"
5-
"fmt"
65
"io"
76
"time"
87

@@ -542,9 +541,13 @@ func toRPCColdConfig(config ff.ColdConfig) *rpc.ColdConfig {
542541
func protoToDealError(des []*rpc.DealError) ([]ffs.DealError, error) {
543542
res := make([]ffs.DealError, len(des))
544543
for i, de := range des {
545-
propCid, err := cid.Decode(de.ProposalCid)
546-
if err != nil {
547-
return nil, fmt.Errorf("parsing proposal cid: %s", err)
544+
var propCid cid.Cid
545+
if de.ProposalCid != "" {
546+
var err error
547+
propCid, err = cid.Decode(de.ProposalCid)
548+
if err != nil {
549+
propCid = cid.Undef
550+
}
548551
}
549552
res[i] = ffs.DealError{
550553
ProposalCid: propCid,

api/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func NewServer(conf Config) (*Server, error) {
173173
if err != nil {
174174
return nil, fmt.Errorf("creating deal module: %s", err)
175175
}
176-
wm, err := wallet.New(c, &masterAddr, conf.WalletInitialFunds)
176+
wm, err := wallet.New(c, masterAddr, conf.WalletInitialFunds)
177177
if err != nil {
178178
return nil, fmt.Errorf("creating wallet module: %s", err)
179179
}

ffs/integrationtest/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ func newAPIFromDs(t *testing.T, ds datastore.TxnDatastore, iid ffs.APIID, client
12071207
hl := coreipfs.New(ipfsClient, l)
12081208
sched := scheduler.New(js, as, cis, l, hl, cl)
12091209

1210-
wm, err := wallet.New(client, &waddr, *big.NewInt(iWalletBal))
1210+
wm, err := wallet.New(client, waddr, *big.NewInt(iWalletBal))
12111211
require.Nil(t, err)
12121212

12131213
var fapi *api.API

ffs/manager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestGetByAuthToken(t *testing.T) {
101101

102102
func newManager(t *testing.T, ds datastore.TxnDatastore) (*Manager, func()) {
103103
client, addr, _ := tests.CreateLocalDevnet(t, 1)
104-
wm, err := wallet.New(client, &addr, *big.NewInt(4000000000))
104+
wm, err := wallet.New(client, addr, *big.NewInt(4000000000))
105105
require.Nil(t, err)
106106
m, err := New(ds, wm, &mockSched{})
107107
require.Nil(t, err)

wallet/wallet.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
type Module struct {
1616
api *apistruct.FullNodeStruct
1717
iAmount *big.Int
18-
masterAddr *address.Address
18+
masterAddr address.Address
1919
}
2020

2121
// New creates a new wallet module
22-
func New(api *apistruct.FullNodeStruct, maddr *address.Address, iam big.Int) (*Module, error) {
22+
func New(api *apistruct.FullNodeStruct, maddr address.Address, iam big.Int) (*Module, error) {
2323
m := &Module{
2424
api: api,
2525
iAmount: &iam,
@@ -44,9 +44,9 @@ func (m *Module) NewAddress(ctx context.Context, typ string) (string, error) {
4444
return "", err
4545
}
4646

47-
if m.masterAddr != nil {
47+
if m.masterAddr != address.Undef {
4848
msg := &types.Message{
49-
From: *m.masterAddr,
49+
From: m.masterAddr,
5050
To: addr,
5151
Value: types.BigInt{Int: m.iAmount},
5252
GasLimit: 1000,

0 commit comments

Comments
 (0)