Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial wallet support for boost #422

Merged
merged 8 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cli/node/node.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package node

import (
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

crand "crypto/rand"

"github.com/filecoin-project/boost/lib/keystore"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/libp2p/go-libp2p"
Expand Down Expand Up @@ -111,3 +114,38 @@ func keyPath(baseDir string) string {
func walletPath(baseDir string) string {
return filepath.Join(baseDir, "wallet")
}

func (n *Node) GetProvidedOrDefaultWallet(ctx context.Context, provided string) (address.Address, error) {
var walletAddr address.Address
if provided == "" {
var err error
walletAddr, err = n.Wallet.GetDefault()
if err != nil {
return address.Address{}, err
}
} else {
w, err := address.NewFromString(provided)
if err != nil {
return address.Address{}, err
}

addrs, err := n.Wallet.WalletList(ctx)
if err != nil {
return address.Address{}, err
}

found := false
for _, a := range addrs {
if bytes.Equal(a.Bytes(), w.Bytes()) {
walletAddr = w
found = true
}
}

if !found {
return address.Address{}, fmt.Errorf("couldn't find wallet %s locally", provided)
}
}

return walletAddr, nil
}
6 changes: 5 additions & 1 deletion cmd/boost/deal_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ var dealFlags = []cli.Flag{
Usage: "whether the deal funds should come from verified client data-cap",
Value: true,
},
&cli.StringFlag{
Name: "wallet",
Usage: "wallet address to be used to initiate the deal",
},
}

var dealCmd = &cli.Command{
Expand Down Expand Up @@ -134,7 +138,7 @@ func dealCmdAction(cctx *cli.Context, isOnline bool) error {
}
defer closer()

walletAddr, err := n.Wallet.GetDefault()
walletAddr, err := n.GetProvidedOrDefaultWallet(ctx, cctx.String("wallet"))
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/boost/deal_status_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ var dealStatusCmd = &cli.Command{
Usage: "",
Required: true,
},
&cli.StringFlag{
Name: "wallet",
Usage: "wallet address used to sign the deal proposal",
nonsense marked this conversation as resolved.
Show resolved Hide resolved
},
},
Before: before,
Action: func(cctx *cli.Context) error {
Expand All @@ -61,7 +65,7 @@ var dealStatusCmd = &cli.Command{
}
defer closer()

walletAddr, err := n.Wallet.GetDefault()
walletAddr, err := n.GetProvidedOrDefaultWallet(ctx, cctx.String("wallet"))
if err != nil {
return err
}
Expand Down
41 changes: 41 additions & 0 deletions cmd/boost/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"io"
"os"

ufcli "github.com/urfave/cli/v2"
)

type AppFmt struct {
app *ufcli.App
Stdin io.Reader
}

func NewAppFmt(a *ufcli.App) *AppFmt {
var stdin io.Reader
istdin, ok := a.Metadata["stdin"]
if ok {
stdin = istdin.(io.Reader)
} else {
stdin = os.Stdin
}
return &AppFmt{app: a, Stdin: stdin}
}

func (a *AppFmt) Print(args ...interface{}) {
fmt.Fprint(a.app.Writer, args...)
}

func (a *AppFmt) Println(args ...interface{}) {
fmt.Fprintln(a.app.Writer, args...)
}

func (a *AppFmt) Printf(fmtstr string, args ...interface{}) {
fmt.Fprintf(a.app.Writer, fmtstr, args...)
}

func (a *AppFmt) Scan(args ...interface{}) (int, error) {
return fmt.Fscan(a.Stdin, args...)
}
1 change: 1 addition & 0 deletions cmd/boost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func main() {
dealCmd,
dealStatusCmd,
offlineDealCmd,
walletCmd,
},
}
app.Setup()
Expand Down
Loading