Skip to content

Commit

Permalink
lotus shed addr decode
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Jul 20, 2022
1 parent 40bc05a commit 316d35f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/lotus-shed/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"bytes"
"encoding/hex"
"fmt"

"github.com/urfave/cli/v2"

"github.com/filecoin-project/go-address"
)

var addressCmd = &cli.Command{
Name: "addr",
Usage: "decode hex bytes into address",
Action: func(cctx *cli.Context) error {
addrHex := cctx.Args().First()
bs, err := hex.DecodeString(addrHex)
if err != nil {
return err
}
// first try cbor
var a address.Address
err = a.UnmarshalCBOR((bytes.NewReader(bs)))
if err != nil {
fmt.Printf("failed to unmarshal as CBOR, trying raw\n")
} else {
fmt.Printf("%s\n", a)
return nil
}

// next try raw payload
a, err = address.NewFromBytes(bs)
if err != nil {
return err
}
fmt.Printf("%s\n", a)
return nil
},
}
1 change: 1 addition & 0 deletions cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
logging.SetLogLevel("*", "INFO")

local := []*cli.Command{
addressCmd,
base64Cmd,
base32Cmd,
base16Cmd,
Expand Down

0 comments on commit 316d35f

Please sign in to comment.