From 70210f3ef947cbf486412352d1be40d0f7c58215 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 18 Apr 2016 15:08:54 +0200 Subject: [PATCH] Minor: rename some fields in Command to be consistent with AuthenticatedObject, just to simplify the next refactor --- core/src/main/kotlin/core/Structures.kt | 8 ++++---- core/src/main/kotlin/core/TransactionBuilder.kt | 12 ++++++------ core/src/main/kotlin/core/TransactionGraphSearch.kt | 2 +- core/src/main/kotlin/core/Transactions.kt | 2 +- src/main/kotlin/core/TransactionTools.kt | 4 ++-- .../kotlin/core/node/services/NodeInterestRates.kt | 4 ++-- .../core/node/services/NodeTimestamperService.kt | 6 +++--- src/test/kotlin/contracts/CashTests.kt | 12 ++++++------ src/test/kotlin/core/MockServices.kt | 2 +- .../core/node/services/NodeInterestRatesTest.kt | 2 +- .../serialization/TransactionSerializationTests.kt | 2 +- src/test/kotlin/core/testutils/TestUtils.kt | 4 ++-- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/core/src/main/kotlin/core/Structures.kt b/core/src/main/kotlin/core/Structures.kt index 33495be6b4..f6ab805168 100644 --- a/core/src/main/kotlin/core/Structures.kt +++ b/core/src/main/kotlin/core/Structures.kt @@ -95,15 +95,15 @@ abstract class TypeOnlyCommandData : CommandData { } /** Command data/content plus pubkey pair: the signature is stored at the end of the serialized bytes */ -data class Command(val data: CommandData, val pubkeys: List) { +data class Command(val value: CommandData, val signers: List) { init { - require(pubkeys.isNotEmpty()) + require(signers.isNotEmpty()) } constructor(data: CommandData, key: PublicKey) : this(data, listOf(key)) - private fun commandDataToString() = data.toString().let { if (it.contains("@")) it.replace('$', '.').split("@")[0] else it } - override fun toString() = "${commandDataToString()} with pubkeys ${pubkeys.map { it.toStringShort() }}" + private fun commandDataToString() = value.toString().let { if (it.contains("@")) it.replace('$', '.').split("@")[0] else it } + override fun toString() = "${commandDataToString()} with pubkeys ${signers.map { it.toStringShort() }}" } /** Wraps an object that was signed by a public key, which may be a well known/recognised institutional key. */ diff --git a/core/src/main/kotlin/core/TransactionBuilder.kt b/core/src/main/kotlin/core/TransactionBuilder.kt index 4fc8aec543..9c51868854 100644 --- a/core/src/main/kotlin/core/TransactionBuilder.kt +++ b/core/src/main/kotlin/core/TransactionBuilder.kt @@ -25,7 +25,7 @@ class TransactionBuilder(private val inputs: MutableList = arrayListOf private val outputs: MutableList = arrayListOf(), private val commands: MutableList = arrayListOf()) { - val time: TimestampCommand? get() = commands.mapNotNull { it.data as? TimestampCommand }.singleOrNull() + val time: TimestampCommand? get() = commands.mapNotNull { it.value as? TimestampCommand }.singleOrNull() /** * Places a [TimestampCommand] in this transaction, removing any existing command if there is one. @@ -41,7 +41,7 @@ class TransactionBuilder(private val inputs: MutableList = arrayListOf */ fun setTime(time: Instant, authenticatedBy: Party, timeTolerance: Duration) { check(currentSigs.isEmpty()) { "Cannot change timestamp after signing" } - commands.removeAll { it.data is TimestampCommand } + commands.removeAll { it.value is TimestampCommand } addCommand(TimestampCommand(time, timeTolerance), authenticatedBy.owningKey) } @@ -63,7 +63,7 @@ class TransactionBuilder(private val inputs: MutableList = arrayListOf fun signWith(key: KeyPair) { check(currentSigs.none { it.by == key.public }) { "This partial transaction was already signed by ${key.public}" } - check(commands.count { it.pubkeys.contains(key.public) } > 0) { "Trying to sign with a key that isn't in any command" } + check(commands.count { it.signers.contains(key.public) } > 0) { "Trying to sign with a key that isn't in any command" } val data = toWireTransaction().serialize() addSignatureUnchecked(key.signWithECDSA(data.bits)) } @@ -87,7 +87,7 @@ class TransactionBuilder(private val inputs: MutableList = arrayListOf * @throws IllegalArgumentException if the signature key doesn't appear in any command. */ fun checkSignature(sig: DigitalSignature.WithKey) { - require(commands.count { it.pubkeys.contains(sig.by) } > 0) { "Signature key doesn't match any command" } + require(commands.count { it.signers.contains(sig.by) } > 0) { "Signature key doesn't match any command" } sig.verifyWithECDSA(toWireTransaction().serialized) } @@ -129,8 +129,8 @@ class TransactionBuilder(private val inputs: MutableList = arrayListOf if (checkSufficientSignatures) { val gotKeys = currentSigs.map { it.by }.toSet() for (command in commands) { - if (!gotKeys.containsAll(command.pubkeys)) - throw IllegalStateException("Missing signatures on the transaction for a ${command.data.javaClass.canonicalName} command") + if (!gotKeys.containsAll(command.signers)) + throw IllegalStateException("Missing signatures on the transaction for a ${command.value.javaClass.canonicalName} command") } } return SignedTransaction(toWireTransaction().serialize(), ArrayList(currentSigs)) diff --git a/core/src/main/kotlin/core/TransactionGraphSearch.kt b/core/src/main/kotlin/core/TransactionGraphSearch.kt index f0f5eaec90..1099579fab 100644 --- a/core/src/main/kotlin/core/TransactionGraphSearch.kt +++ b/core/src/main/kotlin/core/TransactionGraphSearch.kt @@ -45,7 +45,7 @@ class TransactionGraphSearch(val transactions: Map, verifySignatures() // Verify that every command key was in the set that we just verified: there should be no commands that were // unverified. - val cmdKeys = tx.commands.flatMap { it.pubkeys }.toSet() + val cmdKeys = tx.commands.flatMap { it.signers }.toSet() val sigKeys = sigs.map { it.by }.toSet() if (sigKeys == cmdKeys) return emptySet() diff --git a/src/main/kotlin/core/TransactionTools.kt b/src/main/kotlin/core/TransactionTools.kt index ff88afcd61..06b4a1ea09 100644 --- a/src/main/kotlin/core/TransactionTools.kt +++ b/src/main/kotlin/core/TransactionTools.kt @@ -12,8 +12,8 @@ import java.io.FileNotFoundException fun WireTransaction.toLedgerTransaction(identityService: IdentityService, attachmentStorage: AttachmentStorage): LedgerTransaction { val authenticatedArgs = commands.map { - val institutions = it.pubkeys.mapNotNull { pk -> identityService.partyFromKey(pk) } - AuthenticatedObject(it.pubkeys, institutions, it.data) + val institutions = it.signers.mapNotNull { pk -> identityService.partyFromKey(pk) } + AuthenticatedObject(it.signers, institutions, it.value) } val attachments = attachments.map { attachmentStorage.openAttachment(it) ?: throw FileNotFoundException(it.toString()) diff --git a/src/main/kotlin/core/node/services/NodeInterestRates.kt b/src/main/kotlin/core/node/services/NodeInterestRates.kt index 1b42371ffd..885816968d 100644 --- a/src/main/kotlin/core/node/services/NodeInterestRates.kt +++ b/src/main/kotlin/core/node/services/NodeInterestRates.kt @@ -98,8 +98,8 @@ object NodeInterestRates { fun sign(wtx: WireTransaction): DigitalSignature.LegallyIdentifiable { // Extract the fix commands marked as being signable by us. val fixes: List = wtx.commands. - filter { identity.owningKey in it.pubkeys && it.data is Fix }. - map { it.data as Fix } + filter { identity.owningKey in it.signers && it.value is Fix }. + map { it.value as Fix } // Reject this signing attempt if there are no commands of the right kind. if (fixes.isEmpty()) diff --git a/src/main/kotlin/core/node/services/NodeTimestamperService.kt b/src/main/kotlin/core/node/services/NodeTimestamperService.kt index ad00a00ab4..fb5c19fb68 100644 --- a/src/main/kotlin/core/node/services/NodeTimestamperService.kt +++ b/src/main/kotlin/core/node/services/NodeTimestamperService.kt @@ -56,12 +56,12 @@ class NodeTimestamperService(net: MessagingService, // except the relevant command, and a future privacy upgrade should ensure we only get a torn-off command // rather than the full transaction. val tx = req.tx.deserialize() - val cmd = tx.commands.filter { it.data is TimestampCommand }.singleOrNull() + val cmd = tx.commands.filter { it.value is TimestampCommand }.singleOrNull() if (cmd == null) throw TimestampingError.RequiresExactlyOneCommand() - if (!cmd.pubkeys.contains(identity.owningKey)) + if (!cmd.signers.contains(identity.owningKey)) throw TimestampingError.NotForMe() - val tsCommand = cmd.data as TimestampCommand + val tsCommand = cmd.value as TimestampCommand val before = tsCommand.before val after = tsCommand.after diff --git a/src/test/kotlin/contracts/CashTests.kt b/src/test/kotlin/contracts/CashTests.kt index 6e0208cff8..052eb02422 100644 --- a/src/test/kotlin/contracts/CashTests.kt +++ b/src/test/kotlin/contracts/CashTests.kt @@ -106,8 +106,8 @@ class CashTests { assertEquals(100.DOLLARS, s.amount) assertEquals(MINI_CORP, s.deposit.party) assertEquals(DUMMY_PUBKEY_1, s.owner) - assertTrue(ptx.commands()[0].data is Cash.Commands.Issue) - assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].pubkeys[0]) + assertTrue(ptx.commands()[0].value is Cash.Commands.Issue) + assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].signers[0]) } @Test @@ -318,7 +318,7 @@ class CashTests { val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1) assertEquals(WALLET[0].ref, wtx.inputs[0]) assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputs[0]) - assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0]) + assertEquals(OUR_PUBKEY_1, wtx.commands[0].signers[0]) } @Test @@ -334,7 +334,7 @@ class CashTests { assertEquals(WALLET[0].ref, wtx.inputs[0]) assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputs[0]) assertEquals(WALLET[0].state.copy(amount = 90.DOLLARS), wtx.outputs[1]) - assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0]) + assertEquals(OUR_PUBKEY_1, wtx.commands[0].signers[0]) } @Test @@ -343,7 +343,7 @@ class CashTests { assertEquals(WALLET[0].ref, wtx.inputs[0]) assertEquals(WALLET[1].ref, wtx.inputs[1]) assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputs[0]) - assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0]) + assertEquals(OUR_PUBKEY_1, wtx.commands[0].signers[0]) } @Test @@ -354,7 +354,7 @@ class CashTests { assertEquals(WALLET[2].ref, wtx.inputs[2]) assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputs[0]) assertEquals(WALLET[2].state.copy(owner = THEIR_PUBKEY_1), wtx.outputs[1]) - assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0]) + assertEquals(OUR_PUBKEY_1, wtx.commands[0].signers[0]) } @Test diff --git a/src/test/kotlin/core/MockServices.kt b/src/test/kotlin/core/MockServices.kt index cf69602411..2aaf7bf1a6 100644 --- a/src/test/kotlin/core/MockServices.kt +++ b/src/test/kotlin/core/MockServices.kt @@ -33,7 +33,7 @@ class DummyTimestamper(var clock: Clock = Clock.fixed(TEST_TX_TIME, ZoneId.syste override fun timestamp(wtxBytes: SerializedBytes): DigitalSignature.LegallyIdentifiable { val wtx = wtxBytes.deserialize() - val timestamp = wtx.commands.mapNotNull { it.data as? TimestampCommand }.single() + val timestamp = wtx.commands.mapNotNull { it.value as? TimestampCommand }.single() if (timestamp.before!! until clock.instant() > tolerance) throw TimestampingError.NotOnTimeException() return DummyTimestampingAuthority.key.signWithECDSA(wtxBytes.bits, identity) diff --git a/src/test/kotlin/core/node/services/NodeInterestRatesTest.kt b/src/test/kotlin/core/node/services/NodeInterestRatesTest.kt index d1ff044b0c..12ff06f161 100644 --- a/src/test/kotlin/core/node/services/NodeInterestRatesTest.kt +++ b/src/test/kotlin/core/node/services/NodeInterestRatesTest.kt @@ -101,7 +101,7 @@ class NodeInterestRatesTest { future.get() // We should now have a valid signature over our tx from the oracle. - val fix = tx.toSignedTransaction(true).tx.commands.map { it.data as Fix }.first() + val fix = tx.toSignedTransaction(true).tx.commands.map { it.value as Fix }.first() assertEquals(fixOf, fix.of) assertEquals("0.678".bd, fix.value) } diff --git a/src/test/kotlin/core/serialization/TransactionSerializationTests.kt b/src/test/kotlin/core/serialization/TransactionSerializationTests.kt index cda3ea5755..1c937475f3 100644 --- a/src/test/kotlin/core/serialization/TransactionSerializationTests.kt +++ b/src/test/kotlin/core/serialization/TransactionSerializationTests.kt @@ -83,7 +83,7 @@ class TransactionSerializationTests { tx.signWith(TestUtils.keypair) val stx = tx.toSignedTransaction() val ltx = stx.verifyToLedgerTransaction(MockIdentityService, MockStorageService().attachments) - assertEquals(tx.commands().map { it.data }, ltx.commands.map { it.value }) + assertEquals(tx.commands().map { it.value }, ltx.commands.map { it.value }) assertEquals(tx.inputStates(), ltx.inputs) assertEquals(tx.outputStates(), ltx.outputs) assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_TIMESTAMPER.identity)!!.midpoint) diff --git a/src/test/kotlin/core/testutils/TestUtils.kt b/src/test/kotlin/core/testutils/TestUtils.kt index fe1a988ca1..78ddfbe377 100644 --- a/src/test/kotlin/core/testutils/TestUtils.kt +++ b/src/test/kotlin/core/testutils/TestUtils.kt @@ -118,7 +118,7 @@ abstract class AbstractTransactionForTest { open fun output(label: String? = null, s: () -> ContractState) = LabeledOutput(label, s()).apply { outStates.add(this) } protected fun commandsToAuthenticatedObjects(): List> { - return commands.map { AuthenticatedObject(it.pubkeys, it.pubkeys.mapNotNull { MockIdentityService.partyFromKey(it) }, it.data) } + return commands.map { AuthenticatedObject(it.signers, it.signers.mapNotNull { MockIdentityService.partyFromKey(it) }, it.value) } } fun attachment(attachmentID: SecureHash) { @@ -341,7 +341,7 @@ class TransactionGroupDSL(private val stateType: Class) { fun signAll(txnsToSign: List = txns, vararg extraKeys: KeyPair): List { return txnsToSign.map { wtx -> - val allPubKeys = wtx.commands.flatMap { it.pubkeys }.toMutableSet() + val allPubKeys = wtx.commands.flatMap { it.signers }.toMutableSet() val bits = wtx.serialize() require(bits == wtx.serialized) val sigs = ArrayList()