Skip to content

Instantly share code, notes, and snippets.

data class CustomSettlementMethod(
override val accountToPay: String,
override val settlementOracle: Party,
override val paymentFlow: Class<CustomMakeOffLedgerPayment<*>> = CustomMakeOffLedgerPayment::class.java
) : OffLedgerPayment<MakeCustomPayment<*>> {
override fun toString(): String {
return "Pay account $accountToPay and use $settlementOracle as settlement Oracle."
}
}
fun verifyCustomPaymentRailSettlement(obligation: Obligation<TokenType>, payment: CustomPayment<TokenType>): VerifyResult {
val oracleService = serviceHub.cordaService(MyPaymentRailService::class.java)
val result = oracleService.hasPaymentSettled(payment, obligation)
// .. check result status, etc..
}
@CordaService
class MyPaymentRailService(val services: AppServiceHub) : SingletonSerializeAsToken() {
// API Methods here
// checkObligeeReceivedPayment(..)
// hasPaymentSettled(..)
}
class VerifySettlement(private val otherSession: FlowSession) : FlowLogic<Unit>() {
// .. omitting ..
@Suspendable
override fun call() {
// .. omitting ..
// 4. Handle different settlement methods.
val verifyResult = when (settlementMethod) {
abstract class CustomMakeOffLedgerPayment<T: TokenType>(
val amount: Amount<T>,
private val obligationStateAndRef: StateAndRef<Obligation<*>>,
open val settlementMethod: OffLedgerPayment<*>,
override val progressTracker: ProgressTracker = MakeOffLedgerPayment.tracker()
): MakeOffLedgerPayment<T>(amount, obligationStateAndRef, settlementMethod, progressTracker) {
@Suspendable
override fun setup() {
// Perform any setup tasks needed for your payment rail
}
abstract class CustomMakeOffLedgerPayment<T: TokenType>(
val amount: Amount<T>,
private val obligationStateAndRef: StateAndRef<Obligation<*>>,
open val settlementMethod: OffLedgerPayment<*>,
override val progressTracker: ProgressTracker = MakeOffLedgerPayment.tracker()
): MakeOffLedgerPayment<T>(amount, obligationStateAndRef, settlementMethod) {
@Suspendable
override fun setup() {
// Perform any setup tasks needed for your payment rail
}
data class CustomPayment<T : TokenType>(
override val paymentReference: PaymentReference,
override val amount: Amount<T>,
override var status: PaymentStatus = PaymentStatus.SENT
) : Payment<T> {
override fun toString(): String {
return "Amount: $amount, Transaction ID: $paymentReference, Status: $status"
}
}
@CordaService
class MyPaymentRailService(val services: AppServiceHub) : SingletonSerializeAsToken() {
// API methods here
// makePayment()
// checkBalance(), etc..
}
@CordaService
class MyPaymentRailService(val services: AppServiceHub) : SingletonSerializeAsToken() {
// API methods here
// makePayment()
// checkBalance(), etc..
}
@brenden-t-r
brenden-t-r / Flow Issue Task 1.kt
Last active April 6, 2019 15:11
Corda Training Solutions - Flows
@InitiatingFlow
@StartableByRPC
class IOUIssueFlow(val state: IOUState): FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
// Step 1. Get a reference to the notary service on our network and our key pair.
// Note: ongoing work to support multiple notary identities is still in progress.
val notary = serviceHub.networkMapCache.notaryIdentities.first()
// Step 2. Create a new issue command.