/
Witness.ts
130 lines (99 loc) · 2.87 KB
/
Witness.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import camelcaseKeys from 'camelcase-keys'
import type Client from '../Client'
import { Geocode, HTTPHotspotObject, Status } from './Hotspot'
import DataModel from './DataModel'
export type WitnessData = Omit<Witness, 'client'>
export interface HTTPWitnessObject extends HTTPHotspotObject {
witness_for?: string
witness_info?: HTTPWitnessInfoObject
}
interface HTTPWitnessInfoObject {
recent_time?: string
histogram?: Histogram
first_time?: string
}
interface WitnessInfo {
recentTime?: string
histogram?: Histogram
firstTime?: string
}
interface Histogram {
'28'?: number
'-92'?: number
'-84'?: number
'-76'?: number
'-68'?: number
'-60'?: number
'-132'?: number
'-124'?: number
'-116'?: number
'-108'?: number
'-100'?: number
}
export default class Witness extends DataModel {
private client: Client
public scoreUpdateHeight?: number
public score?: number
public rewardScale?: number
public owner?: string
public name?: string
public location?: string
public locationHex?: string
public lng?: number
public lat?: number
public block?: number
public geocode?: Geocode
public address: string
public status?: Status
public nonce?: number
public blockAdded?: number
public timestampAdded?: string
public lastPocChallenge?: number
public lastChangeBlock?: number
public gain?: number
public elevation?: number
public witnessFor?: string
public witnessInfo?: WitnessInfo
public mode?: string
constructor(client: Client, witness: HTTPWitnessObject) {
super()
this.client = client
this.scoreUpdateHeight = witness.score_update_height
this.score = witness.score
this.rewardScale = witness.reward_scale
this.owner = witness.owner
this.name = witness.name
this.location = witness.location
this.locationHex = witness.location_hex
this.lng = witness.lng
this.lat = witness.lat
this.block = witness.block
this.status = {
timestamp: witness.status?.timestamp,
height: witness.status?.height || 0,
online: witness.status?.online || '',
listenAddrs: witness.status?.listen_addrs || [],
}
this.nonce = witness.nonce
this.blockAdded = witness.block_added
this.timestampAdded = witness.timestamp_added
this.lastPocChallenge = witness.last_poc_challenge
this.lastChangeBlock = witness.last_change_block
this.gain = witness.gain
this.elevation = witness.elevation
if (witness.geocode) {
this.geocode = camelcaseKeys(witness.geocode) as any
}
this.address = witness.address
this.witnessFor = witness.witness_for
if (witness.witness_info) {
this.witnessInfo = camelcaseKeys(witness.witness_info) as any
}
this.mode = witness.mode
}
get data(): WitnessData {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { client, ...rest } = this
return { ...rest }
}
}