mirror of
https://github.com/corda/corda.git
synced 2024-12-19 13:08:04 +00:00
Minor: Make a few class field names and constructor layouts more consistent.
This commit is contained in:
parent
d084f76594
commit
749949669f
@ -206,7 +206,7 @@ public class JavaCommercialPaper implements Contract {
|
||||
throw new IllegalArgumentException("Failed Requirement: must be timestamped");
|
||||
Instant time = timestampCommand.getBefore();
|
||||
|
||||
Amount<Issued<Currency>> received = CashKt.sumCashBy(tx.getOutStates(), input.getOwner());
|
||||
Amount<Issued<Currency>> received = CashKt.sumCashBy(tx.getOutputs(), input.getOwner());
|
||||
|
||||
if (!received.equals(input.getFaceValue()))
|
||||
throw new IllegalStateException("Failed Requirement: received amount equals the face value: "
|
||||
|
@ -100,7 +100,7 @@ class CommercialPaper : Contract {
|
||||
// Redemption of the paper requires movement of on-ledger cash.
|
||||
is Commands.Redeem -> {
|
||||
val input = inputs.single()
|
||||
val received = tx.outStates.sumCashBy(input.owner)
|
||||
val received = tx.outputs.sumCashBy(input.owner)
|
||||
val time = timestamp?.after ?: throw IllegalArgumentException("Redemptions must be timestamped")
|
||||
requireThat {
|
||||
"the paper must have matured" by (time >= input.maturityDate)
|
||||
|
@ -8,7 +8,6 @@ import com.r3corda.core.days
|
||||
import com.r3corda.core.node.services.testing.MockStorageService
|
||||
import com.r3corda.core.seconds
|
||||
import com.r3corda.core.testing.*
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
@ -140,7 +139,7 @@ class CommercialPaperTestsGeneric {
|
||||
}
|
||||
|
||||
fun <T : ContractState> cashOutputsToWallet(vararg outputs: TransactionState<T>): Pair<LedgerTransaction, List<StateAndRef<T>>> {
|
||||
val ltx = LedgerTransaction(emptyList(), emptyList(), listOf(*outputs), emptyList(), SecureHash.randomSHA256(), emptyList(), TransactionType.General())
|
||||
val ltx = LedgerTransaction(emptyList(), listOf(*outputs), emptyList(), emptyList(), SecureHash.randomSHA256(), emptyList(), TransactionType.General())
|
||||
return Pair(ltx, outputs.mapIndexed { index, state -> StateAndRef(state, StateRef(ltx.id, index)) })
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ fun WireTransaction.toLedgerTransaction(identityService: IdentityService,
|
||||
val attachments = attachments.map {
|
||||
attachmentStorage.openAttachment(it) ?: throw FileNotFoundException(it.toString())
|
||||
}
|
||||
return LedgerTransaction(inputs, attachments, outputs, authenticatedArgs, id, signers, type)
|
||||
return LedgerTransaction(inputs, outputs, authenticatedArgs, attachments, id, signers, type)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ sealed class TransactionType {
|
||||
fun verifySigners(tx: TransactionForVerification): Set<PublicKey> {
|
||||
val timestamp = tx.commands.noneOrSingle { it.value is TimestampCommand }
|
||||
val timestampKey = timestamp?.signers.orEmpty()
|
||||
val notaryKey = (tx.inStates.map { it.notary.owningKey } + timestampKey).toSet()
|
||||
val notaryKey = (tx.inputs.map { it.notary.owningKey } + timestampKey).toSet()
|
||||
if (notaryKey.size > 1) throw TransactionVerificationException.MoreThanOneNotary(tx)
|
||||
|
||||
val requiredKeys = getRequiredSigners(tx) + notaryKey
|
||||
@ -59,7 +59,7 @@ sealed class TransactionType {
|
||||
// TODO: Check that notary is unchanged
|
||||
val ctx = tx.toTransactionForContract()
|
||||
|
||||
val contracts = (ctx.inStates.map { it.contract } + ctx.outStates.map { it.contract }).toSet()
|
||||
val contracts = (ctx.inputs.map { it.contract } + ctx.outputs.map { it.contract }).toSet()
|
||||
for (contract in contracts) {
|
||||
try {
|
||||
contract.verify(ctx)
|
||||
@ -97,7 +97,7 @@ sealed class TransactionType {
|
||||
*/
|
||||
override fun verifyTransaction(tx: TransactionForVerification) {
|
||||
try {
|
||||
tx.inStates.zip(tx.outStates).forEach {
|
||||
tx.inputs.zip(tx.outputs).forEach {
|
||||
check(it.first.data == it.second.data)
|
||||
check(it.first.notary != it.second.notary)
|
||||
}
|
||||
@ -108,7 +108,7 @@ sealed class TransactionType {
|
||||
}
|
||||
|
||||
override fun getRequiredSigners(tx: TransactionForVerification): Set<PublicKey> {
|
||||
val participantKeys = tx.inStates.flatMap { it.data.participants }.toSet()
|
||||
val participantKeys = tx.inputs.flatMap { it.data.participants }.toSet()
|
||||
return participantKeys
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
|
||||
}
|
||||
|
||||
/** A transaction in fully resolved and sig-checked form, ready for passing as input to a verification function. */
|
||||
data class TransactionForVerification(val inStates: List<TransactionState<ContractState>>,
|
||||
val outStates: List<TransactionState<ContractState>>,
|
||||
data class TransactionForVerification(val inputs: List<TransactionState<ContractState>>,
|
||||
val outputs: List<TransactionState<ContractState>>,
|
||||
val attachments: List<Attachment>,
|
||||
val commands: List<AuthenticatedObject<CommandData>>,
|
||||
val origHash: SecureHash,
|
||||
@ -73,21 +73,26 @@ data class TransactionForVerification(val inStates: List<TransactionState<Contra
|
||||
@Throws(TransactionVerificationException::class)
|
||||
fun verify() = type.verify(this)
|
||||
|
||||
fun toTransactionForContract() = TransactionForContract(inStates.map { it.data }, outStates.map { it.data }, attachments, commands, origHash)
|
||||
fun toTransactionForContract() = TransactionForContract(inputs.map { it.data }, outputs.map { it.data }, attachments, commands, origHash)
|
||||
}
|
||||
|
||||
/**
|
||||
* A transaction to be passed as input to a contract verification function. Defines helper methods to
|
||||
* simplify verification logic in contracts.
|
||||
*/
|
||||
data class TransactionForContract(val inStates: List<ContractState>,
|
||||
val outStates: List<ContractState>,
|
||||
data class TransactionForContract(val inputs: List<ContractState>,
|
||||
val outputs: List<ContractState>,
|
||||
val attachments: List<Attachment>,
|
||||
val commands: List<AuthenticatedObject<CommandData>>,
|
||||
val origHash: SecureHash) {
|
||||
override fun hashCode() = origHash.hashCode()
|
||||
override fun equals(other: Any?) = other is TransactionForContract && other.origHash == origHash
|
||||
|
||||
@Deprecated("This property was renamed to inputs", ReplaceWith("inputs"))
|
||||
val inStates: List<ContractState> get() = inputs
|
||||
@Deprecated("This property was renamed to outputs", ReplaceWith("outputs"))
|
||||
val outStates: List<ContractState> get() = outputs
|
||||
|
||||
/**
|
||||
* Given a type and a function that returns a grouping key, associates inputs and outputs together so that they
|
||||
* can be processed as one. The grouping key is any arbitrary object that can act as a map key (so must implement
|
||||
@ -103,8 +108,8 @@ data class TransactionForContract(val inStates: List<ContractState>,
|
||||
* currency field: the resulting list can then be iterated over to perform the per-currency calculation.
|
||||
*/
|
||||
fun <T : ContractState, K : Any> groupStates(ofType: Class<T>, selector: (T) -> K): List<InOutGroup<T, K>> {
|
||||
val inputs = inStates.filterIsInstance(ofType)
|
||||
val outputs = outStates.filterIsInstance(ofType)
|
||||
val inputs = inputs.filterIsInstance(ofType)
|
||||
val outputs = outputs.filterIsInstance(ofType)
|
||||
|
||||
val inGroups: Map<K, List<T>> = inputs.groupBy(selector)
|
||||
val outGroups: Map<K, List<T>> = outputs.groupBy(selector)
|
||||
@ -115,8 +120,8 @@ data class TransactionForContract(val inStates: List<ContractState>,
|
||||
|
||||
/** See the documentation for the reflection-based version of [groupStates] */
|
||||
inline fun <reified T : ContractState, K : Any> groupStates(selector: (T) -> K): List<InOutGroup<T, K>> {
|
||||
val inputs = inStates.filterIsInstance<T>()
|
||||
val outputs = outStates.filterIsInstance<T>()
|
||||
val inputs = inputs.filterIsInstance<T>()
|
||||
val outputs = outputs.filterIsInstance<T>()
|
||||
|
||||
val inGroups: Map<K, List<T>> = inputs.groupBy(selector)
|
||||
val outGroups: Map<K, List<T>> = outputs.groupBy(selector)
|
||||
|
@ -163,12 +163,12 @@ data class SignedTransaction(val txBits: SerializedBytes<WireTransaction>,
|
||||
data class LedgerTransaction(
|
||||
/** The input states which will be consumed/invalidated by the execution of this transaction. */
|
||||
val inputs: List<StateRef>,
|
||||
/** A list of [Attachment] objects identified by the transaction that are needed for this transaction to verify. */
|
||||
val attachments: List<Attachment>,
|
||||
/** The states that will be generated by the execution of this transaction. */
|
||||
val outputs: List<TransactionState<*>>,
|
||||
/** Arbitrary data passed to the program of each input state. */
|
||||
val commands: List<AuthenticatedObject<CommandData>>,
|
||||
/** A list of [Attachment] objects identified by the transaction that are needed for this transaction to verify. */
|
||||
val attachments: List<Attachment>,
|
||||
/** The hash of the original serialised WireTransaction */
|
||||
override val id: SecureHash,
|
||||
val signers: List<PublicKey>,
|
||||
|
Loading…
Reference in New Issue
Block a user