Remove type-specific transaction builder. Normal transactions should use TransactionBuilder and notary change transactions are created directly.

This commit is contained in:
Andrius Dagys
2017-07-27 13:14:08 +01:00
parent 59edd6f9ae
commit 4ca8b8d681
54 changed files with 347 additions and 375 deletions

View File

@ -3,7 +3,6 @@ package net.corda.node.services
import com.nhaarman.mockito_kotlin.whenever
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.composite.CompositeKey
import net.corda.core.internal.div
@ -13,6 +12,7 @@ import net.corda.core.flows.NotaryFlow
import net.corda.core.getOrThrow
import net.corda.core.identity.Party
import net.corda.core.node.services.ServiceInfo
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.Try
import net.corda.node.internal.AbstractNode
@ -138,8 +138,8 @@ class BFTNotaryServiceTests {
private fun AbstractNode.signInitialTransaction(
notary: Party,
makeUnique: Boolean = false,
block: TransactionType.General.Builder.() -> Any?
) = services.signInitialTransaction(TransactionType.General.Builder(notary).apply {
block: TransactionBuilder.() -> Any?
) = services.signInitialTransaction(TransactionBuilder(notary).apply {
block()
if (makeUnique) {
addAttachment(SecureHash.randomSHA256())

View File

@ -3,13 +3,13 @@ package net.corda.node.services
import com.google.common.util.concurrent.Futures
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.flows.NotaryError
import net.corda.core.flows.NotaryException
import net.corda.core.flows.NotaryFlow
import net.corda.core.getOrThrow
import net.corda.core.identity.Party
import net.corda.core.map
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.internal.AbstractNode
import net.corda.testing.DUMMY_BANK_A
import net.corda.testing.contracts.DummyContract
@ -34,13 +34,13 @@ class RaftNotaryServiceTests : NodeBasedTest() {
val inputState = issueState(bankA, notaryParty)
val firstTxBuilder = TransactionType.General.Builder(notaryParty).withItems(inputState)
val firstTxBuilder = TransactionBuilder(notaryParty).withItems(inputState)
val firstSpendTx = bankA.services.signInitialTransaction(firstTxBuilder)
val firstSpend = bankA.services.startFlow(NotaryFlow.Client(firstSpendTx))
firstSpend.resultFuture.getOrThrow()
val secondSpendBuilder = TransactionType.General.Builder(notaryParty).withItems(inputState).run {
val secondSpendBuilder = TransactionBuilder(notaryParty).withItems(inputState).run {
val dummyState = DummyContract.SingleOwnerState(0, bankA.info.legalIdentity)
addOutputState(dummyState)
this

View File

@ -137,7 +137,7 @@ class NotaryChangeTests {
val stateB = DummyContract.SingleOwnerState(Random().nextInt(), owner.party)
val stateC = DummyContract.SingleOwnerState(Random().nextInt(), owner.party)
val tx = TransactionType.General.Builder(null).apply {
val tx = TransactionBuilder(null).apply {
addCommand(Command(DummyContract.Commands.Create(), owner.party.owningKey))
addOutputState(stateA, notary, encumbrance = 2) // Encumbered by stateB
addOutputState(stateC, notary)

View File

@ -4,7 +4,6 @@ import io.requery.Persistable
import io.requery.kotlin.eq
import io.requery.sql.KotlinEntityDataStore
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.testing.NullPublicKey

View File

@ -9,6 +9,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.node.ServiceHub
import net.corda.core.node.services.VaultService
import net.corda.core.serialization.SingletonSerializeAsToken
import net.corda.core.transactions.TransactionBuilder
import net.corda.testing.ALICE_KEY
import net.corda.testing.DUMMY_CA
import net.corda.testing.DUMMY_NOTARY
@ -280,7 +281,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() {
apply {
val freshKey = services.keyManagementService.freshKey()
val state = TestState(FlowLogicRefFactoryImpl.createForRPC(TestFlowLogic::class.java, increment), instant)
val builder = TransactionType.General.Builder(null).apply {
val builder = TransactionBuilder(null).apply {
addOutputState(state, DUMMY_NOTARY)
addCommand(Command(), freshKey)
}

View File

@ -8,6 +8,7 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party
import net.corda.core.node.services.ServiceInfo
import net.corda.core.node.services.linearHeadsOfType
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.services.network.NetworkMapService
import net.corda.node.services.statemachine.StateMachineManager
import net.corda.node.services.transactions.ValidatingNotaryService
@ -57,7 +58,7 @@ class ScheduledFlowTests {
serviceHub.myInfo.legalIdentity, destination)
val notary = serviceHub.networkMapCache.getAnyNotary()
val builder = TransactionType.General.Builder(notary)
val builder = TransactionBuilder(notary)
builder.withItems(scheduledState)
val tx = serviceHub.signInitialTransaction(builder)
subFlow(FinalityFlow(tx, setOf(serviceHub.myInfo.legalIdentity)))
@ -77,7 +78,7 @@ class ScheduledFlowTests {
require(!scheduledState.processed) { "State should not have been previously processed" }
val notary = state.state.notary
val newStateOutput = scheduledState.copy(processed = true)
val builder = TransactionType.General.Builder(notary)
val builder = TransactionBuilder(notary)
builder.withItems(state, newStateOutput)
val tx = serviceHub.signInitialTransaction(builder)
subFlow(FinalityFlow(tx, setOf(scheduledState.source, scheduledState.destination)))

View File

@ -1,7 +1,6 @@
package net.corda.node.services.persistence
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.DigitalSignature
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.testing.NullPublicKey

View File

@ -4,7 +4,6 @@ import co.paralleluniverse.fibers.Suspendable
import net.corda.contracts.asset.Cash
import net.corda.core.contracts.Amount
import net.corda.core.contracts.Issued
import net.corda.core.contracts.TransactionType
import net.corda.core.contracts.USD
import net.corda.core.flows.BroadcastTransactionFlow.NotifyTxRequest
import net.corda.core.flows.FlowLogic
@ -13,6 +12,7 @@ import net.corda.core.flows.InitiatingFlow
import net.corda.core.identity.Party
import net.corda.core.node.services.unconsumedStates
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.services.NotifyTransactionHandler
import net.corda.testing.DUMMY_NOTARY
import net.corda.testing.MEGA_CORP
@ -50,7 +50,7 @@ class DataVendingServiceTests {
mockNet.runNetwork()
// Generate an issuance transaction
val ptx = TransactionType.General.Builder(null)
val ptx = TransactionBuilder(null)
Cash().generateIssue(ptx, Amount(100, Issued(deposit, USD)), beneficiary, DUMMY_NOTARY)
// Complete the cash transaction, and then manually relay it
@ -80,7 +80,7 @@ class DataVendingServiceTests {
mockNet.runNetwork()
// Generate an issuance transaction
val ptx = TransactionType.General.Builder(DUMMY_NOTARY)
val ptx = TransactionBuilder(DUMMY_NOTARY)
Cash().generateIssue(ptx, Amount(100, Issued(deposit, USD)), beneficiary, DUMMY_NOTARY)
// The transaction tries issuing MEGA_CORP cash, but we aren't the issuer, so it's invalid

View File

@ -3,7 +3,6 @@ package net.corda.node.services.transactions
import com.google.common.util.concurrent.ListenableFuture
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.DigitalSignature
import net.corda.core.flows.NotaryError
import net.corda.core.flows.NotaryException
@ -12,6 +11,7 @@ import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo
import net.corda.core.utilities.seconds
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.internal.AbstractNode
import net.corda.node.services.network.NetworkMapService
import net.corda.testing.DUMMY_NOTARY
@ -50,7 +50,7 @@ class NotaryServiceTests {
fun `should sign a unique transaction with a valid time-window`() {
val stx = run {
val inputState = issueState(clientNode)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
tx.setTimeWindow(Instant.now(), 30.seconds)
clientNode.services.signInitialTransaction(tx)
}
@ -64,7 +64,7 @@ class NotaryServiceTests {
fun `should sign a unique transaction without a time-window`() {
val stx = run {
val inputState = issueState(clientNode)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
clientNode.services.signInitialTransaction(tx)
}
@ -77,7 +77,7 @@ class NotaryServiceTests {
fun `should report error for transaction with an invalid time-window`() {
val stx = run {
val inputState = issueState(clientNode)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
tx.setTimeWindow(Instant.now().plusSeconds(3600), 30.seconds)
clientNode.services.signInitialTransaction(tx)
}
@ -92,7 +92,7 @@ class NotaryServiceTests {
fun `should sign identical transaction multiple times (signing is idempotent)`() {
val stx = run {
val inputState = issueState(clientNode)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
clientNode.services.signInitialTransaction(tx)
}
@ -110,11 +110,11 @@ class NotaryServiceTests {
fun `should report conflict when inputs are reused across transactions`() {
val inputState = issueState(clientNode)
val stx = run {
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
clientNode.services.signInitialTransaction(tx)
}
val stx2 = run {
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
tx.addInputState(issueState(clientNode))
clientNode.services.signInitialTransaction(tx)
}

View File

@ -4,7 +4,6 @@ import com.google.common.util.concurrent.ListenableFuture
import net.corda.core.contracts.Command
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionType
import net.corda.core.crypto.DigitalSignature
import net.corda.core.flows.NotaryError
import net.corda.core.flows.NotaryException
@ -12,6 +11,7 @@ import net.corda.core.flows.NotaryFlow
import net.corda.core.getOrThrow
import net.corda.core.node.services.ServiceInfo
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.internal.AbstractNode
import net.corda.node.services.issueInvalidState
import net.corda.node.services.network.NetworkMapService
@ -52,7 +52,7 @@ class ValidatingNotaryServiceTests {
fun `should report error for invalid transaction dependency`() {
val stx = run {
val inputState = issueInvalidState(clientNode, notaryNode.info.notaryIdentity)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState)
clientNode.services.signInitialTransaction(tx)
}
@ -70,7 +70,7 @@ class ValidatingNotaryServiceTests {
val inputState = issueState(clientNode)
val command = Command(DummyContract.Commands.Move(), expectedMissingKey)
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState, command)
val tx = TransactionBuilder(notaryNode.info.notaryIdentity).withItems(inputState, command)
clientNode.services.signInitialTransaction(tx)
}

View File

@ -403,7 +403,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() {
val freshKey = services.legalIdentityKey
// Issue a txn to Send us some Money
val usefulBuilder = TransactionType.General.Builder(null).apply {
val usefulBuilder = TransactionBuilder(null).apply {
Cash().generateIssue(this, 100.DOLLARS `issued by` MEGA_CORP.ref(1), AnonymousParty(freshKey), DUMMY_NOTARY)
}
val usefulTX = megaCorpServices.signInitialTransaction(usefulBuilder)
@ -416,7 +416,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() {
assertEquals(3, vaultSvc.getTransactionNotes(usefulTX.id).count())
// Issue more Money (GBP)
val anotherBuilder = TransactionType.General.Builder(null).apply {
val anotherBuilder = TransactionBuilder(null).apply {
Cash().generateIssue(this, 200.POUNDS `issued by` MEGA_CORP.ref(1), AnonymousParty(freshKey), DUMMY_NOTARY)
}
val anotherTX = megaCorpServices.signInitialTransaction(anotherBuilder)

View File

@ -10,6 +10,7 @@ import net.corda.core.node.services.VaultService
import net.corda.core.node.services.consumedStates
import net.corda.core.node.services.unconsumedStates
import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.services.database.HibernateConfiguration
import net.corda.node.services.schema.NodeSchemaService
import net.corda.node.utilities.CordaPersistence
@ -93,7 +94,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
database.transaction {
// A tx that sends us money.
val freshKey = services.keyManagementService.freshKey()
val usefulBuilder = TransactionType.General.Builder(null)
val usefulBuilder = TransactionBuilder(null)
Cash().generateIssue(usefulBuilder, 100.DOLLARS `issued by` MEGA_CORP.ref(1), AnonymousParty(freshKey), DUMMY_NOTARY)
val usefulTX = megaCorpServices.signInitialTransaction(usefulBuilder)
@ -101,7 +102,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
services.recordTransactions(usefulTX)
// A tx that spends our money.
val spendTXBuilder = TransactionType.General.Builder(DUMMY_NOTARY)
val spendTXBuilder = TransactionBuilder(DUMMY_NOTARY)
vault.generateSpend(spendTXBuilder, 80.DOLLARS, BOB)
val spendPTX = services.signInitialTransaction(spendTXBuilder, freshKey)
val spendTX = notaryServices.addSignature(spendPTX)
@ -109,7 +110,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
assertEquals(100.DOLLARS, services.getCashBalance(USD))
// A tx that doesn't send us anything.
val irrelevantBuilder = TransactionType.General.Builder(DUMMY_NOTARY)
val irrelevantBuilder = TransactionBuilder(DUMMY_NOTARY)
Cash().generateIssue(irrelevantBuilder, 100.DOLLARS `issued by` MEGA_CORP.ref(1), BOB, DUMMY_NOTARY)
val irrelevantPTX = megaCorpServices.signInitialTransaction(irrelevantBuilder)
@ -147,7 +148,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
backgroundExecutor.submit {
database.transaction {
try {
val txn1Builder = TransactionType.General.Builder(DUMMY_NOTARY)
val txn1Builder = TransactionBuilder(DUMMY_NOTARY)
vault.generateSpend(txn1Builder, 60.DOLLARS, BOB)
val ptxn1 = notaryServices.signInitialTransaction(txn1Builder)
val txn1 = services.addSignature(ptxn1, freshKey)
@ -177,7 +178,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
backgroundExecutor.submit {
database.transaction {
try {
val txn2Builder = TransactionType.General.Builder(DUMMY_NOTARY)
val txn2Builder = TransactionBuilder(DUMMY_NOTARY)
vault.generateSpend(txn2Builder, 80.DOLLARS, BOB)
val ptxn2 = notaryServices.signInitialTransaction(txn2Builder)
val txn2 = services.addSignature(ptxn2, freshKey)
@ -219,7 +220,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
val linearId = UniqueIdentifier()
// Issue a linear state
val dummyIssueBuilder = TransactionType.General.Builder(notary = DUMMY_NOTARY).apply {
val dummyIssueBuilder = TransactionBuilder(notary = DUMMY_NOTARY).apply {
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
}
@ -240,7 +241,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
val linearId = UniqueIdentifier()
// Issue a linear state
val dummyIssueBuilder = TransactionType.General.Builder(notary = DUMMY_NOTARY)
val dummyIssueBuilder = TransactionBuilder(notary = DUMMY_NOTARY)
dummyIssueBuilder.addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
val dummyIssuePtx = notaryServices.signInitialTransaction(dummyIssueBuilder)
val dummyIssue = services.addSignature(dummyIssuePtx)
@ -251,7 +252,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
assertThat(vault.unconsumedStates<DummyLinearContract.State>()).hasSize(1)
// Move the same state
val dummyMoveBuilder = TransactionType.General.Builder(notary = DUMMY_NOTARY).apply {
val dummyMoveBuilder = TransactionBuilder(notary = DUMMY_NOTARY).apply {
addOutputState(DummyLinearContract.State(linearId = linearId, participants = listOf(freshIdentity)))
addInputState(dummyIssue.tx.outRef<LinearState>(0))
}
@ -283,7 +284,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
database.transaction {
// A tx that spends our money.
val spendTXBuilder = TransactionType.General.Builder(DUMMY_NOTARY)
val spendTXBuilder = TransactionBuilder(DUMMY_NOTARY)
vault.generateSpend(spendTXBuilder, 80.DOLLARS, BOB)
val spendPTX = notaryServices.signInitialTransaction(spendTXBuilder)
val spendTX = services.addSignature(spendPTX, freshKey)
@ -313,7 +314,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() {
linearStates.forEach { println(it.state.data.linearId) }
// Create a txn consuming different contract types
val dummyMoveBuilder = TransactionType.General.Builder(notary = DUMMY_NOTARY).apply {
val dummyMoveBuilder = TransactionBuilder(notary = DUMMY_NOTARY).apply {
addOutputState(DummyLinearContract.State(participants = listOf(freshIdentity)))
addOutputState(DummyDealContract.State(ref = "999", participants = listOf(freshIdentity)))
addInputState(linearStates.first())