Skip to content

Commit e1d6aa2

Browse files
cip-82: add withdrawDevelopmentFundCoupon to Wallet API
Signed-off-by: Jose Velasco <jose.velasco@intellecteu.com>
1 parent 54b1933 commit e1d6aa2

File tree

4 files changed

+148
-12
lines changed

4 files changed

+148
-12
lines changed

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/WalletAppReference.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.lfdecentralizedtrust.splice.http.v0.definitions.{
2020
GetBuyTrafficRequestStatusResponse,
2121
GetTransferOfferStatusResponse,
2222
TransferInstructionResultResponse,
23+
WithdrawDevelopmentFundCouponResponse,
2324
}
2425
import org.lfdecentralizedtrust.splice.util.{Contract, ContractWithState}
2526
import org.lfdecentralizedtrust.splice.wallet.admin.api.client.commands.HttpWalletAppClient
@@ -604,7 +605,7 @@ abstract class WalletAppReference(
604605

605606
@Help.Summary("Allocate a DevelopmentFundCoupon")
606607
@Help.Description(
607-
"Allocates development-fund resources by consuming UnclaimedDevelopmentFundCoupons and creating a new " +
608+
"Allocate development-fund resources by consuming UnclaimedDevelopmentFundCoupons and creating a new " +
608609
"DevelopmentFundCoupon for the specified beneficiary and amount."
609610
)
610611
def allocateDevelopmentFundCoupon(
@@ -619,7 +620,7 @@ abstract class WalletAppReference(
619620
): AllocateDevelopmentFundCouponResponse =
620621
consoleEnvironment.run {
621622
httpCommand(
622-
HttpWalletAppClient.AllocateDevelopmentFundCouponRequest(
623+
HttpWalletAppClient.AllocateDevelopmentFundCoupon(
623624
unclaimedDevelopmentFundCouponContractIds,
624625
beneficiary,
625626
amount,
@@ -632,7 +633,7 @@ abstract class WalletAppReference(
632633

633634
@Help.Summary("List active development fund coupons")
634635
@Help.Description(
635-
"List all active development fund coupons for the configured user acting as a beneficiary or development fund manager"
636+
"List all active development fund coupons for the configured user acting as a beneficiary or development fund manager."
636637
)
637638
def listActiveDevelopmentFundCoupons(): Seq[
638639
Contract[
@@ -643,6 +644,20 @@ abstract class WalletAppReference(
643644
consoleEnvironment.run {
644645
httpCommand(HttpWalletAppClient.ListActiveDevelopmentFundCoupons)
645646
}
647+
648+
@Help.Summary("Withdraw a DevelopmentFundCoupon")
649+
@Help.Description(
650+
"Withdraw a DevelopmentFundCoupon where the configured user acts as the development fund manager."
651+
)
652+
def withdrawDevelopmentFundCoupon(
653+
developmentFundCouponContractId: amuletCodegen.DevelopmentFundCoupon.ContractId,
654+
reason: String,
655+
): WithdrawDevelopmentFundCouponResponse =
656+
consoleEnvironment.run {
657+
httpCommand(
658+
HttpWalletAppClient.WithdrawDevelopmentFundCoupon(developmentFundCouponContractId, reason)
659+
)
660+
}
646661
}
647662

648663
/** Client (aka remote) reference to a wallet app in the style of ParticipantClientReference, i.e.,

apps/wallet/src/main/openapi/wallet-internal.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ paths:
891891
"$ref": "#/components/schemas/AllocateDevelopmentFundCouponResponse"
892892
"400":
893893
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/400"
894+
"403":
895+
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/403"
894896
"404":
895897
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/404"
896898
"500":
@@ -913,6 +915,37 @@ paths:
913915
"500":
914916
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/500"
915917

918+
/v0/wallet/development-fund-coupons/{contract_id}/withdraw:
919+
post:
920+
tags: [ wallet ]
921+
x-jvm-package: wallet
922+
operationId: "withdrawDevelopmentFundCoupon"
923+
parameters:
924+
- in: path
925+
name: contract_id
926+
required: true
927+
schema:
928+
type: string
929+
requestBody:
930+
required: true
931+
content:
932+
application/json:
933+
schema:
934+
"$ref": "#/components/schemas/WithdrawDevelopmentFundCouponRequest"
935+
responses:
936+
"200":
937+
description: ok
938+
content:
939+
application/json:
940+
schema:
941+
$ref: "#/components/schemas/WithdrawDevelopmentFundCouponResponse"
942+
"400":
943+
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/400"
944+
"404":
945+
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/404"
946+
"500":
947+
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/responses/500"
948+
916949

917950
components:
918951
schemas:
@@ -1701,3 +1734,20 @@ components:
17011734
type: array
17021735
items:
17031736
$ref: "../../../../common/src/main/openapi/common-external.yaml#/components/schemas/Contract"
1737+
1738+
WithdrawDevelopmentFundCouponRequest:
1739+
type: object
1740+
required:
1741+
- reason
1742+
properties:
1743+
reason:
1744+
type: string
1745+
1746+
WithdrawDevelopmentFundCouponResponse:
1747+
type: object
1748+
required:
1749+
- unclaimed_development_fund_coupon_contract_id
1750+
properties:
1751+
unclaimed_development_fund_coupon_contract_id:
1752+
type: string
1753+

apps/wallet/src/main/scala/org/lfdecentralizedtrust/splice/wallet/admin/api/client/commands/HttpWalletAppClient.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ object HttpWalletAppClient {
13511351
}
13521352
}
13531353

1354-
final case class AllocateDevelopmentFundCouponRequest(
1354+
final case class AllocateDevelopmentFundCoupon(
13551355
unclaimedDevelopmentFundCouponContractIds: Seq[
13561356
amuletCodegen.UnclaimedDevelopmentFundCoupon.ContractId
13571357
],
@@ -1419,4 +1419,32 @@ object HttpWalletAppClient {
14191419
}
14201420
}
14211421

1422+
final case class WithdrawDevelopmentFundCoupon(
1423+
developmentFundCouponContractId: amuletCodegen.DevelopmentFundCoupon.ContractId,
1424+
reason: String,
1425+
) extends InternalBaseCommand[
1426+
http.WithdrawDevelopmentFundCouponResponse,
1427+
definitions.WithdrawDevelopmentFundCouponResponse,
1428+
] {
1429+
override def submitRequest(
1430+
client: WalletClient,
1431+
headers: List[HttpHeader],
1432+
): EitherT[Future, Either[
1433+
Throwable,
1434+
HttpResponse,
1435+
], http.WithdrawDevelopmentFundCouponResponse] = client.withdrawDevelopmentFundCoupon(
1436+
developmentFundCouponContractId.contractId,
1437+
body = definitions.WithdrawDevelopmentFundCouponRequest(reason),
1438+
)
1439+
1440+
override protected def handleOk()(implicit
1441+
decoder: TemplateJsonDecoder
1442+
): PartialFunction[http.WithdrawDevelopmentFundCouponResponse, Either[
1443+
String,
1444+
definitions.WithdrawDevelopmentFundCouponResponse,
1445+
]] = { case http.WithdrawDevelopmentFundCouponResponse.OK(value) =>
1446+
Right(value)
1447+
}
1448+
}
1449+
14221450
}

apps/wallet/src/main/scala/org/lfdecentralizedtrust/splice/wallet/admin/http/HttpWalletHandler.scala

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ import org.lfdecentralizedtrust.splice.http.v0.definitions.{
8484
AllocateDevelopmentFundCouponRequest,
8585
AllocateDevelopmentFundCouponResponse,
8686
CreateTokenStandardTransferRequest,
87+
WithdrawDevelopmentFundCouponRequest,
88+
WithdrawDevelopmentFundCouponResponse,
8789
}
8890
import org.lfdecentralizedtrust.splice.util.SpliceUtil.damlDecimal
89-
9091
import org.lfdecentralizedtrust.splice.wallet.admin.http.UserWalletAuthExtractor.WalletUserRequest
9192

9293
import java.math.RoundingMode as JRM
@@ -1366,13 +1367,55 @@ class HttpWalletHandler(
13661367
override def listActiveDevelopmentFundCoupons(
13671368
respond: v0.WalletResource.ListActiveDevelopmentFundCouponsResponse.type
13681369
)()(
1369-
tuser: WalletUserRequest
1370+
extracted: WalletUserRequest
13701371
): Future[v0.WalletResource.ListActiveDevelopmentFundCouponsResponse] = {
1371-
implicit val WalletUserRequest(user, userWallet, traceContext) = tuser
1372-
listContracts(
1373-
amuletCodegen.DevelopmentFundCoupon.COMPANION,
1374-
userWallet.store,
1375-
d0.ListActiveDevelopmentFundCouponsResponse(_),
1376-
)
1372+
implicit val WalletUserRequest(user, userWallet, traceContext) = extracted
1373+
withSpan(s"$workflowId.listActiveDevelopmentFundCoupons") { _ => _ =>
1374+
listContracts(
1375+
amuletCodegen.DevelopmentFundCoupon.COMPANION,
1376+
userWallet.store,
1377+
d0.ListActiveDevelopmentFundCouponsResponse(_),
1378+
)
1379+
}
1380+
}
1381+
1382+
override def withdrawDevelopmentFundCoupon(
1383+
respond: WalletResource.WithdrawDevelopmentFundCouponResponse.type
1384+
)(contractId: String, body: WithdrawDevelopmentFundCouponRequest)(
1385+
extracted: WalletUserRequest
1386+
): Future[WalletResource.WithdrawDevelopmentFundCouponResponse] = {
1387+
implicit val WalletUserRequest(user, userWallet, traceContext) = extracted
1388+
withSpan(s"$workflowId.withdrawDevelopmentFundCoupon") { _ => _ =>
1389+
val store = userWallet.store
1390+
val developmentFundCouponContractId =
1391+
Codec.tryDecodeJavaContractId(UnclaimedDevelopmentFundCoupon.COMPANION)(contractId)
1392+
for {
1393+
domain <- scanConnection.getAmuletRulesDomain()(traceContext)
1394+
developmentFundCoupon <- store.multiDomainAcsStore
1395+
.getContractById(amuletCodegen.DevelopmentFundCoupon.COMPANION)(
1396+
developmentFundCouponContractId
1397+
)
1398+
.map(
1399+
_.toAssignedContract.getOrElse(
1400+
throw Status.Code.FAILED_PRECONDITION.toStatus
1401+
.withDescription(s"DevelopmentFundCoupon is not assigned to a synchronizer.")
1402+
.asRuntimeException()
1403+
)
1404+
)
1405+
result <- userWallet.connection
1406+
.submit(
1407+
Seq(store.key.validatorParty, store.key.endUserParty),
1408+
Seq.empty,
1409+
developmentFundCoupon.exercise(_.exerciseDevelopmentFundCoupon_Withdraw(body.reason)),
1410+
)
1411+
.withSynchronizerId(domain)
1412+
.noDedup
1413+
.yieldResult()
1414+
} yield WalletResource.WithdrawDevelopmentFundCouponResponseOK(
1415+
WithdrawDevelopmentFundCouponResponse(
1416+
result.exerciseResult.unclaimedDevelopmentFundCouponCid.contractId
1417+
)
1418+
)
1419+
}
13771420
}
13781421
}

0 commit comments

Comments
 (0)