mirror of
https://github.com/corda/corda.git
synced 2024-12-21 05:53:23 +00:00
Sample corrections for M14
* Update node configurations to match changes to test constants * Look up notary via RPC in attachment demo rather than using the static identity to ensure the correct key is resolved * Use notary service identity instead of legal identity in Bank of Corda demo * Correct typo in deprecation annotation in CordaRPCOps * Update from deprecated calls to new equivalents
This commit is contained in:
parent
a60ccded75
commit
2c62f8968a
@ -37,9 +37,9 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
ext.rpcUsers = [['username': "demo", 'password': "demo", 'permissions': ["StartFlow.net.corda.attachmentdemo.AttachmentDemoFlow"]]]
|
||||
|
||||
directory "./build/nodes"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
node {
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
advertisedServices["corda.notary.validating"]
|
||||
p2pPort 10002
|
||||
rpcPort 10003
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.corda.attachmentdemo
|
||||
|
||||
import co.paralleluniverse.fibers.Suspendable
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import joptsimple.OptionParser
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
import net.corda.core.contracts.Contract
|
||||
@ -28,6 +29,7 @@ import java.io.InputStream
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledExecutorService
|
||||
import java.util.jar.JarInputStream
|
||||
import javax.servlet.http.HttpServletResponse.SC_OK
|
||||
import javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION
|
||||
@ -73,13 +75,19 @@ fun main(args: Array<String>) {
|
||||
/** An in memory test zip attachment of at least numOfClearBytes size, will be used. */
|
||||
fun sender(rpc: CordaRPCOps, numOfClearBytes: Int = 1024) { // default size 1K.
|
||||
val (inputStream, hash) = InputStreamAndHash.createInMemoryTestZip(numOfClearBytes, 0)
|
||||
sender(rpc, inputStream, hash)
|
||||
val executor = Executors.newScheduledThreadPool(2)
|
||||
try {
|
||||
sender(rpc, inputStream, hash, executor)
|
||||
} finally {
|
||||
executor.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
fun sender(rpc: CordaRPCOps, inputStream: InputStream, hash: SecureHash.SHA256) {
|
||||
private fun sender(rpc: CordaRPCOps, inputStream: InputStream, hash: SecureHash.SHA256, executor: ScheduledExecutorService) {
|
||||
|
||||
// Get the identity key of the other side (the recipient).
|
||||
val executor = Executors.newScheduledThreadPool(1)
|
||||
val otherSide: Party = poll(executor, DUMMY_BANK_B.name.toString()) { rpc.partyFromX500Name(DUMMY_BANK_B.name) }.get()
|
||||
val notaryFuture: ListenableFuture<Party> = poll(executor, DUMMY_NOTARY.name.toString()) { rpc.partyFromX500Name(DUMMY_NOTARY.name) }
|
||||
val otherSideFuture: ListenableFuture<Party> = poll(executor, DUMMY_BANK_B.name.toString()) { rpc.partyFromX500Name(DUMMY_BANK_B.name) }
|
||||
|
||||
// Make sure we have the file in storage
|
||||
if (!rpc.attachmentExists(hash)) {
|
||||
@ -90,14 +98,14 @@ fun sender(rpc: CordaRPCOps, inputStream: InputStream, hash: SecureHash.SHA256)
|
||||
require(rpc.attachmentExists(hash))
|
||||
}
|
||||
|
||||
val flowHandle = rpc.startTrackedFlow(::AttachmentDemoFlow, otherSide, hash)
|
||||
val flowHandle = rpc.startTrackedFlow(::AttachmentDemoFlow, otherSideFuture.get(), notaryFuture.get(), hash)
|
||||
flowHandle.progress.subscribe(::println)
|
||||
val stx = flowHandle.returnValue.getOrThrow()
|
||||
println("Sent ${stx.id}")
|
||||
}
|
||||
|
||||
@StartableByRPC
|
||||
class AttachmentDemoFlow(val otherSide: Party, val hash: SecureHash.SHA256) : FlowLogic<SignedTransaction>() {
|
||||
class AttachmentDemoFlow(val otherSide: Party, val notary: Party, val hash: SecureHash.SHA256) : FlowLogic<SignedTransaction>() {
|
||||
|
||||
object SIGNING : ProgressTracker.Step("Signing transaction")
|
||||
|
||||
@ -106,7 +114,7 @@ class AttachmentDemoFlow(val otherSide: Party, val hash: SecureHash.SHA256) : Fl
|
||||
@Suspendable
|
||||
override fun call(): SignedTransaction {
|
||||
// Create a trivial transaction with an output that describes the attachment, and the attachment itself
|
||||
val ptx = TransactionBuilder(notary = DUMMY_NOTARY)
|
||||
val ptx = TransactionBuilder(notary)
|
||||
ptx.addOutputState(AttachmentContract.State(hash))
|
||||
ptx.addAttachment(hash)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import net.corda.core.utilities.OpaqueBytes
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.flows.IssuerFlow.IssuanceRequester
|
||||
import net.corda.testing.DUMMY_NOTARY
|
||||
import net.corda.testing.http.HttpApi
|
||||
|
||||
/**
|
||||
@ -33,20 +34,22 @@ class BankOfCordaClientApi(val hostAndPort: NetworkHostAndPort) {
|
||||
val client = CordaRPCClient(hostAndPort)
|
||||
// TODO: privileged security controls required
|
||||
client.start("bankUser", "test").use { connection ->
|
||||
val proxy = connection.proxy
|
||||
val rpc = connection.proxy
|
||||
|
||||
// Resolve parties via RPC
|
||||
val issueToParty = proxy.partyFromX500Name(params.issueToPartyName)
|
||||
val issueToParty = rpc.partyFromX500Name(params.issueToPartyName)
|
||||
?: throw Exception("Unable to locate ${params.issueToPartyName} in Network Map Service")
|
||||
val issuerBankParty = proxy.partyFromX500Name(params.issuerBankName)
|
||||
val issuerBankParty = rpc.partyFromX500Name(params.issuerBankName)
|
||||
?: throw Exception("Unable to locate ${params.issuerBankName} in Network Map Service")
|
||||
val notaryParty = proxy.partyFromX500Name(params.notaryName)
|
||||
?: throw Exception("Unable to locate ${params.notaryName} in Network Map Service")
|
||||
val notaryLegalIdentity = rpc.partyFromX500Name(params.notaryName)
|
||||
?: throw IllegalStateException("Unable to locate ${params.notaryName} in Network Map Service")
|
||||
val notaryNode = rpc.nodeIdentityFromParty(notaryLegalIdentity)
|
||||
?: throw IllegalStateException("Unable to locate notary node in network map cache")
|
||||
|
||||
val amount = Amount(params.amount, currency(params.currency))
|
||||
val issuerToPartyRef = OpaqueBytes.of(params.issueToPartyRefAsString.toByte())
|
||||
|
||||
return proxy.startFlow(::IssuanceRequester, amount, issueToParty, issuerToPartyRef, issuerBankParty, notaryParty, params.anonymous)
|
||||
return rpc.startFlow(::IssuanceRequester, amount, issueToParty, issuerToPartyRef, issuerBankParty, notaryNode.notaryIdentity, params.anonymous)
|
||||
.returnValue.getOrThrow().stx
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ dependencies {
|
||||
|
||||
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
directory "./build/nodes"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
node {
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
advertisedServices = ["corda.notary.validating", "corda.interest_rates"]
|
||||
p2pPort 10002
|
||||
rpcPort 10003
|
||||
@ -115,4 +115,4 @@ publishing {
|
||||
|
||||
jar {
|
||||
from sourceSets.test.output
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ dependencies {
|
||||
|
||||
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
directory "./build/nodes"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
node {
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
advertisedServices = ["corda.notary.validating"]
|
||||
p2pPort 10002
|
||||
cordapps = []
|
||||
|
@ -47,9 +47,9 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
directory "./build/nodes"
|
||||
// This name "Notary" is hard-coded into TraderDemoClientApi so if you change it here, change it there too.
|
||||
// In this demo the node that runs a standalone notary also acts as the network map server.
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
networkMap "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
node {
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=London,C=GB"
|
||||
name "CN=Notary Service,O=R3,OU=corda,L=Zurich,C=CH"
|
||||
advertisedServices = ["corda.notary.validating"]
|
||||
p2pPort 10002
|
||||
cordapps = []
|
||||
|
Loading…
Reference in New Issue
Block a user