This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progressTracker.setCurrentStep(OTHER_TX_COMPONENTS); | |
// Reference input states are constructed from StateAndRefs. | |
ReferencedStateAndRef referenceState = ourStateAndRef.referenced(); | |
// Output states are constructed from scratch. | |
DummyState ourOutputState = new DummyState(); | |
// Or as copies of other states with some properties changed. | |
DummyState ourOtherOutputState = ourOutputState.copy(77); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
progressTracker.setCurrentStep(EXTRACTING_VAULT_STATES); | |
// Let's assume there are already some DummyState in our | |
// node's vault, stored there as a result of running past flows, | |
// and we want to consume them in a transaction. There are many | |
// ways to extract these states from our vault. | |
// For example, we would extract any unconsumed DummyState | |
// from our vault as follows: | |
VaultQueryCriteria criteria = new VaultQueryCriteria(Vault.StateStatus.UNCONSUMED); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UntrustworthyData<Boolean> packet2 = counterpartySession.sendAndReceive(Boolean.class, "You can send and receive any class!"); | |
Boolean bool = packet2.unwrap(data -> { | |
// Perform checking on the object received. | |
// T O D O: Check the received object. | |
// Return the object. | |
return data; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CordaX500Name counterPartyName = new CordaX500Name("NodeA", "London", "GB"); | |
Party namedCounterparty = getServiceHub().getIdentityService().wellKnownPartyFromX500Name(counterPartyName); | |
Party keyedCounterparty = getServiceHub().getIdentityService().partyFromKey(dummyPubKey); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CordaX500Name notaryName = new CordaX500Name("Notary Service", "London", "GB"); | |
Party specificNotary = Objects.requireNonNull(getServiceHub().getNetworkMapCache().getNotary(notaryName)); | |
// Alternatively, we can pick an arbitrary notary from the notary | |
// list. However, it is always preferable to specify the notary | |
// explicitly, as the notary list might change when new notaries are | |
// introduced, or old ones decommissioned. | |
Party firstNotary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simply reverses the bytes that are passed in. | |
*/ | |
public class ReverseEnclave extends Enclave { | |
// We store the previous result to showcase that the enclave internals can be examined in a mock test. | |
byte[] previousResult; | |
@Override | |
protected byte[] receiveFromUntrustedHost(byte[] bytes) { | |
// This is used for host->enclave calls so we don't have to think about authentication. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the client that will upload secrets to the enclave for processing. | |
// In this simple hello world app, we just connect to a TCP socket, take the EnclaveInstanceInfo we're sent | |
// and transmit an encrypted string. The enclave will reverse it and send it back. You can use this sample | |
// as a basis for your own apps. | |
// assume we've gotten our args from outside this code | |
String toReverse = String.join(" ", args); | |
// Connect to the host, it will send us a remote attestation (EnclaveInstanceInfo). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set up server for clients to reach enclave | |
int port = 9999; | |
System.out.println("Listening on port " + port + ". Use the client app to send strings for reversal."); | |
ServerSocket acceptor = new ServerSocket(port); | |
Socket connection = acceptor.accept(); | |
// Just send the attestation straight to whoever connects. It's signed so that is MITM-safe. | |
DataOutputStream output = new DataOutputStream(connection.getOutputStream()); | |
// load our enclave app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyContract extends StandardContract implements Contract { | |
/* Verification logic here. Typically following the lines of: */ | |
if (commandData.equals(new Commands.Action())) { | |
requireThat(require -> { | |
require.using("No inputs should be consumed.", tx.getInputStates().size() == 0); | |
require.using( "Only one output states should be created.", tx.getOutputStates().size() == 1); | |
} | |
} | |
// . . . |