Skip to content

Commit ec55222

Browse files
authored
Merge pull request #65 from corda/fix_notary_selection
Fix notary selection
2 parents 47a25b1 + d48633e commit ec55222

File tree

103 files changed

+370
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+370
-507
lines changed

Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/InternalMessage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.supplychain.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.supplychain.contracts.InternalMessageStateContract;
1112
import net.corda.samples.supplychain.states.InternalMessageState;
@@ -81,13 +82,8 @@ public String call() throws FlowException {
8182
InternalMessageState output = new InternalMessageState(message,new AnonymousParty(myKey),targetAcctAnonymousParty);
8283

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

9288
TransactionBuilder txbuilder = new TransactionBuilder(notary)
9389
.addOutputState(output)

Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendCargo.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.supplychain.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.supplychain.contracts.CargoStateContract;
1112
import net.corda.samples.supplychain.states.CargoState;
@@ -58,13 +59,8 @@ public String call() throws FlowException {
5859
CargoState output = new CargoState(new AnonymousParty(myKey),targetAcctAnonymousParty,cargo,getOurIdentity());
5960

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

6965
TransactionBuilder txbuilder = new TransactionBuilder(notary)
7066
.addOutputState(output)

Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendInvoice.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.supplychain.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.supplychain.contracts.InvoiceStateContract;
1112
import net.corda.samples.supplychain.states.InvoiceState;
@@ -58,13 +59,8 @@ public String call() throws FlowException {
5859
InvoiceState output = new InvoiceState(amount,new AnonymousParty(myKey),targetAcctAnonymousParty, UUID.randomUUID());
5960

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

6965
TransactionBuilder txbuilder = new TransactionBuilder(notary)
7066
.addOutputState(output)

Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendPayment.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.supplychain.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.supplychain.contracts.PaymentStateContract;
1112
import net.corda.samples.supplychain.states.PaymentState;
@@ -57,13 +58,8 @@ public String call() throws FlowException {
5758
PaymentState output = new PaymentState(amount,new AnonymousParty(myKey),targetAcctAnonymousParty);
5859

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

6864
TransactionBuilder txbuilder = new TransactionBuilder(notary)
6965
.addOutputState(output)

Accounts/supplychain/workflows/src/main/java/net/corda/samples/supplychain/flows/SendShippingRequest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.r3.corda.lib.accounts.workflows.services.AccountService;
66
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
77
import com.sun.istack.NotNull;
8+
import net.corda.core.identity.CordaX500Name;
89
import net.corda.samples.supplychain.accountUtilities.NewKeyForAccount;
910
import net.corda.samples.supplychain.contracts.ShippingRequestStateContract;
1011
import net.corda.samples.supplychain.states.ShippingRequestState;
@@ -84,13 +85,8 @@ public String call() throws FlowException {
8485
ShippingRequestState output = new ShippingRequestState(new AnonymousParty(myKey),whereTo,shipper,cargo);
8586

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

9591
TransactionBuilder txbuilder = new TransactionBuilder(notary)
9692
.addOutputState(output)

Accounts/supplychain/workflows/src/test/java/net/corda/samples/supplychain/FlowTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
77
import net.corda.core.contracts.StateAndRef;
88
import net.corda.core.contracts.UniqueIdentifier;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.core.node.NetworkParameters;
1011
import net.corda.core.node.services.Vault;
1112
import net.corda.core.node.services.vault.QueryCriteria;
1213
import net.corda.samples.supplychain.accountUtilities.CreateNewAccount;
1314
import net.corda.samples.supplychain.accountUtilities.ShareAccountTo;
1415
import net.corda.samples.supplychain.flows.SendInvoice;
1516
import net.corda.samples.supplychain.states.InvoiceState;
16-
import net.corda.testing.node.MockNetwork;
17-
import net.corda.testing.node.MockNetworkParameters;
18-
import net.corda.testing.node.TestCordapp;
17+
import net.corda.testing.node.*;
1918
import org.junit.After;
2019
import org.junit.Before;
2120
import org.junit.Test;
22-
import net.corda.testing.node.StartedMockNode;
21+
2322
import java.util.*;
2423
import java.time.Instant;
2524
import java.util.concurrent.ExecutionException;
@@ -42,7 +41,9 @@ public void setup() {
4241
TestCordapp.findCordapp("net.corda.samples.supplychain.contracts"),
4342
TestCordapp.findCordapp("net.corda.samples.supplychain.flows"),
4443
TestCordapp.findCordapp("com.r3.corda.lib.accounts.contracts"),
45-
TestCordapp.findCordapp("com.r3.corda.lib.accounts.workflows"))).withNetworkParameters(testNetworkParameters));
44+
TestCordapp.findCordapp("com.r3.corda.lib.accounts.workflows"))).withNetworkParameters(testNetworkParameters)
45+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB"))))
46+
);
4647
a = network.createPartyNode(null);
4748
b = network.createPartyNode(null);
4849
network.runNetwork();

Accounts/tictacthor/workflows/src/main/java/net/corda/samples/tictacthor/flows/EndGameFlow.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.tictacthor.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.tictacthor.contracts.BoardContract;
1112
import net.corda.samples.tictacthor.states.BoardState;
@@ -94,13 +95,8 @@ public String call() throws FlowException {
9495
//generating State for transfer
9596

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

105101
TransactionBuilder txbuilder = new TransactionBuilder(notary)
106102
.addInputState(inputBoardStateAndRef)

Accounts/tictacthor/workflows/src/main/java/net/corda/samples/tictacthor/flows/StartGameFlow.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.r3.corda.lib.accounts.workflows.flows.RequestKeyForAccount;
77
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
88
import com.sun.istack.NotNull;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.samples.tictacthor.accountUtilities.NewKeyForAccount;
1011
import net.corda.samples.tictacthor.contracts.BoardContract;
1112
import net.corda.samples.tictacthor.states.BoardState;
@@ -93,13 +94,8 @@ public UniqueIdentifier call() throws FlowException {
9394
targetAcctAnonymousParty);
9495

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

104100
TransactionBuilder txbuilder = new TransactionBuilder(notary)
105101
.addOutputState(initialBoardState)

Accounts/tictacthor/workflows/src/main/java/net/corda/samples/tictacthor/flows/SubmitTurnFlow.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ public String call() throws FlowException {
106106
BoardState outputBoardState = inputBoardState.returnNewBoardAfterMove(new Pair<>(x,y),new AnonymousParty(myKey), targetAcctAnonymousParty);
107107

108108
// Obtain a reference to a notary we wish to use.
109-
/** METHOD 1: Take first notary on network, WARNING: use for test, non-prod environments, and single-notary networks only!*
110-
* METHOD 2: Explicit selection of notary by CordaX500Name - argument can by coded in flow or parsed from config (Preferred)
111-
*
112-
* * - For production you always want to use Method 2 as it guarantees the expected notary is returned.
113-
*/
114-
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0); // METHOD 1
115-
// final Party notary = getServiceHub().getNetworkMapCache().getNotary(CordaX500Name.parse("O=Notary,L=London,C=GB")); // METHOD 2
109+
Party notary = inputBoardStateAndRef.getState().getNotary();
116110

117111
TransactionBuilder txbuilder = new TransactionBuilder(notary)
118112
.addInputState(inputBoardStateAndRef)

Accounts/tictacthor/workflows/src/test/java/net/corda/samples/tictacthor/FlowTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
import com.r3.corda.lib.accounts.workflows.services.KeyManagementBackedAccountService;
77
import net.corda.core.contracts.StateAndRef;
88
import net.corda.core.contracts.UniqueIdentifier;
9+
import net.corda.core.identity.CordaX500Name;
910
import net.corda.core.node.NetworkParameters;
1011
import net.corda.core.node.services.vault.QueryCriteria;
1112
import net.corda.samples.tictacthor.accountUtilities.CreateNewAccount;
1213
import net.corda.samples.tictacthor.accountUtilities.ShareAccountTo;
1314
import net.corda.samples.tictacthor.flows.StartGameFlow;
1415
import net.corda.samples.tictacthor.states.BoardState;
15-
import net.corda.testing.node.MockNetwork;
16-
import net.corda.testing.node.MockNetworkParameters;
17-
import net.corda.testing.node.TestCordapp;
16+
import net.corda.testing.node.*;
1817
import org.junit.After;
1918
import org.junit.Before;
2019
import org.junit.Test;
21-
import net.corda.testing.node.StartedMockNode;
20+
2221
import java.util.*;
2322
import java.time.Instant;
2423
import java.util.concurrent.ExecutionException;
@@ -40,7 +39,9 @@ public void setup() {
4039
TestCordapp.findCordapp("net.corda.samples.tictacthor.contracts"),
4140
TestCordapp.findCordapp("net.corda.samples.tictacthor.flows"),
4241
TestCordapp.findCordapp("com.r3.corda.lib.accounts.contracts"),
43-
TestCordapp.findCordapp("com.r3.corda.lib.accounts.workflows"))).withNetworkParameters(testNetworkParameters));
42+
TestCordapp.findCordapp("com.r3.corda.lib.accounts.workflows"))).withNetworkParameters(testNetworkParameters)
43+
.withNotarySpecs(ImmutableList.of(new MockNetworkNotarySpec(CordaX500Name.parse("O=Notary,L=London,C=GB"))))
44+
);
4445
a = network.createPartyNode(null);
4546
b = network.createPartyNode(null);
4647
network.runNetwork();

0 commit comments

Comments
 (0)