From 253a70f55eab9273251a3f8f88462a91fa9b7168 Mon Sep 17 00:00:00 2001 From: Jose Coll Date: Mon, 31 Oct 2016 14:01:07 +0000 Subject: [PATCH] Fixed bug in generateSpending whereby Issuer Ref was not being checked. --- .../test/kotlin/com/r3corda/contracts/asset/CashTests.kt | 6 +++--- .../main/kotlin/com/r3corda/core/node/services/Services.kt | 2 +- .../main/kotlin/com/r3corda/node/internal/ServerRPCOps.kt | 4 ++-- .../com/r3corda/node/services/vault/NodeVaultService.kt | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt b/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt index 4e0b5ce720..22887040e4 100644 --- a/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt +++ b/contracts/src/test/kotlin/com/r3corda/contracts/asset/CashTests.kt @@ -32,7 +32,7 @@ import java.util.* import kotlin.test.* class CashTests { - val defaultRef = OpaqueBytes(ByteArray(1, {1})) + val defaultRef = OpaqueBytes(ByteArray(1, { 1 })) val defaultIssuer = MEGA_CORP.ref(defaultRef) val inState = Cash.State( amount = 1000.DOLLARS `issued by` defaultIssuer, @@ -264,7 +264,7 @@ class CashTests { // Include the previously issued cash in a new issuance command ptx = TransactionType.General.Builder(DUMMY_NOTARY) ptx.addInputState(tx.tx.outRef(0)) - Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP_PUBKEY, notary = DUMMY_NOTARY) + Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP_PUBKEY, notary = DUMMY_NOTARY) } @Test @@ -569,7 +569,7 @@ class CashTests { databaseTransaction(database) { val tx = TransactionType.General.Builder(DUMMY_NOTARY) - vault.generateSpend(tx, 80.DOLLARS, ALICE_PUBKEY, setOf(MINI_CORP)) + vault.generateSpend(tx, 80.DOLLARS, ALICE_PUBKEY, setOf(MINI_CORP.ref(1))) assertEquals(vaultService.states.elementAt(2).ref, tx.inputStates()[0]) } diff --git a/core/src/main/kotlin/com/r3corda/core/node/services/Services.kt b/core/src/main/kotlin/com/r3corda/core/node/services/Services.kt index 322517c859..46b154e665 100644 --- a/core/src/main/kotlin/com/r3corda/core/node/services/Services.kt +++ b/core/src/main/kotlin/com/r3corda/core/node/services/Services.kt @@ -171,7 +171,7 @@ interface VaultService { fun generateSpend(tx: TransactionBuilder, amount: Amount, to: PublicKey, - onlyFromParties: Set? = null): Pair> + onlyFromIssuers: Set? = null): Pair> } inline fun VaultService.linearHeadsOfType() = linearHeadsOfType_(T::class.java) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/ServerRPCOps.kt b/node/src/main/kotlin/com/r3corda/node/internal/ServerRPCOps.kt index 38b1ec0a7f..54bbbdae0c 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/ServerRPCOps.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/ServerRPCOps.kt @@ -79,8 +79,8 @@ class ServerRPCOps( val builder: TransactionBuilder = TransactionType.General.Builder(null) // TODO: Have some way of restricting this to states the caller controls try { - val (spendTX, keysForSigning) = services.vaultService.generateSpend(builder, req.amount.withoutIssuer(), req.recipient.owningKey) - + val (spendTX, keysForSigning) = services.vaultService.generateSpend(builder, req.amount.withoutIssuer(), req.recipient.owningKey, + setOf(req.amount.token.issuer)) keysForSigning.forEach { val key = services.keyManagementService.keys[it] ?: throw IllegalStateException("Could not find signing key for ${it.toStringShort()}") builder.signWith(KeyPair(it, key)) diff --git a/node/src/main/kotlin/com/r3corda/node/services/vault/NodeVaultService.kt b/node/src/main/kotlin/com/r3corda/node/services/vault/NodeVaultService.kt index 425ac15549..183f34c3fa 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/vault/NodeVaultService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/vault/NodeVaultService.kt @@ -120,7 +120,7 @@ class NodeVaultService(private val services: ServiceHub) : SingletonSerializeAsT override fun generateSpend(tx: TransactionBuilder, amount: Amount, to: PublicKey, - onlyFromParties: Set?): Pair> { + onlyFromIssuers: Set?): Pair> { // Discussion // // This code is analogous to the Wallet.send() set of methods in bitcoinj, and has the same general outline. @@ -146,8 +146,8 @@ class NodeVaultService(private val services: ServiceHub) : SingletonSerializeAsT val currency = amount.token var acceptableCoins = run { val ofCurrency = assetsStates.filter { it.state.data.amount.token.product == currency } - if (onlyFromParties != null) - ofCurrency.filter { it.state.data.amount.token.issuer.party in onlyFromParties } + if (onlyFromIssuers != null) + ofCurrency.filter { it.state.data.amount.token.issuer.party in onlyFromIssuers } else ofCurrency }