Remove type property from transactions

This commit is contained in:
Andrius Dagys 2017-07-27 11:18:08 +01:00
parent 92a056f869
commit 59edd6f9ae
21 changed files with 20 additions and 52 deletions

View File

@ -12,6 +12,6 @@ sealed class TransactionType {
object General : TransactionType() {
/** Just uses the default [TransactionBuilder] with no special logic */
@Deprecated("Use TransactionBuilder directly instead", ReplaceWith("TransactionBuilder()"))
class Builder(notary: Party?) : TransactionBuilder(General, notary)
class Builder(notary: Party?) : TransactionBuilder(notary)
}
}

View File

@ -13,7 +13,6 @@ import net.corda.core.transactions.CoreTransaction
import net.corda.core.transactions.NotaryChangeWireTransaction
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.WireTransaction
import net.corda.core.utilities.OpaqueBytes
import net.i2p.crypto.eddsa.EdDSAPrivateKey
import net.i2p.crypto.eddsa.EdDSAPublicKey
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec
@ -244,7 +243,6 @@ object WireTransactionSerializer : Serializer<WireTransaction>() {
kryo.writeClassAndObject(output, obj.outputs)
kryo.writeClassAndObject(output, obj.commands)
kryo.writeClassAndObject(output, obj.notary)
kryo.writeClassAndObject(output, obj.type)
kryo.writeClassAndObject(output, obj.timeWindow)
kryo.writeClassAndObject(output, obj.privacySalt)
}
@ -272,10 +270,9 @@ object WireTransactionSerializer : Serializer<WireTransaction>() {
val outputs = kryo.readClassAndObject(input) as List<TransactionState<ContractState>>
val commands = kryo.readClassAndObject(input) as List<Command<*>>
val notary = kryo.readClassAndObject(input) as Party?
val transactionType = kryo.readClassAndObject(input) as TransactionType
val timeWindow = kryo.readClassAndObject(input) as TimeWindow?
val privacySalt = kryo.readClassAndObject(input) as PrivacySalt
return WireTransaction(inputs, attachmentHashes, outputs, commands, notary, transactionType, timeWindow, privacySalt)
return WireTransaction(inputs, attachmentHashes, outputs, commands, notary, timeWindow, privacySalt)
}
}
}

View File

@ -35,7 +35,6 @@ data class LedgerTransaction(
override val id: SecureHash,
override val notary: Party?,
val timeWindow: TimeWindow?,
val type: TransactionType,
val privacySalt: PrivacySalt
) : FullTransaction() {
//DOCEND 1

View File

@ -47,7 +47,6 @@ interface TraversableTransaction {
val outputs: List<TransactionState<ContractState>>
val commands: List<Command<*>>
val notary: Party?
val type: TransactionType?
val timeWindow: TimeWindow?
/**
* For privacy purposes, each part of a transaction should be accompanied by a nonce.
@ -69,7 +68,6 @@ interface TraversableTransaction {
* - Each output that is present
* - Each command that is present
* - The notary [Party], if present
* - The type of the transaction, if present
* - The time-window of the transaction, if present
* - The privacy salt required for nonces, always presented in [WireTransaction] and always null in [FilteredLeaves]
*/
@ -82,7 +80,6 @@ interface TraversableTransaction {
// torn-off transaction and id calculation.
val result = mutableListOf(inputs, attachments, outputs, commands).flatten().toMutableList()
notary?.let { result += it }
type?.let { result += it }
timeWindow?.let { result += it }
privacySalt?.let { result += it }
return result
@ -108,7 +105,6 @@ class FilteredLeaves(
override val outputs: List<TransactionState<ContractState>>,
override val commands: List<Command<*>>,
override val notary: Party?,
override val type: TransactionType?,
override val timeWindow: TimeWindow?,
val nonces: List<SecureHash>
) : TraversableTransaction {

View File

@ -26,7 +26,6 @@ import java.util.*
* [TransactionState] with this notary specified will be generated automatically.
*/
open class TransactionBuilder(
protected val type: TransactionType = TransactionType.General,
var notary: Party? = null,
var lockId: UUID = (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID(),
protected val inputs: MutableList<StateRef> = arrayListOf(),
@ -36,13 +35,12 @@ open class TransactionBuilder(
protected var window: TimeWindow? = null,
protected var privacySalt: PrivacySalt = PrivacySalt()
) {
constructor(type: TransactionType, notary: Party) : this(type, notary, (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID())
constructor(notary: Party) : this (notary, (Strand.currentStrand() as? FlowStateMachine<*>)?.id?.uuid ?: UUID.randomUUID())
/**
* Creates a copy of the builder.
*/
fun copy() = TransactionBuilder(
type = type,
notary = notary,
inputs = ArrayList(inputs),
attachments = ArrayList(attachments),
@ -73,7 +71,7 @@ open class TransactionBuilder(
// DOCEND 1
fun toWireTransaction() = WireTransaction(ArrayList(inputs), ArrayList(attachments),
ArrayList(outputs), ArrayList(commands), notary, type, window, privacySalt)
ArrayList(outputs), ArrayList(commands), notary, window, privacySalt)
@Throws(AttachmentResolutionException::class, TransactionResolutionException::class)
fun toLedgerTransaction(services: ServiceHub) = toWireTransaction().toLedgerTransaction(services)

View File

@ -26,8 +26,6 @@ data class WireTransaction(
/** Ordered list of ([CommandData], [PublicKey]) pairs that instruct the contracts what to do. */
override val commands: List<Command<*>>,
override val notary: Party?,
// TODO: remove type
override val type: TransactionType,
override val timeWindow: TimeWindow?,
override val privacySalt: PrivacySalt = PrivacySalt()
) : CoreTransaction(), TraversableTransaction {
@ -41,7 +39,7 @@ data class WireTransaction(
override val id: SecureHash get() = merkleTree.hash
override val availableComponents: List<Any>
get() = listOf(inputs, attachments, outputs, commands).flatten() + listOf(notary, type, timeWindow).filterNotNull()
get() = listOf(inputs, attachments, outputs, commands).flatten() + listOf(notary, timeWindow).filterNotNull()
/** Public keys that need to be fulfilled by signatures in order for the transaction to be valid. */
val requiredSigningKeys: Set<PublicKey> get() {
@ -93,7 +91,7 @@ data class WireTransaction(
val resolvedInputs = inputs.map { ref ->
resolveStateRef(ref)?.let { StateAndRef(it, ref) } ?: throw TransactionResolutionException(ref.txhash)
}
return LedgerTransaction(resolvedInputs, outputs, authenticatedArgs, attachments, id, notary, timeWindow, type, privacySalt)
return LedgerTransaction(resolvedInputs, outputs, authenticatedArgs, attachments, id, notary, timeWindow, privacySalt)
}
/**
@ -143,8 +141,7 @@ data class WireTransaction(
outputs.filterIndexed { index, it -> filterAndNoncesUpdate(filtering, it, index + offsets[1]) },
commands.filterIndexed { index, it -> filterAndNoncesUpdate(filtering, it, index + offsets[2]) },
notNullFalseAndNoncesUpdate(notary, offsets[3]) as Party?,
notNullFalseAndNoncesUpdate(type, offsets[4]) as TransactionType?,
notNullFalseAndNoncesUpdate(timeWindow, offsets[5]) as TimeWindow?,
notNullFalseAndNoncesUpdate(timeWindow, offsets[4]) as TimeWindow?,
nonces
)
}
@ -162,7 +159,6 @@ data class WireTransaction(
} else {
offsets.add(offsets.last())
}
offsets.add(offsets.last() + 1) // For tx type.
if (timeWindow != null) {
offsets.add(offsets.last() + 1)
} else {

View File

@ -39,7 +39,6 @@ class TransactionTests : TestDependencyInjectionBase() {
outputs = emptyList(),
commands = listOf(dummyCommand(compKey, DUMMY_KEY_1.public, DUMMY_KEY_2.public)),
notary = DUMMY_NOTARY,
type = TransactionType.General,
timeWindow = null
)
assertEquals(
@ -66,7 +65,6 @@ class TransactionTests : TestDependencyInjectionBase() {
outputs = emptyList(),
commands = listOf(dummyCommand(DUMMY_KEY_1.public, DUMMY_KEY_2.public)),
notary = DUMMY_NOTARY,
type = TransactionType.General,
timeWindow = null
)
assertFailsWith<IllegalArgumentException> { makeSigned(wtx, notarySig = false).verifyRequiredSignatures() }
@ -108,7 +106,6 @@ class TransactionTests : TestDependencyInjectionBase() {
id,
null,
timeWindow,
TransactionType.General,
privacySalt
)
@ -124,7 +121,6 @@ class TransactionTests : TestDependencyInjectionBase() {
outputs = emptyList(),
commands = listOf(dummyCommand(DUMMY_KEY_1.public, DUMMY_KEY_2.public)),
notary = DUMMY_NOTARY,
type = TransactionType.General,
timeWindow = null
)
@ -151,7 +147,6 @@ class TransactionTests : TestDependencyInjectionBase() {
id,
notary,
timeWindow,
TransactionType.General,
privacySalt
)

View File

@ -3,7 +3,6 @@ package net.corda.core.contracts.clauses
import net.corda.core.contracts.AuthenticatedObject
import net.corda.core.contracts.CommandData
import net.corda.core.contracts.PrivacySalt
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.SecureHash
import net.corda.core.transactions.LedgerTransaction
import org.junit.Test
@ -17,7 +16,7 @@ class AllOfTests {
fun minimal() {
val counter = AtomicInteger(0)
val clause = AllOf(matchedClause(counter), matchedClause(counter))
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>())
// Check that we've run the verify() function of two clauses
@ -27,7 +26,7 @@ class AllOfTests {
@Test
fun `not all match`() {
val clause = AllOf(matchedClause(), unmatchedClause())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
assertFailsWith<IllegalStateException> { verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>()) }
}
}

View File

@ -3,7 +3,6 @@ package net.corda.core.contracts.clauses
import net.corda.core.contracts.AuthenticatedObject
import net.corda.core.contracts.CommandData
import net.corda.core.contracts.PrivacySalt
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.SecureHash
import net.corda.core.transactions.LedgerTransaction
import org.junit.Test
@ -16,7 +15,7 @@ class AnyOfTests {
fun minimal() {
val counter = AtomicInteger(0)
val clause = AnyOf(matchedClause(counter), matchedClause(counter))
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>())
// Check that we've run the verify() function of two clauses
@ -27,7 +26,7 @@ class AnyOfTests {
fun `not all match`() {
val counter = AtomicInteger(0)
val clause = AnyOf(matchedClause(counter), unmatchedClause(counter))
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>())
// Check that we've run the verify() function of one clause
@ -38,7 +37,7 @@ class AnyOfTests {
fun `none match`() {
val counter = AtomicInteger(0)
val clause = AnyOf(unmatchedClause(counter), unmatchedClause(counter))
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
assertFailsWith(IllegalArgumentException::class) {
verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>())
}

View File

@ -20,7 +20,7 @@ class VerifyClausesTests {
outputs: List<ContractState>,
commands: List<AuthenticatedObject<CommandData>>, groupingKey: Unit?): Set<CommandData> = emptySet()
}
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), emptyList(), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
verifyClause(tx, clause, emptyList<AuthenticatedObject<CommandData>>())
}
@ -33,7 +33,7 @@ class VerifyClausesTests {
commands: List<AuthenticatedObject<CommandData>>, groupingKey: Unit?): Set<CommandData> = emptySet()
}
val command = AuthenticatedObject(emptyList(), emptyList(), DummyContract.Commands.Create())
val tx = LedgerTransaction(emptyList(), emptyList(), listOf(command), emptyList(), SecureHash.randomSHA256(), null, null, TransactionType.General, PrivacySalt())
val tx = LedgerTransaction(emptyList(), emptyList(), listOf(command), emptyList(), SecureHash.randomSHA256(), null, null, PrivacySalt())
// The clause is matched, but doesn't mark the command as consumed, so this should error
assertFailsWith<IllegalStateException> { verifyClause(tx, clause, listOf(command)) }
}

View File

@ -1,6 +1,5 @@
package net.corda.core.crypto
import com.esotericsoftware.kryo.KryoException
import net.corda.contracts.asset.Cash
import net.corda.core.contracts.*
@ -120,7 +119,6 @@ class PartialMerkleTreeTest : TestDependencyInjectionBase() {
assertEquals(1, leaves.outputs.size)
assertEquals(1, leaves.commands.size)
assertNull(mt.filteredLeaves.notary)
assertNull(mt.filteredLeaves.type)
assertNotNull(mt.filteredLeaves.timeWindow)
assertNull(mt.filteredLeaves.privacySalt)
assertEquals(4, leaves.nonces.size)
@ -244,7 +242,6 @@ class PartialMerkleTreeTest : TestDependencyInjectionBase() {
outputs = testTx.outputs,
commands = testTx.commands,
notary = notary,
type = TransactionType.General,
timeWindow = timeWindow
)
}

View File

@ -40,7 +40,7 @@ class FinalityFlowTests {
@Test
fun `finalise a simple transaction`() {
val amount = Amount(1000, Issued(nodeA.info.legalIdentity.ref(0), GBP))
val builder = TransactionBuilder(TransactionType.General, notary)
val builder = TransactionBuilder(notary)
Cash().generateIssue(builder, amount, nodeB.info.legalIdentity, notary)
val stx = nodeA.services.signInitialTransaction(builder)
val flow = nodeA.services.startFlow(FinalityFlow(stx))

View File

@ -4,7 +4,6 @@ import net.corda.contracts.asset.Cash
import net.corda.core.contracts.Amount
import net.corda.core.contracts.GBP
import net.corda.core.contracts.Issued
import net.corda.core.contracts.TransactionType
import net.corda.core.getOrThrow
import net.corda.core.identity.Party
import net.corda.core.transactions.TransactionBuilder
@ -43,7 +42,7 @@ class ManualFinalityFlowTests {
@Test
fun `finalise a simple transaction`() {
val amount = Amount(1000, Issued(nodeA.info.legalIdentity.ref(0), GBP))
val builder = TransactionBuilder(TransactionType.General, notary)
val builder = TransactionBuilder(notary)
Cash().generateIssue(builder, amount, nodeB.info.legalIdentity, notary)
val stx = nodeA.services.signInitialTransaction(builder)
val flow = nodeA.services.startFlow(ManualFinalityFlow(stx, setOf(nodeC.info.legalIdentity)))

View File

@ -311,7 +311,7 @@ public class FlowCookbookJava {
progressTracker.setCurrentStep(TX_BUILDING);
// DOCSTART 19
TransactionBuilder txBuilder = new TransactionBuilder(General.INSTANCE, specificNotary);
TransactionBuilder txBuilder = new TransactionBuilder(specificNotary);
// DOCEND 19
// We add items to the transaction builder using ``TransactionBuilder.withItems``:

View File

@ -292,7 +292,7 @@ object FlowCookbook {
progressTracker.currentStep = TX_BUILDING
// DOCSTART 19
val txBuilder: TransactionBuilder = TransactionBuilder(General, specificNotary)
val txBuilder: TransactionBuilder = TransactionBuilder(specificNotary)
// DOCEND 19
// We add items to the transaction builder using ``TransactionBuilder.withItems``:

View File

@ -73,7 +73,6 @@ class WiredTransactionGenerator : Generator<WireTransaction>(WireTransaction::cl
outputs = TransactionStateGenerator(ContractStateGenerator()).generateList(random, status),
commands = commands,
notary = PartyGenerator().generate(random, status),
type = TransactionType.General,
timeWindow = TimeWindowGenerator().generate(random, status)
)
}

View File

@ -129,7 +129,6 @@ class VaultSchemaTest : TestDependencyInjectionBase() {
id,
notary,
timeWindow,
TransactionType.General,
privacySalt
)
}
@ -161,7 +160,6 @@ class VaultSchemaTest : TestDependencyInjectionBase() {
id,
notary,
timeWindow,
TransactionType.General,
privacySalt
)
}

View File

@ -210,7 +210,6 @@ class RequeryConfigurationTest : TestDependencyInjectionBase() {
outputs = emptyList(),
commands = emptyList(),
notary = DUMMY_NOTARY,
type = TransactionType.General,
timeWindow = null
)
return SignedTransaction(wtx, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))

View File

@ -148,7 +148,6 @@ class DBTransactionStorageTests : TestDependencyInjectionBase() {
outputs = emptyList(),
commands = emptyList(),
notary = DUMMY_NOTARY,
type = TransactionType.General,
timeWindow = null
)
return SignedTransaction(wtx, listOf(DigitalSignature.WithKey(NullPublicKey, ByteArray(1))))

View File

@ -458,7 +458,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() {
val amount = Amount(1000, Issued(BOC.ref(1), GBP))
// Issue then move some cash
val issueTx = TransactionBuilder(TransactionType.General, services.myInfo.legalIdentity).apply {
val issueTx = TransactionBuilder(services.myInfo.legalIdentity).apply {
Cash().generateIssue(this,
amount, anonymousIdentity.party, services.myInfo.legalIdentity)
}.toWireTransaction()
@ -468,7 +468,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() {
val expectedIssueUpdate = Vault.Update(emptySet(), setOf(cashState), null)
database.transaction {
val moveTx = TransactionBuilder(TransactionType.General, services.myInfo.legalIdentity).apply {
val moveTx = TransactionBuilder(services.myInfo.legalIdentity).apply {
service.generateSpend(this, Amount(1000, GBP), thirdPartyIdentity)
}.toWireTransaction()
service.notify(moveTx)

View File

@ -74,7 +74,6 @@ data class GeneratedLedger(
outputs,
commands.map { it.first },
null,
TransactionType.General,
null
)
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->
@ -107,7 +106,6 @@ data class GeneratedLedger(
outputs,
commands.map { it.first },
inputNotary,
TransactionType.General,
null
)
val newOutputStateAndRefs = outputs.mapIndexed { i, state ->