90 lines
2.3 KiB
Plaintext
90 lines
2.3 KiB
Plaintext
|
package exchanges
|
||
|
|
||
|
/*--------------------------------+
|
||
|
| Code generated by exchanges |
|
||
|
| DO NOT EDIT |
|
||
|
+--------------------------------*/
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
|
)
|
||
|
|
||
|
type Exchange struct {
|
||
|
code string
|
||
|
name string
|
||
|
symbol string
|
||
|
logo string
|
||
|
addresses []common.Address
|
||
|
}
|
||
|
|
||
|
func (e *Exchange) Code() string { return e.code }
|
||
|
|
||
|
func (e *Exchange) Name() string { return e.name }
|
||
|
|
||
|
func (e *Exchange) Symbol() string { return e.symbol }
|
||
|
|
||
|
func (e *Exchange) Logo() string { return e.logo }
|
||
|
|
||
|
func (e *Exchange) Addresses() []common.Address { return e.addresses }
|
||
|
|
||
|
// Get returns an exchange struct if the provided
|
||
|
// code is contained within the valid codes. Otherwise
|
||
|
// an error will be returned
|
||
|
func GetCentralizedExchangeWithCode(code string) (*Exchange, error) {
|
||
|
if Valid(code) {
|
||
|
val, ok := centralizedExchangesByCode[code]
|
||
|
if ok {
|
||
|
return val, nil
|
||
|
}
|
||
|
}
|
||
|
return nil, fmt.Errorf("exchange: could not find exchange with code: %q", code)
|
||
|
}
|
||
|
|
||
|
// Get returns an exchange struct which owns the given
|
||
|
// address. If the address does not belong to any exchange,
|
||
|
// nil will be returned
|
||
|
func GetCentralizedExchangeWithAddress(address common.Address) (*Exchange) {
|
||
|
return centralizedExchangesByAddress[address.String()]
|
||
|
}
|
||
|
|
||
|
// Valid checks if a provided code is contained
|
||
|
// inside the provided ValidCodes slice
|
||
|
func Valid(code string) bool {
|
||
|
for _, c := range ValidCodes {
|
||
|
if c == code {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// Following are all the structs containing exchange data
|
||
|
var (
|
||
|
{{ range $k, $v := . -}}
|
||
|
// {{$v.Code}} Exchange struct
|
||
|
{{toVariableName $v.Code}} = Exchange{ code: "{{$v.Code}}", name: "{{$v.Name}}", symbol: "{{$v.Symbol}}", logo: "{{$v.Logo}}", addresses: []common.Address{ {{addressesJoin $v.Addresses}} } }
|
||
|
{{ end }}
|
||
|
)
|
||
|
|
||
|
var centralizedExchangesByCode = map[string]*Exchange{
|
||
|
{{ range $k, $v := . -}}
|
||
|
"{{$v.Code}}": &{{toVariableName $v.Code}},
|
||
|
{{ end }}
|
||
|
}
|
||
|
|
||
|
var centralizedExchangesByAddress = map[string]*Exchange{
|
||
|
{{ range $k, $v := . -}}
|
||
|
{{ range $i, $a := $v.Addresses}}
|
||
|
"{{$a}}": &{{toVariableName $v.Code}},
|
||
|
{{ end }}
|
||
|
{{ end }}
|
||
|
}
|
||
|
|
||
|
var ValidCodes = []string{
|
||
|
{{ range $k, $v := . -}}
|
||
|
"{{$v.Code}}",
|
||
|
{{ end }}
|
||
|
}
|