Skip to content

Commit be5252c

Browse files
committed
stock pay dividend
1 parent 6fc74db commit be5252c

File tree

16 files changed

+86
-202
lines changed

16 files changed

+86
-202
lines changed

Tokens/stockpaydividend/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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`

Tokens/stockpaydividend/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ buildscript {
1212
slf4j_version = constants.getProperty("slf4jVersion")
1313
corda_platform_version = constants.getProperty("platformVersion")
1414
guava_version = constants.getProperty("guavaVersion")
15+
16+
//token dependency
1517
tokens_release_group = 'com.r3.corda.lib.tokens'
16-
tokens_release_version = '1.0'
18+
tokens_release_version = '1.2'
1719
}
1820

1921
repositories {
@@ -98,7 +100,6 @@ dependencies {
98100
// Token SDK dependencies.
99101
cordapp "$tokens_release_group:tokens-contracts:$tokens_release_version"
100102
cordapp "$tokens_release_group:tokens-workflows:$tokens_release_version"
101-
cordapp "$tokens_release_group:tokens-money:$tokens_release_version"
102103
}
103104

104105
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
@@ -108,7 +109,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
108109
}
109110
cordapp("$tokens_release_group:tokens-contracts:$tokens_release_version")
110111
cordapp("$tokens_release_group:tokens-workflows:$tokens_release_version")
111-
cordapp("$tokens_release_group:tokens-money:$tokens_release_version")
112112
cordapp project(':contracts')
113113
cordapp project(':workflows')
114114
}

Tokens/stockpaydividend/contracts/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ 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"
2726

2827
// Guave
2928
compile "com.google.guava:guava:$guava_version"

Tokens/stockpaydividend/contracts/src/main/java/net/corda/examples/stockpaydividend/states/StockState.java

Lines changed: 7 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.core.schemas.StatePersistable;
68
import net.corda.core.serialization.CordaSerializable;
79
import net.corda.examples.stockpaydividend.contracts.StockContract;
@@ -91,4 +93,9 @@ public List<Party> getMaintainers() {
9193
return ImmutableList.of(issuer);
9294
}
9395

96+
/* This method returns a TokenPointer by using the linear Id of the evolvable state */
97+
public TokenPointer<StockState> toPointer(){
98+
LinearPointer<StockState> linearPointer = new LinearPointer<>(linearId, StockState.class);
99+
return new TokenPointer<>(linearPointer, fractionDigits);
100+
}
94101
}

Tokens/stockpaydividend/workflows/build.gradle

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

5353
// Token SDK dependencies.
54-
cordaCompile "$tokens_release_group:tokens-money:$tokens_release_version"
5554
cordaCompile "$tokens_release_group:tokens-workflows:$tokens_release_version"
5655
}
5756

Tokens/stockpaydividend/workflows/src/main/java/net/corda/examples/stockpaydividend/flows/AnnounceDividend.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
import com.google.common.collect.ImmutableList;
55
import com.r3.corda.lib.tokens.workflows.flows.evolvable.UpdateEvolvableTokenFlow;
66
import com.r3.corda.lib.tokens.workflows.flows.evolvable.UpdateEvolvableTokenFlowHandler;
7-
import com.r3.corda.lib.tokens.workflows.flows.rpc.UpdateEvolvableToken;
87
import net.corda.core.contracts.StateAndRef;
98
import net.corda.core.flows.*;
109
import net.corda.core.identity.Party;
1110
import net.corda.core.node.services.IdentityService;
1211
import net.corda.core.transactions.SignedTransaction;
13-
import net.corda.examples.stockpaydividend.flows.utilities.ObserversUtilities;
14-
import net.corda.examples.stockpaydividend.flows.utilities.QueryUtilities;
12+
import net.corda.examples.stockpaydividend.flows.utilities.CustomQuery;
1513
import net.corda.examples.stockpaydividend.states.StockState;
1614

1715
import java.math.BigDecimal;
18-
import java.util.ArrayList;
19-
import java.util.Date;
20-
import java.util.List;
16+
import java.util.*;
2117

2218
/**
2319
* Designed initiating node : Company
@@ -48,7 +44,7 @@ public Initiator(String symbol, BigDecimal dividendPercentage, Date executionDat
4844
public String call() throws FlowException {
4945

5046
// Retrieved the unconsumed StockState from the vault
51-
StateAndRef<StockState> stockStateRef = QueryUtilities.queryStock(symbol, getServiceHub());
47+
StateAndRef<StockState> stockStateRef = CustomQuery.queryStock(symbol, getServiceHub());
5248
StockState stock = stockStateRef.getState().getData();
5349

5450
// Form the output state here with a dividend to be announced
@@ -65,7 +61,7 @@ public String call() throws FlowException {
6561

6662
// Get predefined observers
6763
IdentityService identityService = getServiceHub().getIdentityService();
68-
List<Party> observers = ObserversUtilities.getObserverLegalIdenties(identityService);
64+
List<Party> observers = getObserverLegalIdenties(identityService);
6965
List<FlowSession> obSessions = new ArrayList<>();
7066
for(Party observer : observers){
7167
obSessions.add(initiateFlow(observer));
@@ -78,7 +74,7 @@ public String call() throws FlowException {
7874
}
7975

8076
@InitiatedBy(AnnounceDividend.Initiator.class)
81-
public static class Responder extends FlowLogic<SignedTransaction> {
77+
public static class Responder extends FlowLogic<Void> {
8278
private FlowSession counterSession;
8379

8480
public Responder(FlowSession counterSession) {
@@ -87,9 +83,24 @@ public Responder(FlowSession counterSession) {
8783

8884
@Suspendable
8985
@Override
90-
public SignedTransaction call() throws FlowException {
86+
public Void call() throws FlowException {
9187
// To implement the responder flow, simply call the subflow of UpdateEvolvableTokenFlowHandler
92-
return subFlow(new UpdateEvolvableTokenFlowHandler(counterSession));
88+
subFlow(new UpdateEvolvableTokenFlowHandler(counterSession));
89+
return null;
9390
}
9491
}
92+
93+
94+
public static List<Party> getObserverLegalIdenties(IdentityService identityService){
95+
List<Party> observers = new ArrayList<>();
96+
for(String observerName : Arrays.asList("Observer", "Shareholder")){
97+
Set<Party> observerSet = identityService.partiesFromName(observerName, false);
98+
if (observerSet.size() != 1) {
99+
final String errMsg = String.format("Found %d identities for the observer.", observerSet.size());
100+
throw new IllegalStateException(errMsg);
101+
}
102+
observers.add(observerSet.iterator().next());
103+
}
104+
return observers;
105+
}
95106
}

Tokens/stockpaydividend/workflows/src/main/java/net/corda/examples/stockpaydividend/flows/ClaimDividendReceivable.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.r3.corda.lib.tokens.contracts.types.TokenPointer;
77
import com.r3.corda.lib.tokens.contracts.types.TokenType;
88
import com.r3.corda.lib.tokens.workflows.types.PartyAndAmount;
9-
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilitiesKt;
9+
import com.r3.corda.lib.tokens.workflows.utilities.QueryUtilities;
1010
import net.corda.core.contracts.*;
1111
import net.corda.core.crypto.SecureHash;
1212
import net.corda.core.flows.*;
@@ -16,7 +16,7 @@
1616
import net.corda.core.transactions.TransactionBuilder;
1717
import net.corda.core.utilities.ProgressTracker;
1818
import net.corda.examples.stockpaydividend.contracts.DividendContract;
19-
import net.corda.examples.stockpaydividend.flows.utilities.QueryUtilities;
19+
import net.corda.examples.stockpaydividend.flows.utilities.CustomQuery;
2020
import net.corda.examples.stockpaydividend.states.DividendState;
2121
import net.corda.examples.stockpaydividend.states.StockState;
2222

@@ -51,12 +51,13 @@ public Initiator(String symbol) {
5151
public String call() throws FlowException {
5252

5353
// Retrieve the stock and pointer
54-
TokenPointer stockPointer = QueryUtilities.queryStockPointer(symbol, getServiceHub());
54+
TokenPointer stockPointer = CustomQuery.queryStockPointer(symbol, getServiceHub());
55+
5556
StateAndRef<StockState> stockStateRef = stockPointer.getPointer().resolve(getServiceHub());
5657
StockState stockState = stockStateRef.getState().getData();
5758

5859
// Query the current Stock amount from shareholder
59-
Amount<TokenType> stockAmount = QueryUtilitiesKt.tokenBalance(getServiceHub().getVaultService(), stockPointer);
60+
Amount<TokenType> stockAmount = QueryUtilities.tokenBalance(getServiceHub().getVaultService(), stockPointer);
6061

6162
// Prepare to send the stock amount to the company to request dividend issuance
6263
ClaimNotification stockToClaim = new ClaimNotification(stockAmount);
@@ -114,7 +115,7 @@ public SignedTransaction call() throws FlowException {
114115
StockState stockState = holderStockState.getState().getData();
115116

116117
// Query the stored state of the company
117-
TokenPointer stockPointer = QueryUtilities.queryStockPointer(stockState.getSymbol(), getServiceHub());
118+
TokenPointer stockPointer = CustomQuery.queryStockPointer(stockState.getSymbol(), getServiceHub());
118119
StateAndRef<StockState> stockStateRef = stockPointer.getPointer().resolve(getServiceHub());
119120

120121
// Receives the amount that the shareholder holds
@@ -124,8 +125,6 @@ public SignedTransaction call() throws FlowException {
124125
return it;
125126
});
126127

127-
PartyAndAmount<TokenType> stockPartyAndAmount = new PartyAndAmount<TokenType>(getOurIdentity(), claimNoticication.getAmount());
128-
129128
// Preparing the token type of the paying fiat currency
130129
Currency currency = Currency.getInstance(stockState.getCurrency());
131130
TokenType dividendTokenType = new TokenType(currency.getCurrencyCode(), currency.getDefaultFractionDigits());

Tokens/stockpaydividend/workflows/src/main/java/net/corda/examples/stockpaydividend/flows/IssueStock.java renamed to Tokens/stockpaydividend/workflows/src/main/java/net/corda/examples/stockpaydividend/flows/CreateAndIssueStock.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.r3.corda.lib.tokens.contracts.types.IssuedTokenType;
77
import com.r3.corda.lib.tokens.workflows.flows.rpc.CreateEvolvableTokens;
88
import com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens;
9+
import com.r3.corda.lib.tokens.workflows.utilities.FungibleTokenBuilder;
910
import net.corda.core.node.services.IdentityService;
10-
import net.corda.examples.stockpaydividend.flows.utilities.ObserversUtilities;
1111
import net.corda.examples.stockpaydividend.states.StockState;
1212
import net.corda.core.contracts.Amount;
1313
import net.corda.core.contracts.TransactionState;
@@ -23,6 +23,8 @@
2323
import java.util.Date;
2424
import java.util.List;
2525

26+
import static net.corda.examples.stockpaydividend.flows.AnnounceDividend.getObserverLegalIdenties;
27+
2628
/**
2729
* Designed initiating node : Company
2830
* This flow issues a stock to the node itself just to keep things simple
@@ -32,7 +34,7 @@
3234
*/
3335
@InitiatingFlow
3436
@StartableByRPC
35-
public class IssueStock extends FlowLogic<String> {
37+
public class CreateAndIssueStock extends FlowLogic<String> {
3638

3739
private String symbol;
3840
private String name;
@@ -43,7 +45,7 @@ public class IssueStock extends FlowLogic<String> {
4345
// Using NetworkmapCache.getNotaryIdentities().get(0) is not encouraged due to multi notary is introduced
4446
private Party notary;
4547

46-
public IssueStock(String symbol, String name, String currency, BigDecimal price, int issueVol, Party notary) {
48+
public CreateAndIssueStock(String symbol, String name, String currency, BigDecimal price, int issueVol, Party notary) {
4749
this.symbol = symbol;
4850
this.name = name;
4951
this.currency = currency;
@@ -58,7 +60,7 @@ public String call() throws FlowException {
5860

5961
// Sample specific - retrieving the hard-coded observers
6062
IdentityService identityService = getServiceHub().getIdentityService();
61-
List<Party> observers = ObserversUtilities.getObserverLegalIdenties(identityService);
63+
List<Party> observers = getObserverLegalIdenties(identityService);
6264

6365
Party company = getOurIdentity();
6466

@@ -81,14 +83,14 @@ public String call() throws FlowException {
8183
// Using the build-in flow to create an evolvable token type -- Stock
8284
subFlow(new CreateEvolvableTokens(transactionState, observers));
8385

84-
// Similar in IssueMoney flow, class of IssuedTokenType represents the stock is issued by the company party
85-
IssuedTokenType issuedStock = new IssuedTokenType(company, stockState.toPointer(stockState.getClass()));
86-
87-
// Create an specified amount of stock with a pointer that refers to the StockState
88-
Amount<IssuedTokenType> issueAmount = new Amount(new Long(issueVol), issuedStock);
89-
9086
// Indicate the recipient which is the issuing party itself here
91-
FungibleToken stockToken = new FungibleToken(issueAmount, getOurIdentity(), null);
87+
//new FungibleToken(issueAmount, getOurIdentity(), null);
88+
FungibleToken stockToken = new FungibleTokenBuilder()
89+
.ofTokenType(stockState.toPointer())
90+
.withAmount(issueVol)
91+
.issuedBy(getOurIdentity())
92+
.heldBy(getOurIdentity())
93+
.buildFungibleToken();
9294

9395
// Finally, use the build-in flow to issue the stock tokens. Observer parties provided here will record a copy of the transactions
9496
SignedTransaction stx = subFlow(new IssueTokens(ImmutableList.of(stockToken), observers));

Tokens/stockpaydividend/workflows/src/main/java/net/corda/examples/stockpaydividend/flows/GetStockUpdate.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)