@@ -525,21 +525,38 @@ pub async fn store_batch_receipts(
525525 let mut values = Vec :: with_capacity ( receipts_len) ;
526526
527527 for receipt in receipts {
528- let receipt = match receipt. signed_receipt ( ) {
529- TapReceipt :: V1 ( receipt) => receipt,
530- TapReceipt :: V2 ( _) => unimplemented ! ( "V2 receipts not supported" ) ,
528+ match receipt. signed_receipt ( ) {
529+ TapReceipt :: V1 ( receipt) => {
530+ signers. push (
531+ receipt
532+ . recover_signer ( & TAP_EIP712_DOMAIN_SEPARATOR )
533+ . unwrap ( )
534+ . encode_hex ( ) ,
535+ ) ;
536+ signatures. push ( receipt. signature . as_bytes ( ) . to_vec ( ) ) ;
537+ allocation_ids. push ( receipt. message . allocation_id . encode_hex ( ) . to_string ( ) ) ;
538+ timestamps. push ( BigDecimal :: from ( receipt. message . timestamp_ns ) ) ;
539+ nonces. push ( BigDecimal :: from ( receipt. message . nonce ) ) ;
540+ values. push ( BigDecimal :: from ( receipt. message . value ) ) ;
541+ }
542+ TapReceipt :: V2 ( receipt) => {
543+ use thegraph_core:: CollectionId ;
544+ // For V2, store collection_id in the allocation_id field (as per the database reuse strategy)
545+ let collection_id_as_allocation =
546+ CollectionId :: from ( receipt. message . collection_id ) . as_address ( ) ;
547+ signers. push (
548+ receipt
549+ . recover_signer ( & TAP_EIP712_DOMAIN_SEPARATOR )
550+ . unwrap ( )
551+ . encode_hex ( ) ,
552+ ) ;
553+ signatures. push ( receipt. signature . as_bytes ( ) . to_vec ( ) ) ;
554+ allocation_ids. push ( collection_id_as_allocation. encode_hex ( ) . to_string ( ) ) ;
555+ timestamps. push ( BigDecimal :: from ( receipt. message . timestamp_ns ) ) ;
556+ nonces. push ( BigDecimal :: from ( receipt. message . nonce ) ) ;
557+ values. push ( BigDecimal :: from ( receipt. message . value ) ) ;
558+ }
531559 } ;
532- signers. push (
533- receipt
534- . recover_signer ( & TAP_EIP712_DOMAIN_SEPARATOR )
535- . unwrap ( )
536- . encode_hex ( ) ,
537- ) ;
538- signatures. push ( receipt. signature . as_bytes ( ) . to_vec ( ) ) ;
539- allocation_ids. push ( receipt. message . allocation_id . encode_hex ( ) . to_string ( ) ) ;
540- timestamps. push ( BigDecimal :: from ( receipt. message . timestamp_ns ) ) ;
541- nonces. push ( BigDecimal :: from ( receipt. message . nonce ) ) ;
542- values. push ( BigDecimal :: from ( receipt. message . value ) ) ;
543560 }
544561 let _ = sqlx:: query!(
545562 r#"INSERT INTO scalar_tap_receipts (
@@ -579,7 +596,7 @@ pub async fn store_invalid_receipt(
579596) -> anyhow:: Result < u64 > {
580597 match signed_receipt {
581598 TapReceipt :: V1 ( signed_receipt) => store_invalid_receipt_v1 ( pgpool, signed_receipt) . await ,
582- TapReceipt :: V2 ( _ ) => unimplemented ! ( "V2 not supported" ) ,
599+ TapReceipt :: V2 ( signed_receipt ) => store_invalid_receipt_v2 ( pgpool , signed_receipt ) . await ,
583600 }
584601}
585602
@@ -613,6 +630,41 @@ pub async fn store_invalid_receipt_v1(
613630 Ok ( id)
614631}
615632
633+ pub async fn store_invalid_receipt_v2 (
634+ pgpool : & PgPool ,
635+ signed_receipt : & tap_graph:: v2:: SignedReceipt ,
636+ ) -> anyhow:: Result < u64 > {
637+ use thegraph_core:: CollectionId ;
638+ let encoded_signature = signed_receipt. signature . as_bytes ( ) . to_vec ( ) ;
639+
640+ // Store collection_id in allocation_id field (database reuse strategy)
641+ let collection_id_as_allocation =
642+ CollectionId :: from ( signed_receipt. message . collection_id ) . as_address ( ) ;
643+
644+ let record = sqlx:: query!(
645+ r#"
646+ INSERT INTO scalar_tap_receipts_invalid (signer_address, signature, allocation_id, timestamp_ns, nonce, value)
647+ VALUES ($1, $2, $3, $4, $5, $6)
648+ RETURNING id
649+ "# ,
650+ signed_receipt
651+ . recover_signer( & TAP_EIP712_DOMAIN_SEPARATOR )
652+ . unwrap( )
653+ . encode_hex( ) ,
654+ encoded_signature,
655+ collection_id_as_allocation. encode_hex( ) ,
656+ BigDecimal :: from( signed_receipt. message. timestamp_ns) ,
657+ BigDecimal :: from( signed_receipt. message. nonce) ,
658+ BigDecimal :: from( BigInt :: from( signed_receipt. message. value) ) ,
659+ )
660+ . fetch_one ( pgpool)
661+ . await ?;
662+
663+ // id is BIGSERIAL, so it should be safe to cast to u64.
664+ let id: u64 = record. id . try_into ( ) ?;
665+ Ok ( id)
666+ }
667+
616668/// Fixture to generate a wallet and address
617669pub fn wallet ( index : u32 ) -> ( PrivateKeySigner , Address ) {
618670 let wallet: PrivateKeySigner = MnemonicBuilder :: < English > :: default ( )
0 commit comments