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:
Andrius Dagys
2017-07-27 08:32:33 +01:00
committed by GitHub
parent 25be649f7b
commit 4487408526
42 changed files with 764 additions and 724 deletions

View File

@ -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

View File

@ -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"
}