mirror of
https://github.com/corda/corda.git
synced 2025-06-15 05:38:14 +00:00
Refactor notary change mechanism (#1019)
* Introduce new NotaryChangeWireTransaction (similar to WireTransaction and NotaryChangeTransaction (similar to LedgerTransaction) types. Remove 'mustSign' and 'signers' fields from transactions Deprecate the TransactionType concept. When receiving a SignedTransaction, the verification and signature checking branches out for regular and notary change transactions. Add custom handling logic for notary change transactions to the vault
This commit is contained in:
@ -46,15 +46,13 @@ class MyValidatingNotaryFlow(otherSide: Party, service: MyCustomValidatingNotary
|
||||
override fun receiveAndVerifyTx(): TransactionParts {
|
||||
val stx = receive<SignedTransaction>(otherSide).unwrap { it }
|
||||
checkSignatures(stx)
|
||||
resolveTransaction(stx)
|
||||
validateTransaction(stx)
|
||||
val wtx = stx.tx
|
||||
validateTransaction(wtx)
|
||||
val ltx = validateTransaction(wtx)
|
||||
processTransaction(ltx)
|
||||
|
||||
return TransactionParts(wtx.id, wtx.inputs, wtx.timeWindow)
|
||||
}
|
||||
|
||||
fun processTransaction(ltx: LedgerTransaction) {
|
||||
fun processTransaction(stx: SignedTransaction) {
|
||||
// Add custom transaction processing logic here
|
||||
}
|
||||
|
||||
@ -67,12 +65,10 @@ class MyValidatingNotaryFlow(otherSide: Party, service: MyCustomValidatingNotary
|
||||
}
|
||||
|
||||
@Suspendable
|
||||
fun validateTransaction(wtx: WireTransaction): LedgerTransaction {
|
||||
fun validateTransaction(stx: SignedTransaction) {
|
||||
try {
|
||||
resolveTransaction(wtx)
|
||||
val ltx = wtx.toLedgerTransaction(serviceHub)
|
||||
ltx.verify()
|
||||
return ltx
|
||||
resolveTransaction(stx)
|
||||
stx.verify(serviceHub, false)
|
||||
} catch (e: Exception) {
|
||||
throw when (e) {
|
||||
is TransactionVerificationException,
|
||||
@ -83,6 +79,6 @@ class MyValidatingNotaryFlow(otherSide: Party, service: MyCustomValidatingNotary
|
||||
}
|
||||
|
||||
@Suspendable
|
||||
private fun resolveTransaction(wtx: WireTransaction) = subFlow(ResolveTransactionsFlow(wtx, otherSide))
|
||||
private fun resolveTransaction(stx: SignedTransaction) = subFlow(ResolveTransactionsFlow(stx, otherSide))
|
||||
}
|
||||
// END 2
|
||||
|
@ -227,16 +227,17 @@ class RecordCompletionFlow(val source: Party) : FlowLogic<Unit>() {
|
||||
// First we receive the verdict transaction signed by their single key
|
||||
val completeTx = receive<SignedTransaction>(source).unwrap {
|
||||
// Check the transaction is signed apart from our own key and the notary
|
||||
val wtx = it.verifySignaturesExcept(serviceHub.myInfo.legalIdentity.owningKey, it.tx.notary!!.owningKey)
|
||||
it.verifySignaturesExcept(serviceHub.myInfo.legalIdentity.owningKey, it.tx.notary!!.owningKey)
|
||||
// Check the transaction data is correctly formed
|
||||
wtx.toLedgerTransaction(serviceHub).verify()
|
||||
val ltx = it.toLedgerTransaction(serviceHub, false)
|
||||
ltx.verify()
|
||||
// Confirm that this is the expected type of transaction
|
||||
require(wtx.commands.single().value is TradeApprovalContract.Commands.Completed) {
|
||||
require(ltx.commands.single().value is TradeApprovalContract.Commands.Completed) {
|
||||
"Transaction must represent a workflow completion"
|
||||
}
|
||||
// Check the context dependent parts of the transaction as the
|
||||
// Contract verify method must not use serviceHub queries.
|
||||
val state = wtx.outRef<TradeApprovalContract.State>(0)
|
||||
val state = ltx.outRef<TradeApprovalContract.State>(0)
|
||||
require(state.state.data.source == serviceHub.myInfo.legalIdentity) {
|
||||
"Proposal not one of our original proposals"
|
||||
}
|
||||
|
Reference in New Issue
Block a user