Skip to content

Instantly share code, notes, and snippets.

data class RpcStartFlowResponse(
val flowId: FlowId,
val clientId: String?
)
@CordaSerializable
data class RpcStartFlowRequest(
val flowName: String,
val clientId: String,
val parameters: RpcStartFlowRequestParameters
)
@StartableByRPC
public class SampleFlow implements Flow<SignedTransactionDigest> {
private RpcStartFlowRequestParameters params;
@CordaInject
private JsonMarshallingService jsonMarshallingService;
@JsonConstructor
public SampleFlow(RpcStartFlowRequestParameters params) {
public static void main(String[] args) throws Exception{
// Establish connection, get attestation and send bid code here.
...
byte[] encryptedReply = new byte[fromHost.readInt()];
System.out.println("Reading reply mail of length " + encryptedReply.length + " bytes.");
fromHost.readFully(encryptedReply);
EnclaveMail reply = postOffice.decryptMail(encryptedReply);
System.out.println("Enclave gave us the answer '" + new String(reply.getBodyAsBytes()) + "'");
private static int getUserBidInput(String args[]) throws Exception{
if(args.length > 0 && args[0].equals("BID")) {
System.out.println("Please enter your Bid Amount");
System.out.println();
System.out.println("---------------------------");
System.out.println("Bid Amount: ");
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String bidAmount = reader.readLine();
return Integer.valueOf(bidAmount);
public static void main(String[] args) throws Exception{
// Establish connection and get attestaion code here
...
int bid = getUserBidInput(args);
Output serializedOutput = serializeMessage(messageType, bid);
PrivateKey myKey = Curve25519PrivateKey.random();
PostOffice postOffice = attestation.createPostOffice(myKey, UUID.randomUUID().toString());
byte[] encryptedMail = postOffice.encryptMail(serializedOutput.getBuffer());
private static Pair<DataInputStream, DataOutputStream> establishConnection() throws Exception{
DataInputStream fromHost;
DataOutputStream toHost;
while (true) {
try {
System.out.println("Attempting to connect to Host at localhost:5051");
Socket socket = new Socket();
socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), 5051), 10000);
fromHost = new DataInputStream(socket.getInputStream());
toHost = new DataOutputStream(socket.getOutputStream());
public class AuctionClient {
public static void main(String[] args) throws Exception{
Pair<DataInputStream, DataOutputStream> streams = establishConnection();
DataInputStream fromHost = streams.getFirst();
DataOutputStream toHost = streams.getSecond();
EnclaveInstanceInfo attestation = getAttestation(fromHost);
...
}
private void recieveMailFromClientAndDeliverToEnclave(Socket clientSocket, String routingHint){
try {
DataInputStream input = new DataInputStream(clientSocket.getInputStream());
byte[] mailBytes = new byte[input.readInt()];
input.readFully(mailBytes);
enclaveHost.deliverMail(1, mailBytes, routingHint);
}catch (IOException ioException){
ioException.printStackTrace();
}
private void sendMessageToClient(String routingHint, byte[] content){
try {
Socket clientSocket = clientMap.get(routingHint);
DataOutputStream outputStream = new DataOutputStream(clientSocket.getOutputStream());
outputStream.writeInt(content.length);
outputStream.write(content);
outputStream.flush();
}catch (IOException ioe){
ioe.printStackTrace();
return;