Skip to content

Commit

Permalink
Refactor + BurnToken
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshmeher-r3 committed Aug 29, 2023
1 parent b31b60e commit 1c8298a
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 148 deletions.
71 changes: 49 additions & 22 deletions java-samples/shinny-tokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ using Next-Gen Corda.
In this application, we will mint gold tokens and then transfer these tokens.

In this app you can:
1. Write a flow to Create a Gold Asset/State on Ledger. `MintGoldTokensFlow`
1. Write a flow to Create a Gold Asset/State on Ledger. `IssueGoldTokensFlow`
2. List out the gold entries you had. `ListGoldTokens`
4. Claim and transfer the tokens to a new member. `TransferGoldTokenFlow`
3. Claim and transfer the tokens to a new member. `TransferGoldTokenFlow`
4. Burn tokens available with a member. `BurnGoldTokenFlow`

### Setting up

Expand All @@ -36,20 +37,20 @@ Pick a VNode identity, and get its short hash. (Let's pick Alice.).
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
```
{
"clientRequestId": "mint-1",
"flowClassName": "com.r3.developers.samples.tokens.workflows.MintGoldTokensFlow",
"clientRequestId": "issue-1",
"flowClassName": "com.r3.developers.samples.tokens.workflows.IssueGoldTokensFlow",
"requestBody": {
"symbol":"GOLD",
"issuer":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB",
"value":"20"
}
"symbol": "GOLD",
"owner": "CN=Bob, OU=Test Dept, O=R3, L=London, C=GB",
"amount": "20"
}
}
```

After trigger the MintGoldTokensFlow flow, hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the short hash(Alice's hash) and clientrequestid to view the flow result
After trigger the IssueGoldTokensFlow flow, hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the short hash(Alice's hash) and clientrequestid to view the flow result

#### Step 2: List the gold state
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:
```
{
"clientRequestId": "list-1",
Expand All @@ -59,28 +60,27 @@ Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Ali
```
After trigger the ListGoldTokens flow, again, we need to hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}`
and check the result.
As the screenshot shows, in the response body, we will see a list of the gold state we created.

#### Step 3: Transfer the gold token with `TransferGoldTokenFlow`
In this step, Alice will transfer some tokens from his vault to Charlie.
In this step, Bob will transfer some tokens from his vault to Charlie.
Goto `POST /flow/{holdingidentityshorthash}`, enter the identity short hash and request body.
Use Alice's holdingidentityshorthash to fire this post API.
Use Bob's holdingidentityshorthash to fire this post API.
```
{
"clientRequestId": "transfer-1",
"flowClassName": "com.r3.developers.samples.tokens.workflows.TransferGoldTokenFlow",
"requestBody": {
"symbol":"GOLD",
"issuer":"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB",
"newOwner":"CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB",
"value": "5"
"symbol": "GOLD",
"issuer": "CN=Alice, OU=Test Dept, O=R3, L=London, C=GB",
"receiver": "CN=Charlie, OU=Test Dept, O=R3, L=London, C=GB",
"amount": "5"
}
}
```
And as for the result of this flow, go to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the required fields.

#### Step 4: Confirm the token balances of Alice and Charlie
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
#### Step 4: Confirm the token balances of Bob and Charlie
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:
```
{
"clientRequestId": "list-2",
Expand All @@ -98,10 +98,37 @@ Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Cha
```

And as for the result, you need to go to the Get API again and enter the short hash and client request ID.
Thus, we have concluded a full run through of the token app.

#### Step 5: Burn gold token with BurnGoldTokenFlow
Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:
```
{
"clientRequestId": "burn-1",
"flowClassName": "com.r3.developers.samples.tokens.workflows.BurnGoldTokenFlow",
"requestBody": {
"symbol": "GOLD",
"issuer": "CN=Alice, OU=Test Dept, O=R3, L=London, C=GB",
"amount": "5"
}
}
```
Go to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the required fields to check the result of
the flow.

#### Step 4: Confirm the token balance of Bob

Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Bob's hash) and request body:
```
{
"clientRequestId": "list-4",
"flowClassName": "com.r3.developers.samples.tokens.workflows.ListGoldTokens",
"requestBody": {}
}
```

And as for the result, you need to go to the Get API again and enter the short hash and client request ID.
Thus, we have concluded a full run through of the token app.

# Additional Information

To read more about Token Selection API, you can visit the [docs](https://docs.r3.com/en/platform/corda/5.0-beta/developing/api/api-ledger-token-selection.html#tokens) and
read [this](https://r3-cev.atlassian.net/wiki/spaces/DR/pages/4435017960/Shiny+tokens+in+Next-Gen+Corda) blog.
To read more about Token Selection API, you can visit the [docs](https://docs.r3.com/en/platform/corda/5.0/developing-applications/api/ledger/utxo-ledger/token-selection.html)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GoldContract implements Contract {

private final static Logger log = LoggerFactory.getLogger(GoldContract.class);

public static class Create implements Command { }
public static class Issue implements Command { }

public static class Transfer implements Command { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.corda.v5.crypto.SecureHash;
import net.corda.v5.ledger.utxo.BelongsToContract;
import net.corda.v5.ledger.utxo.ContractState;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.security.PublicKey;
Expand All @@ -13,17 +14,17 @@
public class GoldState implements ContractState {

private SecureHash issuer;
private String symbol;
private BigDecimal value;
private SecureHash owner;
private String symbol;
private BigDecimal amount;
public List<PublicKey> participants;

public GoldState(SecureHash issuer, String symbol, BigDecimal value, List<PublicKey> participants, SecureHash owner) {
public GoldState(SecureHash issuer, SecureHash owner, String symbol, BigDecimal amount, List<PublicKey> participants) {
this.issuer = issuer;
this.owner = owner;
this.symbol = symbol;
this.value = value;
this.amount = amount;
this.participants = participants;
this.owner = owner;
}

public SecureHash getIssuer() {
Expand All @@ -34,21 +35,18 @@ public String getSymbol() {
return symbol;
}

public BigDecimal getValue() {
return value;
public BigDecimal getAmount() {
return amount;
}

public SecureHash getOwner() {
return owner;
}

@NotNull
@Override
public List<PublicKey> getParticipants() {
return participants;
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public Class<GoldState> getStateType() {
public UtxoToken onCommit(@NotNull GoldState state, @NotNull DigestService digestService) {
//generate a pool with key - type, issuer and symbol to mint the tokens
UtxoTokenPoolKey poolKey = new UtxoTokenPoolKey(GoldState.class.getName(), state.getIssuer(), state.getSymbol());
return new UtxoToken(poolKey, state.getValue(), new UtxoTokenFilterFields(null, state.getOwner()));
return new UtxoToken(poolKey, state.getAmount(), new UtxoTokenFilterFields(null, state.getOwner()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.r3.developers.samples.tokens.workflows;

public class BurnGoldTokenFLowArgs {

public BurnGoldTokenFLowArgs() {
}

private String symbol;
private String issuer;
private String amount;

public BurnGoldTokenFLowArgs(String symbol, String issuer, String amount) {
this.symbol = symbol;
this.issuer = issuer;
this.amount = amount;
}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}

public String getIssuer() {
return issuer;
}

public void setIssuer(String issuer) {
this.issuer = issuer;
}

public String getAmount() {
return amount;
}

public void setAmount(String amount) {
this.amount = amount;
}
}
Loading

0 comments on commit 1c8298a

Please sign in to comment.