• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vocdoni / vocdoni-node / 19464799321

18 Nov 2025 11:38AM UTC coverage: 50.45% (-12.2%) from 62.676%
19464799321

push

github

p4u
disable hash check on vote package

Signed-off-by: p4u <pau@dabax.net>

12041 of 23867 relevant lines covered (50.45%)

37738.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.71
/api/api_types.go
1
package api
2

3
import (
4
        "encoding/json"
5
        "time"
6

7
        comettypes "github.com/cometbft/cometbft/types"
8
        "github.com/google/uuid"
9
        "go.vocdoni.io/dvote/types"
10
        "go.vocdoni.io/dvote/vochain/indexer/indexertypes"
11
        "go.vocdoni.io/proto/build/go/models"
12
        "google.golang.org/protobuf/encoding/protojson"
13
)
14

15
// ### Params accepted ###
16

17
// PaginationParams allows the client to request a specific page, and how many items per page
18
type PaginationParams struct {
19
        Page  int `json:"page,omitempty"`
20
        Limit int `json:"limit,omitempty"`
21
}
22

23
// ElectionParams allows the client to filter elections
24
type ElectionParams struct {
25
        PaginationParams
26
        OrganizationID  string     `json:"organizationId,omitempty"`
27
        ElectionID      string     `json:"electionId,omitempty"`
28
        Status          string     `json:"status,omitempty"`
29
        WithResults     *bool      `json:"withResults,omitempty"`
30
        FinalResults    *bool      `json:"finalResults,omitempty"`
31
        ManuallyEnded   *bool      `json:"manuallyEnded,omitempty"`
32
        StartDateAfter  *time.Time `json:"startDateAfter,omitempty"`
33
        StartDateBefore *time.Time `json:"startDateBefore,omitempty"`
34
        EndDateAfter    *time.Time `json:"endDateAfter,omitempty"`
35
        EndDateBefore   *time.Time `json:"endDateBefore,omitempty"`
36
}
37

38
// OrganizationParams allows the client to filter organizations
39
type OrganizationParams struct {
40
        PaginationParams
41
        OrganizationID string `json:"organizationId,omitempty"`
42
}
43

44
// AccountParams allows the client to filter accounts
45
type AccountParams struct {
46
        PaginationParams
47
        AccountID string `json:"accountId,omitempty"`
48
}
49

50
// TransactionParams allows the client to filter transactions
51
type TransactionParams struct {
52
        PaginationParams
53
        Hash    string `json:"hash,omitempty"`
54
        Height  uint64 `json:"height,omitempty"`
55
        Type    string `json:"type,omitempty"`
56
        Subtype string `json:"subtype,omitempty"`
57
        Signer  string `json:"signer,omitempty"`
58
}
59

60
// BlockParams allows the client to filter blocks
61
type BlockParams struct {
62
        PaginationParams
63
        ChainID         string `json:"chainId,omitempty"`
64
        Hash            string `json:"hash,omitempty"`
65
        ProposerAddress string `json:"proposerAddress,omitempty"`
66
}
67

68
// FeesParams allows the client to filter fees
69
type FeesParams struct {
70
        PaginationParams
71
        Reference string `json:"reference,omitempty"`
72
        Type      string `json:"type,omitempty"`
73
        AccountID string `json:"accountId,omitempty"`
74
}
75

76
// TransfersParams allows the client to filter transfers
77
type TransfersParams struct {
78
        PaginationParams
79
        AccountID     string `json:"accountId,omitempty"`
80
        AccountIDFrom string `json:"accountIdFrom,omitempty"`
81
        AccountIDTo   string `json:"accountIdTo,omitempty"`
82
}
83

84
// VoteParams allows the client to filter votes
85
type VoteParams struct {
86
        PaginationParams
87
        ElectionID string `json:"electionId,omitempty"`
88
}
89

90
// ### Objects returned ###
91

92
// CountResult wraps a count inside an object
93
type CountResult struct {
94
        Count uint64 `json:"count" example:"10"`
95
}
96

97
// Pagination contains all the values needed for the UI to easily organize the returned data
98
type Pagination struct {
99
        TotalItems   uint64  `json:"totalItems"`
100
        PreviousPage *uint64 `json:"previousPage"`
101
        CurrentPage  uint64  `json:"currentPage"`
102
        NextPage     *uint64 `json:"nextPage"`
103
        LastPage     uint64  `json:"lastPage"`
104
}
105

106
type OrganizationSummary struct {
107
        OrganizationID types.HexBytes `json:"organizationID"  example:"0x370372b92514d81a0e3efb8eba9d036ae0877653"`
108
        ElectionCount  uint64         `json:"electionCount" example:"1"`
109
}
110

111
// OrganizationsList is used to return a paginated list to the client
112
type OrganizationsList struct {
113
        Organizations []*OrganizationSummary `json:"organizations"`
114
        Pagination    *Pagination            `json:"pagination"`
115
}
116

117
type ElectionSummary struct {
118
        ElectionID     types.HexBytes    `json:"electionId" `
119
        OrganizationID types.HexBytes    `json:"organizationId" `
120
        Status         string            `json:"status"`
121
        StartDate      time.Time         `json:"startDate"`
122
        EndDate        time.Time         `json:"endDate"`
123
        VoteCount      uint64            `json:"voteCount"`
124
        FinalResults   bool              `json:"finalResults"`
125
        Results        [][]*types.BigInt `json:"result,omitempty"`
126
        ManuallyEnded  bool              `json:"manuallyEnded"`
127
        ChainID        string            `json:"chainId"`
128
}
129

130
// ElectionsList is used to return a paginated list to the client
131
type ElectionsList struct {
132
        Elections  []*ElectionSummary `json:"elections"`
133
        Pagination *Pagination        `json:"pagination"`
134
}
135

136
// ElectionResults is the struct used to wrap the results of an election
137
type ElectionResults struct {
138
        // ABIEncoded is the abi encoded election results
139
        ABIEncoded string `json:"abiEncoded" swaggerignore:"true"`
140
        // CensusRoot is the root of the census tree
141
        CensusRoot types.HexBytes `json:"censusRoot" `
142
        // ElectionID is the ID of the election
143
        ElectionID types.HexBytes `json:"electionId" `
144
        // OrganizationID is the ID of the organization that created the election
145
        OrganizationID types.HexBytes `json:"organizationId" `
146
        // Results is the list of votes
147
        Results [][]*types.BigInt `json:"results"`
148
        // SourceContractAddress is the address of the smart contract containing the census
149
        SourceContractAddress types.HexBytes `json:"sourceContractAddress,omitempty" `
150
}
151

152
type Election struct {
153
        ElectionSummary
154
        Census       *ElectionCensus `json:"census,omitempty"`
155
        MetadataURL  string          `json:"metadataURL"`
156
        CreationTime time.Time       `json:"creationTime"`
157
        VoteMode     VoteMode        `json:"voteMode,omitempty"`
158
        ElectionMode ElectionMode    `json:"electionMode,omitempty"`
159
        TallyMode    TallyMode       `json:"tallyMode,omitempty"`
160
        Metadata     any             `json:"metadata,omitempty"`
161
}
162

163
type ElectionKeys struct {
164
        PublicKeys  []Key `json:"publicKeys,omitempty" swaggertype:"string"`
165
        PrivateKeys []Key `json:"privateKeys,omitempty" swaggertype:"string"`
166
}
167

168
type ElectionCensus struct {
169
        CensusOrigin           string         `json:"censusOrigin"`
170
        CensusRoot             types.HexBytes `json:"censusRoot" `
171
        PostRegisterCensusRoot types.HexBytes `json:"postRegisterCensusRoot" `
172
        CensusURL              string         `json:"censusURL"`
173
        MaxCensusSize          uint64         `json:"maxCensusSize"`
174
}
175

176
type ElectionCreate struct {
177
        TxPayload                 []byte         `json:"txPayload,omitempty"`
178
        Metadata                  []byte         `json:"metadata,omitempty"`
179
        TxHash                    types.HexBytes `json:"txHash" `
180
        ElectionID                types.HexBytes `json:"electionID" `
181
        MetadataURL               string         `json:"metadataURL"`
182
        MetadataEncryptionPrivKey types.HexBytes `json:"metadataEncryptionPrivKey,omitempty"`
183
}
184

185
type ElectionDescription struct {
186
        Title        LanguageString        `json:"title"`
187
        Description  LanguageString        `json:"description"`
188
        Header       string                `json:"header"`
189
        StreamURI    string                `json:"streamUri"`
190
        StartDate    time.Time             `json:"startDate,omitempty"`
191
        EndDate      time.Time             `json:"endDate"`
192
        VoteType     VoteType              `json:"voteType"`
193
        ElectionType ElectionType          `json:"electionType"`
194
        Questions    []Question            `json:"questions"`
195
        Census       CensusTypeDescription `json:"census"`
196
        TempSIKs     bool                  `json:"tempSIKs"`
197
}
198

199
type Key struct {
200
        Index int            `json:"index"`
201
        Key   types.HexBytes `json:"key" `
202
}
203

204
type Vote struct {
205
        TxPayload []byte         `json:"txPayload,omitempty"  extensions:"x-omitempty" swaggerignore:"true"`
206
        TxHash    types.HexBytes `json:"txHash,omitempty"  extensions:"x-omitempty" `
207
        // VoteID here produces a `voteID` over JSON that differs in casing from the rest of params and JSONs
208
        // but is kept for backwards compatibility
209
        VoteID types.HexBytes `json:"voteID,omitempty"  extensions:"x-omitempty" `
210
        // Sent only for encrypted elections (no results until the end)
211
        EncryptionKeyIndexes []uint32 `json:"encryptionKeys,omitempty" extensions:"x-omitempty"`
212
        // For encrypted elections this will be codified
213
        VotePackage      json.RawMessage `json:"package,omitempty" extensions:"x-omitempty"`
214
        VoteWeight       string          `json:"weight,omitempty" extensions:"x-omitempty"` // [math/big.Int.String]
215
        VoteNumber       *uint32         `json:"number,omitempty" extensions:"x-omitempty"`
216
        ElectionID       types.HexBytes  `json:"electionID,omitempty" extensions:"x-omitempty" `
217
        VoterID          types.HexBytes  `json:"voterID,omitempty" extensions:"x-omitempty" `
218
        BlockHeight      uint32          `json:"blockHeight,omitempty" extensions:"x-omitempty"`
219
        TransactionIndex *int32          `json:"transactionIndex,omitempty" extensions:"x-omitempty"`
220
        OverwriteCount   *uint32         `json:"overwriteCount,omitempty" extensions:"x-omitempty"`
221
        // Date when the vote was emitted
222
        Date *time.Time `json:"date,omitempty" extensions:"x-omitempty"`
223
}
224

225
type VotesList struct {
226
        Votes      []*Vote     `json:"votes"`
227
        Pagination *Pagination `json:"pagination"`
228
}
229

230
type CensusTypeDescription struct {
231
        Type      string         `json:"type"`
232
        Size      uint64         `json:"size"`
233
        URL       string         `json:"url,omitempty"`
234
        PublicKey types.HexBytes `json:"publicKey,omitempty" `
235
        RootHash  types.HexBytes `json:"rootHash,omitempty" `
236
}
237

238
type CensusParticipants struct {
239
        Participants []CensusParticipant `json:"participants"`
240
}
241

242
type CensusParticipant struct {
243
        Key    types.HexBytes `json:"key" `
244
        Weight *types.BigInt  `json:"weight"`
245
}
246

247
type VoteType struct {
248
        UniqueChoices     bool `json:"uniqueChoices"`
249
        MaxVoteOverwrites int  `json:"maxVoteOverwrites"`
250
        CostFromWeight    bool `json:"costFromWeight"`
251
        CostExponent      int  `json:"costExponent"`
252
        MaxCount          int  `json:"maxCount"`
253
        MaxValue          int  `json:"maxValue"`
254
}
255

256
type ElectionType struct {
257
        Autostart         bool `json:"autostart"`
258
        Interruptible     bool `json:"interruptible"`
259
        DynamicCensus     bool `json:"dynamicCensus"`
260
        SecretUntilTheEnd bool `json:"secretUntilTheEnd"`
261
        Anonymous         bool `json:"anonymous"`
262
}
263

264
type Transaction struct {
265
        Payload   []byte            `json:"payload,omitempty" extensions:"x-omitempty" swaggerignore:"true"`
266
        Hash      types.HexBytes    `json:"hash,omitempty" extensions:"x-omitempty" `
267
        Response  []byte            `json:"response,omitempty" extensions:"x-omitempty" swaggertype:"string" format:"base64"`
268
        Code      *uint32           `json:"code,omitempty" extensions:"x-omitempty"`
269
        Costs     map[string]uint64 `json:"costs,omitempty" extensions:"x-omitempty" swaggerignore:"true"`
270
        Address   types.HexBytes    `json:"address,omitempty" extensions:"x-omitempty" swaggerignore:"true" `
271
        ProcessID types.HexBytes    `json:"processId,omitempty" extensions:"x-omitempty" swaggerignore:"true" `
272
}
273

274
type TransactionReference struct {
275
        Height uint32 `json:"blockHeight"`
276
        Index  uint32 `json:"transactionIndex"`
277
}
278

279
// TransactionsList is used to return a paginated list to the client
280
type TransactionsList struct {
281
        Transactions []*indexertypes.TransactionMetadata `json:"transactions"`
282
        Pagination   *Pagination                         `json:"pagination"`
283
}
284

285
// FeesList is used to return a paginated list to the client
286
type FeesList struct {
287
        Fees       []*indexertypes.TokenFeeMeta `json:"fees"`
288
        Pagination *Pagination                  `json:"pagination"`
289
}
290

291
// TransfersList is used to return a paginated list to the client
292
type TransfersList struct {
293
        Transfers  []*indexertypes.TokenTransferMeta `json:"transfers"`
294
        Pagination *Pagination                       `json:"pagination"`
295
}
296

297
type GenericTransactionWithInfo struct {
298
        TxContent json.RawMessage           `json:"tx"`
299
        TxInfo    *indexertypes.Transaction `json:"txInfo"`
300
        Signature types.HexBytes            `json:"signature"`
301
}
302

303
type ChainInfo struct {
304
        ID                string    `json:"chainId" example:"azeno"`
305
        BlockTime         [5]uint64 `json:"blockTime" example:"12000,11580,11000,11100,11100"`
306
        ElectionCount     uint64    `json:"electionCount" example:"120"`
307
        OrganizationCount uint64    `json:"organizationCount" example:"20"`
308
        GenesisTime       time.Time `json:"genesisTime"  format:"date-time" example:"2022-11-17T18:00:57.379551614Z"`
309
        InitialHeight     uint32    `json:"initialHeight"  example:"5467"`
310
        Height            uint32    `json:"height" example:"5467"`
311
        BlockStoreBase    uint32    `json:"blockStoreBase" example:"5467"`
312
        Syncing           bool      `json:"syncing" example:"true"`
313
        Timestamp         int64     `json:"blockTimestamp" swaggertype:"string" format:"date-time" example:"2022-11-17T18:00:57.379551614Z"`
314
        TransactionCount  uint64    `json:"transactionCount" example:"554"`
315
        ValidatorCount    uint32    `json:"validatorCount" example:"5"`
316
        VoteCount         uint64    `json:"voteCount" example:"432"`
317
        CircuitVersion    string    `json:"circuitVersion" example:"v1.0.0"`
318
        MaxCensusSize     uint64    `json:"maxCensusSize" example:"50000"`
319
        NetworkCapacity   uint64    `json:"networkCapacity" example:"2000"`
320
}
321

322
type Account struct {
323
        Address        types.HexBytes   `json:"address" `
324
        Nonce          uint32           `json:"nonce"`
325
        Balance        uint64           `json:"balance"`
326
        ElectionIndex  uint32           `json:"electionIndex"`
327
        TransfersCount uint64           `json:"transfersCount,omitempty"`
328
        FeesCount      uint64           `json:"feesCount,omitempty"`
329
        InfoURL        string           `json:"infoURL,omitempty"`
330
        Token          *uuid.UUID       `json:"token,omitempty" swaggerignore:"true"`
331
        Metadata       *AccountMetadata `json:"metadata,omitempty"`
332
        SIK            types.HexBytes   `json:"sik"`
333
}
334

335
type AccountsList struct {
336
        Accounts   []*indexertypes.Account `json:"accounts"`
337
        Pagination *Pagination             `json:"pagination"`
338
}
339

340
type AccountSet struct {
341
        TxPayload   []byte         `json:"txPayload,omitempty" swaggerignore:"true"`
342
        Metadata    []byte         `json:"metadata,omitempty" swaggerignore:"true"`
343
        TxHash      types.HexBytes `json:"txHash" `
344
        MetadataURL string         `json:"metadataURL" swaggertype:"string"`
345
}
346

347
type Census struct {
348
        // CensusID here produces a `censusID` over JSON that differs in casing from the rest of params and JSONs
349
        // but is kept for backwards compatibility
350
        CensusID types.HexBytes `json:"censusID,omitempty"`
351
        Type     string         `json:"type,omitempty"`
352
        Weight   *types.BigInt  `json:"weight,omitempty"`
353
        Size     uint64         `json:"size,omitempty"`
354
        Valid    bool           `json:"valid,omitempty"`
355
        URI      string         `json:"uri,omitempty"`
356
        // proof stuff
357
        CensusRoot     types.HexBytes `json:"censusRoot,omitempty"`
358
        CensusProof    types.HexBytes `json:"censusProof,omitempty"`
359
        Key            types.HexBytes `json:"key,omitempty"`
360
        Value          types.HexBytes `json:"value,omitempty"`
361
        CensusSiblings []string       `json:"censusSiblings,omitempty"`
362
}
363

364
type File struct {
365
        Payload []byte `json:"payload,omitempty" swaggerignore:"true"`
366
        CID     string `json:"cid,omitempty"`
367
}
368

369
type ValidatorList struct {
370
        Validators []Validator `json:"validators"`
371
}
372

373
type Validator struct {
374
        Power            uint64         `json:"power"`
375
        PubKey           types.HexBytes `json:"pubKey"`
376
        AccountAddress   types.HexBytes `json:"address"`
377
        Name             string         `json:"name"`
378
        ValidatorAddress types.HexBytes `json:"validatorAddress"`
379
        JoinHeight       uint64         `json:"joinHeight"`
380
        Votes            uint64         `json:"votes"`
381
        Proposals        uint64         `json:"proposals"`
382
        Score            uint32         `json:"score"`
383
}
384

385
type BuildElectionID struct {
386
        Delta          int32          `json:"delta"` // 0 means build next ElectionID
387
        OrganizationID types.HexBytes `json:"organizationId"`
388
        CensusOrigin   int32          `json:"censusOrigin"`
389
        EnvelopeType   struct {
390
                Serial         bool `json:"serial"`
391
                Anonymous      bool `json:"anonymous"`
392
                EncryptedVotes bool `json:"encryptedVotes"`
393
                UniqueValues   bool `json:"uniqueValues"`
394
                CostFromWeight bool `json:"costFromWeight"`
395
        } `json:"envelopeType"`
396
}
397

398
// Protobuf wrappers
399

400
type VoteMode struct {
401
        *models.EnvelopeType
402
}
403

404
func (v VoteMode) MarshalJSON() ([]byte, error) {
5✔
405
        m := protojson.MarshalOptions{EmitUnpopulated: true, UseEnumNumbers: false}
5✔
406
        return m.Marshal(&v)
5✔
407
}
5✔
408

409
type ElectionMode struct {
410
        *models.ProcessMode
411
}
412

413
func (e ElectionMode) MarshalJSON() ([]byte, error) {
5✔
414
        m := protojson.MarshalOptions{EmitUnpopulated: true, UseEnumNumbers: false}
5✔
415
        return m.Marshal(&e)
5✔
416
}
5✔
417

418
type TallyMode struct {
419
        *models.ProcessVoteOptions
420
}
421

422
func (t TallyMode) MarshalJSON() ([]byte, error) {
5✔
423
        m := protojson.MarshalOptions{EmitUnpopulated: true, UseEnumNumbers: false}
5✔
424
        return m.Marshal(&t)
5✔
425
}
5✔
426

427
func CensusTypeToOrigin(ctype CensusTypeDescription) (models.CensusOrigin, []byte, error) {
×
428
        var origin models.CensusOrigin
×
429
        var root []byte
×
430
        switch ctype.Type {
×
431
        case CensusTypeCSP:
×
432
                origin = models.CensusOrigin_OFF_CHAIN_CA
×
433
                root = ctype.PublicKey
×
434
        case CensusTypeWeighted, CensusTypeZKWeighted:
×
435
                origin = models.CensusOrigin_OFF_CHAIN_TREE_WEIGHTED
×
436
                root = ctype.RootHash
×
437
        case CensusTypeFarcaster:
×
438
                origin = models.CensusOrigin_FARCASTER_FRAME
×
439
                root = ctype.RootHash
×
440
        default:
×
441
                return 0, nil, ErrCensusTypeUnknown.Withf("%q", ctype)
×
442
        }
443
        if root == nil {
×
444
                return 0, nil, ErrCensusRootIsNil
×
445
        }
×
446
        return origin, root, nil
×
447
}
448

449
type Block struct {
450
        comettypes.Header `json:"header"`
451
        Hash              types.HexBytes `json:"hash" `
452
        TxCount           int64          `json:"txCount"`
453
}
454

455
// BlockList is used to return a paginated list to the client
456
type BlockList struct {
457
        Blocks     []*indexertypes.Block `json:"blocks"`
458
        Pagination *Pagination           `json:"pagination"`
459
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc