Skip to content

Commit 2eafe0d

Browse files
authored
Merge pull request #467 from onflow/feature/dev-wallet
Integrate Dev Wallet
2 parents 0801f5d + 1207c89 commit 2eafe0d

File tree

5 files changed

+166
-3
lines changed

5 files changed

+166
-3
lines changed

cmd/flow/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/onflow/flow-cli/internal/signatures"
3737
"github.com/onflow/flow-cli/internal/snapshot"
3838
"github.com/onflow/flow-cli/internal/status"
39+
"github.com/onflow/flow-cli/internal/tools"
3940
"github.com/onflow/flow-cli/internal/transactions"
4041
"github.com/onflow/flow-cli/internal/version"
4142
"github.com/onflow/flow-cli/pkg/flowkit/util"
@@ -53,7 +54,10 @@ func main() {
5354
quick.InitCommand.AddToParent(cmd)
5455
quick.DeployCommand.AddToParent(cmd)
5556
quick.RunCommand.AddToParent(cmd)
57+
58+
// single commands
5659
status.Command.AddToParent(cmd)
60+
tools.DevWallet.AddToParent(cmd)
5761

5862
// structured commands
5963
cmd.AddCommand(cadence.Cmd)

docs/tools.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Start Development Tools with the Flow CLI
3+
sidebar_title: Development Tools
4+
description: How to start development tools using the Flow CLI
5+
---
6+
7+
The Flow CLI integrates different development tools, which can now be easily started
8+
and managed from a single place.
9+
10+
Currently the CLI supports starting:
11+
- [FCL Development Wallet](https://github.com/onflow/fcl-dev-wallet)
12+
13+
14+
## FCL Development Wallet
15+
16+
The FCL dev wallet is a mock Flow wallet that simulates the protocols used by FCL to interact with the Flow blockchain on behalf of simulated user accounts.
17+
18+
**Be sure you have the emulator running before starting this command**
19+
_You can start it using the `flow emulator` command_.
20+
21+
```shell
22+
flow dev-wallet
23+
```
24+
_⚠️ This project implements an FCL compatible
25+
interface, but should **not** be used as a reference for
26+
building a production grade wallet._
27+
28+
After starting dev-wallet, you can set your fcl config to use it like below:
29+
30+
```javascript
31+
import * as fcl from "@onflow/fcl"
32+
33+
fcl.config()
34+
// Point App at Emulator
35+
.put("accessNode.api", "http://localhost:8080")
36+
// Point FCL at dev-wallet (default port)
37+
.put("discovery.wallet", "http://localhost:8701/fcl/authn")
38+
```
39+
You can read more about setting up dev-wallet at [FCL Dev Wallet Project](https://github.com/onflow/fcl-dev-wallet)
40+
41+
42+
## Flags
43+
44+
### Port
45+
46+
- Flag: `--port`
47+
- Valid inputs: Number
48+
- Default: `8701`
49+
50+
Port on which the dev wallet server will listen on.
51+
52+
### Emulator Port
53+
54+
- Flag: `--emulator-port`
55+
- Valid inputs: Number
56+
57+
Port on which the emulator is listening on.
58+
59+
### Configuration
60+
61+
- Flag: `--config-path`
62+
- Short Flag: `-f`
63+
- Valid inputs: valid filename
64+
65+
Specify a filename for the configuration files, you can provide multiple configuration
66+
files by using `-f` flag multiple times.
67+
68+
69+
70+
71+

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ require (
1111
github.com/manifoldco/promptui v0.9.0
1212
github.com/onflow/cadence v0.23.0
1313
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831
14+
github.com/onflow/fcl-dev-wallet v0.4.0
1415
github.com/onflow/flow-core-contracts/lib/go/templates v0.10.1
15-
github.com/onflow/flow-emulator v0.29.0
16+
github.com/onflow/flow-emulator v0.30.0
1617
github.com/onflow/flow-go v0.23.2-0.20220304145234-bf10d55c40fa
1718
github.com/onflow/flow-go-sdk v0.24.0
1819
github.com/psiemens/sconfig v0.1.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,8 @@ github.com/onflow/cadence/languageserver v0.16.0/go.mod h1:UPV1so9LcMrhj27IegrTu
14021402
github.com/onflow/cadence/languageserver v0.18.2/go.mod h1:ehuDCUevEEavUzgJqLevcZPjfmTzMBX7Sglbi5ur9uU=
14031403
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831 h1:89apbCF/MbTL5ldqYKvwnt8OLN+NuCkdMMJN5clEgrE=
14041404
github.com/onflow/cadence/languageserver v0.18.3-0.20220202133308-207188a51831/go.mod h1:sOABh+6LBUWgY6r5iYhu98mDgfiBVTXAKVYHPQV/nvo=
1405+
github.com/onflow/fcl-dev-wallet v0.4.0 h1:lmjp4tO57m2LCbJ0P79u4BxpGca8bcFtBJrmtxV39LY=
1406+
github.com/onflow/fcl-dev-wallet v0.4.0/go.mod h1:xWVEyGZgdDt4/+PLSlpuqhtzobjnWy5giceIGoErPzs=
14051407
github.com/onflow/flow v0.2.3-0.20220131193101-d4e2ca43a621 h1:owMor9/wFpw3fua47UkUeDaFwyySK/dIPiNCCyhoO7c=
14061408
github.com/onflow/flow v0.2.3-0.20220131193101-d4e2ca43a621/go.mod h1:lzyAYmbu1HfkZ9cfnL5/sjrrsnJiUU8fRL26CqLP7+c=
14071409
github.com/onflow/flow-cli v0.20.3-0.20210512000809-474effb7e7db/go.mod h1:Yh4dgrNiZdXhbU+3UVUmo4gRM0TEBVvhW4ITKVo82dg=
@@ -1422,8 +1424,8 @@ github.com/onflow/flow-emulator v0.19.0/go.mod h1:k5un51XlFJavboagCqTxd6x8Gle7lx
14221424
github.com/onflow/flow-emulator v0.20.3/go.mod h1:xNdVsrMJiAaYJ59Dwo+xvj0ENdvk/bI14zkGN4V0ozs=
14231425
github.com/onflow/flow-emulator v0.21.0/go.mod h1:/2dNG6K4fKtpZsazdIeK8Fs0IWXUzqvO3qK5467pYsc=
14241426
github.com/onflow/flow-emulator v0.28.1-0.20220202131242-21a2c6e3eac7/go.mod h1:75iLaCkteYi8VsRnPH7RC9jeKjOIXogFq4TkPU71r1c=
1425-
github.com/onflow/flow-emulator v0.29.0 h1:YfTLD5mC/0mpwOkPu7pWx66EpwuMCseeYaWHuNnVCGQ=
1426-
github.com/onflow/flow-emulator v0.29.0/go.mod h1:jhun5qkwgdkJnmJpG6ghNKbSMfPWZPDSMWhNzqCTuDA=
1427+
github.com/onflow/flow-emulator v0.30.0 h1:czxxhtFWv5wYUiNG1KXWuwXrx2JaIHE+yDBsDKGSsuU=
1428+
github.com/onflow/flow-emulator v0.30.0/go.mod h1:jhun5qkwgdkJnmJpG6ghNKbSMfPWZPDSMWhNzqCTuDA=
14271429
github.com/onflow/flow-ft/lib/go/contracts v0.5.0 h1:Cg4gHGVblxcejfNNG5Mfj98Wf4zbY76O0Y28QB0766A=
14281430
github.com/onflow/flow-ft/lib/go/contracts v0.5.0/go.mod h1:1zoTjp1KzNnOPkyqKmWKerUyf0gciw+e6tAEt0Ks3JE=
14291431
github.com/onflow/flow-go v0.16.3-0.20210427194927-6050c2a3ae42/go.mod h1:9GUEbBhOGDVf91ZJB6QWqVNQkrM3INEudNyDtIttOu0=

internal/tools/wallet.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Flow CLI
3+
*
4+
* Copyright 2019-2022 Dapper Labs, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package tools
20+
21+
import (
22+
"fmt"
23+
"strings"
24+
25+
"github.com/onflow/flow-cli/internal/command"
26+
"github.com/onflow/flow-cli/pkg/flowkit"
27+
"github.com/onflow/flow-cli/pkg/flowkit/output"
28+
"github.com/onflow/flow-cli/pkg/flowkit/services"
29+
30+
devWallet "github.com/onflow/fcl-dev-wallet"
31+
"github.com/spf13/cobra"
32+
)
33+
34+
type FlagsWallet struct {
35+
Port uint `default:"8701" flag:"port" info:"Dev wallet port to listen on"`
36+
}
37+
38+
var walletFlags = FlagsWallet{}
39+
40+
var DevWallet = &command.Command{
41+
Cmd: &cobra.Command{
42+
Use: "dev-wallet",
43+
Short: "Starts a dev wallet",
44+
Example: "flow dev-wallet",
45+
Args: cobra.ExactArgs(0),
46+
},
47+
Flags: &walletFlags,
48+
RunS: wallet,
49+
}
50+
51+
func wallet(
52+
_ []string,
53+
_ flowkit.ReaderWriter,
54+
_ command.GlobalFlags,
55+
_ *services.Services,
56+
state *flowkit.State,
57+
) (command.Result, error) {
58+
service, err := state.EmulatorServiceAccount()
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
key := service.Key().ToConfig()
64+
conf := devWallet.Config{
65+
Address: fmt.Sprintf("0x%s", service.Address().String()),
66+
PrivateKey: strings.TrimPrefix(key.PrivateKey.String(), "0x"),
67+
PublicKey: strings.TrimPrefix(key.PrivateKey.PublicKey().String(), "0x"),
68+
AccessNode: "http://localhost:8080",
69+
}
70+
71+
srv, err := devWallet.NewHTTPServer(walletFlags.Port, &conf)
72+
if err != nil {
73+
return nil, err
74+
}
75+
76+
fmt.Printf("%s Starting dev wallet server on port %d\n", output.SuccessEmoji(), walletFlags.Port)
77+
fmt.Printf("%s Make sure the emulator is running\n", output.WarningEmoji())
78+
79+
err = srv.Start()
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
return nil, nil
85+
}

0 commit comments

Comments
 (0)