Skip to content

Instantly share code, notes, and snippets.

@njgheorghita
Last active July 7, 2017 20:41
Show Gist options
  • Save njgheorghita/88834bed50db7f6b331a58a7b1e9f856 to your computer and use it in GitHub Desktop.
Save njgheorghita/88834bed50db7f6b331a58a7b1e9f856 to your computer and use it in GitHub Desktop.

Trade Finance Cordapp Outline

Seller SME -> S // Buyer SME -> B // Seller Bank -> SB // Buyer Bank -> BB

Assumptions

  • simplify dlt as much as possible. time is better spent on frontend as per Rashi.
  • since we're using api calls & security is out of scope, do we need / want authentication on who can update? how?
  • exact status terms are not finalized!
  • two flows (proposeTradeTxFlow & updateTradeTxFlow) keeps it simple.
  • move bank identities to model?

Proposal (via proposeTradeTxFlow)

  • S creates a tradeTx proposal
  • API request -> {purchase_order_id, seller_id, buyer_id, tx_amount, delivery_date, seller_bank_name, buyer_bank_name}
  • API response -> {boolean}

Created on DLT

  • tradeTx Model (immutable throughout tradeTx lifecycle (enforced via contract)) { purchase_order_id: Int, seller_id: Int, buyer_id: Int, tx_amount: Int, delivery_date: Date }
  • tradeTx Output State { tradeTx: Model, sellerBank: Party, buyerBank: Party, status: pendingBuyerApproval, contract: TradeTxContract, actionDate: Date, (records the day this state was created, can be used to look up all dates when tradeTx was updated) linearId: UniqueIdentifier }

Buyer Decision

via updateTradeTxFlow & buyerApproval command

  • If B doesn't agree to terms -> updates tradeTx status to Rejected (via updateTradeTxFlow & Reject command)
  • If B agrees this is a valid tradeTx . . .
  • Consumes pendingBuyerApproval state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> pendingBbApproval, actionDate -> today

Buyer Bank Decision

via updateTradeTxFlow & buyerBankApproval command

  • If BB doesn't agree to terms -> updates tradeTx status to Rejected (via updateTradeTxFlow & Reject command)
  • If BB aggrees this is a valid tradeTx . . .
  • Consumes pendingBbApproval state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> pendingSbApproval, actionDate -> today

Seller Bank Decision

via updateTradeTxFlow & sellerBankApproval command

  • If SB doesn't agree to terms -> updates tradeTx status to Rejected (via updateTradeTxFlow & Reject command)

  • If SB aggrees this is a valid tradeTx . . .

  • Consumes pendingSbApproval state

  • Creates new state

    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> Approved, actionDate -> today
  • At this point, we have 4 parties consensus on an immutable state - tradeTx is a go. tradeTx can no longer be rejected

Approved -> Ready

via updateTradeTxFlow & Ready command

  • API request {/tradeTxId/ready}
  • API response {boolean}
  • Consumes Approved state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> Ready, actionDate -> today

Ready -> Shipped

via updateTradeTxFlow & Shipped command

  • API request {/tradeTxId/shipped}
  • API response {boolean}
  • Consumes Ready state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> Shipped, actionDate -> today

Shipped -> Received

via updateTradeTxFlow & Received command

  • API request {/tradeTxId/ready}
  • API response {boolean}
  • Consumes Shipped state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> Received, actionDate -> today

Received -> PaymentSent

via updateTradeTxFlow & PaymentSent command

  • API request {/tradeTxId/ready}
  • API response {boolean}
  • Consumes Received state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> PaymentSent, actionDate -> today

PaymentSent -> Complete

via updateTradeTxFlow & Complete command

  • API request {/tradeTxId/ready}
  • API response {boolean}
  • Consumes PaymentSent state
  • Creates new state
    • same: tradeTx, sellerBank, buyerBank, contract, linearId
    • status -> Complete, actionDate -> today

Other API Endpoints

TradeTx Current State

  • GET {/tradeTxId/current}
  • API response -> returns current tradeTxState for a tradeTx

TradeTx Transaction History

  • GET {/tradeTxId/history}
  • API response -> returns history of tradeTxStates for a tradeTx

All Current TradeTx's for a Bank ??

  • GET {/bankName/getBankTrades}

All Current TradeTx's for an SME ??

  • GET {/smeId/getSmeTrades}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment