Skip to content

Commit 5737725

Browse files
authored
Merge pull request #17 from corda/javatoken-update
Token upgrades from 1.0 to 1.2
2 parents 2c0a4a8 + ed7532c commit 5737725

File tree

26 files changed

+186
-254
lines changed

26 files changed

+186
-254
lines changed

Tokens/bikemarket/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ buildscript {
1515
guava_version = constants.getProperty("guavaVersion")
1616
//Tokens
1717
tokens_release_group = 'com.r3.corda.lib.tokens'
18-
tokens_release_version = '1.0'
19-
18+
tokens_release_version = '1.2'
19+
//CI
20+
confidential_id_release_group = "com.r3.corda.lib.ci"
21+
confidential_id_release_version = "1.0"
2022
}
2123

2224
repositories {
@@ -108,7 +110,10 @@ dependencies {
108110
// Token SDK dependencies.
109111
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
110112
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
111-
cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
113+
114+
// CI dependencies
115+
cordapp "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
116+
112117
}
113118
cordapp {
114119
info {
@@ -125,7 +130,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
125130
}
126131
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
127132
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
128-
cordapp("$tokens_release_group:tokens-money:$tokens_release_version")
133+
cordapp("$confidential_id_release_group:ci-workflows:$confidential_id_release_version")
129134
cordapp project(':contracts')
130135
cordapp project(':workflows')
131136
}

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/states/FrameTokenState.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.common.collect.ImmutableList;
44
import com.r3.corda.lib.tokens.contracts.states.EvolvableTokenType;
5+
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
6+
import net.corda.core.contracts.LinearPointer;
57
import net.corda.examples.bikemarket.contracts.FrameContract;
68
import net.corda.core.contracts.BelongsToContract;
79
import net.corda.core.contracts.UniqueIdentifier;
@@ -50,4 +52,10 @@ public List<Party> getMaintainers() {
5052
public UniqueIdentifier getLinearId() {
5153
return this.uniqueIdentifier;
5254
}
55+
56+
/* This method returns a TokenPointer by using the linear Id of the evolvable state */
57+
public TokenPointer<FrameTokenState> toPointer(){
58+
LinearPointer<FrameTokenState> linearPointer = new LinearPointer<>(uniqueIdentifier, FrameTokenState.class);
59+
return new TokenPointer<>(linearPointer, fractionDigits);
60+
}
5361
}

Tokens/bikemarket/contracts/src/main/java/net/corda/examples/bikemarket/states/WheelsTokenState.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.common.collect.ImmutableList;
44
import com.r3.corda.lib.tokens.contracts.states.EvolvableTokenType;
5+
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
6+
import net.corda.core.contracts.LinearPointer;
57
import net.corda.examples.bikemarket.contracts.WheelsContract;
68
import net.corda.core.contracts.BelongsToContract;
79
import net.corda.core.contracts.UniqueIdentifier;
@@ -47,4 +49,10 @@ public List<Party> getMaintainers() {
4749
public UniqueIdentifier getLinearId() {
4850
return this.uniqueIdentifier;
4951
}
52+
53+
/* This method returns a TokenPointer by using the linear Id of the evolvable state */
54+
public TokenPointer<WheelsTokenState> toPointer(){
55+
LinearPointer<WheelsTokenState> linearPointer = new LinearPointer<>(uniqueIdentifier, WheelsTokenState.class);
56+
return new TokenPointer<>(linearPointer, fractionDigits);
57+
}
5058
}

Tokens/bikemarket/workflows/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ dependencies {
5959
cordapp project(":contracts")
6060

6161
// Token SDK dependencies.
62-
cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
6362
cordaCompile "$tokens_release_group:tokens-workflows:$tokens_release_version"
63+
cordaCompile "$confidential_id_release_group:ci-workflows:$confidential_id_release_version"
6464
}
6565

6666
task integrationTest(type: Test, dependsOn: []) {

Tokens/bikemarket/workflows/src/main/java/net/corda/examples/bikemarket/flows/IssueNewBike.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.common.collect.ImmutableList;
55
import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken;
66
import com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens;
7+
import com.r3.corda.lib.tokens.workflows.utilities.NonFungibleTokenBuilder;
78
import net.corda.examples.bikemarket.states.FrameTokenState;
89
import net.corda.examples.bikemarket.states.WheelsTokenState;
910
import net.corda.core.contracts.StateAndRef;
@@ -49,12 +50,12 @@ public String call() throws FlowException {
4950
//get the pointer to the frame
5051
TokenPointer frametokenPointer = frametokentype.toPointer(frametokentype.getClass());
5152

52-
//assign the issuer to the frame type who will be issuing the tokens
53-
IssuedTokenType frameissuedTokenType = new IssuedTokenType(getOurIdentity(), frametokenPointer);
54-
5553
//mention the current holder also
56-
NonFungibleToken frametoken = new NonFungibleToken(frameissuedTokenType, holder, new UniqueIdentifier(), TransactionUtilitiesKt.getAttachmentIdForGenericParam(frametokenPointer));
57-
54+
NonFungibleToken frametoken = new NonFungibleTokenBuilder()
55+
.ofTokenType(frametokentype.toPointer())
56+
.issuedBy(getOurIdentity())
57+
.heldBy(holder)
58+
.buildNonFungibleToken();
5859

5960
//Step 2: Wheels Token
6061
StateAndRef<WheelsTokenState> wheelStateStateAndRef = getServiceHub().getVaultService().
@@ -67,11 +68,12 @@ public String call() throws FlowException {
6768
//get the pointer pointer to the wheel
6869
TokenPointer wheeltokenPointer = wheeltokentype.toPointer(wheeltokentype.getClass());
6970

70-
//assign the issuer to the wheel type who will be issuing the tokens
71-
IssuedTokenType wheelissuedTokenType = new IssuedTokenType(getOurIdentity(), wheeltokenPointer);
72-
7371
//mention the current holder also
74-
NonFungibleToken wheeltoken = new NonFungibleToken(wheelissuedTokenType, holder, new UniqueIdentifier(), TransactionUtilitiesKt.getAttachmentIdForGenericParam(wheeltokenPointer));
72+
NonFungibleToken wheeltoken = new NonFungibleTokenBuilder()
73+
.ofTokenType(wheeltokentype.toPointer())
74+
.issuedBy(getOurIdentity())
75+
.heldBy(holder)
76+
.buildNonFungibleToken();
7577

7678
//distribute the new bike (two token to be exact)
7779
//call built in flow to issue non fungible tokens

Tokens/bikemarket/workflows/src/main/java/net/corda/examples/bikemarket/flows/TransferBikeTokens.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import co.paralleluniverse.fibers.Suspendable;
44
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
5+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
56
import com.r3.corda.lib.tokens.workflows.flows.rpc.MoveNonFungibleTokens;
67
import com.r3.corda.lib.tokens.workflows.flows.rpc.MoveNonFungibleTokensHandler;
8+
import com.r3.corda.lib.tokens.workflows.internal.flows.distribution.UpdateDistributionListFlow;
9+
import com.r3.corda.lib.tokens.workflows.internal.flows.finality.ObserverAwareFinalityFlow;
710
import com.r3.corda.lib.tokens.workflows.types.PartyAndToken;
11+
import com.r3.corda.lib.tokens.workflows.utilities.NotaryUtilities;
12+
import net.corda.core.transactions.TransactionBuilder;
813
import net.corda.examples.bikemarket.states.FrameTokenState;
914
import net.corda.examples.bikemarket.states.WheelsTokenState;
1015
import net.corda.core.contracts.StateAndRef;
1116
import net.corda.core.flows.*;
1217
import net.corda.core.identity.Party;
1318
import net.corda.core.transactions.SignedTransaction;
1419

20+
import java.util.Collections;
21+
1522
public class TransferBikeTokens {
1623
public TransferBikeTokens() {
1724
}
@@ -45,10 +52,6 @@ public String call() throws FlowException {
4552
//get the pointer to the frame
4653
TokenPointer frametokenPointer = frametokentype.toPointer(frametokentype.getClass());
4754

48-
PartyAndToken partyAndFrameToken = new PartyAndToken(holder, frametokenPointer);
49-
50-
SignedTransaction stx1 = (SignedTransaction) subFlow(new MoveNonFungibleTokens(partyAndFrameToken));
51-
5255
//Step 2: Wheels Token
5356
StateAndRef<WheelsTokenState> wheelStateStateAndRef = getServiceHub().getVaultService().
5457
queryBy(WheelsTokenState.class).getStates().stream().filter(sf -> sf.getState().getData().getModelNum().equals(this.wheelsModel)).findAny()
@@ -60,13 +63,22 @@ public String call() throws FlowException {
6063
//get the pointer to the wheel
6164
TokenPointer wheeltokenPointer = wheeltokentype.toPointer(wheeltokentype.getClass());
6265

63-
PartyAndToken partyAndWheelToken = new PartyAndToken(holder, wheeltokenPointer);
6466

65-
SignedTransaction stx2 = (SignedTransaction) subFlow(new MoveNonFungibleTokens(partyAndWheelToken));
67+
FlowSession sellerSession = initiateFlow(holder);
68+
TransactionBuilder txBuilder = new TransactionBuilder(NotaryUtilities.getPreferredNotary(getServiceHub()));
69+
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), frametokenPointer, holder);
70+
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), wheeltokenPointer, holder);
71+
72+
SignedTransaction ptx = getServiceHub().signInitialTransaction(txBuilder);
73+
SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx, Collections.singletonList(sellerSession)));
74+
75+
// Update the distribution list
76+
subFlow(new UpdateDistributionListFlow(stx));
77+
SignedTransaction ftx = subFlow(new ObserverAwareFinalityFlow(stx, Collections.singletonList(sellerSession)));
6678

6779
return "\nTransfer ownership of a bike (Frame serial#: "+ this.frameModel + ", Wheels serial#: " + this.wheelsModel + ") to "
6880
+ this.holder.getName().getOrganisation() + "\nTransaction IDs: "
69-
+ stx1.getId() + ", " + stx2.getId();
81+
+ ftx.getId();
7082
}
7183
}
7284

Tokens/bikemarket/workflows/src/main/java/net/corda/examples/bikemarket/flows/TransferPartTokens.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import co.paralleluniverse.fibers.Suspendable;
44
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
5+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
56
import com.r3.corda.lib.tokens.workflows.flows.rpc.MoveNonFungibleTokens;
67
import com.r3.corda.lib.tokens.workflows.flows.rpc.MoveNonFungibleTokensHandler;
8+
import com.r3.corda.lib.tokens.workflows.internal.flows.distribution.UpdateDistributionListFlow;
9+
import com.r3.corda.lib.tokens.workflows.internal.flows.finality.ObserverAwareFinalityFlow;
710
import com.r3.corda.lib.tokens.workflows.types.PartyAndToken;
11+
import com.r3.corda.lib.tokens.workflows.utilities.NotaryUtilities;
12+
import net.corda.core.transactions.TransactionBuilder;
813
import net.corda.examples.bikemarket.states.FrameTokenState;
914
import net.corda.examples.bikemarket.states.WheelsTokenState;
1015
import net.corda.core.contracts.StateAndRef;
1116
import net.corda.core.flows.*;
1217
import net.corda.core.identity.Party;
1318
import net.corda.core.transactions.SignedTransaction;
1419

20+
import java.util.Collections;
21+
1522
public class TransferPartTokens {
1623

1724
public TransferPartTokens() {
@@ -52,11 +59,20 @@ public String call() throws FlowException {
5259

5360
//get the pointer to the frame
5461
TokenPointer frametokenPointer = frametokentype.toPointer(frametokentype.getClass());
55-
PartyAndToken partyAndFrameToken = new PartyAndToken(holder, frametokenPointer);
5662

57-
SignedTransaction stx = (SignedTransaction) subFlow(new MoveNonFungibleTokens(partyAndFrameToken));
63+
FlowSession sellerSession = initiateFlow(holder);
64+
TransactionBuilder txBuilder = new TransactionBuilder(NotaryUtilities.getPreferredNotary(getServiceHub()));
65+
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), frametokenPointer, holder);
66+
67+
SignedTransaction ptx = getServiceHub().signInitialTransaction(txBuilder);
68+
SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx, Collections.singletonList(sellerSession)));
69+
70+
// Update the distribution list
71+
subFlow(new UpdateDistributionListFlow(stx));
72+
SignedTransaction ftx = subFlow(new ObserverAwareFinalityFlow(stx, Collections.singletonList(sellerSession)));
73+
5874
return "Transfer ownership of the frame ("+this.frameModel+") to" +this.holder.getName().getOrganisation()
59-
+ "\nTransaction ID: " + stx.getId();
75+
+ "\nTransaction ID: " + ftx.getId();
6076

6177
} else {
6278
//Step 2: Wheels Token
@@ -70,11 +86,18 @@ public String call() throws FlowException {
7086

7187
//get the pointer to the wheel
7288
TokenPointer wheeltokenPointer = wheeltokentype.toPointer(wheeltokentype.getClass());
73-
PartyAndToken partyAndWheelToken = new PartyAndToken(holder, wheeltokenPointer);
89+
FlowSession sellerSession = initiateFlow(holder);
90+
TransactionBuilder txBuilder = new TransactionBuilder(NotaryUtilities.getPreferredNotary(getServiceHub()));
91+
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), wheeltokenPointer, holder);
92+
93+
SignedTransaction ptx = getServiceHub().signInitialTransaction(txBuilder);
94+
SignedTransaction stx = subFlow(new CollectSignaturesFlow(ptx, Collections.singletonList(sellerSession)));
7495

75-
SignedTransaction stx = (SignedTransaction) subFlow(new MoveNonFungibleTokens(partyAndWheelToken));
96+
// Update the distribution list
97+
subFlow(new UpdateDistributionListFlow(stx));
98+
SignedTransaction ftx = subFlow(new ObserverAwareFinalityFlow(stx, Collections.singletonList(sellerSession)));
7699
return "Transfer ownership of the wheels (" +this.wheelModel+") to" +this.holder.getName().getOrganisation()
77-
+ "\nTransaction ID: " + stx.getId();
100+
+ "\nTransaction ID: " + ftx.getId();
78101
}
79102
}
80103
}

Tokens/constants.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cordaCoreReleaseGroup=net.corda
22
cordaReleaseGroup=net.corda
3-
cordaVersion=4.5-RC02
4-
cordaCoreVersion=4.5-RC02
3+
cordaVersion=4.5
4+
cordaCoreVersion=4.5
55
gradlePluginsVersion=5.0.10
66
kotlinVersion=1.2.71
77
junitVersion=4.12

Tokens/dollartohousetoken/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515

1616
//Tokens
1717
tokens_release_group = 'com.r3.corda.lib.tokens'
18-
tokens_release_version = '1.2-RC02-PRESIGN'
18+
tokens_release_version = '1.2'
1919

2020
}
2121

Tokens/stockpaydividend/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This Stock Exchange CorDapp includes:
3535
### Keys to learn
3636
* Basic usage of TokenSDK
3737
* How the state of stock (ie. EvolvableToken) updates independently without stock holders involved
38-
* Use of `TokenSelection.generateMove()` and `MoveTokensUtilitiesKt.addMoveTokens()` to generate move of tokens
38+
* Use of `TokenSelection.generateMove()` and `MoveTokensUtilities.addMoveTokens()` to generate move of tokens
3939
* Adding observers in token transactions with TokenSDK
4040

4141
*Note that some date constraint(eg. payday) is being commented out to make sure the sample can be ran smoothly
@@ -129,7 +129,7 @@ This can be executed anytime before step 6.
129129
130130
##### 1. IssueStock - Stock Issuer
131131
WayneCo creates a StockState and issues some stock tokens associated to the created StockState.
132-
>On company WayneCo's node, execute <br>`start IssueStock symbol: TEST, name: "Stock, SP500", currency: USD, price: 7.4, issueVol: 500, notary: Notary`
132+
>On company WayneCo's node, execute <br>`start CreateAndIssueStock symbol: TEST, name: "Stock, SP500", currency: USD, price: 7.4, issueVol: 500, notary: Notary`
133133
134134
##### 2. MoveStock - Stock Issuer
135135
WayneCo transfers some stock tokens to the Shareholder.
@@ -142,19 +142,16 @@ Now at the Shareholder's terminal, we can see that it received 100 stock tokens:
142142
WayneCo announces the dividends that will be paid on the payday.
143143
>On WayneCo's node, execute <br>`start AnnounceDividend symbol: TEST, dividendPercentage: 0.05, executionDate: "2019-11-22T00:00:00Z", payDate: "2019-11-23T00:00:00Z"`
144144
145-
##### 4. GetStockUpdate - Shareholder
146-
Shareholders retrieves the newest stock state from the company.
147-
>On shareholder node, execute <br>`start GetStockUpdate symbol: TEST`
148145

149-
##### 5. ClaimDividendReceivable - Shareholder
146+
##### 4. ClaimDividendReceivable - Shareholder
150147
Shareholders finds the dividend is announced and claims the dividends base on the owning stock.
151148
>On shareholder node, execute <br>`start ClaimDividendReceivable symbol: TEST`
152149
153-
##### 6. PayDividend - Company
150+
##### 5. PayDividend - Company
154151
On the payday, the company pay off the stock with fiat currencies.
155152
>On WayneCo node, execute <br>`start PayDividend`
156153
157-
##### 7. Get token balances - Any node
154+
##### 6. Get token balances - Any node
158155
Query the balances of different nodes. This can be executed at anytime.
159156
> Get stock token balances
160157
<br>`start GetStockBalance symbol: TEST`

0 commit comments

Comments
 (0)