Skip to content

Instantly share code, notes, and snippets.

@parisyup
Created May 28, 2024 13:42
Show Gist options
  • Save parisyup/0544617632530b19ec96b933f035669a to your computer and use it in GitHub Desktop.
Save parisyup/0544617632530b19ec96b933f035669a to your computer and use it in GitHub Desktop.
// Multiple Commands not permitted
results["Multiple Commands not permitted"] = try {
val iouState = IOUState(
amount = 10,
paid = 3,
lender = myInfo.name,
borrower = otherMember.name,
linearId = UUID.randomUUID(),
participants = listOf(myInfo.ledgerKeys.first(), otherMember.ledgerKeys.first())
)
val txBuilder = ledgerService.createTransactionBuilder()
.setNotary(notary.name)
.setTimeWindowBetween(Instant.now(), Instant.now().plusMillis(Duration.ofDays(1).toMillis()))
.addOutputState(iouState)
.addInputState(inputStateRef)
.addCommand(IOUContract.Issue())
.addCommand(IOUContract.Transfer())
.addSignatories(iouState.participants)
@Suppress("DEPRECATION", "UNUSED_VARIABLE")
val signedTransaction = txBuilder.toSignedTransaction()
"Fail"
} catch (e:Exception) {
val exceptionMessage = e.message ?: "No exception message"
if (exceptionMessage.contains("Requires a single command.")) {
"Pass" }
else {
"Contract failed but with a different Exception: ${e.message}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment