33
44package org .lfdecentralizedtrust .splice .wallet .store .db
55
6- import com .daml .ledger .javaapi .data .codegen .ContractId
76import com .daml .ledger .javaapi .data .codegen .json .JsonLfReader
87import org .lfdecentralizedtrust .splice .codegen .java .splice .amulet as amuletCodegen
98import org .lfdecentralizedtrust .splice .codegen .java .splice .amuletrules .TransferPreapproval
@@ -15,13 +14,14 @@ import org.lfdecentralizedtrust.splice.codegen.java.splice.wallet.subscriptions
1514import org .lfdecentralizedtrust .splice .codegen .java .splice .wallet .transferpreapproval .TransferPreapprovalProposal
1615import org .lfdecentralizedtrust .splice .environment .RetryProvider
1716import org .lfdecentralizedtrust .splice .migration .DomainMigrationInfo
18- import org .lfdecentralizedtrust .splice .store .MultiDomainAcsStore .{ ContractCompanion , QueryResult }
17+ import org .lfdecentralizedtrust .splice .store .MultiDomainAcsStore .QueryResult
1918import org .lfdecentralizedtrust .splice .store .db .AcsQueries .{AcsStoreId , SelectFromAcsTableResult }
2019import org .lfdecentralizedtrust .splice .store .db .StoreDescriptor
2120import org .lfdecentralizedtrust .splice .store .db .{
2221 AcsQueries ,
2322 AcsTables ,
2423 DbTxLogAppStore ,
24+ DbTransferInputQueries ,
2525 TxLogQueries ,
2626}
2727import org .lfdecentralizedtrust .splice .store .{Limit , LimitHelpers , PageLimit , TxLogStore }
@@ -46,7 +46,6 @@ import com.digitalasset.canton.resource.DbStorage.Implicits.BuilderChain.toSQLAc
4646import com .digitalasset .canton .topology .{ParticipantId , PartyId }
4747import org .lfdecentralizedtrust .splice .config .IngestionConfig
4848import org .lfdecentralizedtrust .splice .store .db .TxLogQueries .TxLogStoreId
49- import slick .jdbc .canton .SQLActionBuilder
5049
5150import scala .concurrent .*
5251import scala .jdk .OptionConverters .*
@@ -60,9 +59,9 @@ class DbUserWalletStore(
6059 participantId : ParticipantId ,
6160 ingestionConfig : IngestionConfig ,
6261)(implicit
63- ec : ExecutionContext ,
64- templateJsonDecoder : TemplateJsonDecoder ,
65- closeContext : CloseContext ,
62+ override protected val ec : ExecutionContext ,
63+ override protected val templateJsonDecoder : TemplateJsonDecoder ,
64+ override protected val closeContext : CloseContext ,
6665) extends DbTxLogAppStore [TxLogEntry ](
6766 storage = storage,
6867 acsTableName = WalletTables .acsTableName,
@@ -98,6 +97,7 @@ class DbUserWalletStore(
9897 ingestionConfig,
9998 )
10099 with UserWalletStore
100+ with DbTransferInputQueries
101101 with AcsTables
102102 with AcsQueries
103103 with TxLogQueries [TxLogEntry ]
@@ -106,9 +106,11 @@ class DbUserWalletStore(
106106 import multiDomainAcsStore .waitUntilAcsIngested
107107 import org .lfdecentralizedtrust .splice .util .FutureUnlessShutdownUtil .futureUnlessShutdownToFuture
108108
109- private def acsStoreId : AcsStoreId = multiDomainAcsStore.acsStoreId
109+ override protected def acsStoreId : AcsStoreId = multiDomainAcsStore.acsStoreId
110110 private def txLogStoreId : TxLogStoreId = multiDomainAcsStore.txLogStoreId
111111 override def domainMigrationId : Long = domainMigrationInfo.currentMigrationId
112+ override protected def acsTableName : String = WalletTables .acsTableName
113+ override protected def dbStorage : DbStorage = storage
112114
113115 override def toString : String = show " DbUserWalletStore(endUserParty= ${key.endUserParty}) "
114116
@@ -188,53 +190,6 @@ class DbUserWalletStore(
188190 ccValue = sql " rti.issuance * acs.reward_coupon_weight " ,
189191 )
190192
191- private def listSortedRewardCoupons [C , TCid <: ContractId [? ], T ](
192- companion : C ,
193- issuingRoundsMap : Map [Round , IssuingMiningRound ],
194- roundToIssuance : IssuingMiningRound => Option [BigDecimal ],
195- limit : Limit ,
196- ccValue : SQLActionBuilder = sql " rti.issuance " ,
197- )(implicit
198- companionClass : ContractCompanion [C , TCid , T ],
199- traceContext : TraceContext ,
200- ): Future [Seq [(Contract [TCid , T ], BigDecimal )]] = {
201- val packageQualifiedName = companionClass.packageQualifiedName(companion)
202- issuingRoundsMap
203- .flatMap { case (round, contract) =>
204- roundToIssuance(contract).map(round.number.longValue() -> _)
205- }
206- .map { case (round, issuance) =>
207- sql " ( $round, $issuance) "
208- }
209- .reduceOption { (acc, next) =>
210- (acc ++ sql " , " ++ next).toActionBuilder
211- } match {
212- case None => Future .successful(Seq .empty) // no rounds = no results
213- case Some (roundToIssuance) =>
214- for {
215- result <- storage.query(
216- (sql """
217- with round_to_issuance(round, issuance) as (values """ ++ roundToIssuance ++ sql """ )
218- select
219- # ${SelectFromAcsTableResult .sqlColumnsCommaSeparated()}, """ ++ ccValue ++ sql """
220- from # ${WalletTables .acsTableName} acs join round_to_issuance rti on acs.reward_coupon_round = rti.round
221- where acs.store_id = $acsStoreId
222- and migration_id = $domainMigrationId
223- and acs.package_name = ${packageQualifiedName.packageName}
224- and acs.template_id_qualified_name = ${packageQualifiedName.qualifiedName}
225- order by (acs.reward_coupon_round, - """ ++ ccValue ++ sql """ )
226- limit ${sqlLimit(limit)}""" ).toActionBuilder
227- .as[(SelectFromAcsTableResult , BigDecimal )],
228- s " listSorted: $packageQualifiedName" ,
229- )
230- } yield applyLimit(s " listSorted: $packageQualifiedName" , limit, result).map {
231- case (row, issuance) =>
232- val contract = contractFromRow(companion)(row)
233- contract -> issuance
234- }
235- }
236- }
237-
238193 override def listTransactions (
239194 beginAfterEventIdO : Option [String ],
240195 limit : PageLimit ,
0 commit comments