forked from privacy-scaling-explorations/maci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.js
118 lines (104 loc) · 2.71 KB
/
admin.js
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
const argparse = require('argparse')
const {updateRecord, removeRecord, queryRecord} = require('./db')
const {readJSONFile} = require('maci-common')
const updateSubparser = (subparsers) => {
const createParser = subparsers.addParser(
'update',
{ addHelp: true },
)
createParser.addArgument(
['-f', '--file_record'],
{
required: true,
type: 'string',
help: 'file location of deployed contract addresses'
}
)
createParser.addArgument(
['-p', '--process_messages_zkey'],
{
action: 'store',
type: 'string',
help: 'The .zkey file for the message processing circuit. '
}
)
createParser.addArgument(
['-t', '--tally_votes_zkey'],
{
action: 'store',
type: 'string',
help: 'The .zkey file for the vote tallying circuit. '
}
)
}
const removeSubparser = (subparsers) => {
const createParser = subparsers.addParser(
'delete',
{ addHelp: true },
)
createParser.addArgument(
['-x', '--maci_addr'],
{
required: true,
type: 'string',
help: 'Delete record of given maci address',
}
)
}
const querySubparser = (subparsers) => {
const createParser = subparsers.addParser(
'query',
{ addHelp: true },
)
createParser.addArgument(
['-x', '--maci_addr'],
{
required: true,
type: 'string',
help: 'query record of given maci address',
}
)
}
const update = async (args) => {
let data = readJSONFile(args.file_record)
if (args.process_messages_zkey) {
data["messageZkey"] = args.process_messages_zkey
}
if (args.tally_votes_zkey) {
data["tallyZkey"] = args.tally_votes_zkey
}
updateRecord(data)
return
}
const remove = async (args) => {
removeRecord(args.maci_addr)
return
}
const query = async (args) => {
queryRecord(args.maci_addr)
return
}
const main = async () => {
const parser = new argparse.ArgumentParser({
description: 'MACI Database Management',
})
const subparsers = parser.addSubparsers({
title: 'Subcommands',
dest: 'subcommand',
})
updateSubparser(subparsers)
removeSubparser(subparsers)
querySubparser(subparsers)
const args = parser.parseArgs()
// Execute the subcommand method
if (args.subcommand === 'update') {
await update(args)
} else if (args.subcommand == 'delete') {
await remove(args)
} else if (args.subcommand == 'query') {
await query(args)
}
}
if (require.main === module) {
main()
}