Skip to content

Commit c517576

Browse files
committed
update notary selection -Basic
1 parent 66723e0 commit c517576

File tree

11 files changed

+59
-64
lines changed

11 files changed

+59
-64
lines changed

Basic/cordapp-example/.idea/workspace.xml

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Basic/cordapp-example/workflows/src/main/java/net/corda/samples/example/flows/ExampleFlow.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Arrays;
1818

1919
import static net.corda.core.contracts.ContractsDSL.requireThat;
20+
import net.corda.core.identity.CordaX500Name;
2021

2122
/**
2223
* This flow allows two parties (the [Initiator] and the [Acceptor]) to come to an agreement about the IOU encapsulated
@@ -82,13 +83,8 @@ public ProgressTracker getProgressTracker() {
8283
public SignedTransaction call() throws FlowException {
8384

8485
// Obtain a reference to a notary we wish to use.
85-
/** METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
86-
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flow or parsed from config (Preferred)
87-
*
88-
* * - For production you always want to use Method 2 as it guarantees the expected notary is returned.
89-
*/
90-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
91-
// final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
86+
/** Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)*/
87+
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));
9288

9389
// Stage 1.
9490
progressTracker.setCurrentStep(GENERATING_TRANSACTION);

Basic/cordapp-example/workflows/src/test/java/net/corda/samples/example/FlowTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.corda.samples.example;
22

3+
import net.corda.core.identity.CordaX500Name;
34
import net.corda.samples.example.flows.ExampleFlow;
45
import net.corda.samples.example.states.IOUState;
56
import com.google.common.collect.ImmutableList;
@@ -9,10 +10,7 @@
910
import net.corda.core.contracts.TransactionState;
1011
import net.corda.core.contracts.TransactionVerificationException;
1112
import net.corda.core.transactions.SignedTransaction;
12-
import net.corda.testing.node.MockNetwork;
13-
import net.corda.testing.node.MockNetworkParameters;
14-
import net.corda.testing.node.StartedMockNode;
15-
import net.corda.testing.node.TestCordapp;
13+
import net.corda.testing.node.*;
1614
import org.junit.After;
1715
import org.junit.Before;
1816
import org.junit.Rule;
@@ -34,7 +32,9 @@ public void setup() {
3432

3533
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
3634
TestCordapp.findCordapp("net.corda.samples.example.contracts"),
37-
TestCordapp.findCordapp("net.corda.samples.example.flows"))));
35+
TestCordapp.findCordapp("net.corda.samples.example.flows")))
36+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB"))))
37+
);
3838
a = network.createPartyNode(null);
3939
b = network.createPartyNode(null);
4040
network.runNetwork();

Basic/tutorial-applestamp/workflows/src/main/java/com/tutorial/flows/CreateAndIssueAppleStamp.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.util.ArrayList;
1313
import java.util.Arrays;
14+
import net.corda.core.identity.CordaX500Name;
1415

1516
public class CreateAndIssueAppleStamp {
1617

@@ -31,12 +32,8 @@ public CreateAndIssueAppleStampInitiator(String stampDescription, Party holder)
3132
public SignedTransaction call() throws FlowException {
3233

3334
/* Obtain a reference to a notary we wish to use.
34-
* METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
35-
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)
36-
* * - For production you always want to1 use Method 2 as it guarantees the expected notary is returned.
37-
*/
38-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
39-
//final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
35+
/** Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)*/
36+
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));
4037

4138
//Building the output AppleStamp state
4239
UniqueIdentifier uniqueID = new UniqueIdentifier();

Basic/tutorial-applestamp/workflows/src/main/java/com/tutorial/flows/PackageApples.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.corda.core.transactions.TransactionBuilder;
1010

1111
import java.util.Collections;
12+
import net.corda.core.identity.CordaX500Name;
1213

1314
public class PackageApples {
1415

@@ -28,13 +29,9 @@ public PackApplesInitiator(String appleDescription, int weight) {
2829
@Suspendable
2930
public SignedTransaction call() throws FlowException {
3031

31-
/* Obtain a reference to a notary we wish to use.
32-
* METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
33-
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)
34-
* * - For production you always want to use Method 2 as it guarantees the expected notary is returned.
35-
*/
36-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
37-
//final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
32+
// Obtain a reference to a notary we wish to use.
33+
/** Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)*/
34+
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));
3835

3936
//Create the output object
4037
BasketOfApple basket = new BasketOfApple(this.appleDescription,this.getOurIdentity(),this.weight);

Basic/tutorial-applestamp/workflows/src/main/java/com/tutorial/flows/RedeemApples.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ public RedeemApplesInitiator(Party buyer, UniqueIdentifier stampId) {
3535
@Suspendable
3636
public SignedTransaction call() throws FlowException {
3737

38-
/* Obtain a reference to a notary we wish to use.
39-
* METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
40-
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)
41-
* * - For production you always want to use Method 2 as it guarantees the expected notary is returned.
42-
*/
43-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
44-
//final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
45-
4638
//Query the AppleStamp
4739
QueryCriteria.LinearStateQueryCriteria inputCriteria = new QueryCriteria.LinearStateQueryCriteria()
4840
.withUuid(Arrays.asList(UUID.fromString(stampId.toString())))
@@ -60,6 +52,9 @@ public SignedTransaction call() throws FlowException {
6052
//Modify output to address the owner change
6153
BasketOfApple output = originalBasketOfApple.changeOwner(buyer);
6254

55+
/* Obtain a reference to a notary we wish to use.*/
56+
Party notary = basketOfAppleStateAndRef.getState().getNotary();
57+
6358
//Build Transaction
6459
TransactionBuilder txBuilder = new TransactionBuilder(notary)
6560
.addInputState(appleStampStateAndRef)

Basic/tutorial-applestamp/workflows/src/main/java/com/tutorial/flows/TemplateInitiator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.List;
1414
import java.util.stream.Collectors;
15+
import net.corda.core.identity.CordaX500Name;
1516

1617
// ******************
1718
// * TemplateInitiator flow *
@@ -44,8 +45,9 @@ public SignedTransaction call() throws FlowException {
4445
this.sender = getOurIdentity();
4546

4647
// Step 1. Get a reference to the notary service on our network and our key pair.
47-
// Note: ongoing work to support multiple notary identities is still in progress.
48-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
48+
// Obtain a reference to a notary we wish to use.
49+
/** Explicit selection of notary by CordaX500Name - argument can by coded in flows or parsed from config (Preferred)*/
50+
final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB"));
4951

5052
//Compose the State that carries the Hello World message
5153
final TemplateState output = new TemplateState(msg,sender,receiver);

Basic/tutorial-applestamp/workflows/src/test/java/com/tutorial/CreateAndIssueAppleStampTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import com.tutorial.flows.TemplateInitiator;
66
import com.tutorial.states.AppleStamp;
77
import com.tutorial.states.TemplateState;
8+
import net.corda.core.identity.CordaX500Name;
89
import net.corda.core.node.services.Vault;
910
import net.corda.core.node.services.vault.QueryCriteria;
1011
import net.corda.core.transactions.SignedTransaction;
11-
import net.corda.testing.node.MockNetwork;
12-
import net.corda.testing.node.MockNetworkParameters;
13-
import net.corda.testing.node.StartedMockNode;
14-
import net.corda.testing.node.TestCordapp;
12+
import net.corda.testing.node.*;
1513
import org.junit.After;
1614
import org.junit.Before;
1715
import org.junit.Test;
@@ -27,7 +25,9 @@ public class CreateAndIssueAppleStampTest {
2725
public void setup() {
2826
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
2927
TestCordapp.findCordapp("com.tutorial.contracts"),
30-
TestCordapp.findCordapp("com.tutorial.flows"))));
28+
TestCordapp.findCordapp("com.tutorial.flows")))
29+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB"))))
30+
);
3131
a = network.createPartyNode(null);
3232
b = network.createPartyNode(null);
3333
network.runNetwork();

Basic/tutorial-applestamp/workflows/src/test/java/com/tutorial/FarmerSelfCreateBasketOfAppleTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
import com.tutorial.flows.PackageApples;
55
import com.tutorial.states.AppleStamp;
66
import com.tutorial.states.BasketOfApple;
7+
import net.corda.core.identity.CordaX500Name;
78
import net.corda.core.node.services.Vault;
89
import net.corda.core.node.services.vault.QueryCriteria;
910
import net.corda.core.transactions.SignedTransaction;
10-
import net.corda.testing.node.MockNetwork;
11-
import net.corda.testing.node.MockNetworkParameters;
12-
import net.corda.testing.node.StartedMockNode;
13-
import net.corda.testing.node.TestCordapp;
11+
import net.corda.testing.node.*;
1412
import org.junit.After;
1513
import org.junit.Before;
1614
import org.junit.Test;
@@ -26,7 +24,8 @@ public class FarmerSelfCreateBasketOfAppleTest {
2624
public void setup() {
2725
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
2826
TestCordapp.findCordapp("com.tutorial.contracts"),
29-
TestCordapp.findCordapp("com.tutorial.flows"))));
27+
TestCordapp.findCordapp("com.tutorial.flows")))
28+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB")))));
3029
a = network.createPartyNode(null);
3130
b = network.createPartyNode(null);
3231
network.runNetwork();

Basic/tutorial-applestamp/workflows/src/test/java/com/tutorial/FlowTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import com.google.common.collect.ImmutableList;
44
import com.tutorial.flows.TemplateInitiator;
55
import com.tutorial.states.TemplateState;
6+
import net.corda.core.identity.CordaX500Name;
67
import net.corda.core.node.services.Vault;
78
import net.corda.core.node.services.vault.QueryCriteria;
89
import net.corda.core.transactions.SignedTransaction;
9-
import net.corda.testing.node.MockNetwork;
10-
import net.corda.testing.node.MockNetworkParameters;
11-
import net.corda.testing.node.StartedMockNode;
12-
import net.corda.testing.node.TestCordapp;
10+
import net.corda.testing.node.*;
1311
import org.junit.After;
1412
import org.junit.Before;
1513
import org.junit.Test;
@@ -25,7 +23,9 @@ public class FlowTests {
2523
public void setup() {
2624
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
2725
TestCordapp.findCordapp("com.tutorial.contracts"),
28-
TestCordapp.findCordapp("com.tutorial.flows"))));
26+
TestCordapp.findCordapp("com.tutorial.flows")))
27+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB"))))
28+
);
2929
a = network.createPartyNode(null);
3030
b = network.createPartyNode(null);
3131
network.runNetwork();

0 commit comments

Comments
 (0)