Merged in andrius-minor-transaction-cleanup (pull request #329)

Minor TransactionBuilder cleanup
This commit is contained in:
Andrius Dagys 2016-09-06 13:14:07 +01:00
commit f3b4379e06
3 changed files with 9 additions and 8 deletions

View File

@ -19,6 +19,10 @@ import java.util.*
* @param notary Notary used for the transaction. If null, this indicates the transaction DOES NOT have a notary. * @param notary Notary used for the transaction. If null, this indicates the transaction DOES NOT have a notary.
* When this is set to a non-null value, an output state can be added by just passing in a [ContractState] a * When this is set to a non-null value, an output state can be added by just passing in a [ContractState] a
* [TransactionState] with this notary specified will be generated automatically. * [TransactionState] with this notary specified will be generated automatically.
*
* @param signers The set of public keys the transaction needs signatures for. The logic for building the signers set
* can be customised for every [TransactionType]. E.g. in the general case it contains the command and notary public keys,
* but for the [TransactionType.NotaryChange] transactions it is the set of all input [ContractState.participants].
*/ */
open class TransactionBuilder( open class TransactionBuilder(
protected val type: TransactionType = TransactionType.General(), protected val type: TransactionType = TransactionType.General(),
@ -30,7 +34,6 @@ open class TransactionBuilder(
protected val signers: MutableSet<PublicKey> = mutableSetOf(), protected val signers: MutableSet<PublicKey> = mutableSetOf(),
protected var timestamp: Timestamp? = null) { protected var timestamp: Timestamp? = null) {
@Deprecated("use timestamp instead")
val time: Timestamp? get() = timestamp val time: Timestamp? get() = timestamp
init { init {
@ -139,13 +142,12 @@ open class TransactionBuilder(
return SignedTransaction(toWireTransaction().serialize(), ArrayList(currentSigs)) return SignedTransaction(toWireTransaction().serialize(), ArrayList(currentSigs))
} }
open fun addInputState(stateAndRef: StateAndRef<*>) = addInputState(stateAndRef.ref, stateAndRef.state.notary) open fun addInputState(stateAndRef: StateAndRef<*>) {
fun addInputState(stateRef: StateRef, notary: Party) {
check(currentSigs.isEmpty()) check(currentSigs.isEmpty())
val notary = stateAndRef.state.notary
require(notary == this.notary) { "Input state requires notary \"${notary}\" which does not match the transaction notary \"${this.notary}\"." } require(notary == this.notary) { "Input state requires notary \"${notary}\" which does not match the transaction notary \"${this.notary}\"." }
signers.add(notary.owningKey) signers.add(notary.owningKey)
inputs.add(stateRef) inputs.add(stateAndRef.ref)
} }
fun addAttachment(attachmentId: SecureHash) { fun addAttachment(attachmentId: SecureHash) {

View File

@ -163,7 +163,6 @@ data class SignedTransaction(val txBits: SerializedBytes<WireTransaction>,
* Returns the set of missing signatures - a signature must be present for each signer public key. * Returns the set of missing signatures - a signature must be present for each signer public key.
*/ */
private fun getMissingSignatures(): Set<PublicKey> { private fun getMissingSignatures(): Set<PublicKey> {
val notaryKey = tx.notary?.owningKey
val requiredKeys = tx.signers.toSet() val requiredKeys = tx.signers.toSet()
val sigKeys = sigs.map { it.by }.toSet() val sigKeys = sigs.map { it.by }.toSet()

View File

@ -106,8 +106,8 @@ data class TestTransactionDSLInterpreter private constructor(
internal fun toWireTransaction() = transactionBuilder.toWireTransaction() internal fun toWireTransaction() = transactionBuilder.toWireTransaction()
override fun input(stateRef: StateRef) { override fun input(stateRef: StateRef) {
val notary = ledgerInterpreter.resolveStateRef<ContractState>(stateRef).notary val state = ledgerInterpreter.resolveStateRef<ContractState>(stateRef)
transactionBuilder.addInputState(stateRef, notary) transactionBuilder.addInputState(StateAndRef(state, stateRef))
} }
override fun _output(label: String?, notary: Party, contractState: ContractState) { override fun _output(label: String?, notary: Party, contractState: ContractState) {