wowok 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +17 -0
- package/dist/demand.js +91 -30
- package/dist/guard.js +206 -80
- package/dist/machine.js +130 -65
- package/dist/passport.js +14 -5
- package/dist/permission.js +117 -49
- package/dist/progress.js +74 -30
- package/dist/protocol.js +85 -53
- package/dist/repository.js +154 -50
- package/dist/reward.js +134 -28
- package/dist/service.js +457 -161
- package/dist/util.js +25 -1
- package/dist/vote.js +134 -56
- package/package.json +11 -7
- package/src/demand.ts +96 -52
- package/src/graphql.ts +103 -0
- package/src/guard.ts +268 -114
- package/src/index.ts +12 -0
- package/src/machine.ts +137 -86
- package/src/passport.ts +67 -30
- package/src/permission.ts +115 -59
- package/src/progress.ts +149 -63
- package/src/protocol.ts +94 -40
- package/src/repository.ts +152 -79
- package/src/reward.ts +134 -45
- package/src/service.ts +437 -209
- package/src/util.ts +28 -1
- package/src/vote.ts +141 -74
package/src/util.ts
CHANGED
|
@@ -88,9 +88,15 @@ export class Bcs {
|
|
|
88
88
|
ser_option_u64(data:number) : Uint8Array {
|
|
89
89
|
return this.bcs.ser('Option<u64>', {'some': data}).toBytes();
|
|
90
90
|
}
|
|
91
|
+
ser_option_address(data:string) : Uint8Array {
|
|
92
|
+
return this.bcs.ser('Option<address>', {'some': data}).toBytes();
|
|
93
|
+
}
|
|
91
94
|
ser_vector_string(data:string[]) : Uint8Array {
|
|
92
95
|
return this.bcs.ser('vector<string>', data).toBytes();
|
|
93
96
|
}
|
|
97
|
+
ser_vector_vector_u8(data:string[]) : Uint8Array {
|
|
98
|
+
return this.bcs.ser('vector<vector<u8>>', data).toBytes();
|
|
99
|
+
}
|
|
94
100
|
ser_vector_u64(data:number[]) : Uint8Array {
|
|
95
101
|
return this.bcs.ser('vector<u64>', data).toBytes();
|
|
96
102
|
}
|
|
@@ -131,4 +137,25 @@ export const objectids_from_response = (response:SuiTransactionBlockResponse, co
|
|
|
131
137
|
})
|
|
132
138
|
}
|
|
133
139
|
return ret;
|
|
134
|
-
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
export function stringToUint8Array(str:string) : Uint8Array {
|
|
144
|
+
var arr = [];
|
|
145
|
+
for (var i = 0, j = str.length; i < j; ++i) {
|
|
146
|
+
arr.push(str.charCodeAt(i));
|
|
147
|
+
}
|
|
148
|
+
var tmpUint8Array = new Uint8Array(arr);
|
|
149
|
+
return tmpUint8Array
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function numToUint8Array(num:number) : Uint8Array {
|
|
153
|
+
if (!num) return new Uint8Array(0)
|
|
154
|
+
const a = [];
|
|
155
|
+
a.unshift(num & 255)
|
|
156
|
+
while (num >= 256) {
|
|
157
|
+
num = num >>> 8
|
|
158
|
+
a.unshift(num & 255)
|
|
159
|
+
}
|
|
160
|
+
return new Uint8Array(a)
|
|
161
|
+
}
|
package/src/vote.ts
CHANGED
|
@@ -1,251 +1,318 @@
|
|
|
1
|
-
import { TransactionBlock
|
|
2
|
-
import { BCS
|
|
3
|
-
import { CLOCK_OBJECT, FnCallType,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
1
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
import { BCS } from '@mysten/bcs';
|
|
3
|
+
import { CLOCK_OBJECT, FnCallType, PROTOCOL, PassportObject, PermissionObject, GuardObject, VoteAddress,
|
|
4
|
+
VoteObject, IsValidObjects, IsValidDesription, IsValidUint, IsValidAddress, OptionNone, TXB_OBJECT,
|
|
5
|
+
IsValidArray, IsValidName} from './protocol';
|
|
6
|
+
import { BCS_CONVERT, array_unique } from './util';
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export const MAX_AGREES_COUNT = 200;
|
|
9
|
+
export const MAX_CHOICE_COUNT = 200;
|
|
10
10
|
|
|
11
11
|
export function vote(txb:TransactionBlock, permission:PermissionObject, description:string, minutes_duration:number,
|
|
12
|
-
max_choice_count
|
|
13
|
-
|
|
14
|
-
if (
|
|
12
|
+
max_choice_count?:number, reference_address?:string, passport?:PassportObject) : VoteObject | boolean {
|
|
13
|
+
if (!IsValidObjects([permission])) return false;
|
|
14
|
+
if (!IsValidDesription(description)) return false;
|
|
15
|
+
if (!IsValidUint(minutes_duration)) return false;
|
|
16
|
+
if (max_choice_count && !IsValidUint(max_choice_count)) return false;
|
|
17
|
+
if (max_choice_count && max_choice_count > MAX_CHOICE_COUNT) return false;
|
|
18
|
+
if (reference_address && !IsValidAddress(reference_address)) return false;
|
|
19
|
+
|
|
20
|
+
let reference = reference_address? txb.pure(BCS_CONVERT.ser_option_address(reference_address)) : OptionNone(txb);
|
|
21
|
+
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
15
22
|
|
|
16
23
|
if (passport) {
|
|
17
24
|
return txb.moveCall({
|
|
18
25
|
target:PROTOCOL.VoteFn('new_with_passport') as FnCallType,
|
|
19
|
-
arguments:[passport, txb.pure(
|
|
20
|
-
txb.pure(minutes_duration, BCS.U64), txb.pure(
|
|
26
|
+
arguments:[passport, txb.pure(description), reference, txb.pure(CLOCK_OBJECT),
|
|
27
|
+
txb.pure(minutes_duration, BCS.U64), txb.pure(choice_count, BCS.U8), TXB_OBJECT(txb, permission)]
|
|
21
28
|
})
|
|
22
29
|
} else {
|
|
23
30
|
return txb.moveCall({
|
|
24
31
|
target:PROTOCOL.VoteFn('new') as FnCallType,
|
|
25
|
-
arguments:[txb.pure(
|
|
26
|
-
txb.pure(minutes_duration, BCS.U64), txb.pure(
|
|
32
|
+
arguments:[txb.pure(description), reference, txb.pure(CLOCK_OBJECT),
|
|
33
|
+
txb.pure(minutes_duration, BCS.U64), txb.pure(choice_count, BCS.U8), TXB_OBJECT(txb, permission)]
|
|
27
34
|
})
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
|
-
export function launch(txb:TransactionBlock, vote:VoteObject) : VoteAddress {
|
|
37
|
+
export function launch(txb:TransactionBlock, vote:VoteObject) : VoteAddress | boolean {
|
|
38
|
+
if (!IsValidObjects([vote])) return false;
|
|
31
39
|
return txb.moveCall({
|
|
32
40
|
target:PROTOCOL.VoteFn('create') as FnCallType,
|
|
33
|
-
arguments:[vote]
|
|
41
|
+
arguments:[TXB_OBJECT(txb, vote)]
|
|
34
42
|
})
|
|
35
43
|
}
|
|
36
|
-
export function destroy(txb:TransactionBlock, vote:VoteObject) {
|
|
44
|
+
export function destroy(txb:TransactionBlock, vote:VoteObject) : boolean {
|
|
45
|
+
if (!IsValidObjects([vote])) return false;
|
|
37
46
|
txb.moveCall({
|
|
38
47
|
target:PROTOCOL.VoteFn('destroy') as FnCallType,
|
|
39
|
-
arguments:[vote]
|
|
48
|
+
arguments:[TXB_OBJECT(txb, vote)]
|
|
40
49
|
})
|
|
50
|
+
return true
|
|
41
51
|
}
|
|
42
|
-
export function vote_set_description(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
52
|
+
export function vote_set_description(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
53
|
+
description:string, passport?:PassportObject) : boolean {
|
|
54
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
55
|
+
if (!IsValidDesription(description)) return false;
|
|
56
|
+
|
|
43
57
|
if (passport) {
|
|
44
58
|
txb.moveCall({
|
|
45
59
|
target:PROTOCOL.VoteFn('description_set_with_passport') as FnCallType,
|
|
46
|
-
arguments:[passport, vote, txb.pure(
|
|
60
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(description), TXB_OBJECT(txb, permission)]
|
|
47
61
|
})
|
|
48
62
|
} else {
|
|
49
63
|
txb.moveCall({
|
|
50
64
|
target:PROTOCOL.VoteFn('description_set') as FnCallType,
|
|
51
|
-
arguments:[vote, txb.pure(
|
|
65
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(description), TXB_OBJECT(txb, permission)]
|
|
52
66
|
})
|
|
53
67
|
}
|
|
68
|
+
return true
|
|
54
69
|
}
|
|
55
70
|
|
|
56
|
-
export function vote_set_reference(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
57
|
-
|
|
58
|
-
if (
|
|
71
|
+
export function vote_set_reference(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
72
|
+
reference_address?:string, passport?:PassportObject) : boolean {
|
|
73
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
74
|
+
if (reference_address && !IsValidAddress(reference_address)) return false;
|
|
75
|
+
let reference = reference_address? txb.pure(BCS_CONVERT.ser_option_address(reference_address)) : OptionNone(txb);
|
|
59
76
|
|
|
60
77
|
if (passport) {
|
|
61
78
|
txb.moveCall({
|
|
62
79
|
target:PROTOCOL.VoteFn('reference_set_with_passport') as FnCallType,
|
|
63
|
-
arguments:[passport, vote, reference, permission]
|
|
80
|
+
arguments:[passport, TXB_OBJECT(txb, vote), reference, TXB_OBJECT(txb, permission)]
|
|
64
81
|
})
|
|
65
82
|
} else {
|
|
66
83
|
txb.moveCall({
|
|
67
84
|
target:PROTOCOL.VoteFn('reference_set') as FnCallType,
|
|
68
|
-
arguments:[vote, reference, permission]
|
|
85
|
+
arguments:[TXB_OBJECT(txb, vote), reference, TXB_OBJECT(txb, permission)]
|
|
69
86
|
})
|
|
70
87
|
}
|
|
88
|
+
return true
|
|
71
89
|
}
|
|
72
|
-
export function vote_add_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
90
|
+
export function vote_add_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
91
|
+
guard:GuardObject, vote_weight:number, passport?:PassportObject) : boolean {
|
|
92
|
+
if (!IsValidObjects([vote, permission, guard])) return false;
|
|
93
|
+
if (!IsValidUint(vote_weight)) return false;
|
|
94
|
+
|
|
73
95
|
if (passport) {
|
|
74
96
|
txb.moveCall({
|
|
75
97
|
target:PROTOCOL.VoteFn('guard_add_with_passport') as FnCallType,
|
|
76
|
-
arguments:[passport, vote, guard, txb.pure(vote_weight, BCS.U64), permission]
|
|
98
|
+
arguments:[passport, TXB_OBJECT(txb, vote), TXB_OBJECT(txb, guard), txb.pure(vote_weight, BCS.U64), TXB_OBJECT(txb, permission)]
|
|
77
99
|
})
|
|
78
100
|
} else {
|
|
79
101
|
txb.moveCall({
|
|
80
102
|
target:PROTOCOL.VoteFn('guard_add') as FnCallType,
|
|
81
|
-
arguments:[vote, guard, txb.pure(vote_weight, BCS.U64), permission]
|
|
103
|
+
arguments:[TXB_OBJECT(txb, vote), TXB_OBJECT(txb, guard), txb.pure(vote_weight, BCS.U64), TXB_OBJECT(txb, permission)]
|
|
82
104
|
})
|
|
83
105
|
}
|
|
106
|
+
return true
|
|
84
107
|
}
|
|
85
|
-
export function vote_remove_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
108
|
+
export function vote_remove_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
109
|
+
guard_address:string[], removeall?:boolean, passport?:PassportObject) : boolean {
|
|
110
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
111
|
+
if (!removeall && !guard_address) return false;
|
|
112
|
+
if (guard_address && !IsValidArray(guard_address, IsValidAddress)) return false;
|
|
113
|
+
|
|
86
114
|
if (passport) {
|
|
87
115
|
if (removeall) {
|
|
88
116
|
txb.moveCall({
|
|
89
117
|
target:PROTOCOL.VoteFn('guard_remove_all_with_passport') as FnCallType,
|
|
90
|
-
arguments:[passport, vote, permission]
|
|
118
|
+
arguments:[passport, TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
91
119
|
})
|
|
92
120
|
} else {
|
|
93
121
|
txb.moveCall({
|
|
94
122
|
target:PROTOCOL.VoteFn('guard_remove_with_passport') as FnCallType,
|
|
95
|
-
arguments:[passport, vote, txb.pure(guard_address, 'vector<address>'), permission]
|
|
123
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(array_unique(guard_address), 'vector<address>'), TXB_OBJECT(txb, permission)]
|
|
96
124
|
})
|
|
97
125
|
}
|
|
98
126
|
} else {
|
|
99
127
|
if (removeall) {
|
|
100
128
|
txb.moveCall({
|
|
101
129
|
target:PROTOCOL.VoteFn('guard_remove_all') as FnCallType,
|
|
102
|
-
arguments:[vote, permission]
|
|
130
|
+
arguments:[TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
103
131
|
})
|
|
104
132
|
} else {
|
|
105
133
|
txb.moveCall({
|
|
106
134
|
target:PROTOCOL.VoteFn('guard_remove') as FnCallType,
|
|
107
|
-
arguments:[vote, txb.pure(guard_address, 'vector<address>'), permission]
|
|
135
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(array_unique(guard_address), 'vector<address>'), TXB_OBJECT(txb, permission)]
|
|
108
136
|
})
|
|
109
137
|
}
|
|
110
138
|
}
|
|
139
|
+
return true
|
|
111
140
|
}
|
|
112
141
|
export type VoteOption = {
|
|
113
142
|
name:string;
|
|
114
143
|
reference_address?:string;
|
|
115
144
|
}
|
|
116
|
-
export function vote_add_option(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
145
|
+
export function vote_add_option(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
146
|
+
options:VoteOption[], passport?:PassportObject) : boolean {
|
|
147
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
148
|
+
if (!options) return false;
|
|
149
|
+
let bValid = true;
|
|
150
|
+
options.forEach((v) => {
|
|
151
|
+
if (!IsValidName(v.name)) bValid = false;
|
|
152
|
+
if (v?.reference_address && IsValidAddress(v.reference_address)) bValid = false;
|
|
153
|
+
})
|
|
154
|
+
if (!bValid) return false;
|
|
155
|
+
|
|
117
156
|
options.forEach((option) => {
|
|
118
|
-
let reference = txb.pure(
|
|
119
|
-
if (option.reference_address) { reference = txb.pure(option.reference_address, BCS.ADDRESS) }
|
|
157
|
+
let reference = option?.reference_address ? txb.pure(BCS_CONVERT.ser_option_address(option.reference_address)) : OptionNone(txb);
|
|
120
158
|
if (passport) {
|
|
121
159
|
txb.moveCall({
|
|
122
160
|
target:PROTOCOL.VoteFn('agrees_add_with_passport') as FnCallType,
|
|
123
|
-
arguments:[passport, vote, txb.pure(
|
|
161
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(option.name), reference, TXB_OBJECT(txb, permission)]
|
|
124
162
|
})
|
|
125
163
|
} else {
|
|
126
164
|
txb.moveCall({
|
|
127
165
|
target:PROTOCOL.VoteFn('agrees_add') as FnCallType,
|
|
128
|
-
arguments:[vote, txb.pure(
|
|
166
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(option.name), reference, TXB_OBJECT(txb, permission)]
|
|
129
167
|
})
|
|
130
168
|
}
|
|
131
169
|
})
|
|
170
|
+
return true
|
|
132
171
|
}
|
|
133
|
-
export function vote_remove_option(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
172
|
+
export function vote_remove_option(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
173
|
+
options:string[], removeall?:boolean, passport?:PassportObject) : boolean {
|
|
174
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
175
|
+
if (!removeall && !options) return false;
|
|
176
|
+
if (options && !IsValidArray(options, IsValidAddress)) return false;
|
|
177
|
+
|
|
134
178
|
if (passport) {
|
|
135
179
|
if (removeall) {
|
|
136
180
|
txb.moveCall({
|
|
137
181
|
target:PROTOCOL.VoteFn('agrees_remove_all_with_passport') as FnCallType,
|
|
138
|
-
arguments:[passport, vote, permission]
|
|
182
|
+
arguments:[passport, TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
139
183
|
})
|
|
140
184
|
} else {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
})
|
|
146
|
-
})
|
|
185
|
+
txb.moveCall({
|
|
186
|
+
target:PROTOCOL.VoteFn('agrees_remove_with_passport') as FnCallType,
|
|
187
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(options))), TXB_OBJECT(txb, permission)]
|
|
188
|
+
})
|
|
147
189
|
}
|
|
148
190
|
} else {
|
|
149
191
|
if (removeall) {
|
|
150
192
|
txb.moveCall({
|
|
151
193
|
target:PROTOCOL.VoteFn('agrees_remove_all') as FnCallType,
|
|
152
|
-
arguments:[vote, permission]
|
|
194
|
+
arguments:[TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
153
195
|
})
|
|
154
196
|
} else {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
arguments:[vote, txb.pure(name_data(option)), permission]
|
|
159
|
-
})
|
|
197
|
+
txb.moveCall({
|
|
198
|
+
target:PROTOCOL.VoteFn('agrees_remove') as FnCallType,
|
|
199
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(options))), TXB_OBJECT(txb, permission)]
|
|
160
200
|
})
|
|
161
201
|
}
|
|
162
202
|
}
|
|
203
|
+
return true
|
|
163
204
|
}
|
|
164
|
-
export function vote_set_max_choice_count(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
205
|
+
export function vote_set_max_choice_count(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
206
|
+
max_choice_count:number, passport?:PassportObject) : boolean {
|
|
207
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
208
|
+
if (!IsValidUint(max_choice_count) || max_choice_count > MAX_CHOICE_COUNT) return false;
|
|
209
|
+
|
|
165
210
|
if (passport) {
|
|
166
211
|
txb.moveCall({
|
|
167
212
|
target:PROTOCOL.VoteFn('max_choice_count_set_with_passport') as FnCallType,
|
|
168
|
-
arguments:[passport, vote, txb.pure(max_choice_count, BCS.U8), permission]
|
|
213
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(max_choice_count, BCS.U8), TXB_OBJECT(txb, permission)]
|
|
169
214
|
})
|
|
170
215
|
} else {
|
|
171
216
|
txb.moveCall({
|
|
172
217
|
target:PROTOCOL.VoteFn('max_choice_count_set') as FnCallType,
|
|
173
|
-
arguments:[vote, txb.pure(max_choice_count, BCS.U8), permission]
|
|
218
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(max_choice_count, BCS.U8), TXB_OBJECT(txb, permission)]
|
|
174
219
|
})
|
|
175
220
|
}
|
|
221
|
+
return true
|
|
176
222
|
}
|
|
177
|
-
export function vote_open_voting(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
223
|
+
export function vote_open_voting(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
224
|
+
passport?:PassportObject) : boolean {
|
|
225
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
178
226
|
if (passport) {
|
|
179
227
|
txb.moveCall({
|
|
180
228
|
target:PROTOCOL.VoteFn('options_locked_for_voting_with_passport') as FnCallType,
|
|
181
|
-
arguments:[passport, vote, permission]
|
|
229
|
+
arguments:[passport, TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
182
230
|
})
|
|
183
231
|
} else {
|
|
184
232
|
txb.moveCall({
|
|
185
233
|
target:PROTOCOL.VoteFn('options_locked_for_voting') as FnCallType,
|
|
186
|
-
arguments:[vote, permission]
|
|
234
|
+
arguments:[TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
187
235
|
})
|
|
188
236
|
}
|
|
237
|
+
return true
|
|
189
238
|
}
|
|
190
239
|
|
|
191
|
-
export function vote_lock_deadline(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
240
|
+
export function vote_lock_deadline(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
241
|
+
passport?:PassportObject) : boolean {
|
|
242
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
192
243
|
if (passport) {
|
|
193
244
|
txb.moveCall({
|
|
194
245
|
target:PROTOCOL.VoteFn('deadline_locked_with_passport') as FnCallType,
|
|
195
|
-
arguments:[passport, vote, txb.object(CLOCK_OBJECT), permission]
|
|
246
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)]
|
|
196
247
|
})
|
|
197
248
|
} else {
|
|
198
249
|
txb.moveCall({
|
|
199
250
|
target:PROTOCOL.VoteFn('deadline_locked') as FnCallType,
|
|
200
|
-
arguments:[vote, txb.object(CLOCK_OBJECT), permission]
|
|
251
|
+
arguments:[TXB_OBJECT(txb, vote), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)]
|
|
201
252
|
})
|
|
202
253
|
}
|
|
254
|
+
return true
|
|
203
255
|
}
|
|
204
256
|
|
|
205
|
-
export function vote_expand_deadline(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
257
|
+
export function vote_expand_deadline(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
258
|
+
minutes_expand:number, passport?:PassportObject) : boolean {
|
|
259
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
260
|
+
if (!IsValidUint(minutes_expand)) return false;
|
|
261
|
+
|
|
206
262
|
if (passport) {
|
|
207
263
|
txb.moveCall({
|
|
208
264
|
target:PROTOCOL.VoteFn('deadline_expand_with_passport') as FnCallType,
|
|
209
|
-
arguments:[passport, vote, txb.pure(minutes_expand, BCS.U64), permission]
|
|
265
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(minutes_expand, BCS.U64), TXB_OBJECT(txb, permission)]
|
|
210
266
|
})
|
|
211
267
|
} else {
|
|
212
268
|
txb.moveCall({
|
|
213
269
|
target:PROTOCOL.VoteFn('deadline_expand') as FnCallType,
|
|
214
|
-
arguments:[vote, txb.pure(minutes_expand, BCS.U64), permission]
|
|
270
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(minutes_expand, BCS.U64), TXB_OBJECT(txb, permission)]
|
|
215
271
|
})
|
|
216
272
|
}
|
|
273
|
+
return true
|
|
217
274
|
}
|
|
218
|
-
export function vote_lock_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
275
|
+
export function vote_lock_guard(txb:TransactionBlock, vote:VoteObject, permission:PermissionObject,
|
|
276
|
+
passport?:PassportObject) : boolean {
|
|
277
|
+
if (!IsValidObjects([vote, permission])) return false;
|
|
219
278
|
if (passport) {
|
|
220
279
|
txb.moveCall({
|
|
221
280
|
target:PROTOCOL.VoteFn('guard_lock_with_passport') as FnCallType,
|
|
222
|
-
arguments:[passport, vote, permission]
|
|
281
|
+
arguments:[passport, TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
223
282
|
})
|
|
224
283
|
} else {
|
|
225
284
|
txb.moveCall({
|
|
226
285
|
target:PROTOCOL.VoteFn('guard_lock') as FnCallType,
|
|
227
|
-
arguments:[vote, permission]
|
|
286
|
+
arguments:[TXB_OBJECT(txb, vote), TXB_OBJECT(txb, permission)]
|
|
228
287
|
})
|
|
229
288
|
}
|
|
289
|
+
return true
|
|
230
290
|
}
|
|
231
291
|
|
|
232
|
-
export function agree(txb:TransactionBlock, vote:VoteObject, options:string[], passport?:PassportObject) {
|
|
292
|
+
export function agree(txb:TransactionBlock, vote:VoteObject, options:string[], passport?:PassportObject) : boolean {
|
|
293
|
+
if (!IsValidObjects([vote])) return false;
|
|
294
|
+
if (!options || options.length > MAX_CHOICE_COUNT) return false;
|
|
295
|
+
|
|
233
296
|
if (passport) {
|
|
234
297
|
txb.moveCall({
|
|
235
298
|
target:PROTOCOL.VoteFn('vote_with_passport') as FnCallType,
|
|
236
|
-
arguments:[passport, vote, txb.pure(options
|
|
299
|
+
arguments:[passport, TXB_OBJECT(txb, vote), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(options)))]
|
|
237
300
|
})
|
|
238
301
|
} else {
|
|
239
302
|
txb.moveCall({
|
|
240
303
|
target:PROTOCOL.VoteFn('vote') as FnCallType,
|
|
241
|
-
arguments:[vote, txb.pure(options
|
|
304
|
+
arguments:[TXB_OBJECT(txb, vote), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(options)))]
|
|
242
305
|
})
|
|
243
306
|
}
|
|
307
|
+
return true
|
|
244
308
|
}
|
|
245
309
|
|
|
246
|
-
export function change_permission(txb:TransactionBlock, vote:VoteObject, old_permission:PermissionObject,
|
|
310
|
+
export function change_permission(txb:TransactionBlock, vote:VoteObject, old_permission:PermissionObject,
|
|
311
|
+
new_permission:PermissionObject) : boolean {
|
|
312
|
+
if (!IsValidObjects([vote, old_permission, new_permission])) return false;
|
|
247
313
|
txb.moveCall({
|
|
248
314
|
target:PROTOCOL.VoteFn('permission_set') as FnCallType,
|
|
249
|
-
arguments: [vote, old_permission, new_permission],
|
|
315
|
+
arguments: [TXB_OBJECT(txb, vote), TXB_OBJECT(txb, old_permission), TXB_OBJECT(txb, new_permission)],
|
|
250
316
|
})
|
|
317
|
+
return true
|
|
251
318
|
}
|