-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethereum.go
30 lines (23 loc) · 905 Bytes
/
ethereum.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
package types
import (
"fmt"
"reflect"
gethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
type EthereumAddress gethCommon.Address
// NewEthereumAddress is a constructor function for EthereumAddress
func NewEthereumAddress(address string) EthereumAddress {
return EthereumAddress(gethCommon.HexToAddress(address))
}
// Route should return the name of the module
func (ethereumAddress EthereumAddress) String() string {
return gethCommon.Address(ethereumAddress).String()
}
// Route should return the name of the module
func (ethereumAddress EthereumAddress) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%v\"", ethereumAddress.String())), nil
}
func (a *EthereumAddress) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(reflect.TypeOf(gethCommon.Address{}), input, a[:])
}