-
Notifications
You must be signed in to change notification settings - Fork 19
/
address.go
61 lines (49 loc) · 1.87 KB
/
address.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
package types
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
)
// ExternalEVMAddress is a type alias of common.Address to represent an address
// on an external EVM, e.g. Ethereum. This is used to make external / internal
// addresses type safe and un-assignable to each other. This also makes it more
// clear which address belongs where.
type ExternalEVMAddress struct {
common.Address
}
// NewExternalEVMAddress returns a new ExternalEVMAddress from a common.Address.
func NewExternalEVMAddress(addr common.Address) ExternalEVMAddress {
return ExternalEVMAddress{
Address: addr,
}
}
// NewExternalEVMAddressFromString returns a new ExternalEVMAddress from a hex
// string. Returns an error if hex string is invalid.
func NewExternalEVMAddressFromString(addrStr string) (ExternalEVMAddress, error) {
if !common.IsHexAddress(addrStr) {
return ExternalEVMAddress{}, fmt.Errorf("string is not a hex address %v", addrStr)
}
// common.HexToAddress ignores hex decoding errors
addr := common.HexToAddress(addrStr)
return NewExternalEVMAddress(addr), nil
}
// InternalEVMAddress is a type alias of common.Address to represent an address
// on the Kava EVM.
type InternalEVMAddress struct {
common.Address
}
// NewInternalEVMAddress returns a new InternalEVMAddress from a common.Address.
func NewInternalEVMAddress(addr common.Address) InternalEVMAddress {
return InternalEVMAddress{
Address: addr,
}
}
// NewInternalEVMAddressFromString returns a new InternalEVMAddress from a hex
// string. Returns an error if hex string is invalid.
func NewInternalEVMAddressFromString(addrStr string) (InternalEVMAddress, error) {
if !common.IsHexAddress(addrStr) {
return InternalEVMAddress{}, fmt.Errorf("string is not a hex address %v", addrStr)
}
// common.HexToAddress ignores hex decoding errors
addr := common.HexToAddress(addrStr)
return NewInternalEVMAddress(addr), nil
}