Skip to content

Commit

Permalink
Fix auto receive for unopened accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed Jul 10, 2024
1 parent 5a2bacf commit c2b3f4f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion libs/wallet/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,32 @@ func (w *NanoWallet) createSendBlock(wallet *ent.Wallet, sender *ent.Account, am

// Get account info
accountInfo, err := w.RpcClient.MakeAccountInfoRequest(sender.Address)
if err != nil {
if errors.Is(err, nanorpc.ErrAccountNotFound) && w.Config.Wallet.AutoReceiveOnSend != nil && *w.Config.Wallet.AutoReceiveOnSend {
// See if account has a pending balance to open the accountt
bal, err := w.RpcClient.MakeAccountBalanceRequest(sender.Address)
if err != nil {
return nil, err
}
receivable, ok := big.NewInt(0).SetString(bal.Receivable, 10)
if !ok {
return nil, errors.New("Unable to parse receivable amount")
}
if receivable.Cmp(sendAmount) < 0 {
return nil, ErrInsufficientBalance
}
receivedCount, err := w.receiveAll(wallet, sender, bpowKey)
if err != nil {
return nil, err
}
if receivedCount == 0 {
return nil, ErrInsufficientBalance
}
// Re-get accountInfo
accountInfo, err = w.RpcClient.MakeAccountInfoRequest(sender.Address)
if err != nil {
return nil, err
}
} else if err != nil {
return nil, err
}

Expand Down

0 comments on commit c2b3f4f

Please sign in to comment.