-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcid-dskey.go
41 lines (38 loc) · 959 Bytes
/
cid-dskey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"fmt"
ds "gx/ipfs/QmVG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k/go-datastore"
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
dshelp "gx/ipfs/Qmd39D2vUhmPKQA2fgykjo2JXwekHKeJUggmGRpYuVMA2Z/go-ipfs-ds-help"
"os"
)
func main() {
cidstring := flag.String("c", "", "input cid")
dskeystring := flag.String("d", "", "input dskey")
flag.Parse()
if *cidstring == "" && *dskeystring == "" {
fmt.Println("Please Input cid or dskey!")
os.Exit(0)
}
if *cidstring != "" && *dskeystring != "" {
fmt.Println("you can input cid or dskey,only input one type!")
os.Exit(0)
}
if *cidstring != "" {
c, err := cid.Decode(*cidstring)
dsKey := dshelp.CidToDsKey(c)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(dsKey)
}
} else if *dskeystring != "" {
c, err := dshelp.DsKeyToCid(ds.NewKey(*dskeystring))
if err != nil {
fmt.Println(err)
} else {
fmt.Println(c)
}
}
}