Send Yo's! to all your friends running Corda nodes!
In the original yo application, the app sent what is essentially a nudge from one endpoint and another.
In corda, we can use abstractions to accomplish the same thing.
We define a state (the yo to be shared), define a contract (the way to make sure the yo is legit), and define the flow (the control flow of our cordapp).
We define a Yo as a state, or a corda fact.
public YoState(Party origin, Party target) {
this.origin = origin;
this.target = target;
this.yo = "Yo!";
}We define the "Yo Social Contract", which, in this case, verifies some basic assumptions about a Yo.
@Override
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
CommandWithParties<Commands.Send> command = requireSingleCommand(tx.getCommands(), Commands.Send.class);
requireThat(req -> {
req.using("There can be no inputs when Yo'ing other parties", tx.getInputs().isEmpty());
req.using("There must be one output: The Yo!", tx.getOutputs().size() == 1);
YoState yo = tx.outputsOfType(YoState.class).get(0);
req.using("No sending Yo's to yourself!", !yo.getTarget().equals(yo.getOrigin()));
req.using("The Yo! must be signed by the sender.", command.getSigners().contains(yo.getOrigin().getOwningKey()));
return null;
});
}And then we send the Yo within a flow.
Party me = getOurIdentity();
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
Command<YoContract.Commands.Send> command = new Command<YoContract.Commands.Send>(new YoContract.Commands.Send(), ImmutableList.of(me.getOwningKey()));
YoState state = new YoState(me, target);
StateAndContract stateAndContract = new StateAndContract(state, YoContract.ID);
TransactionBuilder utx = new TransactionBuilder(notary).withItems(stateAndContract, command);On the receiving end, the other corda node will simply receive the Yo using corda provided subroutines, or subflows.
return subFlow(new ReceiveFinalityFlow(counterpartySession));See https://docs.corda.net/getting-set-up.html.
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
./gradlew clean deployNodes
Then type: (to run the nodes)
./build/nodes/runnodes
We will interact with the nodes via their specific shells. When the nodes are up and running, use the following command to send a Yo to another node:
flow start YoFlow target: PartyB
Where NODE_NAME is 'PartyA' or 'PartyB'. The space after the : is required. You are not required to use the full
X500 name in the node shell. Note you can't sent a Yo! to yourself because that's not cool!
To see all the Yo's! other nodes have sent you in your vault (you do not store the Yo's! you send yourself), run:
run vaultQuery contractStateType: net.corda.examples.yo.states.YoState