mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Minor: rename some fields in Command to be consistent with AuthenticatedObject, just to simplify the next refactor
This commit is contained in:
parent
306ff69312
commit
70210f3ef9
@ -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<PublicKey>) {
|
||||
data class Command(val value: CommandData, val signers: List<PublicKey>) {
|
||||
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. */
|
||||
|
@ -25,7 +25,7 @@ class TransactionBuilder(private val inputs: MutableList<StateRef> = arrayListOf
|
||||
private val outputs: MutableList<ContractState> = arrayListOf(),
|
||||
private val commands: MutableList<Command> = 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<StateRef> = 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<StateRef> = 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<StateRef> = 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<StateRef> = 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))
|
||||
|
@ -45,7 +45,7 @@ class TransactionGraphSearch(val transactions: Map<SecureHash, SignedTransaction
|
||||
|
||||
private fun Query.matches(tx: WireTransaction): Boolean {
|
||||
if (withCommandOfType != null) {
|
||||
if (tx.commands.any { it.data.javaClass.isAssignableFrom(withCommandOfType) })
|
||||
if (tx.commands.any { it.value.javaClass.isAssignableFrom(withCommandOfType) })
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -122,7 +122,7 @@ data class SignedTransaction(val txBits: SerializedBytes<WireTransaction>,
|
||||
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()
|
||||
|
@ -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())
|
||||
|
@ -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<Fix> = 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())
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -33,7 +33,7 @@ class DummyTimestamper(var clock: Clock = Clock.fixed(TEST_TX_TIME, ZoneId.syste
|
||||
|
||||
override fun timestamp(wtxBytes: SerializedBytes<WireTransaction>): 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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<AuthenticatedObject<CommandData>> {
|
||||
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<T : ContractState>(private val stateType: Class<T>) {
|
||||
|
||||
fun signAll(txnsToSign: List<WireTransaction> = txns, vararg extraKeys: KeyPair): List<SignedTransaction> {
|
||||
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<DigitalSignature.WithKey>()
|
||||
|
Loading…
Reference in New Issue
Block a user