wowok 1.0.4 → 1.0.6
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/dist/demand.js +2 -2
- package/dist/graphql.js +102 -0
- package/dist/guard.js +175 -41
- package/dist/index.js +46 -0
- package/dist/machine.js +17 -10
- package/dist/passport.js +54 -20
- package/dist/permission.js +8 -2
- package/dist/progress.js +62 -13
- package/dist/protocol.js +15 -7
- package/dist/repository.js +11 -14
- package/dist/reward.js +6 -5
- package/dist/service.js +9 -5
- package/dist/util.js +13 -1
- package/package.json +9 -4
- package/src/demand.ts +2 -2
- package/src/graphql.ts +103 -0
- package/src/guard.ts +191 -43
- package/src/index.ts +32 -0
- package/src/machine.ts +18 -12
- package/src/passport.ts +60 -26
- package/src/permission.ts +7 -2
- package/src/progress.ts +70 -15
- package/src/protocol.ts +16 -9
- package/src/repository.ts +17 -20
- package/src/reward.ts +12 -9
- package/src/service.ts +12 -8
- package/src/{util.ts → utils.ts} +18 -9
- package/src/vote.ts +1 -1
- package/src/address.graphql +0 -0
- package/src/object.graphql +0 -30
package/src/permission.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js
|
|
|
2
2
|
import { BCS } from '@mysten/bcs';
|
|
3
3
|
import { FnCallType, PROTOCOL, TxbObject, PermissionObject, PermissionAddress, TXB_OBJECT, IsValidDesription,
|
|
4
4
|
IsValidObjects, IsValidAddress, IsValidArray, GuardObject, IsValidUint} from './protocol';
|
|
5
|
-
import { array_unique } from './
|
|
5
|
+
import { array_unique } from './utils';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export const MAX_ADMIN_COUNT = 64;
|
|
@@ -93,9 +93,11 @@ export const IsValidUserDefinedIndex = (index:number) : boolean => {
|
|
|
93
93
|
return index >= PermissionIndex.user_defined_start && IsValidUint(index)
|
|
94
94
|
}
|
|
95
95
|
export const IsValidPermissionIndex = (index:PermissionIndexType) : boolean => {
|
|
96
|
+
//console.log(index)
|
|
96
97
|
if (Object.values(PermissionIndex).includes(index)) {
|
|
97
98
|
return true
|
|
98
99
|
}
|
|
100
|
+
//console.log(Object.keys(PermissionIndex))
|
|
99
101
|
return IsValidUserDefinedIndex(index);
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -139,8 +141,11 @@ export function add_entity(txb:TransactionBlock, permission:PermissionObject, en
|
|
|
139
141
|
|
|
140
142
|
let bValid = true;
|
|
141
143
|
let e = entities.forEach((v) => {
|
|
142
|
-
if (!IsValidArray(v.permissions, IsValidPermissionIndex)) bValid = false;
|
|
143
144
|
if (!IsValidAddress(v.entity_address)) bValid = false;
|
|
145
|
+
v.permissions.forEach((p) => {
|
|
146
|
+
if (!IsValidPermissionIndex(p.index)) bValid = false;
|
|
147
|
+
if (p?.guard && !IsValidObjects([p.guard])) bValid = false;
|
|
148
|
+
})
|
|
144
149
|
});
|
|
145
150
|
if (!bValid) return false;
|
|
146
151
|
|
package/src/progress.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { BCS } from '@mysten/bcs';
|
|
3
3
|
import { FnCallType, PROTOCOL, PermissionObject, RepositoryObject, PassportObject, MachineObject, TXB_OBJECT,
|
|
4
|
-
ProgressObject, ProgressAddress, IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidObjects
|
|
5
|
-
|
|
4
|
+
ProgressObject, ProgressAddress, IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidObjects,
|
|
5
|
+
IsValidInt} from './protocol';
|
|
6
|
+
import { BCS_CONVERT, array_unique } from './utils'
|
|
6
7
|
|
|
7
8
|
export const MAX_NAMED_OPERATOR_COUNT = 100;
|
|
8
9
|
|
|
@@ -115,14 +116,62 @@ export function progress_set_context_repository(txb:TransactionBlock, machine:Ma
|
|
|
115
116
|
return true
|
|
116
117
|
}
|
|
117
118
|
export function progress_unhold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject,
|
|
118
|
-
progress:ProgressObject, next:ProgressNext) : boolean {
|
|
119
|
+
progress:ProgressObject, next:ProgressNext, passport?:PassportObject) : boolean {
|
|
119
120
|
if (!IsValidObjects([machine, permission, progress])) return false;
|
|
120
121
|
if (!IsValidProgressNext(next)) return false;
|
|
122
|
+
|
|
123
|
+
if (passport) {
|
|
124
|
+
txb.moveCall({
|
|
125
|
+
target:PROTOCOL.ProgressFn('unhold_with_passport') as FnCallType,
|
|
126
|
+
arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), TXB_OBJECT(txb, permission)],
|
|
127
|
+
})
|
|
128
|
+
} else {
|
|
129
|
+
txb.moveCall({
|
|
130
|
+
target:PROTOCOL.ProgressFn('unhold') as FnCallType,
|
|
131
|
+
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), TXB_OBJECT(txb, permission)],
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return true
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type ParentProgress = {
|
|
139
|
+
parent_progress_id: string;
|
|
140
|
+
parent_session_id: number;
|
|
141
|
+
}
|
|
142
|
+
export function progress_parent(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
|
|
143
|
+
parent_progress?:ParentProgress, passport?:PassportObject) : boolean {
|
|
144
|
+
if (!IsValidObjects([machine, permission, progress])) return false;
|
|
145
|
+
if (parent_progress && (!IsValidAddress(parent_progress.parent_progress_id) || !IsValidInt(parent_progress.parent_session_id))) return false;
|
|
146
|
+
|
|
147
|
+
if (passport) {
|
|
148
|
+
if (parent_progress) {
|
|
149
|
+
txb.moveCall({
|
|
150
|
+
target:PROTOCOL.ProgressFn('parent_set_with_passport') as FnCallType,
|
|
151
|
+
arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(parent_progress.parent_progress_id, BCS.ADDRESS),
|
|
152
|
+
txb.pure(parent_progress.parent_session_id, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
153
|
+
})
|
|
154
|
+
} else {
|
|
155
|
+
txb.moveCall({
|
|
156
|
+
target:PROTOCOL.ProgressFn('parent_none_with_passport') as FnCallType,
|
|
157
|
+
arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
if (parent_progress) {
|
|
162
|
+
txb.moveCall({
|
|
163
|
+
target:PROTOCOL.ProgressFn('parent_set') as FnCallType,
|
|
164
|
+
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(parent_progress.parent_progress_id, BCS.ADDRESS),
|
|
165
|
+
txb.pure(parent_progress.parent_session_id, BCS.U64), TXB_OBJECT(txb, permission)],
|
|
166
|
+
})
|
|
167
|
+
} else {
|
|
168
|
+
txb.moveCall({
|
|
169
|
+
target:PROTOCOL.ProgressFn('parent_none') as FnCallType,
|
|
170
|
+
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
}
|
|
121
174
|
|
|
122
|
-
txb.moveCall({
|
|
123
|
-
target:PROTOCOL.ProgressFn('unhold') as FnCallType,
|
|
124
|
-
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), TXB_OBJECT(txb, permission)],
|
|
125
|
-
})
|
|
126
175
|
return true
|
|
127
176
|
}
|
|
128
177
|
|
|
@@ -135,27 +184,31 @@ function IsValidProgressNext(next:ProgressNext) : boolean {
|
|
|
135
184
|
}
|
|
136
185
|
|
|
137
186
|
export function next(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
|
|
138
|
-
next:ProgressNext, deliverables_address?:string, passport?:PassportObject) : boolean {
|
|
187
|
+
next:ProgressNext, deliverables_address?:string, sub_progress_id?:string, passport?:PassportObject) : boolean {
|
|
139
188
|
if (!IsValidObjects([machine, permission, progress])) return false;
|
|
140
189
|
if (!IsValidProgressNext(next)) return false;
|
|
141
190
|
if (deliverables_address && !IsValidAddress(deliverables_address)) return false;
|
|
191
|
+
if (sub_progress_id && !IsValidAddress(sub_progress_id)) return false;
|
|
142
192
|
|
|
143
193
|
let diliverable = deliverables_address? txb.pure(BCS_CONVERT.ser_option_address(deliverables_address)) : OptionNone(txb)
|
|
194
|
+
let sub = sub_progress_id? txb.pure(BCS_CONVERT.ser_option_address(sub_progress_id)) : OptionNone(txb)
|
|
195
|
+
|
|
144
196
|
if (passport) {
|
|
145
197
|
txb.moveCall({
|
|
146
|
-
target:PROTOCOL.ProgressFn('
|
|
147
|
-
arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name),
|
|
148
|
-
txb.pure(next.forward), diliverable, TXB_OBJECT(txb, permission)],
|
|
198
|
+
target:PROTOCOL.ProgressFn('next_with_passport') as FnCallType,
|
|
199
|
+
arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name, BCS.STRING),
|
|
200
|
+
txb.pure(next.forward, BCS.STRING), diliverable, sub, TXB_OBJECT(txb, permission)],
|
|
149
201
|
})
|
|
150
202
|
} else {
|
|
151
203
|
txb.moveCall({
|
|
152
|
-
target:PROTOCOL.ProgressFn('
|
|
153
|
-
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name),
|
|
154
|
-
txb.pure(next.forward), diliverable, TXB_OBJECT(txb, permission)],
|
|
204
|
+
target:PROTOCOL.ProgressFn('next') as FnCallType,
|
|
205
|
+
arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name, BCS.STRING),
|
|
206
|
+
txb.pure(next.forward, BCS.STRING), diliverable, sub, TXB_OBJECT(txb, permission)],
|
|
155
207
|
})
|
|
156
208
|
}
|
|
157
209
|
return true
|
|
158
210
|
}
|
|
211
|
+
|
|
159
212
|
export function hold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
|
|
160
213
|
next:ProgressNext, hold:boolean) : boolean {
|
|
161
214
|
if (!IsValidObjects([machine, permission, progress])) return false;
|
|
@@ -167,4 +220,6 @@ export function hold(txb:TransactionBlock, machine:MachineObject, permission:Per
|
|
|
167
220
|
txb.pure(next.forward), txb.pure(hold, BCS.BOOL), TXB_OBJECT(txb, permission)],
|
|
168
221
|
})
|
|
169
222
|
return true
|
|
170
|
-
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
package/src/protocol.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SuiClient, SuiObjectResponse, SuiObjectDataOptions, SuiTransactionBlock
|
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
4
4
|
import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
|
|
5
5
|
import { TransactionBlock, Inputs, type TransactionResult, type TransactionArgument } from '@mysten/sui.js/transactions';
|
|
6
|
-
import { capitalize } from './
|
|
6
|
+
import { capitalize } from './utils'
|
|
7
7
|
|
|
8
8
|
export const MAX_DESCRIPTION_LENGTH = 1024;
|
|
9
9
|
export const MAX_NAME_LENGTH = 64;
|
|
@@ -143,6 +143,7 @@ export class Protocol {
|
|
|
143
143
|
protected package = '';
|
|
144
144
|
protected signer = '';
|
|
145
145
|
protected everyone_guard = '';
|
|
146
|
+
protected graphql = '';
|
|
146
147
|
|
|
147
148
|
constructor(network:ENTRYPOINT=ENTRYPOINT.localnet, signer="0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f") {
|
|
148
149
|
this.signer = signer;
|
|
@@ -158,8 +159,9 @@ export class Protocol {
|
|
|
158
159
|
case ENTRYPOINT.devnet:
|
|
159
160
|
break;
|
|
160
161
|
case ENTRYPOINT.testnet:
|
|
161
|
-
this.package = "
|
|
162
|
+
this.package = "0x877375bc3bde063e4b95f428df218af7faaeef431993f4a68f2dfa5ceb8acb2e";
|
|
162
163
|
this.everyone_guard = "0x78a41fcc4f566360839613f6b917fb101ae015e56b43143f496f265b6422fddc";
|
|
164
|
+
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
163
165
|
break;
|
|
164
166
|
case ENTRYPOINT.mainnet:
|
|
165
167
|
break;
|
|
@@ -167,6 +169,8 @@ export class Protocol {
|
|
|
167
169
|
}
|
|
168
170
|
Package(): string { return this.package }
|
|
169
171
|
EveryoneGuard(): string { return this.everyone_guard }
|
|
172
|
+
GraphqlUrl() : string { return this.graphql }
|
|
173
|
+
|
|
170
174
|
NetworkUrl() : string {
|
|
171
175
|
switch(this.network) {
|
|
172
176
|
case ENTRYPOINT.localnet:
|
|
@@ -179,6 +183,7 @@ export class Protocol {
|
|
|
179
183
|
return "https://fullnode.mainnet.sui.io:443";
|
|
180
184
|
}; return "";
|
|
181
185
|
};
|
|
186
|
+
|
|
182
187
|
MachineFn = (fn:any) => { return `${this.package}::${MODULES.machine}::${fn}`};
|
|
183
188
|
NodeFn = (fn: any) => { return `${this.package}::${MODULES.node}::${fn}`};
|
|
184
189
|
ProgressFn = (fn:any) => { return `${this.package}::${MODULES.progress}::${fn}`};
|
|
@@ -207,11 +212,12 @@ export class Protocol {
|
|
|
207
212
|
}
|
|
208
213
|
return res;
|
|
209
214
|
}
|
|
210
|
-
Sign_Excute = async (exes: (txb:TransactionBlock, param:any) => void, priv_key:string, param?:any, options:SuiTransactionBlockResponseOptions={showObjectChanges:true}) : Promise<SuiTransactionBlockResponse> => {
|
|
215
|
+
Sign_Excute = async (exes: ((txb:TransactionBlock, param:any) => void)[], priv_key:string, param?:any, options:SuiTransactionBlockResponseOptions={showObjectChanges:true}) : Promise<SuiTransactionBlockResponse> => {
|
|
211
216
|
const client = new SuiClient({ url: PROTOCOL.NetworkUrl() });
|
|
212
217
|
const txb = new TransactionBlock();
|
|
213
|
-
|
|
214
|
-
exes(txb, param);
|
|
218
|
+
|
|
219
|
+
exes.forEach((e) => { e(txb, param) });
|
|
220
|
+
|
|
215
221
|
const privkey = fromHEX(priv_key);
|
|
216
222
|
const keypair = Ed25519Keypair.fromSecretKey(privkey);
|
|
217
223
|
|
|
@@ -229,8 +235,9 @@ export type Query_Param = {
|
|
|
229
235
|
callback: (response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions)=>void;
|
|
230
236
|
data?: any; // response data filted by callback
|
|
231
237
|
};
|
|
232
|
-
|
|
233
|
-
|
|
234
238
|
export const PROTOCOL = new Protocol();
|
|
235
|
-
export const
|
|
236
|
-
export const
|
|
239
|
+
export const SUI_TYPE = '0x2::coin::Coin<0x2::sui::SUI>';
|
|
240
|
+
export const WOWOK_TYPE = () => {'0x2::coin::Coin<' + PROTOCOL.Package() + '::wowok::WOWOK'};
|
|
241
|
+
|
|
242
|
+
export const OBJECTS_TYPE_PREFIX = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) => { return PROTOCOL.Package() + '::' + key + '::'; })
|
|
243
|
+
export const OBJECTS_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) => { let i = PROTOCOL.Package() + '::' + key + '::'; return i + capitalize(key); })
|
package/src/repository.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { BCS } from '@mysten/bcs';
|
|
3
3
|
import { FnCallType, PROTOCOL, ValueType, IsValidDesription, IsValidAddress, IsValidArray, OptionNone,
|
|
4
|
-
RepositoryObject, RepositoryAddress, PermissionObject, TXB_OBJECT, PassportObject, IsValidObjects
|
|
4
|
+
RepositoryObject, RepositoryAddress, PermissionObject, TXB_OBJECT, PassportObject, IsValidObjects,
|
|
5
|
+
IsValidInt} from './protocol';
|
|
5
6
|
import { IsValidPermissionIndex, PermissionIndexType } from './permission'
|
|
6
|
-
import { BCS_CONVERT, array_unique } from './
|
|
7
|
+
import { BCS_CONVERT, array_unique } from './utils';
|
|
7
8
|
|
|
8
9
|
export const MAX_POLICY_COUNT = 1000;
|
|
9
10
|
export const MAX_KEY_LENGTH = 128;
|
|
@@ -33,7 +34,7 @@ export type Repository_Policy_Data = {
|
|
|
33
34
|
}
|
|
34
35
|
export type Repository_Value = {
|
|
35
36
|
address: string; // UID: address or objectid
|
|
36
|
-
|
|
37
|
+
bcsBytes: Uint8Array;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export function repository(txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
@@ -70,14 +71,14 @@ export function destroy(txb:TransactionBlock, repository:RepositoryObject) : boo
|
|
|
70
71
|
})
|
|
71
72
|
return true
|
|
72
73
|
}
|
|
74
|
+
|
|
73
75
|
export function add_data(txb:TransactionBlock, repository:RepositoryObject, permission:PermissionObject, data:Repository_Policy_Data) : boolean {
|
|
74
76
|
if (!IsValidObjects([repository, permission])) return false;
|
|
75
77
|
if (!IsValidKey(data.key)) return false;
|
|
76
78
|
let bValid = true;
|
|
77
79
|
data.data.forEach((value) => {
|
|
78
|
-
if(!
|
|
79
|
-
|
|
80
|
-
}
|
|
80
|
+
if (!IsValidAddress(value.address)) bValid = false;
|
|
81
|
+
if (!IsValidValue(value.bcsBytes)) bValid = false;
|
|
81
82
|
});
|
|
82
83
|
if (!bValid) return false;
|
|
83
84
|
|
|
@@ -88,7 +89,7 @@ export function add_data(txb:TransactionBlock, repository:RepositoryObject, perm
|
|
|
88
89
|
txb.pure(d.address, BCS.ADDRESS),
|
|
89
90
|
txb.pure(data.key),
|
|
90
91
|
txb.pure(data.value_type, BCS.U8),
|
|
91
|
-
txb.pure([...d.
|
|
92
|
+
txb.pure([...d.bcsBytes], 'vector<u8>'),
|
|
92
93
|
TXB_OBJECT(txb, permission),
|
|
93
94
|
],
|
|
94
95
|
}))
|
|
@@ -98,7 +99,7 @@ export function add_data(txb:TransactionBlock, repository:RepositoryObject, perm
|
|
|
98
99
|
arguments:[TXB_OBJECT(txb, repository),
|
|
99
100
|
txb.pure(d.address, BCS.ADDRESS),
|
|
100
101
|
txb.pure(data.key),
|
|
101
|
-
txb.pure([...d.
|
|
102
|
+
txb.pure([...d.bcsBytes], 'vector<u8>'),
|
|
102
103
|
TXB_OBJECT(txb, permission),
|
|
103
104
|
],
|
|
104
105
|
}))
|
|
@@ -172,12 +173,10 @@ export function repository_remove_policies(txb:TransactionBlock, repository:Repo
|
|
|
172
173
|
arguments:[passport, TXB_OBJECT(txb, repository), TXB_OBJECT(txb, permission)]
|
|
173
174
|
})
|
|
174
175
|
} else {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
})
|
|
180
|
-
})
|
|
176
|
+
txb.moveCall({
|
|
177
|
+
target:PROTOCOL.RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
178
|
+
arguments:[passport, TXB_OBJECT(txb, repository), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(policy_keys))), TXB_OBJECT(txb, permission)]
|
|
179
|
+
})
|
|
181
180
|
}
|
|
182
181
|
} else {
|
|
183
182
|
if (removeall) {
|
|
@@ -186,12 +185,10 @@ export function repository_remove_policies(txb:TransactionBlock, repository:Repo
|
|
|
186
185
|
arguments:[TXB_OBJECT(txb, repository), TXB_OBJECT(txb, permission)]
|
|
187
186
|
})
|
|
188
187
|
} else {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
194
|
-
})
|
|
188
|
+
txb.moveCall({
|
|
189
|
+
target:PROTOCOL.RepositoryFn('policy_remove') as FnCallType,
|
|
190
|
+
arguments:[TXB_OBJECT(txb, repository), txb.pure(BCS_CONVERT.ser_vector_string(array_unique(policy_keys))), TXB_OBJECT(txb, permission)]
|
|
191
|
+
})
|
|
195
192
|
}
|
|
196
193
|
}
|
|
197
194
|
return true;
|
package/src/reward.ts
CHANGED
|
@@ -2,10 +2,15 @@ import { TransactionBlock, type TransactionResult } from '@mysten/sui.js/transac
|
|
|
2
2
|
import { BCS} from '@mysten/bcs';
|
|
3
3
|
import { CLOCK_OBJECT, FnCallType, GuardObject, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidObjects, IsValidUint, PROTOCOL, PassportObject, PermissionObject,
|
|
4
4
|
RewardAddress, RewardObject, TXB_OBJECT} from './protocol';
|
|
5
|
-
import { array_unique } from './
|
|
5
|
+
import { array_unique } from './utils';
|
|
6
6
|
|
|
7
7
|
export type Reward = TransactionResult;
|
|
8
8
|
export type CoinReward = TransactionResult;
|
|
9
|
+
export type RewardGuardPortions = {
|
|
10
|
+
guard:GuardObject;
|
|
11
|
+
portions:number;
|
|
12
|
+
}
|
|
13
|
+
export const MAX_PORTIONS_COUNT = 255;
|
|
9
14
|
|
|
10
15
|
export function reward(reward_type:string, txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
11
16
|
minutes_duration:number, passport?:PassportObject) : RewardObject | boolean {
|
|
@@ -90,10 +95,7 @@ export function reward_expand_time(reward_type:string, txb:TransactionBlock, rew
|
|
|
90
95
|
}
|
|
91
96
|
return true
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
guard:GuardObject;
|
|
95
|
-
portions:number;
|
|
96
|
-
}
|
|
98
|
+
|
|
97
99
|
export function reward_add_guard(reward_type:string, txb:TransactionBlock, reward:RewardObject,
|
|
98
100
|
permission:PermissionObject, gurads:RewardGuardPortions[], passport?:PassportObject) : boolean {
|
|
99
101
|
if (!IsValidObjects([reward, permission])) return false;
|
|
@@ -102,7 +104,7 @@ export function reward_add_guard(reward_type:string, txb:TransactionBlock, rewar
|
|
|
102
104
|
|
|
103
105
|
let bValid = true;
|
|
104
106
|
gurads.forEach((v) => {
|
|
105
|
-
if (!IsValidUint(v.portions)) bValid = false;
|
|
107
|
+
if (!IsValidUint(v.portions) || v.portions > MAX_PORTIONS_COUNT) bValid = false;
|
|
106
108
|
if (!IsValidObjects([v.guard])) bValid = false;
|
|
107
109
|
})
|
|
108
110
|
if (!bValid) return false;
|
|
@@ -111,7 +113,7 @@ export function reward_add_guard(reward_type:string, txb:TransactionBlock, rewar
|
|
|
111
113
|
gurads.forEach((guard) =>
|
|
112
114
|
txb.moveCall({
|
|
113
115
|
target:PROTOCOL.RewardFn('guard_add_with_passport') as FnCallType,
|
|
114
|
-
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.
|
|
116
|
+
arguments:[passport, TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U8), TXB_OBJECT(txb, permission)],
|
|
115
117
|
typeArguments:[reward_type]
|
|
116
118
|
})
|
|
117
119
|
)
|
|
@@ -119,7 +121,7 @@ export function reward_add_guard(reward_type:string, txb:TransactionBlock, rewar
|
|
|
119
121
|
gurads.forEach((guard) =>
|
|
120
122
|
txb.moveCall({
|
|
121
123
|
target:PROTOCOL.RewardFn('guard_add') as FnCallType,
|
|
122
|
-
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.
|
|
124
|
+
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U8), TXB_OBJECT(txb, permission)],
|
|
123
125
|
typeArguments:[reward_type]
|
|
124
126
|
})
|
|
125
127
|
)
|
|
@@ -177,7 +179,7 @@ export function allow_repeat_claim(reward_type:string, txb:TransactionBlock, rew
|
|
|
177
179
|
})
|
|
178
180
|
} else {
|
|
179
181
|
txb.moveCall({
|
|
180
|
-
target:PROTOCOL.RewardFn('
|
|
182
|
+
target:PROTOCOL.RewardFn('allow_repeat_claim') as FnCallType,
|
|
181
183
|
arguments:[TXB_OBJECT(txb, reward), TXB_OBJECT(txb, permission), txb.pure(allow_repeat_claim, BCS.BOOL)],
|
|
182
184
|
typeArguments:[reward_type]
|
|
183
185
|
})
|
|
@@ -228,6 +230,7 @@ export function reward_lock_guards(reward_type:string, txb:TransactionBlock, rew
|
|
|
228
230
|
export function claim(reward_type:string, txb:TransactionBlock, reward:RewardObject, passport?:PassportObject) : boolean {
|
|
229
231
|
if (!IsValidObjects([reward])) return false;
|
|
230
232
|
if (!IsValidArgType(reward_type)) return false;
|
|
233
|
+
|
|
231
234
|
if (passport) {
|
|
232
235
|
txb.moveCall({
|
|
233
236
|
target:PROTOCOL.RewardFn('claim_with_passport') as FnCallType,
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionBlock, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { BCS } from '@mysten/bcs';
|
|
3
|
-
import { BCS_CONVERT, array_unique } from './
|
|
3
|
+
import { BCS_CONVERT, array_unique } from './utils'
|
|
4
4
|
import { CLOCK_OBJECT, FnCallType, GuardObject, PROTOCOL, PassportObject, PermissionObject,
|
|
5
5
|
RepositoryObject, MachineObject, ServiceAddress, ServiceObject, IsValidObjects, IsValidArgType, IsValidDesription,
|
|
6
6
|
IsValidAddress, IsValidEndpoint, OptionNone, TXB_OBJECT, IsValidUint, IsValidInt, IsValidName, DiscountObject,
|
|
@@ -450,8 +450,8 @@ export type Service_Discount = {
|
|
|
450
450
|
time_start?: number; // current time if undefined
|
|
451
451
|
price_greater?: number;
|
|
452
452
|
}
|
|
453
|
-
const MAX_DISCOUNT_COUNT_ONCE = 200;
|
|
454
|
-
const MAX_DISCOUNT_RECEIVER_COUNT = 200;
|
|
453
|
+
export const MAX_DISCOUNT_COUNT_ONCE = 200;
|
|
454
|
+
export const MAX_DISCOUNT_RECEIVER_COUNT = 200;
|
|
455
455
|
|
|
456
456
|
export type DicountDispatch = {
|
|
457
457
|
receiver: string;
|
|
@@ -486,15 +486,19 @@ export function service_discount_transfer(pay_type:string, txb:TransactionBlock,
|
|
|
486
486
|
if (passport) {
|
|
487
487
|
txb.moveCall({
|
|
488
488
|
target:PROTOCOL.ServiceFn('dicscount_create_with_passport') as FnCallType,
|
|
489
|
-
arguments:[passport, TXB_OBJECT(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, BCS.U8),
|
|
490
|
-
|
|
489
|
+
arguments:[passport, TXB_OBJECT(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, BCS.U8),
|
|
490
|
+
txb.pure(discount.discount.off, BCS.U64), price_greater, time_start,
|
|
491
|
+
txb.pure(discount.discount.duration_minutes, BCS.U64), txb.pure(discount.count, BCS.U64),
|
|
492
|
+
TXB_OBJECT(txb, permission), txb.pure(discount.receiver, BCS.ADDRESS), txb.object(CLOCK_OBJECT)],
|
|
491
493
|
typeArguments:[pay_type]
|
|
492
494
|
});
|
|
493
495
|
} else {
|
|
494
496
|
txb.moveCall({
|
|
495
497
|
target:PROTOCOL.ServiceFn('dicscount_create') as FnCallType,
|
|
496
|
-
arguments:[TXB_OBJECT(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, BCS.U8),
|
|
497
|
-
|
|
498
|
+
arguments:[TXB_OBJECT(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, BCS.U8),
|
|
499
|
+
txb.pure(discount.discount.off, BCS.U64), price_greater, time_start,
|
|
500
|
+
txb.pure(discount.discount.duration_minutes, BCS.U64), txb.pure(discount.count, BCS.U64),
|
|
501
|
+
TXB_OBJECT(txb, permission), txb.pure(discount.receiver, BCS.ADDRESS), txb.object(CLOCK_OBJECT)],
|
|
498
502
|
typeArguments:[pay_type]
|
|
499
503
|
})
|
|
500
504
|
}
|
|
@@ -511,7 +515,7 @@ export function service_withdraw(pay_type:string, txb:TransactionBlock, service:
|
|
|
511
515
|
if (passport) {
|
|
512
516
|
txb.moveCall({
|
|
513
517
|
target:PROTOCOL.ServiceFn('withdraw_with_passport') as FnCallType,
|
|
514
|
-
arguments:[passport, TXB_OBJECT(txb, service), TXB_OBJECT(txb, order),
|
|
518
|
+
arguments:[passport, TXB_OBJECT(txb, service), TXB_OBJECT(txb, order), TXB_OBJECT(txb, permission)],
|
|
515
519
|
typeArguments:[pay_type]
|
|
516
520
|
})
|
|
517
521
|
} else {
|
package/src/{util.ts → utils.ts}
RENAMED
|
@@ -2,10 +2,7 @@ import { SuiTransactionBlockResponse, SuiObjectChange } from '@mysten/sui.js/cli
|
|
|
2
2
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
3
3
|
import { PROTOCOL, MODULES, OBJECTS_TYPE } from './protocol';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
value: number;
|
|
7
|
-
length: number;
|
|
8
|
-
} {
|
|
5
|
+
export const ulebDecode = (arr: number[] | Uint8Array) : {value: number, length: number} => {
|
|
9
6
|
let total = 0;
|
|
10
7
|
let shift = 0;
|
|
11
8
|
let len = 0;
|
|
@@ -27,7 +24,7 @@ export function ulebDecode(arr: number[] | Uint8Array): {
|
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export
|
|
27
|
+
export const concatenate = (resultConstructor:any, ...arrays:any[]) => {
|
|
31
28
|
let totalLength = 0;
|
|
32
29
|
for (const arr of arrays) {
|
|
33
30
|
totalLength += arr.length;
|
|
@@ -41,7 +38,7 @@ export function concatenate(resultConstructor:any, ...arrays:any[]) {
|
|
|
41
38
|
return result;
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
export
|
|
41
|
+
export const array_equal = (arr1: any[], arr2: any[]) => {
|
|
45
42
|
// Array.some(): 有一项不满足,返回false
|
|
46
43
|
if (arr1.length !== arr2.length) {
|
|
47
44
|
return false;
|
|
@@ -49,7 +46,7 @@ export function array_equal(arr1: any[], arr2: any[]) {
|
|
|
49
46
|
return !arr1.some((item) => !arr2.includes(item));
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
export
|
|
49
|
+
export const array_unique = (arr:any[]) : any[] => {
|
|
53
50
|
var newArr = [];
|
|
54
51
|
for(var i = 0; i < arr.length; i++) {
|
|
55
52
|
if(newArr.indexOf(arr[i]) == -1) {
|
|
@@ -139,11 +136,23 @@ export const objectids_from_response = (response:SuiTransactionBlockResponse, co
|
|
|
139
136
|
return ret;
|
|
140
137
|
}
|
|
141
138
|
|
|
142
|
-
|
|
139
|
+
|
|
140
|
+
export function stringToUint8Array(str:string) : Uint8Array {
|
|
143
141
|
var arr = [];
|
|
144
142
|
for (var i = 0, j = str.length; i < j; ++i) {
|
|
145
143
|
arr.push(str.charCodeAt(i));
|
|
146
144
|
}
|
|
147
145
|
var tmpUint8Array = new Uint8Array(arr);
|
|
148
146
|
return tmpUint8Array
|
|
149
|
-
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function numToUint8Array(num:number) : Uint8Array {
|
|
150
|
+
if (!num) return new Uint8Array(0)
|
|
151
|
+
const a = [];
|
|
152
|
+
a.unshift(num & 255)
|
|
153
|
+
while (num >= 256) {
|
|
154
|
+
num = num >>> 8
|
|
155
|
+
a.unshift(num & 255)
|
|
156
|
+
}
|
|
157
|
+
return new Uint8Array(a)
|
|
158
|
+
}
|
package/src/vote.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BCS } from '@mysten/bcs';
|
|
|
3
3
|
import { CLOCK_OBJECT, FnCallType, PROTOCOL, PassportObject, PermissionObject, GuardObject, VoteAddress,
|
|
4
4
|
VoteObject, IsValidObjects, IsValidDesription, IsValidUint, IsValidAddress, OptionNone, TXB_OBJECT,
|
|
5
5
|
IsValidArray, IsValidName} from './protocol';
|
|
6
|
-
import { BCS_CONVERT, array_unique } from './
|
|
6
|
+
import { BCS_CONVERT, array_unique } from './utils';
|
|
7
7
|
|
|
8
8
|
export const MAX_AGREES_COUNT = 200;
|
|
9
9
|
export const MAX_CHOICE_COUNT = 200;
|
package/src/address.graphql
DELETED
|
File without changes
|
package/src/object.graphql
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
object(
|
|
3
|
-
address: "0x30feecaf0e3930da9c6deab887413a25e956572330a1071f3b29ad83764ba384"
|
|
4
|
-
) {
|
|
5
|
-
asMoveObject {
|
|
6
|
-
contents {
|
|
7
|
-
json
|
|
8
|
-
type {
|
|
9
|
-
repr
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
dynamicFields {
|
|
14
|
-
pageInfo {
|
|
15
|
-
hasNextPage
|
|
16
|
-
endCursor
|
|
17
|
-
}
|
|
18
|
-
nodes {
|
|
19
|
-
name {
|
|
20
|
-
json
|
|
21
|
-
}
|
|
22
|
-
value {
|
|
23
|
-
... on MoveValue {
|
|
24
|
-
json
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|