-
Notifications
You must be signed in to change notification settings - Fork 2
/
getters.ts
71 lines (68 loc) · 1.95 KB
/
getters.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
import { UnknownVersionError } from '../../../common/errors'
import { DemocracyVoteCall } from '../../../types/calls'
import { CallContext } from '../../types/contexts'
import { BatchContext } from '@subsquid/substrate-processor'
import { Store } from '@subsquid/typeorm-store'
type DemocracyVote =
| {
type: 'Standard'
balance?: bigint
value: number
}
| {
type: 'Split'
aye: bigint
nay: bigint
}
interface DemocracyVoteCallData {
index: number
vote: DemocracyVote
}
export function getVoteData(ctx: BatchContext<Store, unknown>, itemCall: any): DemocracyVoteCallData {
const event = new DemocracyVoteCall(ctx, itemCall)
if (event.isV49) {
const { refIndex, vote } = event.asV49
if (vote.__kind === 'Standard') {
return {
index: refIndex,
vote: {
type: 'Standard',
value: vote.value.vote,
balance: vote.value.balance,
},
}
} else {
return {
index: refIndex,
vote: {
type: 'Split',
aye: vote.value.aye,
nay: vote.value.nay,
},
}
}
} else if (event.isV900) {
const { refIndex, vote } = event.asV900
if (vote.__kind === 'Standard') {
return {
index: refIndex,
vote: {
type: 'Standard',
value: vote.vote,
balance: vote.balance,
},
}
} else {
return {
index: refIndex,
vote: {
type: 'Split',
aye: vote.aye,
nay: vote.nay,
},
}
}
} else {
throw new UnknownVersionError(event.constructor.name)
}
}