Skip to content

Commit 39051d0

Browse files
committed
updated README and adjusted GetTokensBalance error message
1 parent 5737725 commit 39051d0

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

Tokens/fungiblehousetoken/README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,25 @@ We create the representation of a house, within [CreateHouseTokenFlow.java](./wo
2121

2222
```java
2323
public SignedTransaction call() throws FlowException {
24-
//grab the notary
25-
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
24+
// Obtain a reference to a notary we wish to use.
25+
/** METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
26+
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flow or parsed from config (Preferred)
27+
*
28+
* * - For production you always want to use Method 2 as it guarantees the expected notary is returned.
29+
*/
30+
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
31+
// final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
2632

2733
//create token type
2834
FungibleHouseTokenState evolvableTokenType = new FungibleHouseTokenState(valuation, getOurIdentity(),
2935
new UniqueIdentifier(), 0, this.symbol);
3036

3137
//wrap it with transaction state specifying the notary
32-
TransactionState transactionState = new TransactionState(evolvableTokenType, notary);
38+
TransactionState<FungibleHouseTokenState> transactionState = new TransactionState<>(evolvableTokenType, notary);
3339

3440
//call built in sub flow CreateEvolvableTokens. This can be called via rpc or in unit testing
3541
return subFlow(new CreateEvolvableTokens(transactionState));
3642
}
37-
3843
```
3944

4045
We issue tokens [IssueHouseTokenFlow](./workflows/src/main/java/net/corda/examples/tokenizedhouse/flows/RealEstateEvolvableFungibleTokenFlow.java#L81-L105)
@@ -50,22 +55,17 @@ public SignedTransaction call() throws FlowException {
5055
//get the RealEstateEvolvableTokenType object
5156
FungibleHouseTokenState evolvableTokenType = stateAndRef.getState().getData();
5257

53-
//get the pointer to the house
54-
TokenPointer tokenPointer = evolvableTokenType.toPointer(evolvableTokenType.getClass());
55-
56-
//assign the issuer to the house type who will be issuing the tokens
57-
IssuedTokenType issuedTokenType = new IssuedTokenType(getOurIdentity(), tokenPointer);
58-
59-
//specify how much amount to issue to holder
60-
Amount<IssuedTokenType> amount = new Amount(quantity, issuedTokenType);
61-
62-
//create fungible amount specifying the new owner
63-
FungibleToken fungibleToken = new FungibleToken(amount, holder, TransactionUtilitiesKt.getAttachmentIdForGenericParam(tokenPointer));
58+
//create fungible token for the house token type
59+
FungibleToken fungibleToken = new FungibleTokenBuilder()
60+
.ofTokenType(evolvableTokenType.toPointer(FungibleHouseTokenState.class)) // get the token pointer
61+
.issuedBy(getOurIdentity())
62+
.heldBy(holder)
63+
.withAmount(quantity)
64+
.buildFungibleToken();
6465

6566
//use built in flow for issuing tokens on ledger
6667
return subFlow(new IssueTokens(ImmutableList.of(fungibleToken)));
6768
}
68-
6969
```
7070

7171
We then move the house token. [MoveHouseTokenFlow](./workflows/src/main/java/net/corda/examples/tokenizedhouse/flows/RealEstateEvolvableFungibleTokenFlow.java#L127-L146)
@@ -74,18 +74,17 @@ We then move the house token. [MoveHouseTokenFlow](./workflows/src/main/java/net
7474
public SignedTransaction call() throws FlowException {
7575
//get house states on ledger with uuid as input tokenId
7676
StateAndRef<FungibleHouseTokenState> stateAndRef = getServiceHub().getVaultService().
77-
queryBy(FungibleHouseTokenState.class).getStates().stream()
78-
.filter(sf->sf.getState().getData().getSymbol().equals(symbol)).findAny()
79-
.orElseThrow(()-> new IllegalArgumentException("StockState symbol=\""+symbol+"\" not found from vault"));
77+
queryBy(FungibleHouseTokenState.class).getStates().stream()
78+
.filter(sf->sf.getState().getData().getSymbol().equals(symbol)).findAny()
79+
.orElseThrow(()-> new IllegalArgumentException("StockState symbol=\""+symbol+"\" not found from vault"));
8080

8181
//get the RealEstateEvolvableTokenType object
8282
FungibleHouseTokenState tokenstate = stateAndRef.getState().getData();
8383

84-
//get the pointer pointer to the house
85-
TokenPointer<FungibleHouseTokenState> tokenPointer = tokenstate.toPointer(FungibleHouseTokenState.class);
86-
87-
//specify how much amount to transfer to which holder
88-
Amount<TokenType> amount = new Amount(quantity, tokenPointer);
84+
/* specify how much amount to transfer to which holder
85+
* Note: we use a pointer of tokenstate because it of type EvolvableTokenType
86+
*/
87+
Amount<TokenType> amount = new Amount<>(quantity, tokenstate.toPointer(FungibleHouseTokenState.class));
8988
//PartyAndAmount partyAndAmount = new PartyAndAmount(holder, amount);
9089

9190
//use built in flow to move fungible tokens to holder
@@ -146,5 +145,7 @@ Since Buyer now has 50 tokens, Move tokens to Friend from Buyer s terminal
146145

147146
flow start MoveHouseTokenFlow symbol: house, holder: Friend, quantity: 23
148147

148+
You can now view the number of Tokens held by both the Buyer and the friend by executing the following Query flow in their respective terminals.
149149

150+
flow start GetTokenBalance symbol: house
150151

Tokens/fungiblehousetoken/workflows/src/main/java/net/corda/examples/tokenizedhouse/flows/QueryTokens.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String call() throws FlowException {
3838
StateAndRef<FungibleHouseTokenState> stateAndRef = getServiceHub().getVaultService().
3939
queryBy(FungibleHouseTokenState.class).getStates().stream()
4040
.filter(sf->sf.getState().getData().getSymbol().equals(symbol)).findAny()
41-
.orElseThrow(()-> new IllegalArgumentException("StockState symbol=\""+symbol+"\" not found from vault"));
41+
.orElseThrow(()-> new IllegalArgumentException("FungibleHouseTokenState symbol=\""+symbol+"\" not found from vault"));
4242

4343
//get the RealEstateEvolvableTokenType object
4444
FungibleHouseTokenState evolvableTokenType = stateAndRef.getState().getData();

Tokens/fungiblehousetoken/workflows/src/main/java/net/corda/examples/tokenizedhouse/flows/RealEstateEvolvableFungibleTokenFlow.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public SignedTransaction call() throws FlowException {
134134
//get the RealEstateEvolvableTokenType object
135135
FungibleHouseTokenState tokenstate = stateAndRef.getState().getData();
136136

137-
//specify how much amount to transfer to which holder
137+
/* specify how much amount to transfer to which holder
138+
* Note: we use a pointer of tokenstate because it of type EvolvableTokenType
139+
*/
138140
Amount<TokenType> amount = new Amount<>(quantity, tokenstate.toPointer(FungibleHouseTokenState.class));
139141
//PartyAndAmount partyAndAmount = new PartyAndAmount(holder, amount);
140142

0 commit comments

Comments
 (0)