This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"clientRequestId": "sendAndRecieve-2", | |
"flowClassName": "com.r3.developers.samples.obligation.workflows.sendAndReceiveTransaction", | |
"requestBody": { | |
"stateRef": "SHA-256D:8DFDD6723450146F64CE22D6B39D4127652ABF45066E0BDD7C63BC18998EBD9A", | |
"members": ["CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB"], | |
"forceBackchain": "false" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.r3.developers.samples.obligation.workflows; | |
import net.corda.v5.application.crypto.DigestService; | |
import net.corda.v5.application.flows.*; | |
import net.corda.v5.application.marshalling.JsonMarshallingService; | |
import net.corda.v5.application.membership.MemberLookup; | |
import net.corda.v5.application.messaging.FlowMessaging; | |
import net.corda.v5.application.messaging.FlowSession; | |
import net.corda.v5.base.annotations.Suspendable; | |
import net.corda.v5.base.types.MemberX500Name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String call(ClientRequestBody requestBody) { | |
sendAndRecieveTransactionArgs request = requestBody.getRequestBodyAs(jsonMarshallingService, sendAndRecieveTransactionArgs.class); | |
SecureHash transactionId = StateRef.parse(request.getStateRef(), digestService).getTransactionId(); | |
var transaction = requireNotNull(utxoLedgerService.findSignedTransaction(transactionId), | |
"Transaction is not found or verified."); | |
var members = request.getMembers().stream() | |
.map(x500 -> requireNotNull(memberLookup.lookup(MemberX500Name.parse(x500)), | |
"Member " + x500 + " does not exist in the membership group")) | |
.collect(Collectors.toList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InitiatedBy(protocol = "utxo-transaction-transmission-protocol") | |
public class ReceiveTransactionFlow implements ResponderFlow { | |
private static final Logger log = LoggerFactory.getLogger(ReceiveTransactionFlow.class); | |
@CordaInject | |
private UtxoLedgerService utxoLedgerService; | |
@Suspendable | |
@Override | |
public void call(FlowSession session) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
utxoLedgerService.sendTransaction(transaction, sessions); | |
} catch (Exception e) { | |
log.warn("Sending transaction for " + transactionId + " failed.", e); | |
throw e; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InitiatedBy(protocol = "utxo-transaction-transmission-protocol") | |
class ReceiveTransactionFlow: ResponderFlow { | |
private val log = LoggerFactory.getLogger(ReceiveTransactionFlow::class.java) | |
@CordaInject | |
lateinit var utxoLedgerService: UtxoLedgerService | |
@Suspendable | |
override fun call(session: FlowSession) { | |
val transaction = utxoLedgerService.receiveTransaction(session) | |
log.info("Received transaction - ${transaction.id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InitiatingFlow(protocol = "utxo-transaction-transmission-protocol") | |
class sendAndRecieveTransactionFlow : ClientStartableFlow { | |
data class Request( | |
val stateRef: String, | |
val members: List<String>, | |
val forceBackchain: Boolean = false | |
) | |
data class Response(val transactionId: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val transactionId = StateRef.parse(request.stateRef, digestService).transactionId | |
val transaction = requireNotNull(utxoLedgerService.findSignedTransaction(transactionId)) { | |
"Transaction is not found or verified." | |
} | |
val members = request.members.map { x500 -> | |
requireNotNull(memberLookup.lookup(MemberX500Name.parse(x500))) { | |
"Member $x500 does not exist in the membership group" | |
} | |
} | |
val sessions = members.map { flowMessaging.initiateFlow(it.name) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
utxoLedgerService.sendTransaction(transaction, sessions) | |
} catch (e: Exception) { | |
log.warn("Sending transaction for $transactionId failed.", e) | |
throw e | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only Two Participants | |
results["Only Two Participants"] = try { | |
val iouState = IOUState( | |
amount = 10, | |
paid = 3, | |
lender = myInfo.name, | |
borrower = otherMember.name, | |
linearId = UUID.randomUUID(), | |
participants = listOf(myInfo.ledgerKeys.first()) | |
) |
NewerOlder