This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
currency.go
76 lines (63 loc) · 1.61 KB
/
currency.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
package uniswap
import (
"errors"
"github.com/ethereum/go-ethereum/common"
)
// ErrInvalidCurrency diff currency error.
var ErrInvalidCurrency = errors.New("diff currency")
type currency interface {
equals(string) bool
// Address returns the address of the currency.
Address() string
// Decimals returns the number of the currency..
Decimals() uint8
// Name returns the name of the currency.
Name() string
// Symbol returns the symbol of the currency.
Symbol() string
}
type baseCurrency struct {
address common.Address
decimals uint8
symbol string
name string
isNative bool
}
type NativeCurrency struct {
baseCurrency
}
// NewNativeCurrency is the constructor for the native currency.
func NewNativeCurrency(name, symbol string, decimals uint8) *NativeCurrency {
return &NativeCurrency{
baseCurrency: baseCurrency{
name: name,
symbol: symbol,
decimals: decimals,
address: ZeroAddr,
isNative: true,
},
}
}
func (c *NativeCurrency) equals(symbol string) bool {
return c.symbol == symbol
}
// Address is the contract address of the currency.
func (c *NativeCurrency) Address() string {
return c.address.String()
}
// CommonAddress is the common address of the currency.
func (c *NativeCurrency) CommonAddress() common.Address {
return c.address
}
// Decimals returns the number of decimals for the currency.
func (c *NativeCurrency) Decimals() uint8 {
return c.decimals
}
// Name returns the name of the currency.
func (c *NativeCurrency) Name() string {
return c.name
}
// Symbol returns the symbol of the currency.
func (c *NativeCurrency) Symbol() string {
return c.symbol
}