net.corda.protocols / TwoPartyTradeProtocol

# TwoPartyTradeProtocol

`object TwoPartyTradeProtocol`

This asset trading protocol implements a "delivery vs payment" type swap. It has two parties (B and S for buyer and seller) and the following steps:

1. S sends the StateAndRef pointing to what they want to sell to B, along with info about the price they require B to pay. For example this has probably been agreed on an exchange.

2. B sends to S a SignedTransaction that includes the state as input, Bs cash as input, the state with the new owner key as output, and any change cash as output. It contains a single signature from B but isnt valid because it lacks a signature from S authorising movement of the asset.

3. S signs it and hands the now finalised SignedWireTransaction back to B.

Assuming no malicious termination, they both end the protocol being in posession of a valid, signed transaction that represents an atomic asset swap.

Note that its the seller who initiates contact with the buyer, not vice-versa as you might imagine.

To initiate the protocol, use either the runBuyer or runSeller methods, depending on which side of the trade your node is taking. These methods return a future which will complete once the trade is over and a fully signed transaction is available: you can either block your thread waiting for the protocol to complete by using ListenableFuture.get or more usefully, register a callback that will be invoked when the time comes.

To see an example of how to use this class, look at the unit tests.

### Types

Buyer | `class Buyer : ProtocolLogic<SignedTransaction>`
Seller | `class Seller : ProtocolLogic<SignedTransaction>`
SellerTradeInfo | `data class SellerTradeInfo`
SignaturesFromSeller | `data class SignaturesFromSeller`

### Exceptions

AssetMismatchException | `class AssetMismatchException : Exception`
UnacceptablePriceException | `class UnacceptablePriceException : Exception`