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/demand.ts
CHANGED
|
@@ -1,173 +1,217 @@
|
|
|
1
|
-
import { SuiClient, getFullnodeUrl, SuiObjectResponse } from '@mysten/sui.js/client';
|
|
2
1
|
import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
3
2
|
import { BCS } from '@mysten/bcs';
|
|
4
|
-
import { CLOCK_OBJECT, FnCallType, PROTOCOL,
|
|
5
|
-
|
|
6
|
-
import { verify, PassportObject} from './passport'
|
|
7
|
-
import { PermissionIndex, PermissionObject } from './permission'
|
|
8
|
-
import { ServiceObject } from './service'
|
|
9
|
-
|
|
10
|
-
export type DemandAddress = TransactionResult;
|
|
11
|
-
export type DemandObject = TransactionResult;
|
|
3
|
+
import { CLOCK_OBJECT, FnCallType, IsValidDesription, PROTOCOL, PassportObject, PermissionObject, IsValidArgType, GuardObject,
|
|
4
|
+
DemandAddress, DemandObject, TXB_OBJECT, IsValidUint, IsValidAddress, TxbObject, IsValidObjects, ServiceObject } from './protocol';
|
|
12
5
|
|
|
13
6
|
export const MAX_EARNEST_COUNT = 200;
|
|
14
7
|
export const MAX_PRESENTERS_COUNT = 200;
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
|
|
10
|
+
export function demand(earnest_type:string, txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
11
|
+
earnest:TransactionResult, passport?:PassportObject) : DemandObject | boolean {
|
|
12
|
+
if (!IsValidObjects([permission, earnest])) return false;
|
|
13
|
+
if (!IsValidDesription(description) || !IsValidArgType(earnest_type)) return false;
|
|
14
|
+
|
|
17
15
|
if (passport) {
|
|
18
16
|
return txb.moveCall({
|
|
19
17
|
target:PROTOCOL.DemandFn('new_with_passport') as FnCallType,
|
|
20
|
-
arguments:[passport, txb.pure(
|
|
18
|
+
arguments:[passport, txb.pure(description), earnest, TXB_OBJECT(txb, permission)],
|
|
21
19
|
typeArguments:[earnest_type],
|
|
22
20
|
})
|
|
23
21
|
} else {
|
|
24
22
|
return txb.moveCall({
|
|
25
23
|
target:PROTOCOL.DemandFn('new') as FnCallType,
|
|
26
|
-
arguments:[txb.pure(
|
|
24
|
+
arguments:[txb.pure(description), earnest, TXB_OBJECT(txb, permission)],
|
|
27
25
|
typeArguments:[earnest_type],
|
|
28
26
|
})
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
export function launch(earnest_type:string, txb:TransactionBlock, demand:DemandObject) : DemandAddress {
|
|
30
|
+
export function launch(earnest_type:string, txb:TransactionBlock, demand:DemandObject) : DemandAddress | boolean {
|
|
31
|
+
if (!IsValidObjects([demand])) return false;
|
|
32
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
33
33
|
return txb.moveCall({
|
|
34
34
|
target:PROTOCOL.DemandFn('create') as FnCallType,
|
|
35
|
-
arguments:[demand],
|
|
35
|
+
arguments:[TXB_OBJECT(txb, demand)],
|
|
36
36
|
typeArguments:[earnest_type],
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function destroy(earnest_type:string, txb:TransactionBlock, demand:DemandObject) {
|
|
41
|
-
return
|
|
40
|
+
export function destroy(earnest_type:string, txb:TransactionBlock, demand:DemandObject) : boolean {
|
|
41
|
+
if (!IsValidObjects([demand])) return false;
|
|
42
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
43
|
+
txb.moveCall({
|
|
42
44
|
target:PROTOCOL.DemandFn('destroy') as FnCallType,
|
|
43
|
-
arguments: [demand],
|
|
45
|
+
arguments: [TXB_OBJECT(txb, demand)],
|
|
44
46
|
typeArguments:[earnest_type]
|
|
45
|
-
})
|
|
47
|
+
})
|
|
48
|
+
return true
|
|
46
49
|
}
|
|
47
|
-
export function demand_refund(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:
|
|
50
|
+
export function demand_refund(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:PermissionObject,
|
|
51
|
+
passport?:PassportObject) : boolean {
|
|
52
|
+
if (!IsValidObjects([demand, permission])) return false;
|
|
53
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
54
|
+
|
|
48
55
|
if (passport) {
|
|
49
56
|
txb.moveCall({
|
|
50
57
|
target:PROTOCOL.DemandFn('refund_with_passport') as FnCallType,
|
|
51
|
-
arguments:[passport, demand, txb.object(CLOCK_OBJECT), permission],
|
|
58
|
+
arguments:[passport, TXB_OBJECT(txb, demand), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
52
59
|
typeArguments:[earnest_type],
|
|
53
60
|
})
|
|
54
61
|
} else {
|
|
55
62
|
txb.moveCall({
|
|
56
63
|
target:PROTOCOL.DemandFn('refund') as FnCallType,
|
|
57
|
-
arguments:[demand, txb.object(CLOCK_OBJECT), permission],
|
|
64
|
+
arguments:[TXB_OBJECT(txb, demand), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
58
65
|
typeArguments:[earnest_type],
|
|
59
66
|
})
|
|
60
67
|
}
|
|
68
|
+
return true
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
export function demand_expand_time(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:
|
|
64
|
-
minutes_duration:number, passport?:PassportObject) {
|
|
71
|
+
export function demand_expand_time(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:PermissionObject,
|
|
72
|
+
minutes_duration:number, passport?:PassportObject) : boolean {
|
|
73
|
+
if (!IsValidObjects([demand, permission])) return false;
|
|
74
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
75
|
+
if (!IsValidUint(minutes_duration)) return false;
|
|
76
|
+
|
|
65
77
|
if (passport) {
|
|
66
|
-
|
|
78
|
+
txb.moveCall({
|
|
67
79
|
target:PROTOCOL.DemandFn('time_expand_with_passport') as FnCallType,
|
|
68
|
-
arguments:[passport, demand, txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), permission],
|
|
80
|
+
arguments:[passport, TXB_OBJECT(txb, demand), txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
69
81
|
typeArguments:[earnest_type],
|
|
70
82
|
})
|
|
71
83
|
} else {
|
|
72
|
-
|
|
84
|
+
txb.moveCall({
|
|
73
85
|
target:PROTOCOL.DemandFn('time_expand') as FnCallType,
|
|
74
|
-
arguments:[demand, txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), permission],
|
|
86
|
+
arguments:[TXB_OBJECT(txb, demand), txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), TXB_OBJECT(txb, permission)],
|
|
75
87
|
typeArguments:[earnest_type],
|
|
76
88
|
})
|
|
77
89
|
}
|
|
90
|
+
return true
|
|
78
91
|
}
|
|
79
92
|
|
|
80
|
-
export function demand_set_guard(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:
|
|
93
|
+
export function demand_set_guard(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:PermissionObject,
|
|
94
|
+
guard?:GuardObject, passport?:PassportObject) : boolean {
|
|
95
|
+
if (!IsValidObjects([demand, permission])) return false;
|
|
96
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
97
|
+
|
|
81
98
|
if (passport) {
|
|
82
99
|
if (guard) {
|
|
83
|
-
|
|
100
|
+
txb.moveCall({
|
|
84
101
|
target:PROTOCOL.DemandFn('guard_set_with_passport') as FnCallType,
|
|
85
|
-
arguments:[passport, demand, guard, permission],
|
|
102
|
+
arguments:[passport, TXB_OBJECT(txb, demand), TXB_OBJECT(txb, guard), TXB_OBJECT(txb, permission)],
|
|
86
103
|
typeArguments:[earnest_type],
|
|
87
104
|
})
|
|
88
105
|
} else {
|
|
89
|
-
|
|
106
|
+
txb.moveCall({
|
|
90
107
|
target:PROTOCOL.DemandFn('guard_none_with_passport') as FnCallType,
|
|
91
|
-
arguments:[passport, demand, permission],
|
|
108
|
+
arguments:[passport, TXB_OBJECT(txb, demand), TXB_OBJECT(txb, permission)],
|
|
92
109
|
typeArguments:[earnest_type],
|
|
93
110
|
})
|
|
94
111
|
}
|
|
95
112
|
} else {
|
|
96
113
|
if (guard) {
|
|
97
|
-
|
|
114
|
+
txb.moveCall({
|
|
98
115
|
target:PROTOCOL.DemandFn('guard_set') as FnCallType,
|
|
99
|
-
arguments:[demand, guard, permission],
|
|
116
|
+
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, guard), TXB_OBJECT(txb, permission)],
|
|
100
117
|
typeArguments:[earnest_type],
|
|
101
118
|
})
|
|
102
119
|
} else {
|
|
103
|
-
|
|
120
|
+
txb.moveCall({
|
|
104
121
|
target:PROTOCOL.DemandFn('guard_none') as FnCallType,
|
|
105
|
-
arguments:[demand, permission],
|
|
122
|
+
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, permission)],
|
|
106
123
|
typeArguments:[earnest_type],
|
|
107
124
|
})
|
|
108
125
|
}
|
|
109
126
|
}
|
|
127
|
+
return true
|
|
110
128
|
}
|
|
111
129
|
|
|
112
|
-
export function demand_set_description(earnest_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
130
|
+
export function demand_set_description(earnest_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
131
|
+
permission:PermissionObject, description:string, passport?:PassportObject) : boolean {
|
|
132
|
+
if (!IsValidObjects([demand, permission])) return false;
|
|
133
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
134
|
+
if (!IsValidDesription(description)) return false;
|
|
135
|
+
|
|
113
136
|
if (passport) {
|
|
114
137
|
txb.moveCall({
|
|
115
138
|
target:PROTOCOL.DemandFn('description_set_with_passport') as FnCallType,
|
|
116
|
-
arguments:[passport, demand, txb.pure(
|
|
139
|
+
arguments:[passport, TXB_OBJECT(txb, demand), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
117
140
|
typeArguments:[earnest_type],
|
|
118
141
|
})
|
|
119
142
|
} else {
|
|
120
143
|
txb.moveCall({
|
|
121
144
|
target:PROTOCOL.DemandFn('description_set') as FnCallType,
|
|
122
|
-
arguments:[demand, txb.pure(
|
|
145
|
+
arguments:[TXB_OBJECT(txb, demand), txb.pure(description), TXB_OBJECT(txb, permission)],
|
|
123
146
|
typeArguments:[earnest_type],
|
|
124
147
|
})
|
|
125
148
|
}
|
|
149
|
+
return true
|
|
126
150
|
}
|
|
127
151
|
|
|
128
|
-
export function demand_yes(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:
|
|
152
|
+
export function demand_yes(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:PermissionObject,
|
|
153
|
+
service:string, passport?:PassportObject) : boolean {
|
|
154
|
+
if (!IsValidObjects([demand, permission])) return false;
|
|
155
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
156
|
+
if (!IsValidAddress(service)) return false;
|
|
157
|
+
|
|
129
158
|
if (passport) {
|
|
130
159
|
txb.moveCall({
|
|
131
160
|
target:PROTOCOL.DemandFn('yes_with_passport') as FnCallType,
|
|
132
|
-
arguments:[passport, demand, txb.pure(service, BCS.ADDRESS), permission],
|
|
161
|
+
arguments:[passport, TXB_OBJECT(txb, demand), txb.pure(service, BCS.ADDRESS), TXB_OBJECT(txb, permission)],
|
|
133
162
|
typeArguments:[earnest_type],
|
|
134
163
|
})
|
|
135
164
|
} else {
|
|
136
165
|
txb.moveCall({
|
|
137
166
|
target:PROTOCOL.DemandFn('yes') as FnCallType,
|
|
138
|
-
arguments:[demand, txb.pure(service, BCS.ADDRESS), permission],
|
|
167
|
+
arguments:[TXB_OBJECT(txb, demand), txb.pure(service, BCS.ADDRESS), TXB_OBJECT(txb, permission)],
|
|
139
168
|
typeArguments:[earnest_type],
|
|
140
169
|
})
|
|
141
170
|
}
|
|
171
|
+
return true
|
|
142
172
|
}
|
|
143
173
|
|
|
144
|
-
export function deposit(earnest_type:string, txb:TransactionBlock, demand:DemandObject, earnest:
|
|
145
|
-
return
|
|
174
|
+
export function deposit(earnest_type:string, txb:TransactionBlock, demand:DemandObject, earnest:TxbObject) : boolean {
|
|
175
|
+
if (!IsValidObjects([demand, earnest])) return false;
|
|
176
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
177
|
+
txb.moveCall({
|
|
146
178
|
target:PROTOCOL.DemandFn('deposit') as FnCallType,
|
|
147
|
-
arguments:[demand, earnest],
|
|
179
|
+
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, earnest)],
|
|
148
180
|
typeArguments:[earnest_type],
|
|
149
181
|
})
|
|
182
|
+
return true
|
|
150
183
|
}
|
|
151
184
|
|
|
152
|
-
export function present(earnest_type:string, service_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
185
|
+
export function present(earnest_type:string, service_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
186
|
+
service:ServiceObject, tips:string, passport?:PassportObject) : boolean {
|
|
187
|
+
if (!IsValidObjects([demand, service])) return false;
|
|
188
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
189
|
+
if (!IsValidDesription(tips)) return false;
|
|
190
|
+
|
|
153
191
|
if (passport) {
|
|
154
|
-
|
|
192
|
+
txb.moveCall({
|
|
155
193
|
target:PROTOCOL.DemandFn('present_with_passport') as FnCallType,
|
|
156
|
-
arguments:[passport, demand, service, txb.pure(
|
|
194
|
+
arguments:[passport, TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips, BCS.STRING), ],
|
|
157
195
|
typeArguments:[earnest_type, service_type],
|
|
158
196
|
})
|
|
159
197
|
} else {
|
|
160
|
-
|
|
198
|
+
txb.moveCall({
|
|
161
199
|
target:PROTOCOL.DemandFn('present') as FnCallType,
|
|
162
|
-
arguments:[demand, service, txb.pure(
|
|
200
|
+
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips, BCS.STRING), ],
|
|
163
201
|
typeArguments:[earnest_type, service_type],
|
|
164
202
|
})
|
|
165
203
|
}
|
|
204
|
+
return true
|
|
166
205
|
}
|
|
167
|
-
export function change_permission(earnest_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
206
|
+
export function change_permission(earnest_type:string, txb:TransactionBlock, demand:DemandObject,
|
|
207
|
+
old_permission:PermissionObject, new_permission:PermissionObject) : boolean {
|
|
208
|
+
if (!IsValidObjects([demand, old_permission, new_permission])) return false;
|
|
209
|
+
if (!IsValidArgType(earnest_type)) return false;
|
|
210
|
+
|
|
168
211
|
txb.moveCall({
|
|
169
212
|
target:PROTOCOL.DemandFn('permission_set') as FnCallType,
|
|
170
|
-
arguments: [demand, old_permission, new_permission],
|
|
213
|
+
arguments: [TXB_OBJECT(txb, demand), TXB_OBJECT(txb, old_permission), TXB_OBJECT(txb, new_permission)],
|
|
171
214
|
typeArguments:[earnest_type]
|
|
172
215
|
})
|
|
216
|
+
return true
|
|
173
217
|
}
|
package/src/graphql.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
|
|
3
|
+
export const GRAPHQL_OBJECTS_TYPE = gql(`
|
|
4
|
+
query objects_type_version($filter:ObjectFilter!) {
|
|
5
|
+
objects(filter:$filter) {
|
|
6
|
+
nodes {
|
|
7
|
+
address
|
|
8
|
+
version
|
|
9
|
+
asMoveObject {
|
|
10
|
+
contents {
|
|
11
|
+
type {
|
|
12
|
+
repr
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`);
|
|
20
|
+
|
|
21
|
+
export const GRAPHQL_OBJECT = gql(`
|
|
22
|
+
query object($ObjectID:SuiAddress!) {
|
|
23
|
+
object(address:$ObjectID) {
|
|
24
|
+
address
|
|
25
|
+
asMoveObject {
|
|
26
|
+
contents {
|
|
27
|
+
json
|
|
28
|
+
type {
|
|
29
|
+
repr
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
dynamicFields {
|
|
34
|
+
pageInfo {
|
|
35
|
+
hasNextPage
|
|
36
|
+
endCursor
|
|
37
|
+
}
|
|
38
|
+
nodes {
|
|
39
|
+
name {
|
|
40
|
+
json
|
|
41
|
+
}
|
|
42
|
+
value {
|
|
43
|
+
... on MoveValue {
|
|
44
|
+
json
|
|
45
|
+
}
|
|
46
|
+
... on MoveObject {
|
|
47
|
+
contents {
|
|
48
|
+
json
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
|
|
58
|
+
export const GRAPHQL_OWNER = gql(`
|
|
59
|
+
query owner($ObjectID:SuiAddress!) {
|
|
60
|
+
owner (address: $ObjectID) {
|
|
61
|
+
address
|
|
62
|
+
dynamicFields {
|
|
63
|
+
pageInfo {
|
|
64
|
+
hasNextPage
|
|
65
|
+
endCursor
|
|
66
|
+
}
|
|
67
|
+
nodes {
|
|
68
|
+
name {
|
|
69
|
+
json
|
|
70
|
+
}
|
|
71
|
+
value {
|
|
72
|
+
... on MoveValue {
|
|
73
|
+
json
|
|
74
|
+
}
|
|
75
|
+
... on MoveObject {
|
|
76
|
+
contents {
|
|
77
|
+
json
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`);
|
|
86
|
+
|
|
87
|
+
export const GRAPHQL_OBJECTS = gql(`
|
|
88
|
+
query objects($filter:ObjectFilter!){
|
|
89
|
+
objects(filter:$filter) {
|
|
90
|
+
nodes {
|
|
91
|
+
address
|
|
92
|
+
asMoveObject {
|
|
93
|
+
contents {
|
|
94
|
+
json
|
|
95
|
+
type {
|
|
96
|
+
repr
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`);
|