85 lines
1.8 KiB
TypeScript
85 lines
1.8 KiB
TypeScript
import { isAddress } from 'ethers/lib/utils'
|
|
import { ErrorUtils } from 'lib/utils'
|
|
|
|
// TODO: Decide whether to really use below, possibly from external interface
|
|
|
|
type NetworkId = string | number
|
|
type TokenId = string
|
|
type ContractId = string
|
|
type Denomination = number
|
|
|
|
class DataKey<T extends TokenId | NetworkId | ContractId | Denomination> {
|
|
value: string
|
|
isAddress?: boolean
|
|
isSymbol?: boolean
|
|
isName?: boolean
|
|
|
|
constructor(id: T) {
|
|
this.value = this._validate(id)
|
|
}
|
|
|
|
private _validate(id: T): string {
|
|
let type = typeof id
|
|
switch (type) {
|
|
case 'string':
|
|
let val = id as string
|
|
|
|
if (isAddress(val)) {
|
|
this.isAddress = true
|
|
return val
|
|
} else {
|
|
this.isSymbol = true
|
|
this.isName = true
|
|
}
|
|
return val.toLowerCase()
|
|
case 'number':
|
|
return String(id)
|
|
default:
|
|
throw ErrorUtils.getError(`unsupported key type ${type}.`)
|
|
}
|
|
}
|
|
}
|
|
|
|
type NetworkKey = DataKey<NetworkId>
|
|
type TokenKey = DataKey<TokenId>
|
|
type ContractKey = DataKey<ContractId>
|
|
type DenominationKey = DataKey<Denomination>
|
|
|
|
export namespace Json {
|
|
export interface TornadoInstance {
|
|
network: number
|
|
symbol: string
|
|
decimals: number
|
|
denomination: number
|
|
deployBlock: number
|
|
address: string
|
|
}
|
|
|
|
export interface ClassicInstance extends TornadoInstance {
|
|
anonymityMiningEnabled: boolean
|
|
}
|
|
|
|
export interface TokenData {
|
|
network: number
|
|
decimals: number
|
|
address: string
|
|
}
|
|
}
|
|
|
|
export namespace Keys {
|
|
export interface InstanceLookup {
|
|
network: string
|
|
token: string
|
|
denomination: string
|
|
}
|
|
}
|
|
|
|
export interface RelayerProperties {
|
|
address: string
|
|
version: string
|
|
serviceFeePercent: number
|
|
miningFeePercent: number
|
|
status: string
|
|
chainId: number
|
|
}
|