Skip to content

Commit 154b1e2

Browse files
committed
Merge branch 'master' of github.com:corda/samples-java
2 parents 4e2e0cf + 9f9c2f2 commit 154b1e2

File tree

7 files changed

+21
-23
lines changed

7 files changed

+21
-23
lines changed

Tokens/spaceships-javaAPIs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tokens_release_version = '1.2-SNAPSHOT'
1010
You must download the latest source [here](https://github.com/corda/token-sdk) and then run the gradle task 'publishToMavenLocal'
1111

1212
---
13-
This cordapp demonstrates the new Java Apis released with TokenSDK 1.2
13+
This CorDapp demonstrates the new Java APIs released with Token SDK 1.2
1414

1515
For an exploratory overview of usage, checkout the following blog post: [here](https://medium.com/corda/corda-tokens-made-easy-with-new-java-apis-83095693d72)
1616

@@ -36,7 +36,7 @@ Additionally two new Java Builder classes have been added to allow easy creation
3636
- FungibleTokenBuilder
3737
- NonFungibleTokenBuilder
3838

39-
The Cordapp will allow International Planetary Council (IPC) residents to use their local currencies to either purchase unique spaceships (represented by NonFungibleToken) OR invest in partial ownership of a spaceship (represented by a FungibleToken).
39+
The CorDapp will allow International Planetary Council (IPC) residents to use their local currencies to either purchase unique spaceships (represented by NonFungibleToken) OR invest in partial ownership of a spaceship (represented by a FungibleToken).
4040

4141
Examples of the new Java APIs will be used throughout and identified as such.
4242

@@ -47,7 +47,7 @@ Examples of the new Java APIs will be used throughout and identified as such.
4747

4848
### Flows
4949

50-
Flows are executed through the `FlowTests` class in the workflows module. They can also be run through the CrashShell.
50+
Flows are executed through the `FlowTests` class in the workflows module. They can also be run through the CRaSH shell.
5151

5252

5353
## Pre-Requisites

Tokens/spaceships-javaAPIs/contracts/src/main/java/net/corda/examples/spaceships/states/SpaceshipTokenType.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ public List<Party> getMaintainers() {
9898
public UniqueIdentifier getLinearId() {
9999
return linearId;
100100
}
101-
102-
103-
101+
104102
/* This method returns a TokenPointer by using the linear Id of the evolvable state */
105103
public TokenPointer<SpaceshipTokenType> toPointer(){
106104
LinearPointer<SpaceshipTokenType> linearPointer = new LinearPointer<>(linearId, SpaceshipTokenType.class);

Tokens/spaceships-javaAPIs/workflows/src/main/java/net/corda/examples/spaceships/flows/BuySpaceshipFlows.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* To achieve this the steps are:
3636
* 1. Buyer requests the value/sale price of the ship he wants to purchase identified by UUID
3737
* 2. Seller queries his inventory of ships and grabs the value of the associated UUID and sends to Buyer
38-
* 3. Buyer checks to see if he has the money to pay - if not throws exception which ends the flow.
38+
* 3. Buyer checks to see if he has the money to pay - if not throws exception which ends the flow
3939
* 4. Seller sends the transaction of ownership (the tx that created his ownership token) and sends it to Buyer
4040
* 5. Buyer creates transaction with the required currency tokens going to seller, and the ship token going to buyer
4141
* 6. Transaction is signed and finalised
@@ -69,21 +69,21 @@ public SignedTransaction call() throws FlowException {
6969

7070
paymentAmount = shipValue; // first we will try to pay in the native currency of the ship's value
7171

72-
// check if we have enough funds to afford this currency and amount
72+
// Check if we have enough funds to afford this currency and amount
7373
// tokenBalance returns Amount<TokenType> which represents the quantity of this TokenType (currency) in our vault
7474
int fundsAvailable = QueryUtilities.tokenBalance(vaultService, shipValue.getToken()).compareTo(paymentAmount);
7575

7676
if (fundsAvailable >= 0) { // we have enough funds and will go through with the purchase
7777
processSale = true;
7878
} else { // we do NOT have enough, in THAT tokenType but check if we can pay in some other currency using exchange rate
7979

80-
// creates a set of all tokenTypes we are holding
80+
// Creates a set of all tokenTypes we are holding
8181
Set<TokenType> heldTokenTypes = vaultService.queryBy(FungibleToken.class).getStates().stream()
8282
.map(it -> it.getState().getData().getTokenType())
8383
.collect(Collectors.toSet());
8484
heldTokenTypes.remove(shipValue.getToken()); // remove this as it's already been checked
8585

86-
// iterate over all the different TokenTypes (currencies) we hold to see if any have enough value against
86+
// Iterate over all the different TokenTypes (currencies) we hold to see if any have enough value against
8787
// the listed exchange rate (defined in FlowHelpers interface)
8888
for (TokenType currentTokenType : heldTokenTypes) {
8989
paymentAmount = FlowHelpers.exchangeCurrency(shipValue, currentTokenType);
@@ -112,7 +112,7 @@ public SignedTransaction call() throws FlowException {
112112
* We record the transaction in OUR vault so that the TransactionBuilder can access it.
113113
* Important: make sure you have the argument StatesToRecord.ALL_VISIBLE as the default recordTransactions will only
114114
* record states in the transaction which are RELEVANT (i.e. which we participated in) this is not 'our' transaction
115-
* so we need to that argument ALL_VISIBLE.
115+
* so we need that argument ALL_VISIBLE.
116116
*/
117117
getServiceHub().recordTransactions(StatesToRecord.ALL_VISIBLE, Collections.singletonList(shipTokenTransaction));
118118
NonFungibleToken shipNFT = shipTokenTransaction.getCoreTransaction().outputsOfType(NonFungibleToken.class).get(0);
@@ -123,15 +123,15 @@ public SignedTransaction call() throws FlowException {
123123
// here we are generating input and output states which send the correct amount to the seller, and any change back to buyer
124124
.generateMove(Collections.singletonList(new Pair<>(seller, paymentAmount)), getOurIdentity());
125125

126-
// Build the transaction which transfers the curreny tokens AND the spaceship token, in a single transaction
126+
// Build the transaction which transfers the currency tokens AND the spaceship token, in a single transaction
127127
TransactionBuilder txBuilder = new TransactionBuilder(notary);
128128
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), shipTokenPointer, getOurIdentity());
129129
MoveTokensUtilities.addMoveTokens(txBuilder, selectedTokens.getFirst(), selectedTokens.getSecond());
130130

131131
SignedTransaction ptx = getServiceHub().signInitialTransaction(txBuilder);
132132
SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx, Collections.singletonList(sellerSession)));
133133

134-
// update the distribution list
134+
// Update the distribution list
135135
subFlow(new UpdateDistributionListFlow(stx));
136136
return subFlow(new ObserverAwareFinalityFlow(stx, Collections.singletonList(sellerSession)));
137137
}
@@ -148,11 +148,11 @@ public BuySpaceshipResponder(FlowSession counterpartySession) {
148148
@Suspendable
149149
@Override
150150
public Void call() throws FlowException {
151-
// receive request for value of the given shipId
151+
// Receive request for value of the given shipId
152152
String shipId = counterpartySession.receive(String.class).unwrap(it -> it);
153153
UUID shipUUID = UUID.fromString(shipId);
154154

155-
// // Get the state definition from vault to grab the value
155+
// Get the state definition from vault to grab the value
156156
SpaceshipTokenType spaceshipTokenType = FlowHelpers.uuidToSpaceShipTokenType(getServiceHub().getVaultService(), shipUUID);
157157

158158
// (Step 1 - Respond with value) send back value

Tokens/spaceships-javaAPIs/workflows/src/main/java/net/corda/examples/spaceships/flows/FlowHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static Amount<TokenType> exchangeCurrency(Amount<TokenType> amount, TokenType ta
3737
}
3838

3939
/**
40-
* ParseValueFromString takes in a String representation of an Amount (useful for terminal / UI input)
40+
* parseAmountFromString takes in a String representation of an Amount (useful for terminal / UI input)
4141
* and returns the correct object.
4242
* @param value
4343
* @return

Tokens/spaceships-javaAPIs/workflows/src/main/java/net/corda/examples/spaceships/flows/InvestSpaceshipFlows.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public sharesOwnedInSpaceshipResponder(FlowSession counterpartySession) {
5858
@Suspendable
5959
@Override
6060
public Void call() throws FlowException {
61-
// receive request for value of the given shipId
61+
// Receive request for value of the given shipId
6262
String shipId = counterpartySession.receive(String.class).unwrap(it -> it);
6363
UUID shipUUID = UUID.fromString(shipId);
6464

Tokens/spaceships-javaAPIs/workflows/src/main/java/net/corda/examples/spaceships/flows/IssueSpaceshipFlows.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public TokenizeFungibleSpaceship(Party holder, String model, String planetOfOrig
6767
public SignedTransaction call() throws FlowException {
6868
final Party manufacturer = getOurIdentity(); // node that tokenizes assumed to be manufacturer
6969

70-
//NotaryUtilities allows you to set a strategy for notary selection - otherwise you can default to firstnotary, or random
70+
// NotaryUtilities allows you to set a strategy for notary selection - otherwise you can default to firstnotary, or random
7171
final Party notary = NotaryUtilities.getPreferredNotary(getServiceHub());
7272

7373
/**
7474
* Create the evolvableTokenState
7575
*
7676
* CreateEvolvableTokens() will behind the scenes commit our token definition to the ledgers
77-
* of the any maintainers specified in the SpaceshipTokenState (in our case the manufacturer) as well as any observers we pass in as an
77+
* of any maintainers specified in the SpaceshipTokenState (in our case the manufacturer) as well as any observers we pass in as an
7878
* optional argument - we have not passed in any observers to CreateEvolvableTokens()
7979
*/
8080
SpaceshipTokenType evolvableSpaceshipToken = new SpaceshipTokenType(manufacturer, model, planetOfOrigin, seatingCapacity, value, true);
@@ -102,7 +102,7 @@ public SignedTransaction call() throws FlowException {
102102

103103
/**
104104
* A NonFungible Spaceship is one where there is only ONE holder (it can not be split or merged)
105-
* - instances of this type of token will be used ownership of UNIQUE spaceships.
105+
* - instances of this type of token will be used for ownership of UNIQUE spaceships.
106106
*/
107107
@StartableByRPC
108108
class TokenizeNonFungibleSpaceship extends FlowLogic<SignedTransaction> {
@@ -134,7 +134,7 @@ public TokenizeNonFungibleSpaceship(Party holder, String model, String planetOfO
134134
public SignedTransaction call() throws FlowException {
135135
final Party manufacturer = getOurIdentity(); // node that tokenizes assumed to be manufacturer
136136

137-
//NotaryUtilities allows you to set a strategy for notary selection - otherwise you can default to first notary, or random
137+
// NotaryUtilities allows you to set a strategy for notary selection - otherwise you can default to first notary, or random
138138
final Party notary = NotaryUtilities.getPreferredNotary(getServiceHub());
139139

140140
/**

Tokens/spaceships-javaAPIs/workflows/src/main/java/net/corda/examples/spaceships/flows/UtilityFlows.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public Amount<TokenType> call() throws FlowException {
9494

9595
Set<TokenType> tokenTypesAvailable = fetchTokenTypes(FlowHelpers.rates.keySet());
9696

97-
// remove excluded Tokens (will not be in calculation)
97+
// Remove excluded Tokens (will not be in calculation)
9898
if (exclusionList != null) tokenTypesAvailable.removeAll(exclusionList);
9999

100100
List<Amount<TokenType>> amountsOfOutputTokenType = new ArrayList<>();
101101
tokenTypesAvailable.forEach(it -> {
102102
Amount<TokenType> amountOfCurrentToken = QueryUtilities.tokenBalance(vs, it);
103-
// convert to output currency
103+
// Convert to output currency
104104
if (!it.equals(outputTokenType)) {
105105
amountOfCurrentToken = FlowHelpers.exchangeCurrency(amountOfCurrentToken, outputTokenType);
106106
}

0 commit comments

Comments
 (0)