-
Notifications
You must be signed in to change notification settings - Fork 1
/
addrcmd.go
122 lines (107 loc) · 2.62 KB
/
addrcmd.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"fmt"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
ipldcbor "github.com/ipfs/go-ipld-cbor"
"github.com/urfave/cli/v2"
)
func filToEthAddr(cctx *cli.Context) error {
args := cctx.Args()
actorAddrString := args.Get(0)
addr, err := address.NewFromString(actorAddrString)
if err != nil {
return err
}
switch p := addr.Protocol(); p {
case address.ID, address.Delegated:
eaddr, err := ethtypes.EthAddressFromFilecoinAddress(addr)
if err != nil {
return err
}
fmt.Println(eaddr.String())
case address.SECP256K1, address.Actor, address.BLS:
default:
return fmt.Errorf("error unsupported address type %v", p)
}
bg, ts, err := getAnchorPoint(cctx)
if err != nil {
return err
}
defer bg.LogStats()
idAddr, err := lookupID(ipldcbor.NewCborStore(bg), ts, addr)
if err != nil {
return err
}
id, err := address.IDFromAddress(idAddr)
if err != nil {
return err
}
eaddr := ethtypes.EthAddressFromActorID(abi.ActorID(id))
fmt.Println(eaddr.String())
return nil
}
func filAddrs(cctx *cli.Context) error {
args := cctx.Args()
actorAddrString := args.Get(0)
was0xAddr := false
var err error
var eaddr ethtypes.EthAddress
var addr address.Address
if actorAddrString[0] == '0' {
was0xAddr = true
eaddr, err = ethtypes.ParseEthAddress(actorAddrString)
if err != nil {
return err
}
addr, err = eaddr.ToFilecoinAddress()
if err != nil {
return err
}
} else {
addr, err = address.NewFromString(actorAddrString)
if err != nil {
return err
}
}
bg, ts, err := getAnchorPoint(cctx)
if err != nil {
return err
}
defer bg.LogStats()
idAddr, err := lookupID(ipldcbor.NewCborStore(bg), ts, addr)
if err != nil {
return err
}
id, err := address.IDFromAddress(idAddr)
if err != nil {
return err
}
eaddr = ethtypes.EthAddressFromActorID(abi.ActorID(id))
switch p := addr.Protocol(); p {
case address.SECP256K1, address.Actor, address.BLS:
// If it's an f1/f2/f3 return the f0, and 0x addresses
fmt.Println(idAddr)
fmt.Println(eaddr)
case address.ID:
if !was0xAddr {
// If it's an f0 return the 0x and if enabled the expensive reverse lookup for the fX address
fmt.Println(eaddr)
} else {
// If it's a masked 0x address, return the f0 and if enabled the expensive reverse lookup for the fX address
fmt.Println(addr)
}
case address.Delegated:
if !was0xAddr {
fmt.Println(idAddr)
fmt.Println(eaddr)
} else {
fmt.Println(idAddr)
fmt.Println(addr)
}
default:
return fmt.Errorf("error unsupported address type %v", p)
}
return nil
}