mirror of
https://github.com/corda/corda.git
synced 2024-12-21 05:53:23 +00:00
Minor: some more renamings for concision and consistency
This commit is contained in:
parent
6f3b07a600
commit
8d1b318370
@ -87,7 +87,7 @@ object TwoPartyTradeProtocol {
|
|||||||
val wtx: WireTransaction = partialTX.txBits.deserialize()
|
val wtx: WireTransaction = partialTX.txBits.deserialize()
|
||||||
|
|
||||||
requireThat {
|
requireThat {
|
||||||
"transaction sends us the right amount of cash" by (wtx.outputStates.sumCashBy(myKeyPair.public) == price)
|
"transaction sends us the right amount of cash" by (wtx.outputs.sumCashBy(myKeyPair.public) == price)
|
||||||
// There are all sorts of funny games a malicious secondary might play here, we should fix them:
|
// There are all sorts of funny games a malicious secondary might play here, we should fix them:
|
||||||
//
|
//
|
||||||
// - This tx may attempt to send some assets we aren't intending to sell to the secondary, if
|
// - This tx may attempt to send some assets we aren't intending to sell to the secondary, if
|
||||||
|
@ -38,8 +38,8 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
|
|||||||
|
|
||||||
val resolved = HashSet<TransactionForVerification>(transactions.size)
|
val resolved = HashSet<TransactionForVerification>(transactions.size)
|
||||||
for (tx in transactions) {
|
for (tx in transactions) {
|
||||||
val inputs = ArrayList<ContractState>(tx.inStateRefs.size)
|
val inputs = ArrayList<ContractState>(tx.inputs.size)
|
||||||
for (ref in tx.inStateRefs) {
|
for (ref in tx.inputs) {
|
||||||
val conflict = refToConsumingTXMap[ref]
|
val conflict = refToConsumingTXMap[ref]
|
||||||
if (conflict != null)
|
if (conflict != null)
|
||||||
throw TransactionConflictException(ref, tx, conflict)
|
throw TransactionConflictException(ref, tx, conflict)
|
||||||
@ -48,9 +48,9 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
|
|||||||
// Look up the connecting transaction.
|
// Look up the connecting transaction.
|
||||||
val ltx = hashToTXMap[ref.txhash]?.single() ?: throw TransactionResolutionException(ref.txhash)
|
val ltx = hashToTXMap[ref.txhash]?.single() ?: throw TransactionResolutionException(ref.txhash)
|
||||||
// Look up the output in that transaction by index.
|
// Look up the output in that transaction by index.
|
||||||
inputs.add(ltx.outStates[ref.index])
|
inputs.add(ltx.outputs[ref.index])
|
||||||
}
|
}
|
||||||
resolved.add(TransactionForVerification(inputs, tx.outStates, tx.commands, tx.hash))
|
resolved.add(TransactionForVerification(inputs, tx.outputs, tx.commands, tx.hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
for (tx in resolved)
|
for (tx in resolved)
|
||||||
|
@ -54,22 +54,22 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** Transaction ready for serialisation, without any signatures attached. */
|
/** Transaction ready for serialisation, without any signatures attached. */
|
||||||
data class WireTransaction(val inputStates: List<StateRef>,
|
data class WireTransaction(val inputs: List<StateRef>,
|
||||||
val outputStates: List<ContractState>,
|
val outputs: List<ContractState>,
|
||||||
val commands: List<Command>) {
|
val commands: List<Command>) {
|
||||||
fun toLedgerTransaction(identityService: IdentityService, originalHash: SecureHash): LedgerTransaction {
|
fun toLedgerTransaction(identityService: IdentityService, originalHash: SecureHash): LedgerTransaction {
|
||||||
val authenticatedArgs = commands.map {
|
val authenticatedArgs = commands.map {
|
||||||
val institutions = it.pubkeys.mapNotNull { pk -> identityService.partyFromKey(pk) }
|
val institutions = it.pubkeys.mapNotNull { pk -> identityService.partyFromKey(pk) }
|
||||||
AuthenticatedObject(it.pubkeys, institutions, it.data)
|
AuthenticatedObject(it.pubkeys, institutions, it.data)
|
||||||
}
|
}
|
||||||
return LedgerTransaction(inputStates, outputStates, authenticatedArgs, originalHash)
|
return LedgerTransaction(inputs, outputs, authenticatedArgs, originalHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val buf = StringBuilder()
|
val buf = StringBuilder()
|
||||||
buf.appendln("Transaction:")
|
buf.appendln("Transaction:")
|
||||||
for (input in inputStates) buf.appendln("${Emoji.rightArrow}INPUT: $input")
|
for (input in inputs) buf.appendln("${Emoji.rightArrow}INPUT: $input")
|
||||||
for (output in outputStates) buf.appendln("${Emoji.leftArrow}OUTPUT: $output")
|
for (output in outputs) buf.appendln("${Emoji.leftArrow}OUTPUT: $output")
|
||||||
for (command in commands) buf.appendln("${Emoji.diamond}COMMAND: $command")
|
for (command in commands) buf.appendln("${Emoji.diamond}COMMAND: $command")
|
||||||
return buf.toString()
|
return buf.toString()
|
||||||
}
|
}
|
||||||
@ -127,8 +127,8 @@ data class SignedWireTransaction(val txBits: SerializedBytes<WireTransaction>, v
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A mutable transaction that's in the process of being built, before all signatures are present. */
|
/** A mutable transaction that's in the process of being built, before all signatures are present. */
|
||||||
class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayListOf(),
|
class TransactionBuilder(private val inputs: MutableList<StateRef> = arrayListOf(),
|
||||||
private val outputStates: MutableList<ContractState> = arrayListOf(),
|
private val outputs: MutableList<ContractState> = arrayListOf(),
|
||||||
private val commands: MutableList<Command> = arrayListOf()) {
|
private val commands: MutableList<Command> = arrayListOf()) {
|
||||||
|
|
||||||
val time: TimestampCommand? get() = commands.mapNotNull { it.data as? TimestampCommand }.singleOrNull()
|
val time: TimestampCommand? get() = commands.mapNotNull { it.data as? TimestampCommand }.singleOrNull()
|
||||||
@ -155,8 +155,8 @@ class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayL
|
|||||||
public fun withItems(vararg items: Any): TransactionBuilder {
|
public fun withItems(vararg items: Any): TransactionBuilder {
|
||||||
for (t in items) {
|
for (t in items) {
|
||||||
when (t) {
|
when (t) {
|
||||||
is StateRef -> inputStates.add(t)
|
is StateRef -> inputs.add(t)
|
||||||
is ContractState -> outputStates.add(t)
|
is ContractState -> outputs.add(t)
|
||||||
is Command -> commands.add(t)
|
is Command -> commands.add(t)
|
||||||
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
|
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayL
|
|||||||
currentSigs.add(sig)
|
currentSigs.add(sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toWireTransaction() = WireTransaction(ArrayList(inputStates), ArrayList(outputStates), ArrayList(commands))
|
fun toWireTransaction() = WireTransaction(ArrayList(inputs), ArrayList(outputs), ArrayList(commands))
|
||||||
|
|
||||||
fun toSignedTransaction(checkSufficientSignatures: Boolean = true): SignedWireTransaction {
|
fun toSignedTransaction(checkSufficientSignatures: Boolean = true): SignedWireTransaction {
|
||||||
if (checkSufficientSignatures) {
|
if (checkSufficientSignatures) {
|
||||||
@ -229,12 +229,12 @@ class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayL
|
|||||||
|
|
||||||
fun addInputState(ref: StateRef) {
|
fun addInputState(ref: StateRef) {
|
||||||
check(currentSigs.isEmpty())
|
check(currentSigs.isEmpty())
|
||||||
inputStates.add(ref)
|
inputs.add(ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addOutputState(state: ContractState) {
|
fun addOutputState(state: ContractState) {
|
||||||
check(currentSigs.isEmpty())
|
check(currentSigs.isEmpty())
|
||||||
outputStates.add(state)
|
outputs.add(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCommand(arg: Command) {
|
fun addCommand(arg: Command) {
|
||||||
@ -248,8 +248,8 @@ class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayL
|
|||||||
fun addCommand(data: CommandData, keys: List<PublicKey>) = addCommand(Command(data, keys))
|
fun addCommand(data: CommandData, keys: List<PublicKey>) = addCommand(Command(data, keys))
|
||||||
|
|
||||||
// Accessors that yield immutable snapshots.
|
// Accessors that yield immutable snapshots.
|
||||||
fun inputStates(): List<StateRef> = ArrayList(inputStates)
|
fun inputStates(): List<StateRef> = ArrayList(inputs)
|
||||||
fun outputStates(): List<ContractState> = ArrayList(outputStates)
|
fun outputStates(): List<ContractState> = ArrayList(outputs)
|
||||||
fun commands(): List<Command> = ArrayList(commands)
|
fun commands(): List<Command> = ArrayList(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,19 +260,19 @@ class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayL
|
|||||||
*/
|
*/
|
||||||
data class LedgerTransaction(
|
data class LedgerTransaction(
|
||||||
/** The input states which will be consumed/invalidated by the execution of this transaction. */
|
/** The input states which will be consumed/invalidated by the execution of this transaction. */
|
||||||
val inStateRefs: List<StateRef>,
|
val inputs: List<StateRef>,
|
||||||
/** The states that will be generated by the execution of this transaction. */
|
/** The states that will be generated by the execution of this transaction. */
|
||||||
val outStates: List<ContractState>,
|
val outputs: List<ContractState>,
|
||||||
/** Arbitrary data passed to the program of each input state. */
|
/** Arbitrary data passed to the program of each input state. */
|
||||||
val commands: List<AuthenticatedObject<CommandData>>,
|
val commands: List<AuthenticatedObject<CommandData>>,
|
||||||
/** The hash of the original serialised SignedTransaction */
|
/** The hash of the original serialised SignedTransaction */
|
||||||
val hash: SecureHash
|
val hash: SecureHash
|
||||||
) {
|
) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T : ContractState> outRef(index: Int) = StateAndRef(outStates[index] as T, StateRef(hash, index))
|
fun <T : ContractState> outRef(index: Int) = StateAndRef(outputs[index] as T, StateRef(hash, index))
|
||||||
|
|
||||||
fun <T : ContractState> outRef(state: T): StateAndRef<T> {
|
fun <T : ContractState> outRef(state: T): StateAndRef<T> {
|
||||||
val i = outStates.indexOf(state)
|
val i = outputs.indexOf(state)
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
throw IllegalArgumentException("State not found in this transaction")
|
throw IllegalArgumentException("State not found in this transaction")
|
||||||
return outRef(i)
|
return outRef(i)
|
||||||
|
@ -60,7 +60,7 @@ class E2ETestWalletService(private val services: ServiceHub) : WalletService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val statesAndRefs = transactions.map {
|
val statesAndRefs = transactions.map {
|
||||||
StateAndRef(it.tx.outputStates[0] as OwnableState, StateRef(it.id, 0))
|
StateAndRef(it.tx.outputs[0] as OwnableState, StateRef(it.id, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.locked {
|
mutex.locked {
|
||||||
|
@ -321,8 +321,8 @@ class CashTests {
|
|||||||
@Test
|
@Test
|
||||||
fun generateSimpleDirectSpend() {
|
fun generateSimpleDirectSpend() {
|
||||||
val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputs[0])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputs[0])
|
||||||
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,29 +336,29 @@ class CashTests {
|
|||||||
@Test
|
@Test
|
||||||
fun generateSimpleSpendWithChange() {
|
fun generateSimpleSpendWithChange() {
|
||||||
val wtx = makeSpend(10.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(10.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputs[0])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputs[0])
|
||||||
assertEquals(WALLET[0].state.copy(amount = 90.DOLLARS), wtx.outputStates[1])
|
assertEquals(WALLET[0].state.copy(amount = 90.DOLLARS), wtx.outputs[1])
|
||||||
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun generateSpendWithTwoInputs() {
|
fun generateSpendWithTwoInputs() {
|
||||||
val wtx = makeSpend(500.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(500.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputs[0])
|
||||||
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
assertEquals(WALLET[1].ref, wtx.inputs[1])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputs[0])
|
||||||
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun generateSpendMixedDeposits() {
|
fun generateSpendMixedDeposits() {
|
||||||
val wtx = makeSpend(580.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(580.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputs[0])
|
||||||
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
assertEquals(WALLET[1].ref, wtx.inputs[1])
|
||||||
assertEquals(WALLET[2].ref, wtx.inputStates[2])
|
assertEquals(WALLET[2].ref, wtx.inputs[2])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputs[0])
|
||||||
assertEquals(WALLET[2].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[1])
|
assertEquals(WALLET[2].state.copy(owner = THEIR_PUBKEY_1), wtx.outputs[1])
|
||||||
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ package core.serialization
|
|||||||
import contracts.Cash
|
import contracts.Cash
|
||||||
import core.*
|
import core.*
|
||||||
import core.crypto.SecureHash
|
import core.crypto.SecureHash
|
||||||
import core.testutils.*
|
import core.testutils.DUMMY_PUBKEY_1
|
||||||
|
import core.testutils.MINI_CORP
|
||||||
|
import core.testutils.TEST_TX_TIME
|
||||||
|
import core.testutils.TestUtils
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.security.SignatureException
|
import java.security.SignatureException
|
||||||
@ -92,8 +95,8 @@ class TransactionSerializationTests {
|
|||||||
val stx = tx.toSignedTransaction()
|
val stx = tx.toSignedTransaction()
|
||||||
val ltx = stx.verifyToLedgerTransaction(MockIdentityService)
|
val ltx = stx.verifyToLedgerTransaction(MockIdentityService)
|
||||||
assertEquals(tx.commands().map { it.data }, ltx.commands.map { it.value })
|
assertEquals(tx.commands().map { it.data }, ltx.commands.map { it.value })
|
||||||
assertEquals(tx.inputStates(), ltx.inStateRefs)
|
assertEquals(tx.inputStates(), ltx.inputs)
|
||||||
assertEquals(tx.outputStates(), ltx.outStates)
|
assertEquals(tx.outputStates(), ltx.outputs)
|
||||||
assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_TIMESTAMPER.identity)!!.midpoint)
|
assertEquals(TEST_TX_TIME, ltx.commands.getTimestampBy(DUMMY_TIMESTAMPER.identity)!!.midpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,9 +34,9 @@ class GraphVisualiser(val dsl: TransactionGroupDSL<in ContractState>) {
|
|||||||
txNode.styleClass = "tx"
|
txNode.styleClass = "tx"
|
||||||
|
|
||||||
// Now create a vertex for each output state.
|
// Now create a vertex for each output state.
|
||||||
for (outIndex in tx.outStates.indices) {
|
for (outIndex in tx.outputs.indices) {
|
||||||
val node = graph.addNode<Node>(tx.outRef<ContractState>(outIndex).ref.toString())
|
val node = graph.addNode<Node>(tx.outRef<ContractState>(outIndex).ref.toString())
|
||||||
val state = tx.outStates[outIndex]
|
val state = tx.outputs[outIndex]
|
||||||
node.label = stateToLabel(state)
|
node.label = stateToLabel(state)
|
||||||
node.styleClass = stateToCSSClass(state) + ",state"
|
node.styleClass = stateToCSSClass(state) + ",state"
|
||||||
node.setAttribute("state", state)
|
node.setAttribute("state", state)
|
||||||
@ -55,7 +55,7 @@ class GraphVisualiser(val dsl: TransactionGroupDSL<in ContractState>) {
|
|||||||
}
|
}
|
||||||
// And now all states and transactions were mapped to graph nodes, hook up the input edges.
|
// And now all states and transactions were mapped to graph nodes, hook up the input edges.
|
||||||
for ((txIndex, tx) in tg.transactions.withIndex()) {
|
for ((txIndex, tx) in tg.transactions.withIndex()) {
|
||||||
for ((inputIndex, ref) in tx.inStateRefs.withIndex()) {
|
for ((inputIndex, ref) in tx.inputs.withIndex()) {
|
||||||
val edge = graph.addEdge<Edge>("tx$txIndex-in$inputIndex", ref.toString(), "tx$txIndex", true)
|
val edge = graph.addEdge<Edge>("tx$txIndex-in$inputIndex", ref.toString(), "tx$txIndex", true)
|
||||||
edge.weight = 1.2
|
edge.weight = 1.2
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user