Varun
Varun

Reputation: 5061

CORDA: Invoke custom query on all parties involved in transaction

I have multiple questions on Corda:

  1. Can we predefine the h2 configuration to pick in build.gradle file?
  2. I have a transaction in my corda network where i want to validate something based on custom fields the validation has to happen based on query that needs to be fired on all 3 parties sender, receiver, notary how can i fetch the session of all 3 nodes? i am able to pull the session of sender using getServiceHub().jdbcSession()
  3. What will be the most suggested way to query a notary for custom fields? Can it be done using creating a sub-flow if yes then how?
  4. we have validating and non validating notaries, where do we actually validate using notary? Where do we write the validation code?
  5. how can we enable autosuggest in intellij for java api of corda?

Upvotes: 0

Views: 400

Answers (1)

Joel
Joel

Reputation: 23140

  1. You can set the h2Port option in deployNodes:

    node {
        name "O=PartyA,L=London,C=GB"
        advertisedServices = []
        p2pPort 10005
        rpcPort 10006
        webPort 10007
        h2Port 10008
        cordapps = ["net.corda:corda-finance:$corda_release_version"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
    

    Is that the kind of configuration you needed?

  2. Each node's database is private by design, and cannot be queried from another node. Instead, you need to communicate with the other nodes as part of your flow in a way that causes them to initiate a response flow on their end where they query their own databases and send the results back. Something like:

    public class CollectDBDataFlow {
    @InitiatingFlow
    @StartableByRPC
    public static class Initiator extends FlowLogic<List<Object>> {
        Party counterparty;
    
        public Initiator(Party counterparty) {
            this.counterparty = counterparty;
        }
    
        @Suspendable
        @Override public List<Object> call() {
            // TODO: Implement queryMyDatabase to perform querying.
            Object myDBData = queryMyDatabase();
    
            FlowSession counterpartySession = initiateFlow(counterparty);
            Object theirDBData = counterpartySession.receive(Object.class);
    
            return ImmutableList.of(myDBData, theirDBData);
        }
    }
    
    @InitiatedBy(Initiator.class)
    public static class Responder extends FlowLogic<Void> {
        private FlowSession counterpartySession;
    
        public Responder(FlowSession counterpartySession) {
            this.counterpartySession = counterpartySession;
        }
    
        @Suspendable
        @Override
        public Void call() {
            // TODO: Implement queryMyDatabase to perform querying.
            Object myDBData = queryMyDatabase();
    
            counterpartySession.send(myDBData);
    
            return null;
        }
    }
    }
    
  3. The role of the notary isn't to be queried for data, but to prevent double-spends. You could technically do it using the method described in (2) above, but it wouldn't be advised. What are you trying to achieve?

  4. The validation logic is written into the platform. See https://github.com/corda/corda/blob/release-V1/node/src/main/kotlin/net/corda/node/services/transactions/ValidatingNotaryFlow.kt.

  5. The auto-complete should appear automatically, just like any other library.

Upvotes: 1

Related Questions