isRelevant didn't work for composite ownership, it's now fixed (under certain assumptions). (#3967)

This commit is contained in:
Konstantinos Chalkias 2018-09-19 10:03:16 +01:00 committed by GitHub
parent c9bce39696
commit 7b4c4803b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -102,7 +102,11 @@ fun PublicKey.isValid(content: ByteArray, signature: DigitalSignature): Boolean
/** Render a public key to its hash (in Base58) of its serialised form using the DL prefix. */ /** Render a public key to its hash (in Base58) of its serialised form using the DL prefix. */
fun PublicKey.toStringShort(): String = "DL" + this.toSHA256Bytes().toBase58() fun PublicKey.toStringShort(): String = "DL" + this.toSHA256Bytes().toBase58()
/** Return a [Set] of the contained keys if this is a [CompositeKey]; otherwise, return a [Set] with a single element (this [PublicKey]). */ /**
* Return a [Set] of the contained leaf keys if this is a [CompositeKey].
* Otherwise, return a [Set] with a single element (this [PublicKey]).
* <i>Note that leaf keys cannot be of type [CompositeKey].</i>
*/
val PublicKey.keys: Set<PublicKey> get() = (this as? CompositeKey)?.leafKeys ?: setOf(this) val PublicKey.keys: Set<PublicKey> get() = (this as? CompositeKey)?.leafKeys ?: setOf(this)
/** Return true if [otherKey] fulfils the requirements of this [PublicKey]. */ /** Return true if [otherKey] fulfils the requirements of this [PublicKey]. */
@ -110,7 +114,12 @@ fun PublicKey.isFulfilledBy(otherKey: PublicKey): Boolean = isFulfilledBy(setOf(
/** Return true if [otherKeys] fulfil the requirements of this [PublicKey]. */ /** Return true if [otherKeys] fulfil the requirements of this [PublicKey]. */
fun PublicKey.isFulfilledBy(otherKeys: Iterable<PublicKey>): Boolean = (this as? CompositeKey)?.isFulfilledBy(otherKeys) ?: (this in otherKeys) fun PublicKey.isFulfilledBy(otherKeys: Iterable<PublicKey>): Boolean = (this as? CompositeKey)?.isFulfilledBy(otherKeys) ?: (this in otherKeys)
/** Checks whether any of the given [keys] matches a leaf on the [CompositeKey] tree or a single [PublicKey]. */ /**
* Checks whether any of the given [keys] matches a leaf on the [CompositeKey] tree or a single [PublicKey].
*
* <i>Note that this function checks against leaves, which cannot be of type [CompositeKey]. Due to that, if any of the
* [otherKeys] is a [CompositeKey], this function will not find a match.</i>
*/
fun PublicKey.containsAny(otherKeys: Iterable<PublicKey>): Boolean { fun PublicKey.containsAny(otherKeys: Iterable<PublicKey>): Boolean {
return if (this is CompositeKey) keys.intersect(otherKeys).isNotEmpty() return if (this is CompositeKey) keys.intersect(otherKeys).isNotEmpty()
else this in otherKeys else this in otherKeys

View File

@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand import co.paralleluniverse.strands.Strand
import net.corda.core.contracts.* import net.corda.core.contracts.*
import net.corda.core.crypto.SecureHash import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.containsAny
import net.corda.core.internal.* import net.corda.core.internal.*
import net.corda.core.messaging.DataFeed import net.corda.core.messaging.DataFeed
import net.corda.core.node.ServicesForResolution import net.corda.core.node.ServicesForResolution
@ -433,7 +434,7 @@ class NodeVaultService(
is OwnableState -> (state.participants.map { it.owningKey } + state.owner.owningKey).toSet() is OwnableState -> (state.participants.map { it.owningKey } + state.owner.owningKey).toSet()
else -> state.participants.map { it.owningKey } else -> state.participants.map { it.owningKey }
} }
return keysToCheck.any { it in myKeys } return keysToCheck.any { it.containsAny(myKeys) }
} }
@Throws(VaultQueryException::class) @Throws(VaultQueryException::class)