Minor: Rename args to commands for consistency

This commit is contained in:
Mike Hearn 2015-11-17 13:08:18 +01:00
parent 5e604a5b0a
commit fa1c6cb01b
6 changed files with 32 additions and 32 deletions

View File

@ -78,7 +78,7 @@ object Cash : Contract {
// anyone with access to the network can issue cash claims of arbitrary amounts! It is up to the recipient
// to decide if the backing institution is trustworthy or not, via some as-yet-unwritten identity service.
// See ADP-22 for discussion.
val issueCommand = args.select<Commands.Issue>().singleOrNull()
val issueCommand = commands.select<Commands.Issue>().singleOrNull()
if (issueCommand != null) {
requireThat {
"the issue command has a nonce" by (issueCommand.value.nonce != 0L)
@ -113,7 +113,7 @@ object Cash : Contract {
val inputAmount = inputs.map { it.amount }.sumOrThrow()
val outputAmount = outputs.map { it.amount }.sumOrZero(currency)
val issuerCommand = args.select<Commands.Exit>(institution = deposit.institution).singleOrNull()
val issuerCommand = commands.select<Commands.Exit>(institution = deposit.institution).singleOrNull()
val amountExitingLedger = issuerCommand?.value?.amount ?: Amount(0, inputAmount.currency)
requireThat {
@ -127,7 +127,7 @@ object Cash : Contract {
// see a signature from each of those keys. The actual signatures have been verified against the transaction
// data by the platform before execution.
val owningPubKeys = cashInputs.map { it.owner }.toSortedSet()
val keysThatSigned = args.requireSingleCommand<Commands.Move>().signers.toSortedSet()
val keysThatSigned = commands.requireSingleCommand<Commands.Move>().signers.toSortedSet()
requireThat {
"the owning keys are the same as the signing keys" by (owningPubKeys == keysThatSigned)
}

View File

@ -47,7 +47,7 @@ object CommercialPaper : Contract {
with(tx) {
// There are two possible things that can be done with CP. The first is trading it. The second is redeeming it
// for cash on or after the maturity date.
val command = args.requireSingleCommand<CommercialPaper.Commands>()
val command = commands.requireSingleCommand<CommercialPaper.Commands>()
// For now do not allow multiple pieces of CP to trade in a single transaction. Study this more!
val input = inStates.filterIsInstance<CommercialPaper.State>().single()

View File

@ -71,7 +71,7 @@ public class JavaCommercialPaper implements Contract {
// for cash on or after the maturity date.
// Find the command that instructs us what to do and check there's exactly one.
AuthenticatedObject<Command> cmd = requireSingleCommand(tx.getArgs(), Commands.class);
AuthenticatedObject<Command> cmd = requireSingleCommand(tx.getCommands(), Commands.class);
// For now do not allow multiple pieces of CP to trade in a single transaction. Study this more!
State input = single(filterIsInstance(tx.getInStates(), State.class));

View File

@ -46,11 +46,11 @@ data class WireCommand(val command: Command, val pubkeys: List<PublicKey>) : Ser
/** Transaction ready for serialisation, without any signatures attached. */
data class WireTransaction(val inputStates: List<ContractStateRef>,
val outputStates: List<ContractState>,
val args: List<WireCommand>) : SerializeableWithKryo {
val commands: List<WireCommand>) : SerializeableWithKryo {
val hash: SecureHash get() = SecureHash.sha256(serialize())
fun toLedgerTransaction(timestamp: Instant, institutionKeyMap: Map<PublicKey, Institution>): LedgerTransaction {
val authenticatedArgs = args.map {
val authenticatedArgs = commands.map {
val institutions = it.pubkeys.mapNotNull { pk -> institutionKeyMap[pk] }
AuthenticatedObject(it.pubkeys, institutions, it.command)
}
@ -61,7 +61,7 @@ data class WireTransaction(val inputStates: List<ContractStateRef>,
/** A mutable transaction that's in the process of being built, before all signatures are present. */
class PartialTransaction(private val inputStates: MutableList<ContractStateRef> = arrayListOf(),
private val outputStates: MutableList<ContractState> = arrayListOf(),
private val args: MutableList<WireCommand> = arrayListOf()) {
private val commands: MutableList<WireCommand> = arrayListOf()) {
/** A more convenient constructor that sorts things into the right lists for you */
constructor(vararg things: Any) : this() {
@ -69,7 +69,7 @@ class PartialTransaction(private val inputStates: MutableList<ContractStateRef>
when (t) {
is ContractStateRef -> inputStates.add(t)
is ContractState -> outputStates.add(t)
is WireCommand -> args.add(t)
is WireCommand -> commands.add(t)
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
}
}
@ -80,15 +80,15 @@ class PartialTransaction(private val inputStates: MutableList<ContractStateRef>
fun signWith(key: KeyPair) {
check(currentSigs.none { it.by == key.public }) { "This partial transaction was already signed by ${key.public}" }
check(args.count { it.pubkeys.contains(key.public) } > 0) { "Trying to sign with a key that isn't in any command" }
check(commands.count { it.pubkeys.contains(key.public) } > 0) { "Trying to sign with a key that isn't in any command" }
val bits = toWireTransaction().serialize()
currentSigs.add(key.private.signWithECDSA(bits, key.public))
}
fun toWireTransaction() = WireTransaction(inputStates, outputStates, args)
fun toWireTransaction() = WireTransaction(inputStates, outputStates, commands)
fun toSignedTransaction(): SignedWireTransaction {
val requiredKeys = args.flatMap { it.pubkeys }.toSet()
val requiredKeys = commands.flatMap { it.pubkeys }.toSet()
val gotKeys = currentSigs.map { it.by }.toSet()
check(gotKeys == requiredKeys) { "The set of required signatures isn't equal to the signatures we've got" }
return SignedWireTransaction(toWireTransaction().serialize(), ArrayList(currentSigs))
@ -106,13 +106,13 @@ class PartialTransaction(private val inputStates: MutableList<ContractStateRef>
fun addArg(arg: WireCommand) {
check(currentSigs.isEmpty())
args.add(arg)
commands.add(arg)
}
// Accessors that yield immutable snapshots.
fun inputStates(): List<ContractStateRef> = ArrayList(inputStates)
fun outputStates(): List<ContractState> = ArrayList(outputStates)
fun args(): List<WireCommand> = ArrayList(args)
fun commands(): List<WireCommand> = ArrayList(commands)
}
@ -144,7 +144,7 @@ data class SignedWireTransaction(val txBits: ByteArray, val sigs: List<DigitalSi
val wtx = txBits.deserialize<WireTransaction>()
// Verify that every command key was in the set that we just verified: there should be no commands that were
// unverified.
val cmdKeys = wtx.args.flatMap { it.pubkeys }.toSet()
val cmdKeys = wtx.commands.flatMap { it.pubkeys }.toSet()
val sigKeys = sigs.map { it.by }.toSet()
if (cmdKeys != sigKeys)
throw SignatureException("Command keys don't match the signatures: $cmdKeys vs $sigKeys")
@ -176,7 +176,7 @@ class LedgerTransaction(
/** The states that will be generated by the execution of this transaction. */
val outputStates: List<ContractState>,
/** Arbitrary data passed to the program of each input state. */
val args: List<AuthenticatedObject<Command>>,
val commands: List<AuthenticatedObject<Command>>,
/** The moment the transaction was timestamped for */
val time: Instant
// TODO: nLockTime equivalent?
@ -185,7 +185,7 @@ class LedgerTransaction(
/** A transaction in fully resolved and sig-checked form, ready for passing as input to a verification function. */
class TransactionForVerification(val inStates: List<ContractState>,
val outStates: List<ContractState>,
val args: List<AuthenticatedObject<Command>>,
val commands: List<AuthenticatedObject<Command>>,
val time: Instant) {
fun verify(programMap: Map<SecureHash, Contract>) {

View File

@ -96,8 +96,8 @@ class CashTests {
assertEquals(100.DOLLARS, s.amount)
assertEquals(MINI_CORP, s.deposit.institution)
assertEquals(DUMMY_PUBKEY_1, s.owner)
assertTrue(ptx.args()[0].command is Cash.Commands.Issue)
assertEquals(MINI_CORP_KEY, ptx.args()[0].pubkeys[0])
assertTrue(ptx.commands()[0].command is Cash.Commands.Issue)
assertEquals(MINI_CORP_KEY, ptx.commands()[0].pubkeys[0])
}
@Test
@ -292,7 +292,7 @@ class CashTests {
val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1)
assertEquals(WALLET[0].ref, wtx.inputStates[0])
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[0])
assertEquals(OUR_PUBKEY_1, wtx.args[0].pubkeys[0])
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
}
@Test
@ -301,7 +301,7 @@ class CashTests {
assertEquals(WALLET[0].ref, wtx.inputStates[0])
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputStates[0])
assertEquals(WALLET[0].state.copy(amount = 90.DOLLARS), wtx.outputStates[1])
assertEquals(OUR_PUBKEY_1, wtx.args[0].pubkeys[0])
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
}
@Test
@ -310,7 +310,7 @@ class CashTests {
assertEquals(WALLET[0].ref, wtx.inputStates[0])
assertEquals(WALLET[1].ref, wtx.inputStates[1])
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputStates[0])
assertEquals(OUR_PUBKEY_1, wtx.args[0].pubkeys[0])
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
}
@Test
@ -321,7 +321,7 @@ class CashTests {
assertEquals(WALLET[2].ref, wtx.inputStates[2])
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 500.DOLLARS), wtx.outputStates[0])
assertEquals(WALLET[2].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[1])
assertEquals(OUR_PUBKEY_1, wtx.args[0].pubkeys[0])
assertEquals(OUR_PUBKEY_1, wtx.commands[0].pubkeys[0])
}
@Test

View File

@ -67,22 +67,22 @@ class TransactionForTest() {
override fun hashCode(): Int = state.hashCode()
}
private val outStates = arrayListOf<LabeledOutput>()
private val args: MutableList<AuthenticatedObject<Command>> = arrayListOf()
private val commands: MutableList<AuthenticatedObject<Command>> = arrayListOf()
constructor(inStates: List<ContractState>, outStates: List<ContractState>, args: List<AuthenticatedObject<Command>>) : this() {
constructor(inStates: List<ContractState>, outStates: List<ContractState>, commands: List<AuthenticatedObject<Command>>) : this() {
this.inStates.addAll(inStates)
this.outStates.addAll(outStates.map { LabeledOutput(null, it) })
this.args.addAll(args)
this.commands.addAll(commands)
}
fun input(s: () -> ContractState) = inStates.add(s())
fun output(label: String? = null, s: () -> ContractState) = outStates.add(LabeledOutput(label, s()))
fun arg(vararg key: PublicKey, c: () -> Command) {
val keys = listOf(*key)
args.add(AuthenticatedObject(keys, keys.mapNotNull { TEST_KEYS_TO_CORP_MAP[it] }, c()))
commands.add(AuthenticatedObject(keys, keys.mapNotNull { TEST_KEYS_TO_CORP_MAP[it] }, c()))
}
private fun run(time: Instant) = TransactionForVerification(inStates, outStates.map { it.state }, args, time).verify(TEST_PROGRAM_MAP)
private fun run(time: Instant) = TransactionForVerification(inStates, outStates.map { it.state }, commands, time).verify(TEST_PROGRAM_MAP)
infix fun `fails requirement`(msg: String) = rejects(msg)
// which is uglier?? :)
@ -109,7 +109,7 @@ class TransactionForTest() {
val tx = TransactionForTest()
tx.inStates.addAll(inStates)
tx.outStates.addAll(outStates)
tx.args.addAll(args)
tx.commands.addAll(commands)
tx.body()
return tx
}
@ -133,16 +133,16 @@ class TransactionForTest() {
return """transaction {
inputs: $inStates
outputs: $outStates
args: $args
commands $commands
}"""
}
override fun equals(other: Any?) = this === other || (other is TransactionForTest && inStates == other.inStates && outStates == other.outStates && args == other.args)
override fun equals(other: Any?) = this === other || (other is TransactionForTest && inStates == other.inStates && outStates == other.outStates && commands == other.commands)
override fun hashCode(): Int {
var result = inStates.hashCode()
result += 31 * result + outStates.hashCode()
result += 31 * result + args.hashCode()
result += 31 * result + commands.hashCode()
return result
}
}