Skip to content

Commit 33773eb

Browse files
committed
revert to Token1.1
1 parent 732187b commit 33773eb

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

Accounts/worldcupticketbooking/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buildscript {
2525
confidential_id_release_version = "1.0"
2626

2727
//tokens
28-
tokens_release_version = '1.2'
28+
tokens_release_version = '1.1'
2929
tokens_release_group = 'com.r3.corda.lib.tokens'
3030

3131
//springboot
@@ -116,6 +116,8 @@ dependencies {
116116
//tokens
117117
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
118118
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
119+
cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
120+
cordapp "$tokens_release_group:tokens-selection:$tokens_release_version"
119121

120122

121123
}
@@ -159,6 +161,8 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
159161
//tokens
160162
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
161163
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
164+
cordapp("$tokens_release_group:tokens-money:$tokens_release_version")
165+
cordapp("$tokens_release_group:tokens-selection:$tokens_release_version")
162166
}
163167
node {
164168
name "O=Notary,L=London,C=GB"

Accounts/worldcupticketbooking/workflows/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ dependencies {
6767
// Token SDK dependencies.
6868
cordaCompile "$tokens_release_group:tokens-workflows:$tokens_release_version"
6969
cordaCompile "$tokens_release_group:tokens-contracts:$tokens_release_version"
70+
cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
71+
cordapp "$tokens_release_group:tokens-selection:$tokens_release_version"
7072

7173
}
7274

Accounts/worldcupticketbooking/workflows/src/main/java/com/t20worldcup/flows/DVPAccountsHostedOnDifferentNodes.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import co.paralleluniverse.fibers.Suspendable;
55
import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken;
6-
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
7-
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilities;
6+
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilitiesKt;
87
import com.t20worldcup.states.T20CricketTicket;
98
import com.r3.corda.lib.accounts.contracts.states.AccountInfo;
109
import com.r3.corda.lib.accounts.workflows.UtilitiesKt;
@@ -18,6 +17,7 @@
1817
import com.r3.corda.lib.tokens.selection.TokenQueryBy;
1918
import com.r3.corda.lib.tokens.selection.database.config.DatabaseSelectionConfigKt;
2019
import com.r3.corda.lib.tokens.selection.database.selector.DatabaseTokenSelection;
20+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilitiesKt;
2121
import kotlin.Pair;
2222
import net.corda.core.contracts.*;
2323
import net.corda.core.flows.*;
@@ -93,8 +93,8 @@ public String call() throws FlowException {
9393
//buyer will create generate a move tokens state and send this state with new holder(seller) to seller
9494
Amount<FiatCurrency> amount = new Amount(costOfTicket, FiatCurrency.Companion.getInstance(currency));
9595

96-
//Buyer Query for token balance.
97-
QueryCriteria queryCriteria = QueryUtilities.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount).and(QueryUtilities.sumTokenCriteria());
96+
//Buyer Query for token balance.
97+
QueryCriteria queryCriteria = QueryUtilitiesKt.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount).and(QueryUtilitiesKt.sumTokenCriteria());
9898
List<Object> sum = getServiceHub().getVaultService().queryBy(FungibleToken.class, queryCriteria).component5();
9999
if(sum.size() == 0)
100100
throw new FlowException(buyerAccountName + " has 0 token balance. Please ask the Bank to issue some cash.");
@@ -106,7 +106,7 @@ public String call() throws FlowException {
106106

107107
//the tokens to move to new account which is the seller account
108108
Pair<AbstractParty, Amount<TokenType>> partyAndAmount = new Pair(sellerAccount, amount);
109-
109+
110110
//let's use the DatabaseTokenSelection to get the tokens from the db
111111
DatabaseTokenSelection tokenSelection = new DatabaseTokenSelection(
112112
getServiceHub(),
@@ -115,7 +115,7 @@ public String call() throws FlowException {
115115
DatabaseSelectionConfigKt.RETRY_CAP_DEFAULT,
116116
DatabaseSelectionConfigKt.PAGE_SIZE_DEFAULT
117117
);
118-
118+
119119
//call generateMove which gives us 2 stateandrefs with tokens having new owner as seller.
120120
Pair<List<StateAndRef<FungibleToken>>, List<FungibleToken>> inputsAndOutputs =
121121
tokenSelection.generateMove(Arrays.asList(partyAndAmount), buyerAccount, new TokenQueryBy(), getRunId().getUuid());
@@ -141,7 +141,7 @@ public String call() throws FlowException {
141141
//this is the handler for synckeymapping called by seller. seller must also have created some keys not known to us - buyer
142142
subFlow(new SyncKeyMappingFlowHandler(sellerSession));
143143

144-
//recieve the data from counter session in tx formatt.
144+
//recieve the data from counter session in tx formatt.
145145
subFlow(new SignTransactionFlow(sellerSession) {
146146
@Override
147147
protected void checkTransaction(@NotNull SignedTransaction stx) throws FlowException {
@@ -194,7 +194,7 @@ public Void call() throws FlowException {
194194
AnonymousParty buyerAccount = subFlow(new RequestKeyForAccount(buyerAccountInfo));
195195
AnonymousParty sellerAccount = subFlow(new RequestKeyForAccount(sellerAccountInfo));
196196

197-
//query for all tickets
197+
//query for all tickets
198198
QueryCriteria queryCriteriaForSellerTicketType = new QueryCriteria.VaultQueryCriteria()
199199
.withExternalIds(Arrays.asList(sellerAccountInfo.getIdentifier().getId()))
200200
.withStatus(Vault.StateStatus.UNCONSUMED);
@@ -240,10 +240,10 @@ public Void call() throws FlowException {
240240
TransactionBuilder transactionBuilder = new TransactionBuilder(notary);
241241

242242
//part1 of DVP is to transfer the non fungible token from seller to buyer
243-
MoveTokensUtilities.addMoveNonFungibleTokens(transactionBuilder, getServiceHub(), tokenPointer, buyerAccount);
243+
MoveTokensUtilitiesKt.addMoveNonFungibleTokens(transactionBuilder, getServiceHub(), tokenPointer, buyerAccount);
244244

245245
//part2 of DVP is to transfer cash - fungible token from buyer to seller and return the change to buyer
246-
MoveTokensUtilities.addMoveTokens(transactionBuilder, inputs, moneyReceived);
246+
MoveTokensUtilitiesKt.addMoveTokens(transactionBuilder, inputs, moneyReceived);
247247

248248
//sync keys with buyer, again sync for similar members
249249

Accounts/worldcupticketbooking/workflows/src/main/java/com/t20worldcup/flows/DVPAccountsOnSameNode.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import com.r3.corda.lib.tokens.contracts.states.FungibleToken;
66
import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken;
77
import com.r3.corda.lib.tokens.contracts.types.TokenType;
8-
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilities;
8+
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilitiesKt;
99
import com.t20worldcup.states.T20CricketTicket;
1010
import com.r3.corda.lib.accounts.contracts.states.AccountInfo;
1111
import com.r3.corda.lib.accounts.workflows.UtilitiesKt;
1212
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
1313
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
1414
import com.r3.corda.lib.tokens.money.FiatCurrency;
15-
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
15+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilitiesKt;
1616
import com.r3.corda.lib.tokens.workflows.internal.flows.finality.ObserverAwareFinalityFlow;
1717
import com.r3.corda.lib.tokens.workflows.types.PartyAndAmount;
1818
import net.corda.core.contracts.Amount;
@@ -21,7 +21,6 @@
2121
import net.corda.core.identity.AnonymousParty;
2222
import net.corda.core.identity.Party;
2323
import net.corda.core.node.services.Vault;
24-
import net.corda.core.node.services.VaultService;
2524
import net.corda.core.node.services.vault.QueryCriteria;
2625
import net.corda.core.transactions.SignedTransaction;
2726
import net.corda.core.transactions.TransactionBuilder;
@@ -32,8 +31,6 @@
3231
import java.util.List;
3332
import java.util.UUID;
3433

35-
import static com.r3.corda.lib.tokens.workflows.utilities.QueryUtilities.rowsToAmount;
36-
3734
/**
3835
* This is the DVP flow, where the buyer account buys the ticket token from the dealer account and in turn transfers him cash worth of the ticket.
3936
* Once buyer1 buys the token from the dealer, he can further sell this ticket to other buyers.
@@ -121,26 +118,22 @@ public String call() throws FlowException {
121118

122119
//first part of DVP is to transfer the non fungible token from seller to buyer
123120
//this add inputs and outputs to transactionBuilder
124-
MoveTokensUtilities.addMoveNonFungibleTokens(transactionBuilder, getServiceHub(), tokenPointer, buyerAccount);
121+
MoveTokensUtilitiesKt.addMoveNonFungibleTokens(transactionBuilder, getServiceHub(), tokenPointer, buyerAccount);
125122

126123
//Part2 : Move fungible token - cash from buyer to seller
127-
QueryCriteria queryCriteriaForTokenBalance = QueryUtilities.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount)
128-
.and(QueryUtilities.sumTokenCriteria());
129-
130-
VaultService vaultService = getServiceHub().getVaultService();
131-
Amount<TokenType> rot = rowsToAmount(this.getInstance(currency), vaultService.queryBy(FungibleToken.class,queryCriteriaForTokenBalance));
132-
int fundsAvailable = rot.compareTo(new Amount<TokenType>(this.costOfTicket,this.getInstance(currency)));
133124

125+
QueryCriteria queryCriteriaForTokenBalance = QueryUtilitiesKt.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount).and(QueryUtilitiesKt.sumTokenCriteria());
134126

135-
//List<Object> sum = getServiceHub().getVaultService().queryBy(FungibleToken.class, queryCriteriaForTokenBalance).component5();
127+
List<Object> sum = getServiceHub().getVaultService().
128+
queryBy(FungibleToken.class, queryCriteriaForTokenBalance).component5();
136129

137-
if(fundsAvailable < 0)
130+
if(sum.size() == 0)
138131
throw new FlowException(buyerAccountName + "has 0 token balance. Please ask the Bank to issue some cash.");
139-
// else {
140-
// Long tokenBalance = (Long) sum.get(0);
141-
// if(tokenBalance < costOfTicket)
142-
// throw new FlowException("Available token balance of " + buyerAccountName+ " is less than the cost of the ticket. Please ask the Bank to issue some cash if you wish to buy the ticket ");
143-
// }
132+
else {
133+
Long tokenBalance = (Long) sum.get(0);
134+
if(tokenBalance < costOfTicket)
135+
throw new FlowException("Available token balance of " + buyerAccountName+ " is less than the cost of the ticket. Please ask the Bank to issue some cash if you wish to buy the ticket ");
136+
}
144137

145138
Amount<FiatCurrency> amount = new Amount(costOfTicket, FiatCurrency.Companion.getInstance(currency));
146139

@@ -154,7 +147,7 @@ public String call() throws FlowException {
154147
//call utility function to move the fungible token from buyer to seller account
155148
//this also adds inputs and outputs to the transactionBuilder
156149
//till now we have only 1 transaction with 2 inputs and 2 outputs - one moving fungible tokens other moving non fungible tokens between accounts
157-
MoveTokensUtilities.addMoveFungibleTokens(transactionBuilder, getServiceHub(), Arrays.asList(partyAndAmount), buyerAccount, criteria);
150+
MoveTokensUtilitiesKt.addMoveFungibleTokens(transactionBuilder, getServiceHub(), Arrays.asList(partyAndAmount), buyerAccount, criteria);
158151

159152
//self sign the transaction. note : the host party will first self sign the transaction.
160153
SignedTransaction selfSignedTransaction = getServiceHub().signInitialTransaction(transactionBuilder,

Accounts/worldcupticketbooking/workflows/src/main/java/com/t20worldcup/flows/MoveTokensBetweenAccounts.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import com.r3.corda.lib.tokens.selection.TokenQueryBy;
1010
import com.r3.corda.lib.tokens.selection.database.config.DatabaseSelectionConfigKt;
1111
import com.r3.corda.lib.tokens.selection.database.selector.DatabaseTokenSelection;
12-
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilities;
13-
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilities;
12+
import com.r3.corda.lib.tokens.workflows.flows.move.MoveTokensUtilitiesKt;
13+
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilitiesKt;
1414
import kotlin.Pair;
1515
import net.corda.core.contracts.Amount;
1616
import net.corda.core.contracts.CommandData;
@@ -62,7 +62,7 @@ public String call() throws FlowException {
6262
Amount<TokenType> amount = new Amount(costOfTicket, getInstance(currency));
6363

6464
//Buyer Query for token balance.
65-
QueryCriteria queryCriteria = QueryUtilities.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount).and(QueryUtilities.sumTokenCriteria());
65+
QueryCriteria queryCriteria = QueryUtilitiesKt.heldTokenAmountCriteria(this.getInstance(currency), buyerAccount).and(QueryUtilitiesKt.sumTokenCriteria());
6666
List<Object> sum = getServiceHub().getVaultService().queryBy(FungibleToken.class, queryCriteria).component5();
6767
if(sum.size() == 0)
6868
throw new FlowException(buyerAccountName + " has 0 token balance. Please ask the Bank to issue some cash.");
@@ -92,7 +92,7 @@ public String call() throws FlowException {
9292

9393
TransactionBuilder transactionBuilder = new TransactionBuilder(notary);
9494

95-
MoveTokensUtilities.addMoveTokens(transactionBuilder, inputsAndOutputs.getFirst(), inputsAndOutputs.getSecond());
95+
MoveTokensUtilitiesKt.addMoveTokens(transactionBuilder, inputsAndOutputs.getFirst(), inputsAndOutputs.getSecond());
9696

9797
Set<PublicKey> mySigners = new HashSet<>();
9898

@@ -106,7 +106,7 @@ public String call() throws FlowException {
106106

107107
FlowSession sellerSession = initiateFlow(sellerAccountInfo.getHost());
108108

109-
//sign the transaction with the signers we got by calling filterMyKeys
109+
//sign the transaction with the signers we got by calling filterMyKeys
110110
SignedTransaction selfSignedTransaction = getServiceHub().signInitialTransaction(transactionBuilder, mySigners);
111111

112112
//call FinalityFlow for finality

0 commit comments

Comments
 (0)