@@ -9,6 +9,19 @@ const SNAPSHOT_ENV = process.env.NETWORK || 'testnet';
9
9
const broviderUrl = process . env . BROVIDER_URL || 'https://rpc.snapshot.org' ;
10
10
11
11
export async function validateSpaceSettings ( space : any ) {
12
+ const schemaIsValid : any = snapshot . utils . validateSchema ( snapshot . schemas . space , space , {
13
+ snapshotEnv : SNAPSHOT_ENV
14
+ } ) ;
15
+
16
+ if ( schemaIsValid !== true ) {
17
+ log . warn ( '[writer] Wrong space format' , schemaIsValid ) ;
18
+ const firstErrorObject : any = Object . values ( schemaIsValid ) [ 0 ] ;
19
+ if ( firstErrorObject . message === 'network not allowed' ) {
20
+ return Promise . reject ( firstErrorObject . message ) ;
21
+ }
22
+ return Promise . reject ( 'wrong space format' ) ;
23
+ }
24
+
12
25
if ( SNAPSHOT_ENV !== 'testnet' ) {
13
26
const hasTicket = space . strategies . some ( strategy => strategy . name === 'ticket' ) ;
14
27
const hasVotingValidation =
@@ -31,24 +44,6 @@ export async function validateSpaceSettings(space: any) {
31
44
32
45
export async function verify ( body ) : Promise < any > {
33
46
const msg = jsonParse ( body . msg ) ;
34
-
35
- const schemaIsValid : any = snapshot . utils . validateSchema ( snapshot . schemas . space , msg . payload , {
36
- snapshotEnv : SNAPSHOT_ENV
37
- } ) ;
38
-
39
- if ( schemaIsValid !== true ) {
40
- log . warn ( '[writer] Wrong space format' , schemaIsValid ) ;
41
- const firstErrorObject : any = Object . values ( schemaIsValid ) [ 0 ] ;
42
- if ( firstErrorObject . message === 'network not allowed' ) {
43
- return Promise . reject ( firstErrorObject . message ) ;
44
- }
45
- return Promise . reject ( 'wrong space format' ) ;
46
- }
47
-
48
- const controller = await snapshot . utils . getSpaceController ( msg . space , DEFAULT_NETWORK , {
49
- broviderUrl
50
- } ) ;
51
- const isController = controller === body . address ;
52
47
const space = await getSpace ( msg . space , true ) ;
53
48
54
49
try {
@@ -57,6 +52,11 @@ export async function verify(body): Promise<any> {
57
52
return Promise . reject ( e ) ;
58
53
}
59
54
55
+ const controller = await snapshot . utils . getSpaceController ( msg . space , DEFAULT_NETWORK , {
56
+ broviderUrl
57
+ } ) ;
58
+ const isController = controller === body . address ;
59
+
60
60
if ( space ?. deleted ) return Promise . reject ( 'space deleted, contact admin' ) ;
61
61
const admins = ( space ?. admins || [ ] ) . map ( admin => admin . toLowerCase ( ) ) ;
62
62
const isAdmin = admins . includes ( body . address . toLowerCase ( ) ) ;
0 commit comments