如何在Corda中手动生成网络参数
How to manually generate network parameters in Corda
我已经手动创建并分发了 Corda 节点所需的证书。现在要启动节点,除其他外,它们需要有一个网络参数。问题是,如果我使用 Corda 网络引导程序工具生成网络参数,该文件将由与我的证书颁发者不同的另一个颁发者 ("C=UK, L=London, OU=corda, O=R3, CN=Corda Node Root CA") 签名。我的问题是如何手动创建网络参数以便指定正确的发行者以避免在节点启动期间发生冲突?
您可以使用网络引导程序使用的开发证书签署您的证书:https://github.com/corda/corda/tree/master/node-api/src/main/resources/certificates
如果这对您不起作用,您可以试试这个实验性工具:https://github.com/corda/corda/blob/master/experimental/netparams/src/main/kotlin/net.corda.netparams/NetParams.kt。不过我不能保证它适用于 Corda 3.3。
所以我想出了一个创建网络参数的方法:
private fun getSignedNetworkParameters(): NetworkParameters {
//load the notary from a Keystore. This avoids having to start a flow from a node in order to retrieve NotaryInfo
val notary = loadKeyStore("\path-to-keystore\keystore.jks", "keystore-password")
val certificateAndKeyPair : CertificateAndKeyPair = notary.getCertificateAndKeyPair("entry-alias", "entry-password")
val notaryParty = Party(certificateAndKeyPair.certificate)
val notaryInfo = listOf(NotaryInfo(notaryParty, false))
//map contract ID to the SHA-256 hash of its CorDapp contracts&states JAR file
val whitelistedContractImplementations = mapOf(
TestContract.TEST_CONTRACT_ID to listOf(getCheckSum(contractFile))
)
return NetworkParameters(minimumPlatformVersion = 3, notaries = notaryInfo,
maxMessageSize = n, maxTransactionSize = n, modifiedTime = Instant.now(),
epoch = 1, whitelistedContractImplementations = whitelistedContractImplementations)
}
我已经手动创建并分发了 Corda 节点所需的证书。现在要启动节点,除其他外,它们需要有一个网络参数。问题是,如果我使用 Corda 网络引导程序工具生成网络参数,该文件将由与我的证书颁发者不同的另一个颁发者 ("C=UK, L=London, OU=corda, O=R3, CN=Corda Node Root CA") 签名。我的问题是如何手动创建网络参数以便指定正确的发行者以避免在节点启动期间发生冲突?
您可以使用网络引导程序使用的开发证书签署您的证书:https://github.com/corda/corda/tree/master/node-api/src/main/resources/certificates
如果这对您不起作用,您可以试试这个实验性工具:https://github.com/corda/corda/blob/master/experimental/netparams/src/main/kotlin/net.corda.netparams/NetParams.kt。不过我不能保证它适用于 Corda 3.3。
所以我想出了一个创建网络参数的方法:
private fun getSignedNetworkParameters(): NetworkParameters {
//load the notary from a Keystore. This avoids having to start a flow from a node in order to retrieve NotaryInfo
val notary = loadKeyStore("\path-to-keystore\keystore.jks", "keystore-password")
val certificateAndKeyPair : CertificateAndKeyPair = notary.getCertificateAndKeyPair("entry-alias", "entry-password")
val notaryParty = Party(certificateAndKeyPair.certificate)
val notaryInfo = listOf(NotaryInfo(notaryParty, false))
//map contract ID to the SHA-256 hash of its CorDapp contracts&states JAR file
val whitelistedContractImplementations = mapOf(
TestContract.TEST_CONTRACT_ID to listOf(getCheckSum(contractFile))
)
return NetworkParameters(minimumPlatformVersion = 3, notaries = notaryInfo,
maxMessageSize = n, maxTransactionSize = n, modifiedTime = Instant.now(),
epoch = 1, whitelistedContractImplementations = whitelistedContractImplementations)
}