Skip to content

Commit d6921ce

Browse files
Update to TokenSDK 1.2 Beta
1 parent c353bae commit d6921ce

File tree

8 files changed

+52
-33
lines changed

8 files changed

+52
-33
lines changed

Tokens/dollartohousetoken/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nonfungible house token dvp sample cordapp
1+
# Nonfungible house token dvp sample cordapp
22

33
This CorDapp provides a basic example to create, issue and perform a DvP (Delivery vs Payment) of an Evolvable NonFungible token in
44
Corda utilizing the Token SDK.

Tokens/dollartohousetoken/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ buildscript {
1515

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

2020
}
2121

2222
repositories {
2323
mavenLocal()
2424
mavenCentral()
2525
jcenter()
26-
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
26+
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
2727
}
2828

2929
dependencies {
@@ -105,7 +105,7 @@ dependencies {
105105
// Token SDK dependencies.
106106
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
107107
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
108-
cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
108+
// cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
109109
}
110110

111111
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
@@ -115,7 +115,7 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
115115
}
116116
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
117117
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
118-
cordapp("$tokens_release_group:tokens-money:$tokens_release_version")
118+
//cordapp("$tokens_release_group:tokens-money:$tokens_release_version")
119119
cordapp project(':contracts')
120120
cordapp project(':workflows')
121121
}

Tokens/dollartohousetoken/contracts/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ dependencies {
2323

2424
// Token SDK dependencies.
2525
cordaCompile "$tokens_release_group:tokens-contracts:$tokens_release_version"
26-
cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
26+
// cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
2727
}

Tokens/dollartohousetoken/workflows/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151
cordapp project(":contracts")
5252

5353
// Token SDK dependencies.
54-
cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
54+
// cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
5555
cordaCompile "$tokens_release_group:tokens-workflows:$tokens_release_version"
5656
}
5757

Tokens/dollartohousetoken/workflows/src/main/java/net/corda/examples/dollartohousetoken/flows/FiatCurrencyIssueFlow.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import com.r3.corda.lib.tokens.contracts.types.IssuedTokenType;
77
import com.r3.corda.lib.tokens.contracts.types.TokenType;
88
import com.r3.corda.lib.tokens.money.FiatCurrency;
9+
import com.r3.corda.lib.tokens.money.MoneyUtilities;
910
import com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens;
11+
import com.r3.corda.lib.tokens.workflows.utilities.FungibleTokenBuilder;
1012
import net.corda.core.contracts.Amount;
1113
import net.corda.core.flows.FlowException;
1214
import net.corda.core.flows.FlowLogic;
1315
import net.corda.core.flows.FlowSession;
1416
import net.corda.core.flows.StartableByRPC;
1517
import net.corda.core.identity.Party;
1618
import net.corda.core.transactions.SignedTransaction;
19+
import org.intellij.lang.annotations.Flow;
1720

1821
/**
1922
* Flow class to issue fiat currency. FiatCurrency is defined in the Token SDK and is issued as a Fungible Token.
@@ -37,16 +40,35 @@ public FiatCurrencyIssueFlow(String currency, Long amount, Party recipient) {
3740
@Suspendable
3841
public SignedTransaction call() throws FlowException {
3942
/* Create an instance of the fiat currency token */
40-
TokenType token = FiatCurrency.Companion.getInstance(currency);
41-
42-
/* Create an instance of IssuedTokenType for the fiat currency */
43-
IssuedTokenType issuedTokenType = new IssuedTokenType(getOurIdentity(), token);
43+
TokenType tokenType = getTokenType();
4444

4545
/* Create an instance of FungibleToken for the fiat currency to be issued */
46-
FungibleToken fungibleToken = new FungibleToken(new Amount<>(amount, issuedTokenType), recipient, null);
46+
FungibleToken fungibleToken =
47+
new FungibleTokenBuilder()
48+
.ofTokenType(tokenType)
49+
.withAmount(amount)
50+
.issuedBy(getOurIdentity())
51+
.heldBy(recipient)
52+
.buildFungibleToken();
4753

4854
/* Issue the required amount of the token to the recipient */
4955
return subFlow(new IssueTokens(ImmutableList.of(fungibleToken), ImmutableList.of(recipient)));
5056
}
5157

58+
private TokenType getTokenType() throws FlowException{
59+
switch (currency){
60+
case "USD":
61+
return MoneyUtilities.getUSD();
62+
63+
case "GBP":
64+
return MoneyUtilities.getGBP();
65+
66+
case "EUR":
67+
return MoneyUtilities.getEUR();
68+
69+
default:
70+
throw new FlowException("Currency Not Supported");
71+
}
72+
}
73+
5274
}

Tokens/dollartohousetoken/workflows/src/main/java/net/corda/examples/dollartohousetoken/flows/HouseSaleInitiatorFlow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package net.corda.examples.dollartohousetoken.flows;
22

33
import co.paralleluniverse.fibers.Suspendable;
4+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
45
import net.corda.examples.dollartohousetoken.states.HouseState;
56
import com.google.common.collect.ImmutableList;
67
import com.r3.corda.lib.tokens.contracts.states.FungibleToken;
7-
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilitiesKt;
88
import com.r3.corda.lib.tokens.workflows.internal.flows.distribution.UpdateDistributionListFlow;
99
import net.corda.core.contracts.StateAndRef;
1010
import net.corda.core.flows.*;
@@ -58,7 +58,7 @@ public String call() throws FlowException {
5858

5959
/* Create a move token proposal for the house token using the helper function provided by Token SDK. This would
6060
create the movement proposal and would be committed in the ledgers of parties once the transaction in finalized */
61-
MoveTokensUtilitiesKt.addMoveNonFungibleTokens(txBuilder, getServiceHub(), houseState.toPointer(), buyer);
61+
MoveTokensUtilities.addMoveNonFungibleTokens(txBuilder, getServiceHub(), houseState.toPointer(), buyer);
6262

6363
/* Initiate a flow session with the buyer to send the house valuation and transfer of the fiat currency */
6464
FlowSession buyerSession = initiateFlow(buyer);
@@ -73,7 +73,7 @@ public String call() throws FlowException {
7373
List<FungibleToken> moneyReceived = buyerSession.receive(List.class).unwrap(value -> value);
7474

7575
/* Create a fiat currency proposal for the house token using the helper function provided by Token SDK */
76-
MoveTokensUtilitiesKt.addMoveTokens(txBuilder, inputs, moneyReceived);
76+
MoveTokensUtilities.addMoveTokens(txBuilder, inputs, moneyReceived);
7777

7878
/* Sign the transaction */
7979
SignedTransaction initialSignedTrnx = getServiceHub().signInitialTransaction(txBuilder, getOurIdentity().getOwningKey());

Tokens/dollartohousetoken/workflows/src/main/java/net/corda/examples/dollartohousetoken/flows/HouseSaleResponderFlow.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.r3.corda.lib.tokens.contracts.states.FungibleToken;
66
import com.r3.corda.lib.tokens.contracts.types.TokenType;
77
import com.r3.corda.lib.tokens.money.FiatCurrency;
8-
import com.r3.corda.lib.tokens.workflows.internal.selection.TokenSelection;
8+
import com.r3.corda.lib.tokens.selection.database.selector.DatabaseTokenSelection;
99
import com.r3.corda.lib.tokens.workflows.types.PartyAndAmount;
1010
import kotlin.Pair;
1111
import net.corda.core.contracts.Amount;
@@ -14,6 +14,7 @@
1414
import net.corda.core.transactions.SignedTransaction;
1515
import org.jetbrains.annotations.NotNull;
1616

17+
import java.util.Collections;
1718
import java.util.Currency;
1819
import java.util.List;
1920

@@ -40,17 +41,13 @@ public SignedTransaction call() throws FlowException {
4041
/* Create instance of the fiat currency token amount */
4142
Amount<TokenType> priceToken = new Amount<>(price.getQuantity(), FiatCurrency.Companion.getInstance(price.getToken().getCurrencyCode()));
4243

43-
/* Create an instance of the TokenSelection object, it is used to select the token from the vault and generate the
44-
proposal for the movement of the token. The constructor takes the service hub to perform vault query, the max-number
45-
of retries, the retry sleep interval, and the retry sleep cap interval. This is a temporary solution till in-memory
46-
token selection in implemented */
47-
TokenSelection tokenSelection = new TokenSelection(getServiceHub(), 8, 100, 2000);
4844

4945
/* Generate the move proposal, it returns the input-output pair for the fiat currency transfer, which we need to
5046
send to the Initiator */
5147
PartyAndAmount<TokenType> partyAndAmount = new PartyAndAmount<>(counterpartySession.getCounterparty(), priceToken);
52-
Pair<List<StateAndRef<FungibleToken>>, List<FungibleToken>> inputsAndOutputs =
53-
tokenSelection.generateMove(getRunId().getUuid(), ImmutableList.of(partyAndAmount), getOurIdentity(), null);
48+
Pair<List<StateAndRef<FungibleToken>>, List<FungibleToken>> inputsAndOutputs = new DatabaseTokenSelection(getServiceHub())
49+
// here we are generating input and output states which send the correct amount to the seller, and any change back to buyer
50+
.generateMove(Collections.singletonList(new Pair<>(counterpartySession.getCounterparty(), priceToken)), getOurIdentity());
5451

5552
/* Call SendStateAndRefFlow to send the inputs to the Initiator */
5653
subFlow(new SendStateAndRefFlow(counterpartySession, inputsAndOutputs.getFirst()));

Tokens/dollartohousetoken/workflows/src/main/java/net/corda/examples/dollartohousetoken/flows/HouseTokenCreateAndIssueFlow.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.corda.examples.dollartohousetoken.flows;
22

33
import co.paralleluniverse.fibers.Suspendable;
4+
import com.r3.corda.lib.tokens.workflows.utilities.NonFungibleTokenBuilder;
45
import net.corda.examples.dollartohousetoken.states.HouseState;
56
import com.google.common.collect.ImmutableList;
67
import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken;
@@ -66,16 +67,15 @@ public String call() throws FlowException {
6667
evolvable token in the ledger.*/
6768
subFlow(new CreateEvolvableTokens(transactionState));
6869

69-
/* Create an instance of IssuedTokenType, it is used by our Non-Fungible token which would be issued to the owner.
70-
Note that the IssuedTokenType takes a TokenPointer as an input, since EvolvableTokenType is not TokenType, but is
71-
a LinearState. This is done to separate the state info from the token so that the state can evolve independently.
72-
IssuedTokenType is a wrapper around the TokenType and the issuer. */
73-
IssuedTokenType issuedHouseToken = new IssuedTokenType(issuer, houseState.toPointer());
74-
75-
/* Create an instance of the non-fungible house token with the owner as the token holder. The last parameter is a
76-
hash of the jar containing the TokenType, use the helper function to fetch it. */
77-
NonFungibleToken houseToken =
78-
new NonFungibleToken(issuedHouseToken, owner, UniqueIdentifier.Companion.fromString(UUID.randomUUID().toString()), TransactionUtilitiesKt.getAttachmentIdForGenericParam(houseState.toPointer()));
70+
/* Create an instance of the non-fungible house token with the owner as the token holder.
71+
* Notice the TokenPointer is used as the TokenType, since EvolvableTokenType is not TokenType, but is
72+
* a LinearState. This is done to separate the state info from the token so that the state can evolve independently.
73+
* */
74+
NonFungibleToken houseToken = new NonFungibleTokenBuilder()
75+
.ofTokenType(houseState.toPointer())
76+
.issuedBy(issuer)
77+
.heldBy(owner)
78+
.buildNonFungibleToken();
7979

8080
/* Issue the house token by calling the IssueTokens flow provided with the TokenSDK */
8181
SignedTransaction stx = subFlow(new IssueTokens(ImmutableList.of(houseToken)));

0 commit comments

Comments
 (0)