From 25f65a60c73e0518ff9cbb2918ded0e7e1e149ee Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 5 Aug 2016 14:02:30 +0200 Subject: [PATCH] Address review comments. --- .../r3corda/protocols/TwoPartyTradeProtocol.kt | 7 +++++-- .../core/contracts/TransactionVerification.kt | 12 ------------ .../com/r3corda/core/contracts/Transactions.kt | 15 ++++++--------- docs/source/transaction-data-types.rst | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/contracts/src/main/kotlin/com/r3corda/protocols/TwoPartyTradeProtocol.kt b/contracts/src/main/kotlin/com/r3corda/protocols/TwoPartyTradeProtocol.kt index 7a83042ef7..d3eebd3f93 100644 --- a/contracts/src/main/kotlin/com/r3corda/protocols/TwoPartyTradeProtocol.kt +++ b/contracts/src/main/kotlin/com/r3corda/protocols/TwoPartyTradeProtocol.kt @@ -4,7 +4,10 @@ import co.paralleluniverse.fibers.Suspendable import com.r3corda.contracts.asset.Cash import com.r3corda.contracts.asset.sumCashBy import com.r3corda.core.contracts.* -import com.r3corda.core.crypto.* +import com.r3corda.core.crypto.DigitalSignature +import com.r3corda.core.crypto.Party +import com.r3corda.core.crypto.signWithECDSA +import com.r3corda.core.crypto.toStringsShort import com.r3corda.core.node.NodeInfo import com.r3corda.core.protocols.ProtocolLogic import com.r3corda.core.random63BitValue @@ -122,7 +125,7 @@ object TwoPartyTradeProtocol { val missingSigs: Set = it.verifySignatures(throwIfSignaturesAreMissing = false) val expected = setOf(myKeyPair.public, notaryNode.identity.owningKey) if (missingSigs != expected) - throw SignatureException("The set of missing signatures is not as expected: ${missingSigs.toStringsShort()} vs [${myKeyPair.public.toStringShort()}, ${notaryNode.identity.owningKey.toStringShort()}]") + throw SignatureException("The set of missing signatures is not as expected: ${missingSigs.toStringsShort()} vs ${expected.toStringsShort()}") val wtx: WireTransaction = it.tx logger.trace { "Received partially signed transaction: ${it.id}" } diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/TransactionVerification.kt b/core/src/main/kotlin/com/r3corda/core/contracts/TransactionVerification.kt index 9dd43dadef..c93d2b56f6 100644 --- a/core/src/main/kotlin/com/r3corda/core/contracts/TransactionVerification.kt +++ b/core/src/main/kotlin/com/r3corda/core/contracts/TransactionVerification.kt @@ -8,18 +8,6 @@ import java.util.* // TODO: Consider moving this out of the core module and providing a different way for unit tests to test contracts. -/** A transaction in fully resolved and sig-checked form, ready for passing as input to a verification function. */ -data class TransactionForVerification(val inputs: List>, - val outputs: List>, - val attachments: List, - val commands: List>, - val origHash: SecureHash, - val signers: List, - val type: TransactionType) { - override fun hashCode() = origHash.hashCode() - override fun equals(other: Any?) = other is TransactionForVerification && other.origHash == origHash -} - /** * A transaction to be passed as input to a contract verification function. Defines helper methods to * simplify verification logic in contracts. diff --git a/core/src/main/kotlin/com/r3corda/core/contracts/Transactions.kt b/core/src/main/kotlin/com/r3corda/core/contracts/Transactions.kt index 151ed36402..75e5ff27c7 100644 --- a/core/src/main/kotlin/com/r3corda/core/contracts/Transactions.kt +++ b/core/src/main/kotlin/com/r3corda/core/contracts/Transactions.kt @@ -20,30 +20,27 @@ import java.security.SignatureException * SignedTransaction wraps a serialized WireTransaction. It contains one or more signatures, each one for * a public key that is mentioned inside a transaction command. SignedTransaction is the top level transaction type * and the type most frequently passed around the network and stored. The identity of a transaction is the hash - * of a WireTransaction, therefore if you are storing data keyed by WT hash be aware that multiple different SWTs may + * of a WireTransaction, therefore if you are storing data keyed by WT hash be aware that multiple different STs may * map to the same key (and they could be different in important ways, like validity!). The signatures on a * SignedTransaction might be invalid or missing: the type does not imply validity. * * WireTransaction is a transaction in a form ready to be serialised/unserialised. A WireTransaction can be hashed * in various ways to calculate a *signature hash* (or sighash), this is the hash that is signed by the various involved - * keypairs. A WireTransaction can be safely deserialised from inside a SignedTransaction outside of the sandbox, - * because it consists of only platform defined types. Any user defined object graphs are kept as byte arrays. A - * WireTransaction may be invalid and missing its dependencies (other transactions + attachments). + * keypairs. * * LedgerTransaction is derived from WireTransaction. It is the result of doing the following operations: * * - Downloading and locally storing all the dependencies of the transaction. + * - Resolving the input states and loading them into memory. * - Doing some basic key lookups on WireCommand to see if any keys are from a recognised party, thus converting the * WireCommand objects into AuthenticatedObject. Currently we just assume a hard coded pubkey->party map. * In future it'd make more sense to use a certificate scheme and so that logic would get more complex. - * - Deserialising the included states, sandboxing the contract classes, and generally ensuring the embedded code is - * safe for interaction. + * - Deserialising the output states. * * All the above refer to inputs using a (txhash, output index) pair. * - * TransactionForVerification is the same as LedgerTransaction but with the input states looked up from a local - * database and replaced with the real objects. Likewise, attachments are fully resolved at this point. - * TFV is the form that is finally fed into the contracts. + * There is also TransactionForContract, which is a lightly red-acted form of LedgerTransaction that's fed into the + * contract's verify function. It may be removed in future. */ /** Transaction ready for serialisation, without any signatures attached. */ diff --git a/docs/source/transaction-data-types.rst b/docs/source/transaction-data-types.rst index 8447af7ed3..b59e3a7792 100644 --- a/docs/source/transaction-data-types.rst +++ b/docs/source/transaction-data-types.rst @@ -99,7 +99,7 @@ contract type in the library): // skip signature checking. txb.toWireTransaction().toLedgerTransaction(services).verify() -In a unit test, you would typically use a freshly created ``UnitTestServices`` object, or more realistically, you would +In a unit test, you would typically use a freshly created ``MockServices`` object, or more realistically, you would write your tests using the :doc:`domain specific language for writing tests `. Party and PublicKey