mirror of
https://github.com/corda/corda.git
synced 2025-02-02 09:18:13 +00:00
Remove the SignedTransaction.id field, which took part in serialisation. Calculate it on demand instead.
This commit is contained in:
parent
0b33b52d1a
commit
b8942a2cc9
@ -23,8 +23,7 @@ import java.util.*
|
||||
* A transaction ID should be the hash of the [WireTransaction] Merkle tree root. Thus adding or removing a signature does not change it.
|
||||
*/
|
||||
data class SignedTransaction(val txBits: SerializedBytes<WireTransaction>,
|
||||
val sigs: List<DigitalSignature.WithKey>,
|
||||
override val id: SecureHash
|
||||
val sigs: List<DigitalSignature.WithKey>
|
||||
) : NamedByHash {
|
||||
init {
|
||||
require(sigs.isNotEmpty())
|
||||
@ -33,11 +32,14 @@ data class SignedTransaction(val txBits: SerializedBytes<WireTransaction>,
|
||||
// TODO: This needs to be reworked to ensure that the inner WireTransaction is only ever deserialised sandboxed.
|
||||
|
||||
/** Lazily calculated access to the deserialised/hashed transaction data. */
|
||||
val tx: WireTransaction by lazy {
|
||||
val temp = WireTransaction.deserialize(txBits)
|
||||
check(temp.id == id) { "Supplied transaction ID does not match deserialized transaction's ID - this is probably a problem in serialization/deserialization" }
|
||||
temp
|
||||
}
|
||||
val tx: WireTransaction by lazy { WireTransaction.deserialize(txBits) }
|
||||
|
||||
/**
|
||||
* The Merkle root of the inner [WireTransaction]. Note that this is _not_ the same as the simple hash of
|
||||
* [txBits], which would not use the Merkle tree structure. If the difference isn't clear, please consult
|
||||
* the user guide section "Transaction tear-offs" to learn more about Merkle trees.
|
||||
*/
|
||||
override val id: SecureHash get() = tx.id
|
||||
|
||||
class SignaturesMissingException(val missing: Set<CompositeKey>, val descriptions: List<String>, override val id: SecureHash) : NamedByHash, SignatureException() {
|
||||
override fun toString(): String {
|
||||
|
@ -137,7 +137,7 @@ open class TransactionBuilder(
|
||||
throw IllegalStateException("Missing signatures on the transaction for the public keys: ${missing.joinToString()}")
|
||||
}
|
||||
val wtx = toWireTransaction()
|
||||
return SignedTransaction(wtx.serialize(), ArrayList(currentSigs), wtx.id)
|
||||
return SignedTransaction(wtx.serialize(), ArrayList(currentSigs))
|
||||
}
|
||||
|
||||
open fun addInputState(stateAndRef: StateAndRef<*>) {
|
||||
|
@ -35,7 +35,7 @@ class TransactionTests {
|
||||
timestamp = null
|
||||
)
|
||||
val bytes: SerializedBytes<WireTransaction> = wtx.serialized
|
||||
fun make(vararg keys: KeyPair) = SignedTransaction(bytes, keys.map { it.signWithECDSA(wtx.id.bytes) }, wtx.id)
|
||||
fun make(vararg keys: KeyPair) = SignedTransaction(bytes, keys.map { it.signWithECDSA(wtx.id.bytes) })
|
||||
assertFailsWith<IllegalArgumentException> { make().verifySignatures() }
|
||||
|
||||
assertEquals(
|
||||
|
@ -84,8 +84,7 @@ class SignedTransactionGenerator : Generator<SignedTransaction>(SignedTransactio
|
||||
val wireTransaction = WiredTransactionGenerator().generate(random, status)
|
||||
return SignedTransaction(
|
||||
txBits = wireTransaction.serialized,
|
||||
sigs = listOf(NullSignature),
|
||||
id = wireTransaction.id
|
||||
sigs = listOf(NullSignature)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +167,6 @@ class RequeryConfigurationTest {
|
||||
type = TransactionType.General(),
|
||||
timestamp = null
|
||||
)
|
||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))), wtx.id)
|
||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
||||
}
|
||||
}
|
@ -156,6 +156,6 @@ class DBTransactionStorageTests {
|
||||
type = TransactionType.General(),
|
||||
timestamp = null
|
||||
)
|
||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))), wtx.id)
|
||||
return SignedTransaction(wtx.serialized, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ data class TestLedgerDSLInterpreter private constructor (
|
||||
override fun verifies(): EnforceVerifyOrFail {
|
||||
try {
|
||||
val usedInputs = mutableSetOf<StateRef>()
|
||||
services.recordTransactions(transactionsUnverified.map { SignedTransaction(it.serialized, listOf(NullSignature), it.id) })
|
||||
services.recordTransactions(transactionsUnverified.map { SignedTransaction(it.serialized, listOf(NullSignature)) })
|
||||
for ((key, value) in transactionWithLocations) {
|
||||
val wtx = value.transaction
|
||||
val ltx = wtx.toLedgerTransaction(services)
|
||||
@ -294,7 +294,7 @@ data class TestLedgerDSLInterpreter private constructor (
|
||||
throw DoubleSpentInputs(txIds)
|
||||
}
|
||||
usedInputs.addAll(wtx.inputs)
|
||||
services.recordTransactions(SignedTransaction(wtx.serialized, listOf(NullSignature), wtx.id))
|
||||
services.recordTransactions(SignedTransaction(wtx.serialized, listOf(NullSignature)))
|
||||
}
|
||||
return EnforceVerifyOrFail.Token
|
||||
} catch (exception: TransactionVerificationException) {
|
||||
@ -340,7 +340,7 @@ fun signAll(transactionsToSign: List<WireTransaction>, extraKeys: List<KeyPair>)
|
||||
val key = keyLookup[it] ?: throw IllegalArgumentException("Missing required key for ${it.toStringShort()}")
|
||||
signatures += key.signWithECDSA(wtx.id)
|
||||
}
|
||||
SignedTransaction(bits, signatures, wtx.id)
|
||||
SignedTransaction(bits, signatures)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user