CorDapp Suite and Dependencies - corda

Let's say I want to use a cash-based CorDapp for DVP with my CP Trading CorDapp (But I do not want to be responsible for updating/developing cash). How does one note CorDapp dependencies for deployment? What if the cash CorDapp updates their state or contract definition?
If cash is too specific, let's say I want to use an API that reaches out to another data source for enrichment or validation of my state. Does this have to be an Oracle? Can we implement this API call as a CorDapp that's installed in a CorDapp Suite so it stays decentralized or must it contain a signature of an oracle in order to keep the transaction valid?

You specify the dependencies of your CorDapp in the dependencies section of your build.gradle file. For example, the following line would include the corda-finance module, which includes cash:
cordapp "net.corda:corda-finance:$corda_release_version"
As you can see, you specify the version of the CorDapp that you wish to use.
By default, when you build a CorDapp, the CorDapp jar's name is determined by:
The name of the module where the sources are defined
The version property in a project's gradle.properties file
So if the version number is 0.1, and your module is called clemens-dvp, building the CorDapp jar will create a file called clemens-dvp-0.1.jar.
See further information here: https://docs.corda.net/cordapp-build-systems.html. The docs state:
"The filename of the jar must include some sort of unique identifier to deduplicate it from other releases of the same CorDapp. This is typically done by appending the version string. It should not change once the jar has been deployed on a node."

Related

The transaction currently built is missing an attachment for class - Attempted to find a suitable attachment but could not find any in the storage

Full Error:
transactions.TransactionBuilder. - The transaction currently built is missing an attachment for class: com/gibtn/corda/printutilities/PrintLedgerTransaction. Attempted to find a suitable attachment but could not find any in the storage.
This has been asked here and here but I hope to get better clarification.
Problem:
I have built a set of libraries to perform common tasks in my Flows that I include in all my CorDapps. For now I just copy the JARs into each project, make some changes to the gradle files and everything works great.
I recently put together a small library for performing common tasks in Contracts and added the JAR the same way.
This works fine with MockNodes. But when I test with real nodes I will get this error in the CRaSH shell and the transaction will fail with a NoClassDefFoundError exception.
Question:
Is what I am doing even possible? Or do I always have to keep my utility classes inside the Contracts module in IntelliJ so they are bundled together with the Contracts into a single JAR? That way when the node starts the JAR (containing the Contracts and any utilities) is added to Attachment storage as a single Attachment.
I found a way to solve this. It's a bit dirty but initial testing seems to work. I just created a blank class in my utilities JAR that implements Contract. It's verify() method is empty. Now when the Corda node starts it sees this Contract and adds the JAR to Attachment storage. So from the CRaSH shell if I run:
attachments trustInfo
...my utility JAR will be listed (it wasn't before). I see when I use one of the utility methods in a Contract the utility JAR will be included as a separate Attachment in the WireTransaction.
I'm not crazy about this solution and will probably stop using a utility JAR for Contracts. I'll go back to copying the classes into each project. Nevertheless there is a way to do it. I would just need a more experienced Corda developer to give it their blessing before I'd go forward into production with it.

How to mark / tag spring cloud contract generated test

is there any possibility to annotate / tag the CDC generated tests?
I would like to group the cdc tests and execute them as separate step in my build pipeline.
They are all present under target or build and then /generated-test-sources/contracts. You can by default exclude those paths and have a separate profile in maven or task in gradle that will include those paths when you want to run contract tests

How to get config file for Cordapp?

How to get config file for Cordapp in Java like in sample?
serviceHub.getAppContext().config
After getAppContext() i can't find anything about config file.
This feature is not available in Corda 3. As of this answer, it is only part of the unstable master branch. It will be included in a future release of Corda.
However, you can implement this manually for now as follows: How to provide a CorDapp with custom config in Corda?.

In CorDapps, how can I split the definition of shared classes (e.g. states and contracts) from the definition of other classes?

In Corda, I understand that any CorDapp JAR that includes a class implementing the contract interface will be automatically uploaded to the node as an attachment and propagated to other nodes as part of contract verification so that they have a copy of the contract.
How can I structure my CorDapp so that the JAR only includes definitions of shared resources, such as contracts and states, and nothing that includes proprietary logic, such as flows?
Any production CorDapp should follow the structure defined here: https://docs.corda.net/writing-a-cordapp.html#structure.
This means that your CorDapp should actually be made up of 2+ modules, each of which will be compiled down into its own CorDapp. One module should define all the shared resources, such as contracts and states. The other modules should then depend on this shared module, as documented here: https://docs.corda.net/cordapp-build-systems.html#dependencies-on-other-cordapps.
The CorDapp templates (e.g. https://github.com/corda/cordapp-template-kotlin) display this pattern:
Contracts and states are defined in the cordapp-contracts-states module
The remaining classes are defined in the cordapp module, which has a dependency on the cordapp-contracts-states module

Writing a standalone Corda client that depends on classes defined in a CorDapp

I am writing a Corda RPC client that depends on state classes defined in a separate CorDapp.
How can I include these classes as dependencies when running the client?
You need to include the CorDapp JAR as a dependency in the project where you are defining the RPC client:
Create the CorDapp JAR that your client will depend on. You can do this by running gradlew deployNodes in a project where a deployNodes task is defined and extracting the CorDapp JAR from one of the node's plugins folders
Copy the JAR to somewhere in the RPC client project (e.g. ./lib/cordapp-name.jar)
Reference the JAR as a dependency in your build.gradle file, using the syntax cordapp files('lib/yo.jar'). Make sure you set the relative path correctly (e.g. if the build.gradle file is nested one level down, the above would become cordapp files('../lib/yo.jar'))
Currently, CorDapp JAR dependencies added in this way cannot be referenced from deployNode. This will be addressed in a future version of Corda.
You'll need to add the relevant CorDapp JARs as a dependency to the project containing your RPC Client. First copy your CorDapp JARs to a folder within your RPC client project. Then inside your RPC client's build.gradle file (make sure this is the file in the clients directory or the root of the RPC client project) , within the dependencies{} block, add the following line:
compile fileTree(include: ['*.jar'], dir: '../cordapp-jars')
Make sure to replace the directory path with one that points to the folder that you placed the CorDapp JARs. Lastly, within your RPC client, import the necessary Corda states or flows.

Resources