Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance dollartohousetoken sample app #104

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
**/node_modules/
corda-nodeinfo/corda-nodeinfo.iml
*~*
*.prefs
17 changes: 16 additions & 1 deletion Tokens/dollartohousetoken/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ We can now check the issued house token in PartyB's vault. Since we issued it as

Note that HouseState token is an evolvable token which is a `LinearState`, thus we can check PartyB's vault to view the `EvolvableToken`

run vaultQuery contractStateType: HouseState
//run vaultQuery contractStateType: HouseState
run vaultQuery contractStateType: net.corda.samples.dollartohousetoken.states.HouseState

Note the linearId of the HouseState token from the previous step, we will need it to perform our DvP opearation. Goto PartyB's shell to initiate the token sale.

Expand All @@ -74,3 +75,17 @@ We could now verify that the non-fungible token has been transferred to PartyC a
run vaultQuery contractStateType: com.r3.corda.lib.tokens.contracts.states.FungibleToken
// Run on PartyC's shell
run vaultQuery contractStateType: com.r3.corda.lib.tokens.contracts.states.NonFungibleToken


## Use RPC client
In one terminal:
./gradlew assemble
java -jar clients/build/libs/clients-1.0.jar --server.port=50005 --config.rpc.host=localhost --config.rpc.port=10006 --config.rpc.username=user1 --config.rpc.password=test
In another terminal:
curl -i -X GET http://localhost:50005/me -H 'Content-Type: application/json'
curl -i -X GET http://localhost:50005/states -H 'Content-Type: application/json'
curl -i -X POST 'http://localhost:50005/create-token?amount=100&recipient=O=PartyC,L=Mumbai,C=IN&currency=USD' -H 'Content-Type: application/x-www-form-urlencoded'
curl -i -X POST 'http://localhost:50005/create-token?amount=100&recipient=O=PartyA,L=London,C=GB&currency=USD' -H 'Content-Type: application/x-www-form-urlencoded'
curl -i -X POST 'http://localhost:50005/burn-token?amount=100&recipient=O=PartyC,L=Mumbai,C=IN&currency=USD' -H 'Content-Type: application/x-www-form-urlencoded'
curl -i -X POST 'http://localhost:50005/burn-token?amount=100&recipient=O=PartyA,L=London,C=GB&currency=USD' -H 'Content-Type: application/x-www-form-urlencoded'
curl -i -X POST 'http://localhost:50005/query-token' -H 'Content-Type: application/x-www-form-urlencoded'
5 changes: 5 additions & 0 deletions Tokens/dollartohousetoken/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ buildscript {
tokens_release_group = 'com.r3.corda.lib.tokens'
tokens_release_version = '1.2'

//springboot
spring_boot_version = '2.0.2.RELEASE'
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'

}

repositories {
Expand All @@ -30,6 +34,7 @@ buildscript {
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
}
}

Expand Down
56 changes: 56 additions & 0 deletions Tokens/dollartohousetoken/clients/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apply plugin: 'org.springframework.boot'

sourceSets {
main {
resources {
srcDir rootProject.file("config/dev")
}
}
}

dependencies {
// Corda dependencies.
compile ("$corda_release_group:corda-rpc:$corda_release_version") {
exclude group: "ch.qos.logback", module: "logback-classic"
}
compile "net.corda:corda-jackson:$corda_release_version"

// CorDapp dependencies.
compile project(":contracts")
compile project(":workflows")
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
compile "org.slf4j:jul-to-slf4j:$slf4j_version"
}

springBoot {
mainClassName = "net.corda.samples.example.webserver.Starter"
}

/* The Client is the communication channel between the external and the node. This task will help you immediately
* execute your rpc methods in the main method of the client.kt. You can somewhat see this as a quick test of making
* RPC calls to your nodes.
*/
task runTestClient(type: JavaExec, dependsOn: assemble) {
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Client'
args 'localhost:10006', 'user1', 'test'
}

/* This task will start the springboot server that connects to your node (via RPC connection). All of the http requests
* are in the Controller file. You can leave the Server.kt and NodeRPCConnection.kt file untouched for your use.
*/
task runPartyAServer(type: JavaExec, dependsOn: assemble) {
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Starter'
args '--server.port=50005', '--config.rpc.host=localhost', '--config.rpc.port=10006', '--config.rpc.username=user1', '--config.rpc.password=test'
}

task runPartyBServer(type: JavaExec, dependsOn: assemble) {
classpath = sourceSets.main.runtimeClasspath
main = 'net.corda.samples.example.webserver.Starter'
args '--server.port=50006', '--config.rpc.host=localhost', '--config.rpc.port=10009', '--config.rpc.username=user1', '--config.rpc.password=test'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.corda.samples.example;

import net.corda.client.rpc.CordaRPCClient;
import net.corda.client.rpc.CordaRPCConnection;
import net.corda.core.identity.CordaX500Name;
import net.corda.core.messaging.CordaRPCOps;
import net.corda.core.node.NodeInfo;
import net.corda.core.utilities.NetworkHostAndPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import static net.corda.core.utilities.NetworkHostAndPort.parse;

/**
* Connects to a Corda node via RPC and performs RPC operations on the node.
*
* The RPC connection is configured using command line arguments.
*/
public class Client {
private static final Logger logger = LoggerFactory.getLogger(Client.class);

public static void main(String[] args) {
// Create an RPC connection to the node.
if (args.length != 3) throw new IllegalArgumentException("Usage: Client <node address> <rpc username> <rpc password>");
final NetworkHostAndPort nodeAddress = parse(args[0]);
final String rpcUsername = args[1];
final String rpcPassword = args[2];
final CordaRPCClient client = new CordaRPCClient(nodeAddress);
final CordaRPCConnection clientConnection = client.start(rpcUsername, rpcPassword);
final CordaRPCOps proxy = clientConnection.getProxy();

// Interact with the node.
// Example #1, here we print the nodes on the network.
final List<NodeInfo> nodes = proxy.networkMapSnapshot();
System.out.println("\n-- Here is the networkMap snapshot --");
logger.info("{}", nodes);

// Example #2, here we print the PartyA's node info
CordaX500Name name = proxy.nodeInfo().getLegalIdentities().get(0).getName();//nodeInfo().legalIdentities.first().name
System.out.println("\n-- Here is the node info of the node that the client connected to --");
logger.info("{}", name);

//Close the client connection
clientConnection.close();

}
}
Loading