@@ -57,7 +57,7 @@ import {
5757import { getDenomAndAmount } from "../utils/primitives" ;
5858
5959// this can return undefined because older events do not have this attribute
60- function getClaimProofStatusFromSDK ( item : typeof ClaimProofStatusSDKType | string | number ) : ClaimProofStatus | undefined {
60+ export function getClaimProofStatusFromSDK ( item : typeof ClaimProofStatusSDKType | string | number ) : ClaimProofStatus | undefined {
6161 if ( ! item ) return undefined ;
6262
6363 switch ( item ) {
@@ -151,7 +151,7 @@ function parseAttribute(attribute: unknown = ""): string {
151151}
152152
153153// eslint-disable-next-line complexity
154- function getAttributes ( attributes : CosmosEvent [ "event" ] [ "attributes" ] ) {
154+ export function getAttributes ( attributes : CosmosEvent [ "event" ] [ "attributes" ] ) {
155155
156156 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
157157 // @ts -ignore
@@ -890,121 +890,6 @@ function _handleEventApplicationReimbursementRequest(event: CosmosEvent): EventA
890890 }
891891}
892892
893- async function _handleOldEventSupplierSlashed ( event : CosmosEvent ) {
894- let slashingCoin : CoinSDKType | null = null , operatorAddress = "" ;
895-
896- for ( const attribute of event . event . attributes ) {
897- if ( attribute . key === "slashing_amount" ) {
898- slashingCoin = getDenomAndAmount ( attribute . value as string ) ;
899- if ( ! slashingCoin ) {
900- throw new Error ( `[handleEventSupplierSlashed] event attribute key=${ attribute . key } value=${ attribute . value } is not a valid coin` ) ;
901- }
902- }
903-
904- if ( attribute . key === "proof_missing_penalty" ) {
905- /*
906- [
907- {"key":"application_address","value":"\"pokt16wwc45wjc4ulne7wmaawxhju00vwf900lscfld\""},
908- {"key":"claim_proof_status_int","value":"2"},
909- {"key":"proof_missing_penalty","value":"\"1upokt\""},
910- {"key":"service_id","value":"\"hey\""},
911- {"key":"session_end_block_height","value":"\"363540\""},
912- {"key":"supplier_operator_address","value":"\"pokt1wua234ulad3vkcsqmasu845mn4ugu9aa6jcv23\""},
913- {"key":"mode","value":"EndBlock"}
914- ]
915- */
916- const coins = parseCoins ( parseAttribute ( attribute . value ) ) ;
917- if ( ! coins . length ) {
918- throw new Error ( `[handleEventSupplierSlashed] event attribute key=${ attribute . key } value=${ attribute . value } is not a valid coin` ) ;
919- }
920- }
921-
922- if ( attribute . key === "supplier_operator_addr" || attribute . key === "supplier_operator_address" ) {
923- operatorAddress = parseAttribute ( attribute . value ) ;
924- }
925- }
926-
927- if ( ! slashingCoin ) {
928- throw new Error ( `[handleEventSupplierSlashed] slashingCoin not found in event` ) ;
929- }
930-
931- if ( ! operatorAddress ) {
932- logger . error ( `[handleEventSupplierSlashed] operatorAddress not found in event=${ event . kind } attributes=${ stringify ( event . event . attributes ) } ` ) ;
933- throw new Error ( `[handleEventSupplierSlashed] operatorAddress not found in event` ) ;
934- }
935-
936- const supplier = await Supplier . get ( operatorAddress ) ;
937-
938- if ( ! supplier ) {
939- throw new Error ( `[handleEventSupplierSlashed] supplier not found for operator address ${ operatorAddress } ` ) ;
940- }
941-
942- supplier . stakeAmount -= BigInt ( slashingCoin . amount ) ;
943-
944- await Promise . all ( [
945- supplier . save ( ) ,
946- EventSupplierSlashed . create ( {
947- id : getEventId ( event ) ,
948- supplierId : operatorAddress ,
949- blockId : getBlockId ( event . block ) ,
950- eventId : getEventId ( event ) ,
951- proofMissingPenalty : BigInt ( slashingCoin . amount ) ,
952- proofMissingPenaltyDenom : slashingCoin . denom ,
953- previousStakeAmount : supplier . stakeAmount ,
954- afterStakeAmount : supplier . stakeAmount ,
955- // in alpha this event does not have the values below, so we are setting them to empty values for now
956- applicationId : "" ,
957- serviceId : "" ,
958- sessionId : "" ,
959- sessionStartHeight : BigInt ( 0 ) ,
960- sessionEndHeight : BigInt ( 0 ) ,
961- } ) . save ( ) ,
962- ] ) ;
963- }
964-
965- async function _handleEventSupplierSlashed ( event : CosmosEvent ) {
966- const {
967- claim,
968- proofMissingPenalty,
969- } = getAttributes ( event . event . attributes ) ;
970-
971- if ( ! claim || ! claim . session_header || Object . keys ( claim ) . length === 0 ) {
972- logger . warn ( `[handleEventSupplierSlashed] claim not found in event, trying to handle with previous version` ) ;
973- await _handleOldEventSupplierSlashed ( event ) ;
974- return ;
975- }
976-
977- const supplier = await Supplier . get ( claim . supplier_operator_address ) ;
978-
979- if ( ! supplier ) {
980- throw new Error ( `[handleEventSupplierSlashed] supplier not found for address: ${ claim . supplier_operator_address } ` ) ;
981- }
982-
983- const previousStakeAmount = supplier . stakeAmount . valueOf ( ) ;
984- supplier . stakeAmount -= BigInt ( proofMissingPenalty . amount ) ;
985-
986- await Promise . all ( [
987- supplier . save ( ) ,
988- EventSupplierSlashed . create ( {
989- id : getEventId ( event ) ,
990- supplierId : claim . supplier_operator_address ,
991- // TODO: Create entity for session header
992- applicationId : claim . session_header . application_address ,
993- serviceId : claim . session_header . service_id ,
994- sessionId : claim . session_header . session_id || "" ,
995- sessionEndHeight : BigInt ( claim . session_header . session_end_block_height || "0" ) ,
996- sessionStartHeight : BigInt ( claim . session_header . session_start_block_height || "0" ) ,
997- blockId : getBlockId ( event . block ) ,
998- eventId : getEventId ( event ) ,
999- proofMissingPenalty : BigInt ( proofMissingPenalty . amount ) ,
1000- proofMissingPenaltyDenom : proofMissingPenalty . denom ,
1001- previousStakeAmount,
1002- afterStakeAmount : supplier . stakeAmount ,
1003- proofValidationStatus : getClaimProofStatusFromSDK ( claim . proof_validation_status ) ,
1004- } ) . save ( ) ,
1005- ] ) ;
1006- }
1007-
1008893// eslint-disable-next-line complexity
1009894function _handleEventProofValidityChecked ( event : CosmosEvent ) : EventProofValidityCheckedProps {
1010895 let supplierOperatorAddress = "" ,
@@ -1158,10 +1043,6 @@ export async function handleEventApplicationReimbursementRequest(events: Array<C
11581043 await optimizedBulkCreate ( "EventApplicationReimbursementRequest" , eventsUpdated ) ;
11591044}
11601045
1161- export async function handleEventSupplierSlashed ( events : Array < CosmosEvent > ) : Promise < void > {
1162- await Promise . all ( events . map ( _handleEventSupplierSlashed ) ) ;
1163- }
1164-
11651046export async function handleEventProofValidityChecked ( events : Array < CosmosEvent > ) : Promise < void > {
11661047 await optimizedBulkCreate ( "EventProofValidityChecked" , events . map ( _handleEventProofValidityChecked ) ) ;
11671048}
0 commit comments