From 45ddd8e590a662098c2ee3184d17fe334f998c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 26 Jul 2019 01:26:40 +0200 Subject: [PATCH] Don't pannic on walletDefAddr with no addrs --- lotuspond/front/src/FullNode.js | 5 ++++- node/impl/full.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lotuspond/front/src/FullNode.js b/lotuspond/front/src/FullNode.js index 552308214..d0f12d881 100644 --- a/lotuspond/front/src/FullNode.js +++ b/lotuspond/front/src/FullNode.js @@ -80,7 +80,10 @@ class FullNode extends React.Component { this.setState(() => ({tipset: tipset})) const addrss = await this.state.client.call('Filecoin.WalletList', []) - const defaultAddr = await this.state.client.call('Filecoin.WalletDefaultAddress', []) + let defaultAddr = "" + if (addrss.length > 0) { + defaultAddr = await this.state.client.call('Filecoin.WalletDefaultAddress', []) + } const balances = await addrss.map(async addr => { let balance = 0 diff --git a/node/impl/full.go b/node/impl/full.go index aa74b5331..f87762594 100644 --- a/node/impl/full.go +++ b/node/impl/full.go @@ -2,6 +2,7 @@ package impl import ( "context" + "golang.org/x/xerrors" "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/chain" @@ -132,6 +133,9 @@ func (a *FullNodeAPI) WalletDefaultAddress(ctx context.Context) (address.Address if err != nil { return address.Undef, err } + if len(addrs) == 0 { + return address.Undef, xerrors.New("no addresses in wallet") + } // TODO: store a default address in the config or 'wallet' portion of the repo return addrs[0], nil