mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Attachment query with contract version, related to CORDA-2150, CORDA-2157 (#4357)
TransactionBuilder loads attachment using attachment storage instead of CordappLoader, contract class version is now Integer (format and stored in db as Integer).
This commit is contained in:
@ -7,6 +7,7 @@ import net.corda.testing.core.internal.JarSignatureTestUtils.signJar
|
||||
import net.corda.core.internal.delete
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.toPath
|
||||
import net.corda.core.cordapp.CORDAPP_CONTRACT_VERSION
|
||||
import net.corda.testing.core.ALICE_NAME
|
||||
import java.io.OutputStream
|
||||
import java.net.URI
|
||||
@ -41,7 +42,7 @@ object ContractJarTestUtils {
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun makeTestSignedContractJar(workingDir: Path, contractName: String, version: String = "1.0"): Pair<Path, PublicKey> {
|
||||
fun makeTestSignedContractJar(workingDir: Path, contractName: String, version: Int = 1): Pair<Path, PublicKey> {
|
||||
val alias = "testAlias"
|
||||
val pwd = "testPassword"
|
||||
workingDir.generateKey(alias, pwd, ALICE_NAME.toString())
|
||||
@ -53,13 +54,13 @@ object ContractJarTestUtils {
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun makeTestContractJar(workingDir: Path, contractName: String, signed: Boolean = false, version: String = "1.0"): Path {
|
||||
fun makeTestContractJar(workingDir: Path, contractName: String, signed: Boolean = false, version: Int = 1): Path {
|
||||
val packages = contractName.split(".")
|
||||
val jarName = "attachment-${packages.last()}-$version-${(if (signed) "signed" else "")}.jar"
|
||||
val className = packages.last()
|
||||
createTestClass(workingDir, className, packages.subList(0, packages.size - 1))
|
||||
workingDir.createJar(jarName, "${contractName.replace(".", "/")}.class")
|
||||
workingDir.addManifest(jarName, Pair(Attributes.Name.IMPLEMENTATION_VERSION, version))
|
||||
workingDir.addManifest(jarName, Pair(Attributes.Name(CORDAPP_CONTRACT_VERSION), version.toString()))
|
||||
return workingDir.resolve(jarName)
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,6 @@ object JarSignatureTestUtils {
|
||||
JarInputStream(FileInputStream((this / fileName).toFile())).use { input ->
|
||||
val manifest = input.manifest ?: Manifest()
|
||||
entry.forEach { (attributeName, value) ->
|
||||
// eg. Attributes.Name.IMPLEMENTATION_VERSION, version
|
||||
manifest.mainAttributes[attributeName] = value
|
||||
}
|
||||
val output = JarOutputStream(FileOutputStream((this / fileName).toFile()), manifest)
|
||||
|
@ -26,7 +26,7 @@ import java.util.jar.JarInputStream
|
||||
*/
|
||||
class MockAttachmentStorage : AttachmentStorage, SingletonSerializeAsToken() {
|
||||
|
||||
private data class ContractAttachmentMetadata(val name: ContractClassName, val version: String, val isSigned: Boolean)
|
||||
private data class ContractAttachmentMetadata(val name: ContractClassName, val version: Int, val isSigned: Boolean)
|
||||
|
||||
private val _files = HashMap<SecureHash, Pair<Attachment, ByteArray>>()
|
||||
private val _contractClasses = HashMap<ContractAttachmentMetadata, SecureHash>()
|
||||
@ -54,13 +54,13 @@ class MockAttachmentStorage : AttachmentStorage, SingletonSerializeAsToken() {
|
||||
if (criteria.isSignedCondition != null) {
|
||||
val isSigned = criteria.isSignedCondition == Builder.equal(true)
|
||||
contractClassNames.map {contractClassName ->
|
||||
ContractAttachmentMetadata(contractClassName, "1.0", isSigned)
|
||||
ContractAttachmentMetadata(contractClassName, 1, isSigned)
|
||||
}
|
||||
}
|
||||
else {
|
||||
contractClassNames.flatMap { contractClassName ->
|
||||
listOf(ContractAttachmentMetadata(contractClassName, "1.0", false),
|
||||
ContractAttachmentMetadata(contractClassName, "1.0", true))
|
||||
listOf(ContractAttachmentMetadata(contractClassName, 1, false),
|
||||
ContractAttachmentMetadata(contractClassName, 1, true))
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,10 +102,10 @@ class MockAttachmentStorage : AttachmentStorage, SingletonSerializeAsToken() {
|
||||
if (contractClassNames == null || contractClassNames.isEmpty()) baseAttachment
|
||||
else {
|
||||
contractClassNames.map {contractClassName ->
|
||||
val contractClassMetadata = ContractAttachmentMetadata(contractClassName, "1.0", signers.isNotEmpty())
|
||||
val contractClassMetadata = ContractAttachmentMetadata(contractClassName, 1, signers.isNotEmpty())
|
||||
_contractClasses[contractClassMetadata] = sha256
|
||||
}
|
||||
ContractAttachment(baseAttachment, contractClassNames.first(), contractClassNames.toSet(), uploader, signers, "1.0")
|
||||
ContractAttachment(baseAttachment, contractClassNames.first(), contractClassNames.toSet(), uploader, signers, 1)
|
||||
}
|
||||
_files[sha256] = Pair(attachment, bytes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user