Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 981fa08

Browse files
committed
implement: ipfs key list
Signed-off-by: Max Peng <[email protected]> (cherry picked from commit 64b0a1e)
1 parent c65e6e8 commit 981fa08

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

key.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package shell
2+
3+
import "context"
4+
5+
type Key struct {
6+
Id string
7+
Name string
8+
}
9+
10+
type keyListOutput struct {
11+
Keys []*Key
12+
}
13+
14+
// KeyList List all local keypairs
15+
func (s *Shell) KeyList(ctx context.Context) ([]*Key, error) {
16+
var out keyListOutput
17+
if err := s.Request("key/list").Exec(ctx, &out); err != nil {
18+
return nil, err
19+
}
20+
return out.Keys, nil
21+
}

key_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package shell
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/cheekybits/is"
8+
)
9+
10+
func TestKeyList(t *testing.T) {
11+
is := is.New(t)
12+
s := NewShell(shellUrl)
13+
14+
keys, err := s.KeyList(context.Background())
15+
is.Nil(err)
16+
17+
is.Equal(len(keys), 1)
18+
is.Equal(keys[0].Name, "self")
19+
is.NotNil(keys[0].Id)
20+
}

0 commit comments

Comments
 (0)