1
1
import { Injectable } from '@nestjs/common' ;
2
2
import { EventsWorker , EventData , Log } from '../events/events.worker' ;
3
- import { ACCOUNT_ABI , PolicyKey , asPolicyKey , asUAddress , asUUID } from 'lib' ;
3
+ import { ACCOUNT_ABI , Hex , PolicyKey , asPolicyKey , asUAddress , asUUID } from 'lib' ;
4
4
import { Chain } from 'chains' ;
5
5
import { DatabaseService } from '~/core/database' ;
6
6
import { getAbiItem } from 'viem' ;
@@ -29,6 +29,7 @@ export class PoliciesEventsProcessor {
29
29
chain ,
30
30
log ,
31
31
asPolicyKey ( log . args . key ) ,
32
+ log . args . hash ,
32
33
) ;
33
34
34
35
if ( policyId )
@@ -46,20 +47,21 @@ export class PoliciesEventsProcessor {
46
47
this . policies . event ( { event : PolicyEvent . removed , account, policyId : asUUID ( policyId ) } ) ;
47
48
}
48
49
49
- private async markStateAsActive ( chain : Chain , log : Log , key : PolicyKey ) {
50
- // FIXME: when multiple policies are activated in one block, the wrong one may be marked as active
51
- // This *always* occurs when a policy is activated by a policy update transaction
52
-
50
+ private async markStateAsActive ( chain : Chain , log : Log , key : PolicyKey , hash ?: Hex ) {
53
51
const account = asUAddress ( log . address , chain ) ;
54
52
const r = await this . db . exec ( activatePolicy , {
55
53
account,
56
54
key,
57
- systxHash : log . transactionHash ,
55
+ hash ,
58
56
activationBlock : log . blockNumber ,
59
57
} ) ;
60
58
61
59
await Promise . all ( r . pendingTransactions . map ( ( id ) => this . transactions . tryExecute ( asUUID ( id ) ) ) ) ;
62
60
61
+ if ( ! r . new ) {
62
+ // TODO: this shouldn't happen
63
+ }
64
+
63
65
return { account, old : r . old , new : r . new } ;
64
66
}
65
67
}
0 commit comments