From 50c3956988e9cff73cfca5001eab50efd4809abc Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 30 Nov 2015 16:51:20 +0000 Subject: [PATCH] Rename 'institution' to 'party'. ADP-39 #resolve --- src/contracts/Cash.kt | 18 +++++++++--------- src/contracts/CommercialPaper.kt | 18 +++++++++--------- src/contracts/CrowdFund.kt | 8 ++++---- src/contracts/JavaCommercialPaper.java | 6 +++--- src/core/ContractsDSL.kt | 8 ++++---- src/core/Crypto.kt | 2 +- src/core/Structures.kt | 22 +++++++++++----------- src/core/Transactions.kt | 12 ++++++------ src/core/serialization/Kryo.kt | 4 ++-- tests/contracts/CashTests.kt | 6 +++--- tests/core/testutils/TestUtils.kt | 6 +++--- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/contracts/Cash.kt b/src/contracts/Cash.kt index f4cb23569a..50a39bea48 100644 --- a/src/contracts/Cash.kt +++ b/src/contracts/Cash.kt @@ -44,10 +44,10 @@ class Cash : Contract { */ override val legalContractReference: SecureHash = SecureHash.sha256("https://www.big-book-of-banking-law.gov/cash-claims.html"); - /** A state representing a cash claim against some institution */ + /** A state representing a cash claim against some party */ data class State( /** Where the underlying currency backing this ledger entry can be found (propagated) */ - val deposit: InstitutionReference, + val deposit: PartyReference, val amount: Amount, @@ -92,14 +92,14 @@ class Cash : Contract { // If we have an issue command, perform special processing: the group is allowed to have no inputs, // and the output states must have a deposit reference owned by the signer. Note that this means // literally 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 + // to the recipient to decide if the backing party is trustworthy or not, via some // as-yet-unwritten identity service. See ADP-22 for discussion. - val outputsInstitution = outputs.map { it.deposit.institution }.singleOrNull() + val outputsInstitution = outputs.map { it.deposit.party }.singleOrNull() if (outputsInstitution != null) { requireThat { "the issue command has a nonce" by (issueCommand.value.nonce != 0L) "output deposits are owned by a command signer" by - outputs.all { issueCommand.signingInstitutions.contains(it.deposit.institution) } + outputs.all { issueCommand.signingParties.contains(it.deposit.party) } "there are no inputs in this group" by inputs.isEmpty() } continue @@ -122,11 +122,11 @@ class Cash : Contract { outputs.all { it.amount.currency == inputAmount.currency } } - val exitCommand = tx.commands.select(institution = deposit.institution).singleOrNull() + val exitCommand = tx.commands.select(party = deposit.party).singleOrNull() val amountExitingLedger = exitCommand?.value?.amount ?: Amount(0, inputAmount.currency) requireThat { - "for deposit ${deposit.reference} at issuer ${deposit.institution.name} the amounts balance" by + "for deposit ${deposit.reference} at issuer ${deposit.party.name} the amounts balance" by (inputAmount == outputAmount + amountExitingLedger) } @@ -144,11 +144,11 @@ class Cash : Contract { /** * Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey. */ - fun craftIssue(tx: PartialTransaction, amount: Amount, at: InstitutionReference, owner: PublicKey) { + fun craftIssue(tx: PartialTransaction, amount: Amount, at: PartyReference, owner: PublicKey) { check(tx.inputStates().isEmpty()) check(tx.outputStates().sumCashOrNull() == null) tx.addOutputState(Cash.State(at, amount, owner)) - tx.addArg(WireCommand(Cash.Commands.Issue(), listOf(at.institution.owningKey))) + tx.addArg(WireCommand(Cash.Commands.Issue(), listOf(at.party.owningKey))) } /** diff --git a/src/contracts/CommercialPaper.kt b/src/contracts/CommercialPaper.kt index abb7e31813..fde3c9d92c 100644 --- a/src/contracts/CommercialPaper.kt +++ b/src/contracts/CommercialPaper.kt @@ -33,10 +33,10 @@ class CommercialPaper : Contract { override val legalContractReference: SecureHash = SecureHash.sha256("https://en.wikipedia.org/wiki/Commercial_paper") data class State( - val issuance: InstitutionReference, - val owner: PublicKey, - val faceValue: Amount, - val maturityDate: Instant + val issuance: PartyReference, + val owner: PublicKey, + val faceValue: Amount, + val maturityDate: Instant ) : ContractState { override val programRef = CP_PROGRAM_ID @@ -88,7 +88,7 @@ class CommercialPaper : Contract { requireThat { // Don't allow people to issue commercial paper under other entities identities. "the issuance is signed by the claimed issuer of the paper" by - (command.signers.contains(output.issuance.institution.owningKey)) + (command.signers.contains(output.issuance.party.owningKey)) "the face value is not zero" by (output.faceValue.pennies > 0) "the maturity date is not in the past" by (time < output.maturityDate) // Don't allow an existing CP state to be replaced by this issuance. @@ -103,13 +103,13 @@ class CommercialPaper : Contract { } /** - * Returns a transaction that issues commercial paper, owned by the issuing institution's key. Does not update + * Returns a transaction that issues commercial paper, owned by the issuing parties key. Does not update * an existing transaction because you aren't able to issue multiple pieces of CP in a single transaction * at the moment: this restriction is not fundamental and may be lifted later. */ - fun craftIssue(issuance: InstitutionReference, faceValue: Amount, maturityDate: Instant): PartialTransaction { - val state = State(issuance, issuance.institution.owningKey, faceValue, maturityDate) - return PartialTransaction(state, WireCommand(Commands.Issue(), issuance.institution.owningKey)) + fun craftIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): PartialTransaction { + val state = State(issuance, issuance.party.owningKey, faceValue, maturityDate) + return PartialTransaction(state, WireCommand(Commands.Issue(), issuance.party.owningKey)) } /** diff --git a/src/contracts/CrowdFund.kt b/src/contracts/CrowdFund.kt index a6fc7910a4..3b69aeb508 100644 --- a/src/contracts/CrowdFund.kt +++ b/src/contracts/CrowdFund.kt @@ -151,12 +151,12 @@ class CrowdFund : Contract { } /** - * Returns a transaction that registers a crowd-funding campaing, owned by the issuing institution's key. Does not update + * Returns a transaction that registers a crowd-funding campaing, owned by the issuing parties key. Does not update * an existing transaction because it's not possible to register multiple campaigns in a single transaction */ - fun craftRegister(owner: InstitutionReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): PartialTransaction { - val state = State(owner = owner.institution.owningKey, fundingName = fundingName, fundingTarget = fundingTarget, closingTime = closingTime) - return PartialTransaction(state, WireCommand(CrowdFund.Commands.Register(), owner.institution.owningKey)) + fun craftRegister(owner: PartyReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): PartialTransaction { + val state = State(owner = owner.party.owningKey, fundingName = fundingName, fundingTarget = fundingTarget, closingTime = closingTime) + return PartialTransaction(state, WireCommand(CrowdFund.Commands.Register(), owner.party.owningKey)) } /** diff --git a/src/contracts/JavaCommercialPaper.java b/src/contracts/JavaCommercialPaper.java index 880ee66363..f736934e24 100644 --- a/src/contracts/JavaCommercialPaper.java +++ b/src/contracts/JavaCommercialPaper.java @@ -24,21 +24,21 @@ import static kotlin.CollectionsKt.*; */ public class JavaCommercialPaper implements Contract { public static class State implements ContractState, SerializeableWithKryo { - private InstitutionReference issuance; + private PartyReference issuance; private PublicKey owner; private Amount faceValue; private Instant maturityDate; public State() {} // For serialization - public State(InstitutionReference issuance, PublicKey owner, Amount faceValue, Instant maturityDate) { + public State(PartyReference issuance, PublicKey owner, Amount faceValue, Instant maturityDate) { this.issuance = issuance; this.owner = owner; this.faceValue = faceValue; this.maturityDate = maturityDate; } - public InstitutionReference getIssuance() { + public PartyReference getIssuance() { return issuance; } diff --git a/src/core/ContractsDSL.kt b/src/core/ContractsDSL.kt index 8262ca2165..428eb1c9b7 100644 --- a/src/core/ContractsDSL.kt +++ b/src/core/ContractsDSL.kt @@ -99,12 +99,12 @@ fun Iterable.sumOrZero(currency: Currency) = if (iterator().hasNext()) s //// Authenticated commands /////////////////////////////////////////////////////////////////////////////////////////// -/** Filters the command list by type, institution and public key all at once. */ -inline fun List>.select(signer: PublicKey? = null, institution: Institution? = null) = +/** Filters the command list by type, party and public key all at once. */ +inline fun List>.select(signer: PublicKey? = null, party: Party? = null) = filter { it.value is T }. filter { if (signer == null) true else it.signers.contains(signer) }. - filter { if (institution == null) true else it.signingInstitutions.contains(institution) }. - map { AuthenticatedObject(it.signers, it.signingInstitutions, it.value as T) } + filter { if (party == null) true else it.signingParties.contains(party) }. + map { AuthenticatedObject(it.signers, it.signingParties, it.value as T) } inline fun List>.requireSingleCommand() = try { select().single() diff --git a/src/core/Crypto.kt b/src/core/Crypto.kt index 85e4791512..e14f807f31 100644 --- a/src/core/Crypto.kt +++ b/src/core/Crypto.kt @@ -50,7 +50,7 @@ open class DigitalSignature(bits: ByteArray, val covering: Int = 0) : OpaqueByte fun verifyWithECDSA(content: ByteArray) = by.verifyWithECDSA(content, this) } - class LegallyIdentifiable(val signer: Institution, bits: ByteArray, covering: Int) : WithKey(signer.owningKey, bits, covering) + class LegallyIdentifiable(val signer: Party, bits: ByteArray, covering: Int) : WithKey(signer.owningKey, bits, covering) } diff --git a/src/core/Structures.kt b/src/core/Structures.kt index 8cd9c1b1de..8c6d3e988a 100644 --- a/src/core/Structures.kt +++ b/src/core/Structures.kt @@ -34,20 +34,20 @@ data class ContractStateRef(val txhash: SecureHash, val index: Int) : Serializea /** A StateAndRef is simply a (state, ref) pair. For instance, a wallet (which holds available assets) contains these. */ data class StateAndRef(val state: T, val ref: ContractStateRef) -/** An Institution is well known (name, pubkey) pair. In a real system this would probably be an X.509 certificate. */ -data class Institution(val name: String, val owningKey: PublicKey) : SerializeableWithKryo { +/** A [Party] is well known (name, pubkey) pair. In a real system this would probably be an X.509 certificate. */ +data class Party(val name: String, val owningKey: PublicKey) : SerializeableWithKryo { override fun toString() = name - fun ref(bytes: OpaqueBytes) = InstitutionReference(this, bytes) + fun ref(bytes: OpaqueBytes) = PartyReference(this, bytes) fun ref(vararg bytes: Byte) = ref(OpaqueBytes.of(*bytes)) } /** - * Reference to something being stored or issued by an institution e.g. in a vault or (more likely) on their normal - * ledger. The reference is intended to be encrypted so it's meaningless to anyone other than the institution. + * Reference to something being stored or issued by a party e.g. in a vault or (more likely) on their normal + * ledger. The reference is intended to be encrypted so it's meaningless to anyone other than the party. */ -data class InstitutionReference(val institution: Institution, val reference: OpaqueBytes) : SerializeableWithKryo { - override fun toString() = "${institution.name}$reference" +data class PartyReference(val party: Party, val reference: OpaqueBytes) : SerializeableWithKryo { + override fun toString() = "${party.name}$reference" } /** Marker interface for classes that represent commands */ @@ -61,10 +61,10 @@ abstract class TypeOnlyCommand : Command { /** Wraps an object that was signed by a public key, which may be a well known/recognised institutional key. */ data class AuthenticatedObject( - val signers: List, - /** If any public keys were recognised, the looked up institutions are available here */ - val signingInstitutions: List, - val value: T + val signers: List, + /** If any public keys were recognised, the looked up institutions are available here */ + val signingParties: List, + val value: T ) /** diff --git a/src/core/Transactions.kt b/src/core/Transactions.kt index b1b4bceafa..8cc3fb104d 100644 --- a/src/core/Transactions.kt +++ b/src/core/Transactions.kt @@ -34,8 +34,8 @@ import java.util.* * multiple parties. * * LedgerTransaction is derived from WireTransaction and TimestampedWireTransaction together. It is the result of - * doing some basic key lookups on WireCommand to see if any keys are from a recognised institution, thus converting - * the WireCommand objects into AuthenticatedObject. Currently we just assume a hard coded pubkey->institution + * doing some basic key lookups on WireCommand to see if any keys are from a recognised party, thus converting + * the WireCommand objects into AuthenticatedObject. Currently we just assume a hard coded pubkey->party * map. In future it'd make more sense to use a certificate scheme and so that logic would get more complex. * * All the above refer to inputs using a (txhash, output index) pair. @@ -55,9 +55,9 @@ data class WireTransaction(val inputStates: List, val commands: List) : SerializeableWithKryo { fun serializeForSignature(): ByteArray = serialize() - fun toLedgerTransaction(timestamp: Instant?, institutionKeyMap: Map, originalHash: SecureHash): LedgerTransaction { + fun toLedgerTransaction(timestamp: Instant?, partyKeyMap: Map, originalHash: SecureHash): LedgerTransaction { val authenticatedArgs = commands.map { - val institutions = it.pubkeys.mapNotNull { pk -> institutionKeyMap[pk] } + val institutions = it.pubkeys.mapNotNull { pk -> partyKeyMap[pk] } AuthenticatedObject(it.pubkeys, institutions, it.command) } return LedgerTransaction(inputStates, outputStates, authenticatedArgs, timestamp, originalHash) @@ -198,11 +198,11 @@ data class TimestampedWireTransaction( ) : SerializeableWithKryo { val transactionID: SecureHash = serialize().sha256() - fun verifyToLedgerTransaction(timestamper: TimestamperService, institutionKeyMap: Map): LedgerTransaction { + fun verifyToLedgerTransaction(timestamper: TimestamperService, partyKeyMap: Map): LedgerTransaction { val stx: SignedWireTransaction = signedWireTX.deserialize() val wtx: WireTransaction = stx.verify() val instant: Instant? = if (timestamp.size != 0) timestamper.verifyTimestamp(signedWireTX.sha256(), timestamp) else null - return wtx.toLedgerTransaction(instant, institutionKeyMap, transactionID) + return wtx.toLedgerTransaction(instant, partyKeyMap, transactionID) } } diff --git a/src/core/serialization/Kryo.kt b/src/core/serialization/Kryo.kt index 4a4d5f7429..7b1b7c1f9f 100644 --- a/src/core/serialization/Kryo.kt +++ b/src/core/serialization/Kryo.kt @@ -220,8 +220,8 @@ fun createKryo(): Kryo { // Now register platform types. registerDataClass() registerDataClass() - registerDataClass() - registerDataClass() + registerDataClass() + registerDataClass() registerDataClass() registerDataClass() registerDataClass() diff --git a/tests/contracts/CashTests.kt b/tests/contracts/CashTests.kt index 2e86f1d57d..465a6c276a 100644 --- a/tests/contracts/CashTests.kt +++ b/tests/contracts/CashTests.kt @@ -22,7 +22,7 @@ class CashTests { ) val outState = inState.copy(owner = DUMMY_PUBKEY_2) - fun Cash.State.editInstitution(institution: Institution) = copy(deposit = deposit.copy(institution = institution)) + fun Cash.State.editInstitution(party: Party) = copy(deposit = deposit.copy(party = party)) fun Cash.State.editDepositRef(ref: Byte) = copy(deposit = deposit.copy(reference = OpaqueBytes.of(ref))) @Test @@ -99,7 +99,7 @@ class CashTests { assertTrue(ptx.inputStates().isEmpty()) val s = ptx.outputStates()[0] as Cash.State assertEquals(100.DOLLARS, s.amount) - assertEquals(MINI_CORP, s.deposit.institution) + assertEquals(MINI_CORP, s.deposit.party) assertEquals(DUMMY_PUBKEY_1, s.owner) assertTrue(ptx.commands()[0].command is Cash.Commands.Issue) assertEquals(MINI_CORP_PUBKEY, ptx.commands()[0].pubkeys[0]) @@ -289,7 +289,7 @@ class CashTests { val OUR_PUBKEY_1 = DUMMY_PUBKEY_1 val THEIR_PUBKEY_1 = DUMMY_PUBKEY_2 - fun makeCash(amount: Amount, corp: Institution, depositRef: Byte = 1) = + fun makeCash(amount: Amount, corp: Party, depositRef: Byte = 1) = StateAndRef( Cash.State(corp.ref(depositRef), amount, OUR_PUBKEY_1), ContractStateRef(SecureHash.randomSHA256(), Random().nextInt(32)) diff --git a/tests/core/testutils/TestUtils.kt b/tests/core/testutils/TestUtils.kt index 377c62e3af..154d6b29c4 100644 --- a/tests/core/testutils/TestUtils.kt +++ b/tests/core/testutils/TestUtils.kt @@ -37,10 +37,10 @@ val ALICE_KEY = KeyPairGenerator.getInstance("EC").genKeyPair() val ALICE = ALICE_KEY.public val BOB_KEY = KeyPairGenerator.getInstance("EC").genKeyPair() val BOB = BOB_KEY.public -val MEGA_CORP = Institution("MegaCorp", MEGA_CORP_PUBKEY) -val MINI_CORP = Institution("MiniCorp", MINI_CORP_PUBKEY) +val MEGA_CORP = Party("MegaCorp", MEGA_CORP_PUBKEY) +val MINI_CORP = Party("MiniCorp", MINI_CORP_PUBKEY) -val TEST_KEYS_TO_CORP_MAP: Map = mapOf( +val TEST_KEYS_TO_CORP_MAP: Map = mapOf( MEGA_CORP_PUBKEY to MEGA_CORP, MINI_CORP_PUBKEY to MINI_CORP )