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

V4 #8

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open

V4 #8

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c9157bf
Update gradle wrapper.
florian-f May 31, 2019
44a0db2
Update build.gradle
florian-f May 31, 2019
27a15ee
wip
florian-f Jun 5, 2019
f940f0b
Update example.
florian-f Jun 10, 2019
ffc6189
Move Troubleshooting guide from wiki to file.
florian-f Jun 10, 2019
49e0b13
Fix flow and improve tests.
florian-f Jun 10, 2019
26b99a1
Comment out tests.
florian-f Jun 11, 2019
935e3f4
Move solutions to Solutions.md.
florian-f Jun 11, 2019
11884b8
share run configurations.
florian-f Jun 11, 2019
215e036
Fix tests.
florian-f Jun 11, 2019
47485f0
Improve solutions.md
florian-f Jun 11, 2019
3aadde1
Clean up build.gradle
florian-f Jun 11, 2019
b692e11
Remove 'update for offline use' section from readme.
florian-f Jun 11, 2019
1edbf1f
Clean up build.gradle
florian-f Jun 11, 2019
ca6e071
Updated troubleshooting guide with command line too long error
FreyaRhianna Aug 14, 2019
024fee7
Merge pull request #10 from corda/RSH-update-readme
FreyaRhianna Aug 14, 2019
3acd0c0
Fix readme: deployNodes
zkiss Sep 24, 2019
4fdf210
Merge pull request #14 from corda/fix_readme
chrischabot Oct 10, 2019
0e25dba
vscode unit test fixes
ashutoshmeher-r3 Oct 22, 2019
3174aaf
Merge pull request #16 from corda/vscode
ashutoshmeher-r3 Oct 22, 2019
3cb2602
remove launch.json
ashutoshmeher-r3 Oct 22, 2019
a5f4f94
Merge pull request #17 from corda/vscode
ashutoshmeher-r3 Oct 22, 2019
49cee18
update build.gradle for test output folder
ashutoshmeher-r3 Oct 22, 2019
e4efeb1
Merge pull request #18 from corda/vscode
ashutoshmeher-r3 Oct 22, 2019
cf40497
4.3 upgrade
Mar 11, 2020
fa4caba
Update build.gradle
peterli-r3 Mar 12, 2020
5b9c580
Update build.gradle
peterli-r3 Mar 12, 2020
cf1e561
.settings/pref file added for VSCode JDT compiler compatibility see D…
anixon604 Apr 21, 2020
b404609
blank space added after 'if' of deployNodes condition to allow vscode…
anixon604 Apr 26, 2020
c0e82f4
Update Solutions.md
davidawad May 27, 2020
d748fde
Merge pull request #20 from corda/davidawad-solutions-highlighting
davidawad Jun 10, 2020
e4f483d
add imports / boilerplate to TokenContract.java
davidawad Jun 10, 2020
15ab56a
add imports to TokenIssueFlowInitiator.java
davidawad Jun 10, 2020
b332056
add info to bootcamp to run the nodes
davidawad Jun 10, 2020
78bbe11
Merge pull request #21 from corda/davidawad-patch-1
davidawad Jun 10, 2020
36b3758
Add another import to TokenContract.java
davidawad Jun 10, 2020
4ad46a6
Added try in web ide to README
anixon604 Jun 26, 2020
478502a
Merge branch 'v4' of github.com:corda/bootcamp-cordapp into v4
anixon604 Jun 26, 2020
600ce63
add slides
peterli-r3 Jul 23, 2020
de10347
Adding Integration Test
ashutoshmeher-r3 Aug 20, 2020
89dce01
Add constants.properties, implement in build
olliegilbey May 25, 2021
f9426c8
Add gradle.properties update 5.6.4
olliegilbey May 26, 2021
87c6fdb
small improvements to bootcamp cordapp
Jun 1, 2021
97879a7
improvements to dependencies
Jun 1, 2021
48aa972
Merge pull request #23 from corda/update-to-spec-4-8
Jun 1, 2021
66a63df
Update constants.properties
peterli-r3 Feb 24, 2022
6bddf1f
structure change and add docker deployment
peterli-r3 Mar 21, 2022
21ce444
Merge pull request #25 from corda/bootcamp_with_docker
peterli-r3 Mar 22, 2022
2ba9d7f
remove config
peterli-r3 Mar 22, 2022
ac08191
Update README.md
ja9-look Sep 12, 2022
97df461
Merge pull request #26 from corda/patch/update_command_query_in_read_me
peterli-r3 Sep 12, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ build
lib/dependencies/
.DS_Store
out
bootcamp-cordapp.iml
bootcamp-cordapp.iml
bin/
logs/
13 changes: 13 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016, R3 Limited.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
72 changes: 22 additions & 50 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,23 @@
<img src="https://www.corda.net/wp-content/uploads/2016/11/fg005_corda_b.png" alt="Corda" width="500">
</p>

# Bootcamp CorDapp
# Bootcamp CorDapp [<img src="https://raw.githubusercontent.com/corda/samples-java/master/webIDE.png" height=25 />](https://ide.corda.net/?folder=/home/coder/bootcamp-cordapp)

This project is the template we will use as a basis for developing a complete CorDapp
This project is the template we will use as a basis for developing a complete CorDapp
during today's bootcamp. Our CorDapp will allow the issuance of tokens onto the ledger.

We'll develop the CorDapp using a test-driven approach. At each stage, you'll know your
CorDapp is working once it passes both sets of tests defined in `src/test/java/java_bootcamp`.
We'll develop the CorDapp using a test-driven approach. At each stage, you'll know your
CorDapp is working once it passes both sets of tests defined in `src/test/java/bootcamp`.

## Set up

1. Download and install Oracle JDK 8 JVM (minimum supported version 8u131)
2. Download and install IntelliJ Community Edition (supported versions 2017.x and 2018.x)
1. Download and install a JDK 8 JVM (minimum supported version 8u131)
2. Download and install IntelliJ Community Edition (supported versions: prior than 2021)
3. Download the bootcamp-cordapp repository:

git clone https://github.com/corda/bootcamp-cordapp

4. Open IntelliJ. From the splash screen, click `Import Project`, select the `bootcamp—
cordapp` folder and click `Open`
5. Select `Import project from external model > Gradle > Next > Finish`
6. Click `File > Project Structure…` and select the Project SDK (Oracle JDK 8, 8u131+)

i. Add a new SDK if required by clicking `New…` and selecting the JDK’s folder

7. Open the `Project` view by clicking `View > Tool Windows > Project`
8. Run the test in `src/test/java/java_bootcamp/ProjectImportedOKTest.java`. It should pass!

## Links to useful resources

This project contains example state, contract and flow implementations:

* `src/main/java/java_examples/ArtState`
* `src/main/java/java_examples/ArtContract`
* `src/main/java/java_examples/ArtTransferFlowInitiator`
* `src/main/java/java_examples/ArtTransferFlowResponder`

There are also several web resources that you will likely find useful for this
bootcamp:

* Key Concepts docs (`docs.corda.net/key-concepts.html`)
* API docs (`docs.corda.net/api-index.html`)
* Cheat sheet (`docs.corda.net/cheat-sheet.html`)
* Sample CorDapps (`www.corda.net/samples`)
* Stack Overflow (`www.stackoverflow.com/questions/tagged/corda`)
4. Open IntelliJ load the project

## What we'll be building

Expand Down Expand Up @@ -150,30 +124,28 @@ Once you've finished the CorDapp's code, run it with the following steps:
* Build a test network of nodes by opening a terminal window at the root of
your project and running the following command:

* Windows: `gradlew.bat deployNodesJava`
* macOS: `./gradlew deployNodesJava`
* Windows: `gradlew.bat deployNodes`
* Linux/Mac: `./gradlew deployNodes`

* Start the nodes by running the following command:

* Windows: `build\nodes\runnodes.bat`
* macOS: `build/nodes/runnodes`
* Windows: `build\nodes\runnodes.bat`
* Linux/Mac: `./build/nodes/runnodes`



* Build and Start the nodes using docker:
* Windows: `gradlew.bat prepareDockerNodes`
* Linux/Mac: `./gradlew prepareDockerNodes`
* `ACCEPT_LICENSE=Y | docker-compose -f ./build/nodes/docker-compose.yml up`


* Open the nodes are started, go to the terminal of Party A (not the notary!)
and run the following command to issue 99 tokens to Party B:

`flow start TokenIssueFlow owner: PartyB, amount: 99`
`flow start TokenIssueFlowInitiator owner: PartyB, amount: 99`

* You can now see the tokens in the vaults of Party A and Party B (but not
* You can now see the tokens in the vaults of Party A and Party B (but not
Party C!) by running the following command in their respective terminals:

`run vaultQuery contractStateType: java_bootcamp.TokenState`

## Updating for offline use

* Run the `gatherDependencies` Gradle task from the root of the project to
gather all the CorDapp's dependencies in `lib/dependencies`
* Update `gradle/wrapper/gradle-wrapper.properties` to point to a local Gradle
distribution (e.g.
`distributionUrl=gradle-4.4.1-all.zip`)
* In `build.gradle`, under both `repositories` blocks, comment out any
repositories other than `flatDir { ... }`
`run vaultQuery contractStateType: com.bootcamp.states.TokenState`
179 changes: 179 additions & 0 deletions Solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# TokenState

```java
package com.bootcamp.states;

import com.bootcamp.contracts.TokenContract;
import net.corda.core.contracts.BelongsToContract;
import net.corda.core.contracts.ContractState;
import net.corda.core.identity.AbstractParty;
import net.corda.core.identity.Party;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/* Our state, defining a shared fact on the ledger.
* See src/main/java/examples/ArtState.java for an example. */
@BelongsToContract(TokenContract.class)
public class TokenState implements ContractState {

private final Party issuer;
private final Party owner;
private final int amount;
private final List<AbstractParty> participants;

public TokenState(Party issuer, Party owner, int amount) {
this.issuer = issuer;
this.owner = owner;
this.amount = amount;
this.participants = new ArrayList<>();
participants.add(issuer);
participants.add(owner);
}

public Party getIssuer() {
return issuer;
}

public Party getOwner() {
return owner;
}

public int getAmount() {
return amount;
}

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

```

# TokenContract

```java
package com.bootcamp.contracts;

import com.bootcamp.states.TokenState;
import net.corda.core.contracts.CommandData;
import net.corda.core.contracts.CommandWithParties;
import net.corda.core.contracts.Contract;
import net.corda.core.contracts.ContractState;
import net.corda.core.transactions.LedgerTransaction;

import java.util.List;

import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
import static net.corda.core.contracts.ContractsDSL.requireThat;

public class TokenContract implements Contract {
public static String ID = "com.bootcamp.contracts.TokenContract";

@Override
public void verify(LedgerTransaction tx) throws IllegalArgumentException {

CommandWithParties<TokenContract.Commands> command = requireSingleCommand(tx.getCommands(), TokenContract.Commands.class);

List<ContractState> inputs = tx.getInputStates();
List<ContractState> outputs = tx.getOutputStates();

if (command.getValue() instanceof TokenContract.Commands.Issue) {
requireThat(req -> {
req.using("Transaction must have no input states.", inputs.isEmpty());
req.using("Transaction must have exactly one output.", outputs.size() == 1);
req.using("Output must be a TokenState.", outputs.get(0) instanceof TokenState);
TokenState output = (TokenState) outputs.get(0);
req.using("Issuer must be required singer.", command.getSigners().contains(output.getIssuer().getOwningKey()));
req.using("Owner must be required singer.", command.getSigners().contains(output.getOwner().getOwningKey()));
req.using("Amount must be positive.", output.getAmount() > 0);
return null;
});
} else {
throw new IllegalArgumentException("Unrecognized command");
}
}

public interface Commands extends CommandData {
class Issue implements Commands {
}
}
}
```

# TokenIssueFlowInitiator

```java
@InitiatingFlow
@StartableByRPC
public static class TokenIssueFlowInitiator extends FlowLogic<SignedTransaction> {
private final Party owner;
private final int amount;

public TokenIssueFlowInitiator(Party owner, int amount) {
this.owner = owner;
this.amount = amount;
}

private final ProgressTracker progressTracker = new ProgressTracker();

@Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}

@Suspendable
@Override
public SignedTransaction call() throws FlowException {
/** Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)*/
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));

Party issuer = getOurIdentity();

TokenState tokenState = new TokenState(issuer, owner, amount);

TransactionBuilder transactionBuilder = new TransactionBuilder(notary);

CommandData commandData = new TokenContract.Commands.Issue();

transactionBuilder.addCommand(commandData, issuer.getOwningKey(), owner.getOwningKey());

transactionBuilder.addOutputState(tokenState, TokenContract.ID);

transactionBuilder.verify(getServiceHub());

FlowSession session = initiateFlow(owner);

SignedTransaction signedTransaction = getServiceHub().signInitialTransaction(transactionBuilder);

SignedTransaction fullySignedTransaction = subFlow(new CollectSignaturesFlow(signedTransaction, singletonList(session)));

return subFlow(new FinalityFlow(fullySignedTransaction, singletonList(session)));
}
}
```

# Running our Nodes

```sh
./gradlew clean deploynodes

#(OPTIONAL)
killall -9 java

./build/nodes/runnodes
flow start TokenIssueFlowInitiator owner: PartyB, amount: 50
```

# via docker
```sh
./gradlew clean prepareDockerNodes

ACCEPT_LICENSE=Y | docker-compose -f ./build/nodes/docker-compose.yml up


```

4 changes: 4 additions & 0 deletions TRADEMARK
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.

For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
https://www.r3.com/trademark-policy/.
Loading