Skip to content

Commit a1ffd04

Browse files
excludeDebugFields option to GetChoiceContextRequest (#3413)
Signed-off-by: Chun Lok Ling <chunlok.ling@digitalasset.com>
1 parent 2f114f8 commit a1ffd04

File tree

8 files changed

+86
-27
lines changed

8 files changed

+86
-27
lines changed

apps/scan/src/main/scala/org/lfdecentralizedtrust/splice/scan/admin/http/HttpTokenStandardAllocationHandler.scala

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class HttpTokenStandardAllocationHandler(
5050
allocationId,
5151
requireLockedAmulet = true,
5252
canBeFeatured = true,
53+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
5354
)
5455
} yield v1.Resource.GetAllocationTransferContextResponseOK(choiceContext)
5556
}
@@ -67,6 +68,7 @@ class HttpTokenStandardAllocationHandler(
6768
allocationId,
6869
requireLockedAmulet = false,
6970
canBeFeatured = false,
71+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
7072
)
7173
} yield v1.Resource.GetAllocationCancelContextResponseOK(choiceContext)
7274
}
@@ -84,6 +86,7 @@ class HttpTokenStandardAllocationHandler(
8486
allocationId,
8587
requireLockedAmulet = false,
8688
canBeFeatured = false,
89+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
8790
)
8891
} yield v1.Resource.GetAllocationWithdrawContextResponseOK(choiceContext)
8992
}
@@ -94,6 +97,7 @@ class HttpTokenStandardAllocationHandler(
9497
allocationId: String,
9598
requireLockedAmulet: Boolean,
9699
canBeFeatured: Boolean,
100+
excludeDebugFields: Boolean,
97101
)(implicit
98102
tc: TraceContext
99103
): Future[definitions.ChoiceContext] = {
@@ -125,21 +129,21 @@ class HttpTokenStandardAllocationHandler(
125129
),
126130
store,
127131
clock,
128-
new ChoiceContextBuilder(_),
132+
new ChoiceContextBuilder(_, excludeDebugFields),
129133
)
130134
} yield context
131135
}
132136
}
133137

134138
object HttpTokenStandardAllocationHandler {
135139

136-
final class ChoiceContextBuilder(activeSynchronizerId: String)(implicit
137-
elc: ErrorLoggingContext
140+
final class ChoiceContextBuilder(activeSynchronizerId: String, excludeDebugFields: Boolean)(
141+
implicit elc: ErrorLoggingContext
138142
) extends util.ChoiceContextBuilder[
139143
definitions.DisclosedContract,
140144
definitions.ChoiceContext,
141145
ChoiceContextBuilder,
142-
](activeSynchronizerId) {
146+
](activeSynchronizerId, excludeDebugFields) {
143147

144148
def build(): definitions.ChoiceContext = definitions.ChoiceContext(
145149
choiceContextData = io.circe.parser
@@ -156,6 +160,7 @@ object HttpTokenStandardAllocationHandler {
156160
override protected def toTokenStandardDisclosedContract[TCId, T](
157161
contract: Contract[TCId, T],
158162
synchronizerId: String,
163+
excludeDebugFields: Boolean,
159164
): definitions.DisclosedContract = {
160165
val asHttp = contract.toHttp
161166
definitions.DisclosedContract(
@@ -164,9 +169,15 @@ object HttpTokenStandardAllocationHandler {
164169
createdEventBlob = asHttp.createdEventBlob,
165170
synchronizerId = synchronizerId,
166171
debugPackageName =
167-
DarResources.lookupPackageId(contract.identifier.getPackageId).map(_.metadata.name),
168-
debugPayload = Some(asHttp.payload),
169-
debugCreatedAt = Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
172+
if (excludeDebugFields) None
173+
else
174+
DarResources
175+
.lookupPackageId(contract.identifier.getPackageId)
176+
.map(_.metadata.name),
177+
debugPayload = if (excludeDebugFields) None else Some(asHttp.payload),
178+
debugCreatedAt =
179+
if (excludeDebugFields) None
180+
else Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
170181
)
171182
}
172183
}

apps/scan/src/main/scala/org/lfdecentralizedtrust/splice/scan/admin/http/HttpTokenStandardAllocationInstructionHandler.scala

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class HttpTokenStandardAllocationInstructionHandler(
5656
.getConfigAsOf(now)
5757
.decentralizedSynchronizer
5858
.activeSynchronizer
59+
val excludeDebugFields = body.excludeDebugFields.getOrElse(false)
5960
v1.Resource.GetAllocationFactoryResponseOK(
6061
definitions.FactoryWithChoiceContext(
6162
externalPartyAmuletRules.contractId.contractId,
@@ -78,9 +79,18 @@ class HttpTokenStandardAllocationInstructionHandler(
7879
toTokenStandardDisclosedContract(
7980
externalPartyAmuletRules.contract,
8081
activeSynchronizerId,
82+
excludeDebugFields,
83+
),
84+
toTokenStandardDisclosedContract(
85+
amuletRules,
86+
activeSynchronizerId,
87+
excludeDebugFields,
88+
),
89+
toTokenStandardDisclosedContract(
90+
newestOpenRound.contract,
91+
activeSynchronizerId,
92+
excludeDebugFields,
8193
),
82-
toTokenStandardDisclosedContract(amuletRules, activeSynchronizerId),
83-
toTokenStandardDisclosedContract(newestOpenRound.contract, activeSynchronizerId),
8494
),
8595
),
8696
)
@@ -93,6 +103,7 @@ class HttpTokenStandardAllocationInstructionHandler(
93103
private def toTokenStandardDisclosedContract[TCId, T](
94104
contract: Contract[TCId, T],
95105
synchronizerId: String,
106+
excludeDebugFields: Boolean,
96107
)(implicit elc: ErrorLoggingContext): definitions.DisclosedContract = {
97108
val asHttp = contract.toHttp
98109
definitions.DisclosedContract(
@@ -101,9 +112,15 @@ class HttpTokenStandardAllocationInstructionHandler(
101112
createdEventBlob = asHttp.createdEventBlob,
102113
synchronizerId = synchronizerId,
103114
debugPackageName =
104-
DarResources.lookupPackageId(contract.identifier.getPackageId).map(_.metadata.name),
105-
debugPayload = Some(asHttp.payload),
106-
debugCreatedAt = Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
115+
if (excludeDebugFields) None
116+
else
117+
DarResources
118+
.lookupPackageId(contract.identifier.getPackageId)
119+
.map(_.metadata.name),
120+
debugPayload = if (excludeDebugFields) None else Some(asHttp.payload),
121+
debugCreatedAt =
122+
if (excludeDebugFields) None
123+
else Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
107124
)
108125
}
109126

apps/scan/src/main/scala/org/lfdecentralizedtrust/splice/scan/admin/http/HttpTokenStandardTransferInstructionHandler.scala

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class HttpTokenStandardTransferInstructionHandler(
5757
.asRuntimeException()
5858
)
5959
}
60-
(choiceContextBuilder, newestOpenRound) <- getAmuletRulesTransferContext()
60+
(choiceContextBuilder, newestOpenRound) <- getAmuletRulesTransferContext(
61+
body.excludeDebugFields.getOrElse(false)
62+
)
6163
externalPartyAmuletRules <- store.getExternalPartyAmuletRules()
6264
// pre-approval and featured app rights are only provided if they exist and are required
6365
receiver = PartyId.tryFromProtoPrimitive(transferInstr.transfer.receiver)
@@ -107,6 +109,7 @@ class HttpTokenStandardTransferInstructionHandler(
107109
choiceContext <- getTransferInstructionChoiceContext(
108110
transferInstructionId,
109111
requireLockedAmulet = true,
112+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
110113
)
111114
} yield {
112115
v1.Resource.GetTransferInstructionAcceptContextResponseOK(choiceContext)
@@ -125,6 +128,7 @@ class HttpTokenStandardTransferInstructionHandler(
125128
choiceContext <- getTransferInstructionChoiceContext(
126129
transferInstructionId,
127130
requireLockedAmulet = false,
131+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
128132
)
129133
} yield {
130134
v1.Resource.GetTransferInstructionRejectContextResponseOK(choiceContext)
@@ -143,14 +147,15 @@ class HttpTokenStandardTransferInstructionHandler(
143147
choiceContext <- getTransferInstructionChoiceContext(
144148
transferInstructionId,
145149
requireLockedAmulet = false,
150+
excludeDebugFields = body.excludeDebugFields.getOrElse(false),
146151
)
147152
} yield {
148153
v1.Resource.GetTransferInstructionWithdrawContextResponseOK(choiceContext)
149154
}
150155
}
151156
}
152157

153-
private def getAmuletRulesTransferContext()(implicit
158+
private def getAmuletRulesTransferContext(excludeDebugFields: Boolean)(implicit
154159
tc: TraceContext
155160
): Future[(ChoiceContextBuilder, splice.round.OpenMiningRound)] = {
156161
val now = clock.now
@@ -170,7 +175,8 @@ class HttpTokenStandardTransferInstructionHandler(
170175
AmuletConfigSchedule(amuletRules.payload.configSchedule)
171176
.getConfigAsOf(now)
172177
.decentralizedSynchronizer
173-
.activeSynchronizer
178+
.activeSynchronizer,
179+
excludeDebugFields,
174180
)
175181

176182
(
@@ -187,6 +193,7 @@ class HttpTokenStandardTransferInstructionHandler(
187193
private def getTransferInstructionChoiceContext(
188194
transferInstructionId: String,
189195
requireLockedAmulet: Boolean,
196+
excludeDebugFields: Boolean,
190197
)(implicit
191198
tc: TraceContext
192199
): Future[definitions.ChoiceContext] = {
@@ -216,7 +223,7 @@ class HttpTokenStandardTransferInstructionHandler(
216223
None,
217224
store,
218225
clock,
219-
new ChoiceContextBuilder(_),
226+
new ChoiceContextBuilder(_, excludeDebugFields),
220227
)
221228
} yield context
222229
}
@@ -225,13 +232,13 @@ class HttpTokenStandardTransferInstructionHandler(
225232

226233
object HttpTokenStandardTransferInstructionHandler {
227234

228-
final class ChoiceContextBuilder(activeSynchronizerId: String)(implicit
229-
elc: ErrorLoggingContext
235+
final class ChoiceContextBuilder(activeSynchronizerId: String, excludeDebugFields: Boolean)(
236+
implicit elc: ErrorLoggingContext
230237
) extends util.ChoiceContextBuilder[
231238
definitions.DisclosedContract,
232239
definitions.ChoiceContext,
233240
ChoiceContextBuilder,
234-
](activeSynchronizerId) {
241+
](activeSynchronizerId, excludeDebugFields) {
235242

236243
def build(): definitions.ChoiceContext = definitions.ChoiceContext(
237244
choiceContextData = io.circe.parser
@@ -248,6 +255,7 @@ object HttpTokenStandardTransferInstructionHandler {
248255
override protected def toTokenStandardDisclosedContract[TCId, T](
249256
contract: Contract[TCId, T],
250257
synchronizerId: String,
258+
excludeDebugFields: Boolean,
251259
): definitions.DisclosedContract = {
252260
val asHttp = contract.toHttp
253261
definitions.DisclosedContract(
@@ -256,9 +264,15 @@ object HttpTokenStandardTransferInstructionHandler {
256264
createdEventBlob = asHttp.createdEventBlob,
257265
synchronizerId = synchronizerId,
258266
debugPackageName =
259-
DarResources.lookupPackageId(contract.identifier.getPackageId).map(_.metadata.name),
260-
debugPayload = Some(asHttp.payload),
261-
debugCreatedAt = Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
267+
if (excludeDebugFields) None
268+
else
269+
DarResources
270+
.lookupPackageId(contract.identifier.getPackageId)
271+
.map(_.metadata.name),
272+
debugPayload = if (excludeDebugFields) None else Some(asHttp.payload),
273+
debugCreatedAt =
274+
if (excludeDebugFields) None
275+
else Some(contract.createdAt.atOffset(ZoneOffset.UTC)),
262276
)
263277
}
264278
}

apps/scan/src/main/scala/org/lfdecentralizedtrust/splice/scan/util/ChoiceContextBuilder.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ import scala.collection.mutable.ListBuffer
2121
import scala.concurrent.{ExecutionContext, Future}
2222

2323
abstract class ChoiceContextBuilder[DisclosedContract, ChoiceContext, Self](
24-
val activeSynchronizerId: String
24+
val activeSynchronizerId: String,
25+
val excludeDebugFields: Boolean,
2526
) { self: Self =>
2627

2728
protected def toTokenStandardDisclosedContract[TCid, T](
2829
contract: Contract[TCid, T],
2930
synchronizerId: String,
31+
excludeDebugFields: Boolean,
3032
): DisclosedContract
3133

3234
val disclosedContracts: ListBuffer[DisclosedContract] = ListBuffer.empty
3335
val contextEntries: mutable.Map[String, metadatav1.AnyValue] = mutable.Map.empty
3436

3537
def disclose(contract: Contract[?, ?]): Self = {
36-
disclosedContracts.addOne(toTokenStandardDisclosedContract(contract, activeSynchronizerId))
38+
disclosedContracts.addOne(
39+
toTokenStandardDisclosedContract(contract, activeSynchronizerId, excludeDebugFields)
40+
)
3741
this
3842
}
3943

docs/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
similar to most other SV app endpoints.
4949
Use the public ``/v0/dso`` endpoint in the scan app if you need to fetch DSO info.
5050

51+
- Added an optional ``excludeDebugFields``` boolean to the request body of allocation and transfer endpoints for the Token Standard component.
52+
(``splice-api-token-allocation-v1`` and ``splice-api-token-transfer-instruction-v1``
53+
54+
Clients can now set this to true to omit debug information from the response.
55+
5156
.. release-notes:: 0.5.4
5257

5358
- Participant

token-standard/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token-standard/splice-api-token-allocation-v1/openapi/allocation-v1.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ info:
77
description: |
88
Implemented by token registries for the purpose of the use and management of
99
allocations by wallets and apps orchestrating the settlement of asset transfers.
10-
version: 1.0.0
10+
version: 1.1.0
1111
paths:
1212

1313
/registry/allocations/v1/{allocationId}/choice-contexts/execute-transfer:
@@ -127,6 +127,10 @@ components:
127127
type: object
128128
additionalProperties:
129129
type: string
130+
excludeDebugFields:
131+
description: "If set to true, the response will not include debug fields."
132+
default: false
133+
type: boolean
130134

131135
ChoiceContext:
132136
description: |

token-standard/splice-api-token-transfer-instruction-v1/openapi/transfer-instruction-v1.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ info:
77
description: |
88
Implemented by token registries for the purpose of supporting the initiation
99
of asset transfers; e.g. to settle off-ledger obligations.
10-
version: 1.0.0
10+
version: 1.1.0
1111
paths:
1212

1313
/registry/transfer-instruction/v1/transfer-factory:
@@ -175,6 +175,10 @@ components:
175175
type: object
176176
additionalProperties:
177177
type: string
178+
excludeDebugFields:
179+
description: "If set to true, the response will not include debug fields."
180+
default: false
181+
type: boolean
178182

179183
TransferFactoryWithChoiceContext:
180184
description: |

0 commit comments

Comments
 (0)