mirror of
https://github.com/corda/corda.git
synced 2025-06-22 09:08:49 +00:00
Made TransactionBuilder abstract. Every transaction type now needs to implement and provide its own Builder. This is required since for specific types we need to run different logic when adding new items to the transaction. For example, when adding a new input state to a transaction of type NotaryChange we need to add all of the states participants to the signers list.
This commit is contained in:
@ -8,9 +8,9 @@ import com.r3corda.contracts.testing.`with notary`
|
||||
import com.r3corda.core.bd
|
||||
import com.r3corda.core.contracts.DOLLARS
|
||||
import com.r3corda.core.contracts.Fix
|
||||
import com.r3corda.core.contracts.TransactionBuilder
|
||||
import com.r3corda.core.crypto.Party
|
||||
import com.r3corda.core.crypto.generateKeyPair
|
||||
import com.r3corda.core.contracts.TransactionType
|
||||
import com.r3corda.core.testing.ALICE_PUBKEY
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||
import com.r3corda.core.testing.MEGA_CORP
|
||||
@ -104,7 +104,7 @@ class NodeInterestRatesTest {
|
||||
val (n1, n2) = net.createTwoNodes()
|
||||
n2.interestRatesService.oracle.knownFixes = TEST_DATA
|
||||
|
||||
val tx = TransactionBuilder()
|
||||
val tx = TransactionType.General.Builder()
|
||||
val fixOf = NodeInterestRates.parseFixOf("LIBOR 2016-03-16 1M")
|
||||
val protocol = RatesFixProtocol(tx, n2.info, fixOf, "0.675".bd, "0.1".bd)
|
||||
BriefLogFormatter.initVerbose("rates")
|
||||
@ -119,5 +119,5 @@ class NodeInterestRatesTest {
|
||||
assertEquals("0.678".bd, fix.value)
|
||||
}
|
||||
|
||||
private fun makeTX() = TransactionBuilder(outputs = mutableListOf(1000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY))
|
||||
private fun makeTX() = TransactionType.General.Builder().withItems(1000.DOLLARS.CASH `issued by` DUMMY_CASH_ISSUER `owned by` ALICE_PUBKEY `with notary` DUMMY_NOTARY)
|
||||
}
|
@ -3,7 +3,7 @@ package com.r3corda.node.services
|
||||
import com.r3corda.contracts.cash.Cash
|
||||
import com.r3corda.core.contracts.`issued by`
|
||||
import com.r3corda.core.contracts.DOLLARS
|
||||
import com.r3corda.core.contracts.TransactionBuilder
|
||||
import com.r3corda.core.contracts.TransactionType
|
||||
import com.r3corda.core.contracts.USD
|
||||
import com.r3corda.core.contracts.verifyToLedgerTransaction
|
||||
import com.r3corda.core.node.ServiceHub
|
||||
@ -67,21 +67,21 @@ class NodeWalletServiceTest {
|
||||
|
||||
// A tx that sends us money.
|
||||
val freshKey = services.keyManagementService.freshKey()
|
||||
val usefulTX = TransactionBuilder().apply {
|
||||
val usefulTX = TransactionType.General.Builder().apply {
|
||||
Cash().generateIssue(this, 100.DOLLARS `issued by` MEGA_CORP.ref(1), freshKey.public, DUMMY_NOTARY)
|
||||
signWith(MEGA_CORP_KEY)
|
||||
}.toSignedTransaction()
|
||||
val myOutput = usefulTX.verifyToLedgerTransaction(MOCK_IDENTITY_SERVICE, MockStorageService().attachments).outRef<Cash.State>(0)
|
||||
|
||||
// A tx that spends our money.
|
||||
val spendTX = TransactionBuilder().apply {
|
||||
val spendTX = TransactionType.General.Builder().apply {
|
||||
Cash().generateSpend(this, 80.DOLLARS `issued by` MEGA_CORP.ref(1), BOB_PUBKEY, listOf(myOutput))
|
||||
signWith(freshKey)
|
||||
signWith(DUMMY_NOTARY_KEY)
|
||||
}.toSignedTransaction()
|
||||
|
||||
// A tx that doesn't send us anything.
|
||||
val irrelevantTX = TransactionBuilder().apply {
|
||||
val irrelevantTX = TransactionType.General.Builder().apply {
|
||||
Cash().generateIssue(this, 100.DOLLARS `issued by` MEGA_CORP.ref(1), BOB_KEY.public, DUMMY_NOTARY)
|
||||
signWith(MEGA_CORP_KEY)
|
||||
signWith(DUMMY_NOTARY_KEY)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.r3corda.node.services
|
||||
|
||||
import com.r3corda.core.contracts.TimestampCommand
|
||||
import com.r3corda.core.contracts.TransactionBuilder
|
||||
import com.r3corda.core.contracts.TransactionType
|
||||
import com.r3corda.core.seconds
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY_KEY
|
||||
@ -38,7 +38,7 @@ class NotaryServiceTests {
|
||||
|
||||
@Test fun `should sign a unique transaction with a valid timestamp`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder().withItems(inputState)
|
||||
val tx = TransactionType.General.Builder().withItems(inputState)
|
||||
tx.setTime(Instant.now(), DUMMY_NOTARY, 30.seconds)
|
||||
val wtx = tx.toWireTransaction()
|
||||
|
||||
@ -52,7 +52,7 @@ class NotaryServiceTests {
|
||||
|
||||
@Test fun `should sign a unique transaction without a timestamp`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val wtx = TransactionBuilder().withItems(inputState).toWireTransaction()
|
||||
val wtx = TransactionType.General.Builder().withItems(inputState).toWireTransaction()
|
||||
|
||||
val protocol = NotaryProtocol.Client(wtx)
|
||||
val future = clientNode.smm.add(NotaryProtocol.TOPIC, protocol)
|
||||
@ -64,7 +64,7 @@ class NotaryServiceTests {
|
||||
|
||||
@Test fun `should report error for transaction with an invalid timestamp`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder().withItems(inputState)
|
||||
val tx = TransactionType.General.Builder().withItems(inputState)
|
||||
tx.setTime(Instant.now().plusSeconds(3600), DUMMY_NOTARY, 30.seconds)
|
||||
val wtx = tx.toWireTransaction()
|
||||
|
||||
@ -79,7 +79,7 @@ class NotaryServiceTests {
|
||||
|
||||
@Test fun `should report error for transaction with more than one timestamp`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val tx = TransactionBuilder().withItems(inputState)
|
||||
val tx = TransactionType.General.Builder().withItems(inputState)
|
||||
val timestamp = TimestampCommand(Instant.now(), 30.seconds)
|
||||
tx.addCommand(timestamp, DUMMY_NOTARY.owningKey)
|
||||
tx.addCommand(timestamp, DUMMY_NOTARY.owningKey)
|
||||
@ -96,7 +96,7 @@ class NotaryServiceTests {
|
||||
|
||||
@Test fun `should report conflict for a duplicate transaction`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val wtx = TransactionBuilder().withItems(inputState).toWireTransaction()
|
||||
val wtx = TransactionType.General.Builder().withItems(inputState).toWireTransaction()
|
||||
|
||||
val firstSpend = NotaryProtocol.Client(wtx)
|
||||
val secondSpend = NotaryProtocol.Client(wtx)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.r3corda.node.services
|
||||
|
||||
import com.r3corda.core.contracts.TransactionBuilder
|
||||
import com.r3corda.core.contracts.TransactionType
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY_KEY
|
||||
import com.r3corda.node.internal.testing.MockNetwork
|
||||
@ -34,7 +34,7 @@ class ValidatingNotaryServiceTests {
|
||||
|
||||
@Test fun `should report error for invalid transaction dependency`() {
|
||||
val inputState = issueInvalidState(clientNode)
|
||||
val wtx = TransactionBuilder().withItems(inputState).toWireTransaction()
|
||||
val wtx = TransactionType.General.Builder().withItems(inputState).toWireTransaction()
|
||||
|
||||
val protocol = NotaryProtocol.Client(wtx)
|
||||
val future = clientNode.smm.add(NotaryProtocol.TOPIC, protocol)
|
||||
|
@ -1,7 +1,10 @@
|
||||
package node.services
|
||||
|
||||
import com.r3corda.contracts.DummyContract
|
||||
import com.r3corda.core.contracts.*
|
||||
import com.r3corda.core.contracts.StateAndRef
|
||||
import com.r3corda.core.contracts.StateRef
|
||||
import com.r3corda.core.contracts.TransactionState
|
||||
import com.r3corda.core.contracts.TransactionType
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY
|
||||
import com.r3corda.core.testing.DUMMY_NOTARY_KEY
|
||||
import com.r3corda.node.internal.testing.MockNetwork
|
||||
@ -52,7 +55,7 @@ class NotaryChangeTests {
|
||||
val state = TransactionState(DummyContract.MultiOwnerState(0,
|
||||
listOf(clientNodeA.info.identity.owningKey, clientNodeB.info.identity.owningKey)), DUMMY_NOTARY)
|
||||
|
||||
val tx = TransactionBuilder(type = TransactionType.NotaryChange()).withItems(state)
|
||||
val tx = TransactionType.NotaryChange.Builder().withItems(state)
|
||||
tx.signWith(clientNodeA.storage.myLegalIdentityKey)
|
||||
tx.signWith(clientNodeB.storage.myLegalIdentityKey)
|
||||
tx.signWith(DUMMY_NOTARY_KEY)
|
||||
|
Reference in New Issue
Block a user