@@ -110,20 +110,23 @@ class AnsSubscriptionInitialPaymentTrigger(
110110 }
111111 // if there are existing accepted confirmation of other payment and with the same ans entry name, we will reject this payment.
112112 if (otherPaymentAcceptedConfirmations.isEmpty)
113- dsoStore.lookupAnsEntryByName(entryName, context.clock.now).flatMap {
114- case None =>
115- // confirm to collect the payment and create the entry
116- confirmCollectPayment(
117- ansContext.contract.contractId,
118- payment.contractId,
119- entryName,
120- transferContext,
121- )
122- case Some (entry) =>
123- confirmToReject(
124- s " entry already exists and owned by ${entry.payload.user}. "
125- )
126- }
113+ dsoStore
114+ .lookupAnsEntryByNameWithOffset(entryName, context.clock.now)
115+ .flatMap {
116+ case QueryResult (offset, None ) =>
117+ // confirm to collect the payment and create the entry
118+ confirmCollectPayment(
119+ ansContext.contract.contractId,
120+ payment.contractId,
121+ entryName,
122+ transferContext,
123+ offset,
124+ )
125+ case QueryResult (_, Some (entry)) =>
126+ confirmToReject(
127+ s " entry already exists and owned by ${entry.payload.user}. "
128+ )
129+ }
127130 else {
128131 confirmToReject(
129132 s " other initial payment collection has been confirmed for the same ans name ( $entryName) with confirmation ${otherPaymentAcceptedConfirmations
@@ -193,6 +196,7 @@ class AnsSubscriptionInitialPaymentTrigger(
193196 paymentCid : SubscriptionInitialPayment .ContractId ,
194197 entryName : String ,
195198 transferContext : AppTransferContext ,
199+ ansEntryNameOffset : Long ,
196200 )(implicit tc : TraceContext ): Future [TaskOutcome ] = for {
197201 dsoRules <- dsoStore.getDsoRules()
198202 ansRules <- dsoStore.getAnsRules()
@@ -202,19 +206,19 @@ class AnsSubscriptionInitialPaymentTrigger(
202206 ansRules.contractId,
203207 ansContextCId,
204208 )
205- // look up the confirmation for this payment created by this SV no matter if it is a acceptance or rejection
206- queryResult <- dsoStore.lookupAnsInitialPaymentConfirmationByPaymentIdWithOffset (
207- svParty,
208- paymentCid ,
209- )
209+ ansInitialPaymentConfirmationByAnsName <- dsoStore
210+ .listInitialPaymentConfirmationByAnsName (
211+ svParty,
212+ entryName ,
213+ )
210214 cmd = dsoRules.exercise(
211215 _.exerciseDsoRules_ConfirmAction(
212216 svParty.toProtoPrimitive,
213217 action,
214218 )
215219 )
216- taskOutcome <- queryResult match {
217- case QueryResult (offset, None ) =>
220+ taskOutcome <- ansInitialPaymentConfirmationByAnsName match {
221+ case Seq ( ) =>
218222 connection
219223 .submit(
220224 actAs = Seq (svParty),
@@ -225,17 +229,18 @@ class AnsSubscriptionInitialPaymentTrigger(
225229 commandId = SpliceLedgerConnection .CommandId (
226230 " org.lfdecentralizedtrust.splice.sv.createAnsCollectInitialEntryPaymentConfirmation" ,
227231 Seq (svParty, dsoParty),
228- paymentCid.contractId ,
232+ entryName ,
229233 ),
230- deduplicationOffset = offset,
234+ // we can safely assume that `ansEntryNameOffset` is smaller than the offset from the ansInitialPaymentConfirmation
235+ deduplicationOffset = ansEntryNameOffset,
231236 )
232237 .yieldUnit()
233238 .map { _ =>
234239 TaskSuccess (
235240 s " confirmed to create ans entry $entryName by collecting payment $paymentCid"
236241 )
237242 }
238- case QueryResult (_, Some (_)) =>
243+ case _ =>
239244 TaskSuccess (
240245 s " skipping as confirmation (either acceptance or rejection) from $svParty is already created for this payment $paymentCid"
241246 ).pure[Future ]
0 commit comments