forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORDA-696 - Ensure deterministic transaction id calculation for contr…
…a… (corda#2676) The problem with the previous implementation is that the transaction would be deserialized with the schema specified in the serialized form, but the calculation of the id would involve re-serializing properties using a local serialization context which might produce a different result.
- Loading branch information
Showing
10 changed files
with
208 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/kotlin/net/corda/core/internal/TransactionUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.corda.core.internal | ||
|
||
import net.corda.core.contracts.ContractClassName | ||
import net.corda.core.contracts.PrivacySalt | ||
import net.corda.core.contracts.StateRef | ||
import net.corda.core.crypto.SecureHash | ||
import net.corda.core.crypto.sha256 | ||
import net.corda.core.identity.Party | ||
import net.corda.core.serialization.serialize | ||
import net.corda.core.transactions.ContractUpgradeWireTransaction | ||
import net.corda.core.transactions.NotaryChangeWireTransaction | ||
import java.io.ByteArrayOutputStream | ||
|
||
/** Constructs a [NotaryChangeWireTransaction]. */ | ||
class NotaryChangeTransactionBuilder(val inputs: List<StateRef>, | ||
val notary: Party, | ||
val newNotary: Party) { | ||
fun build(): NotaryChangeWireTransaction { | ||
val components = listOf(inputs, notary, newNotary).map { it.serialize() } | ||
return NotaryChangeWireTransaction(components) | ||
} | ||
} | ||
|
||
/** Constructs a [ContractUpgradeWireTransaction]. */ | ||
class ContractUpgradeTransactionBuilder( | ||
val inputs: List<StateRef>, | ||
val notary: Party, | ||
val legacyContractAttachmentId: SecureHash, | ||
val upgradedContractClassName: ContractClassName, | ||
val upgradedContractAttachmentId: SecureHash, | ||
val privacySalt: PrivacySalt = PrivacySalt()) { | ||
fun build(): ContractUpgradeWireTransaction { | ||
val components = listOf(inputs, notary, legacyContractAttachmentId, upgradedContractClassName, upgradedContractAttachmentId).map { it.serialize() } | ||
return ContractUpgradeWireTransaction(components, privacySalt) | ||
} | ||
} | ||
|
||
/** Concatenates the hash components into a single [ByteArray] and returns its hash. */ | ||
fun combinedHash(components: Iterable<SecureHash>): SecureHash { | ||
val stream = ByteArrayOutputStream() | ||
components.forEach { | ||
stream.write(it.bytes) | ||
} | ||
return stream.toByteArray().sha256() | ||
} |
Oops, something went wrong.