@@ -10,7 +10,7 @@ import {
10
10
hexToString ,
11
11
keccak256 ,
12
12
} from 'viem' ;
13
- import e from '~/edgeql-js' ;
13
+ import e , { Set } from '~/edgeql-js' ;
14
14
import { selectAccount } from '../accounts/accounts.util' ;
15
15
import { ProposalsService , UniqueProposal } from '../proposals/proposals.service' ;
16
16
import {
@@ -34,10 +34,15 @@ import { ethers } from 'ethers';
34
34
import _ from 'lodash' ;
35
35
import { WritableDeep } from 'ts-toolbelt/out/Object/Writable' ;
36
36
import { PoliciesService } from '../policies/policies.service' ;
37
+ import { $uuid } from '~/edgeql-js/modules/std' ;
38
+ import { $ } from 'edgedb' ;
37
39
38
40
export const selectMessage = ( id : UUID | Hex ) =>
39
41
e . select ( e . Message , ( ) => ( { filter_single : isHex ( id ) ? { hash : id } : { id } } ) ) ;
40
42
43
+ export const selectMessage2 = ( id : Set < $uuid , $ . Cardinality . One > ) =>
44
+ e . select ( e . Message , ( ) => ( { filter_single : { id } } ) ) ;
45
+
41
46
@Injectable ( )
42
47
export class MessagesService {
43
48
constructor (
@@ -133,12 +138,19 @@ export class MessagesService {
133
138
}
134
139
135
140
async remove ( proposal : UUID ) {
136
- const selectedMessage = selectMessage ( proposal ) ;
137
- const { account } = await this . db . query (
138
- e . select ( {
139
- account : e . assert_exists ( selectedMessage . account . address ) ,
140
- deleted : e . delete ( selectedMessage ) ,
141
- } ) ,
141
+ const { account } = await this . db . queryWith (
142
+ { id : e . uuid } ,
143
+ ( { id } ) => {
144
+ const m = selectMessage2 ( id ) ;
145
+ return e . with (
146
+ [ m ] ,
147
+ e . select ( {
148
+ account : e . assert_exists ( m . account . address ) ,
149
+ deleted : e . delete ( m ) ,
150
+ } ) ,
151
+ ) ;
152
+ } ,
153
+ { id : proposal } ,
142
154
) ;
143
155
144
156
this . proposals . publish ( { id : proposal , account : asUAddress ( account ) } , ProposalEvent . delete ) ;
@@ -147,22 +159,25 @@ export class MessagesService {
147
159
}
148
160
149
161
private async trySign ( id : UUID ) {
150
- const proposal = await this . db . query (
151
- e . select ( e . Message , ( ) => ( {
152
- filter_single : { id } ,
153
- hash : true ,
154
- message : true ,
155
- typedData : true ,
156
- signature : true ,
157
- approvals : {
158
- approver : { address : true } ,
162
+ const proposal = await this . db . queryWith (
163
+ { id : e . uuid } ,
164
+ ( { id } ) =>
165
+ e . select ( e . Message , ( ) => ( {
166
+ filter_single : { id } ,
167
+ hash : true ,
168
+ message : true ,
169
+ typedData : true ,
159
170
signature : true ,
160
- } ,
161
- account : {
162
- address : true ,
163
- policies : PolicyShape ,
164
- } ,
165
- } ) ) ,
171
+ approvals : {
172
+ approver : { address : true } ,
173
+ signature : true ,
174
+ } ,
175
+ account : {
176
+ address : true ,
177
+ policies : PolicyShape ,
178
+ } ,
179
+ } ) ) ,
180
+ { id } ,
166
181
) ;
167
182
if ( ! proposal ) return undefined ;
168
183
@@ -193,11 +208,14 @@ export class MessagesService {
193
208
approvals,
194
209
} ) ;
195
210
196
- await this . db . query (
197
- e . update ( e . Message , ( ) => ( {
198
- filter_single : { id } ,
199
- set : { signature } ,
200
- } ) ) ,
211
+ await this . db . queryWith (
212
+ { id : e . uuid , signature : e . Bytes } ,
213
+ ( { id, signature } ) =>
214
+ e . update ( e . Message , ( ) => ( {
215
+ filter_single : { id } ,
216
+ set : { signature } ,
217
+ } ) ) ,
218
+ { id, signature } ,
201
219
) ;
202
220
203
221
await this . proposals . publish ( { id, account } , ProposalEvent . signed ) ;
0 commit comments