mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Fix merge
Fix merge Fix merge
This commit is contained in:
parent
29a8c153ed
commit
469ffe473f
@ -10,6 +10,7 @@ import net.corda.core.internal.castIfPossible
|
||||
import net.corda.core.internal.uncheckedCast
|
||||
import net.corda.core.node.NetworkParameters
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.utilities.Try
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import java.util.*
|
||||
import java.util.function.Predicate
|
||||
@ -56,6 +57,7 @@ data class LedgerTransaction @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val logger = loggerFor<LedgerTransaction>()
|
||||
private fun contractClassFor(className: ContractClassName, classLoader: ClassLoader?): Try<Class<out Contract>> {
|
||||
return Try.on {
|
||||
(classLoader ?: this::class.java.classLoader)
|
||||
@ -141,30 +143,6 @@ data class LedgerTransaction @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that for each contract the network wide package owner is respected.
|
||||
*
|
||||
* TODO - revisit once transaction contains network parameters.
|
||||
*/
|
||||
private fun validatePackageOwnership(contractAttachmentsByContract: Map<ContractClassName, ContractAttachment>) {
|
||||
// This should never happen once we have network parameters in the transaction.
|
||||
if (networkParameters == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val contractsAndOwners = allStates.mapNotNull { transactionState ->
|
||||
val contractClassName = transactionState.contract
|
||||
networkParameters.getOwnerOf(contractClassName)?.let { contractClassName to it }
|
||||
}.toMap()
|
||||
|
||||
contractsAndOwners.forEach { contract, owner ->
|
||||
val attachment = contractAttachmentsByContract[contract]!!
|
||||
if (!owner.isFulfilledBy(attachment.signers)) {
|
||||
throw TransactionVerificationException.ContractAttachmentNotSignedByPackageOwnerException(this.id, id, contract)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces the validity of the actual constraints.
|
||||
* * Constraints should be one of the valid supported ones.
|
||||
|
@ -181,7 +181,7 @@ open class TransactionBuilder @JvmOverloads constructor(
|
||||
val resolvedStates: List<TransactionState<ContractState>> = contractAttachmentsAndResolvedOutputStates.mapNotNull { it.second }.flatten()
|
||||
|
||||
// The output states need to preserve the order in which they were added.
|
||||
val resolvedOutputStatesInTheOriginalOrder: List<TransactionState<ContractState>> = outputStates().map { os -> resolvedStates.find { rs -> rs.data == os.data }!! }
|
||||
val resolvedOutputStatesInTheOriginalOrder: List<TransactionState<ContractState>> = outputStates().map { os -> resolvedStates.find { rs -> rs.data == os.data && rs.encumbrance == os.encumbrance}!! }
|
||||
|
||||
val attachments: Collection<AttachmentId> = contractAttachmentsAndResolvedOutputStates.map { it.first } + refStateContractAttachments
|
||||
|
||||
@ -454,7 +454,7 @@ open class TransactionBuilder @JvmOverloads constructor(
|
||||
state: ContractState,
|
||||
contract: ContractClassName = requireNotNull(state.requiredContractClassName) {
|
||||
//TODO: add link to docsite page, when there is one.
|
||||
"""
|
||||
"""
|
||||
Unable to infer Contract class name because state class ${state::class.java.name} is not annotated with
|
||||
@BelongsToContract, and does not have an enclosing class which implements Contract. Either annotate ${state::class.java.name}
|
||||
with @BelongsToContract, or supply an explicit contract parameter to addOutputState().
|
||||
@ -470,7 +470,7 @@ with @BelongsToContract, or supply an explicit contract parameter to addOutputSt
|
||||
state: ContractState,
|
||||
contract: ContractClassName = requireNotNull(state.requiredContractClassName) {
|
||||
//TODO: add link to docsite page, when there is one.
|
||||
"""
|
||||
"""
|
||||
Unable to infer Contract class name because state class ${state::class.java.name} is not annotated with
|
||||
@BelongsToContract, and does not have an enclosing class which implements Contract. Either annotate ${state::class.java.name}
|
||||
with @BelongsToContract, or supply an explicit contract parameter to addOutputState().
|
||||
|
@ -2,6 +2,7 @@ package net.corda.node.internal.cordapp
|
||||
|
||||
import io.github.classgraph.ClassGraph
|
||||
import io.github.classgraph.ScanResult
|
||||
import net.corda.core.contracts.warnContractWithoutConstraintPropagation
|
||||
import net.corda.core.cordapp.Cordapp
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sha256
|
||||
|
@ -7,9 +7,9 @@ import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.internal.packageName
|
||||
import net.corda.core.node.services.*
|
||||
import net.corda.core.node.services.Vault.ConstraintInfo.Type.*
|
||||
import net.corda.core.node.services.vault.*
|
||||
import net.corda.core.node.services.vault.QueryCriteria.*
|
||||
import net.corda.core.node.services.Vault.ConstraintInfo.Type.*
|
||||
import net.corda.core.transactions.LedgerTransaction
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.utilities.*
|
||||
@ -481,7 +481,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = AlwaysAcceptAttachmentConstraint).states.first().state.constraint
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = WhitelistedByZoneAttachmentConstraint).states.first().state.constraint
|
||||
// hash constraint
|
||||
val linearStateHash = vaultFiller.fillWithSomeTestLinearStates(1, constraint = HashAttachmentConstraint(SecureHash.randomSHA256()))
|
||||
val linearStateHash = vaultFiller.fillWithSomeTestLinearStates(1, constraint = AutomaticPlaceholderConstraint) // defaults to the HashConstraint
|
||||
val constraintHash = linearStateHash.states.first().state.constraint as HashAttachmentConstraint
|
||||
// signature constraint (single key)
|
||||
val linearStateSignature = vaultFiller.fillWithSomeTestLinearStates(1, constraint = SignatureAttachmentConstraint(alice.publicKey))
|
||||
@ -504,7 +504,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
val constraintTypeCriteria2 = VaultQueryCriteria(constraintTypes = setOf(HASH))
|
||||
val constraintResults2 = vaultService.queryBy<LinearState>(constraintTypeCriteria2)
|
||||
assertThat(constraintResults2.states).hasSize(2)
|
||||
assertThat(constraintResults2.states.map { it.state.constraint }).containsOnlyOnce(constraintHash)
|
||||
assertThat(constraintResults2.states.map { it.state.constraint }.toSet()).isEqualTo(setOf(constraintHash))
|
||||
|
||||
// search for states with [Vault.ConstraintInfo.Type] either HASH or CZ_WHITELISED
|
||||
// DOCSTART VaultQueryExample30
|
||||
@ -536,7 +536,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
val alwaysAcceptConstraint = vaultFiller.fillWithSomeTestLinearStates(1, constraint = AlwaysAcceptAttachmentConstraint).states.first().state.constraint
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = WhitelistedByZoneAttachmentConstraint)
|
||||
// hash constraint
|
||||
val linearStateHash = vaultFiller.fillWithSomeTestLinearStates(1, constraint = HashAttachmentConstraint(SecureHash.randomSHA256()))
|
||||
val linearStateHash = vaultFiller.fillWithSomeTestLinearStates(1, constraint = AutomaticPlaceholderConstraint) // defaults to the hash constraint.
|
||||
val constraintHash = linearStateHash.states.first().state.constraint as HashAttachmentConstraint
|
||||
// signature constraint (single key)
|
||||
val linearStateSignature = vaultFiller.fillWithSomeTestLinearStates(1, constraint = SignatureAttachmentConstraint(alice.publicKey))
|
||||
@ -559,7 +559,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
// search for states for a specific HashAttachmentConstraint
|
||||
val constraintsCriteria2 = VaultQueryCriteria(constraints = setOf(Vault.ConstraintInfo(constraintHash)))
|
||||
val constraintResults2 = vaultService.queryBy<LinearState>(constraintsCriteria2)
|
||||
assertThat(constraintResults2.states).hasSize(1)
|
||||
assertThat(constraintResults2.states).hasSize(2)
|
||||
assertThat(constraintResults2.states.first().state.constraint).isEqualTo(constraintHash)
|
||||
|
||||
// search for states with a specific SignatureAttachmentConstraint constraint
|
||||
@ -574,7 +574,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
Vault.ConstraintInfo(constraintSignatureCompositeKey), Vault.ConstraintInfo(constraintHash)))
|
||||
val constraintResults = vaultService.queryBy<LinearState>(constraintCriteria)
|
||||
// DOCEND VaultQueryExample31
|
||||
assertThat(constraintResults.states).hasSize(3)
|
||||
assertThat(constraintResults.states).hasSize(4)
|
||||
assertThat(constraintResults.states.map { it.state.constraint }).containsAll(listOf(constraintHash, constraintSignature, constraintSignatureCompositeKey))
|
||||
|
||||
// exercise enriched query
|
||||
@ -1474,8 +1474,9 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, linearNumber = it.toLong(), linearString = it.toString())
|
||||
}
|
||||
val max = builder { DummyLinearStateSchemaV1.PersistentDummyLinearState::linearTimestamp.max(
|
||||
groupByColumns = listOf(DummyLinearStateSchemaV1.PersistentDummyLinearState::linearNumber)
|
||||
)
|
||||
groupByColumns = listOf(DummyLinearStateSchemaV1.PersistentDummyLinearState::linearNumber),
|
||||
orderBy = Sort.Direction.ASC
|
||||
)
|
||||
}
|
||||
val maxCriteria = VaultCustomQueryCriteria(max)
|
||||
val pageSpec = PageSpecification(DEFAULT_PAGE_NUM, MAX_PAGE_SIZE)
|
||||
@ -2336,7 +2337,7 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
||||
database.transaction {
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = WhitelistedByZoneAttachmentConstraint)
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = SignatureAttachmentConstraint(alice.publicKey))
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = HashAttachmentConstraint( SecureHash.randomSHA256()))
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = AutomaticPlaceholderConstraint) // this defaults to the HashConstraint
|
||||
vaultFiller.fillWithSomeTestLinearStates(1, constraint = AlwaysAcceptAttachmentConstraint)
|
||||
|
||||
// Base criteria
|
||||
|
@ -155,10 +155,6 @@ data class TestTransactionDSLInterpreter private constructor(
|
||||
attachment((services.cordappProvider as MockCordappProvider).addMockCordapp(contractClassName, services.attachments as MockAttachmentStorage, attachmentId, signers))
|
||||
}
|
||||
|
||||
override fun _attachment(contractClassName: ContractClassName, attachmentId: AttachmentId, signers: List<PublicKey>){
|
||||
attachment((services.cordappProvider as MockCordappProvider).addMockCordapp(contractClassName, services.attachments as MockAttachmentStorage, attachmentId, signers))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class TestLedgerDSLInterpreter private constructor(
|
||||
|
@ -103,7 +103,7 @@ class VaultFiller @JvmOverloads constructor(
|
||||
linearNumber: Long = 0L,
|
||||
linearBoolean: Boolean = false,
|
||||
linearTimestamp: Instant = now(),
|
||||
constraint: AttachmentConstraint = AutomaticHashConstraint): Vault<LinearState> {
|
||||
constraint: AttachmentConstraint = AutomaticPlaceholderConstraint): Vault<LinearState> {
|
||||
val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
|
||||
val me = AnonymousParty(myKey)
|
||||
val issuerKey = defaultNotary.keyPair
|
||||
@ -134,12 +134,12 @@ class VaultFiller @JvmOverloads constructor(
|
||||
|
||||
@JvmOverloads
|
||||
fun fillWithSomeTestLinearAndDealStates(numberToCreate: Int,
|
||||
externalId: String? = null,
|
||||
participants: List<AbstractParty> = emptyList(),
|
||||
linearString: String = "",
|
||||
linearNumber: Long = 0L,
|
||||
linearBoolean: Boolean = false,
|
||||
linearTimestamp: Instant = now()): Vault<LinearState> {
|
||||
externalId: String? = null,
|
||||
participants: List<AbstractParty> = emptyList(),
|
||||
linearString: String = "",
|
||||
linearNumber: Long = 0L,
|
||||
linearBoolean: Boolean = false,
|
||||
linearTimestamp: Instant = now()): Vault<LinearState> {
|
||||
val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
|
||||
val me = AnonymousParty(myKey)
|
||||
val issuerKey = defaultNotary.keyPair
|
||||
|
Loading…
x
Reference in New Issue
Block a user