Rename 'institution' to 'party'.

ADP-39 #resolve
This commit is contained in:
Mike Hearn 2015-11-30 16:51:20 +00:00
parent 52288bede1
commit 50c3956988
11 changed files with 55 additions and 55 deletions

View File

@ -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<Commands.Exit>(institution = deposit.institution).singleOrNull()
val exitCommand = tx.commands.select<Commands.Exit>(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)))
}
/**

View File

@ -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))
}
/**

View File

@ -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))
}
/**

View File

@ -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;
}

View File

@ -99,12 +99,12 @@ fun Iterable<Amount>.sumOrZero(currency: Currency) = if (iterator().hasNext()) s
//// Authenticated commands ///////////////////////////////////////////////////////////////////////////////////////////
/** Filters the command list by type, institution and public key all at once. */
inline fun <reified T : Command> List<AuthenticatedObject<Command>>.select(signer: PublicKey? = null, institution: Institution? = null) =
/** Filters the command list by type, party and public key all at once. */
inline fun <reified T : Command> List<AuthenticatedObject<Command>>.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<T>(it.signers, it.signingInstitutions, it.value as T) }
filter { if (party == null) true else it.signingParties.contains(party) }.
map { AuthenticatedObject<T>(it.signers, it.signingParties, it.value as T) }
inline fun <reified T : Command> List<AuthenticatedObject<Command>>.requireSingleCommand() = try {
select<T>().single()

View File

@ -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)
}

View File

@ -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<out T : ContractState>(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<out T : Any>(
val signers: List<PublicKey>,
/** If any public keys were recognised, the looked up institutions are available here */
val signingInstitutions: List<Institution>,
val value: T
val signers: List<PublicKey>,
/** If any public keys were recognised, the looked up institutions are available here */
val signingParties: List<Party>,
val value: T
)
/**

View File

@ -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<Command>. 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<Command>. 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<ContractStateRef>,
val commands: List<WireCommand>) : SerializeableWithKryo {
fun serializeForSignature(): ByteArray = serialize()
fun toLedgerTransaction(timestamp: Instant?, institutionKeyMap: Map<PublicKey, Institution>, originalHash: SecureHash): LedgerTransaction {
fun toLedgerTransaction(timestamp: Instant?, partyKeyMap: Map<PublicKey, Party>, 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<PublicKey, Institution>): LedgerTransaction {
fun verifyToLedgerTransaction(timestamper: TimestamperService, partyKeyMap: Map<PublicKey, Party>): 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)
}
}

View File

@ -220,8 +220,8 @@ fun createKryo(): Kryo {
// Now register platform types.
registerDataClass<SecureHash.SHA256>()
registerDataClass<Amount>()
registerDataClass<InstitutionReference>()
registerDataClass<Institution>()
registerDataClass<PartyReference>()
registerDataClass<Party>()
registerDataClass<OpaqueBytes>()
registerDataClass<SignedWireTransaction>()
registerDataClass<ContractStateRef>()

View File

@ -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))

View File

@ -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<PublicKey, Institution> = mapOf(
val TEST_KEYS_TO_CORP_MAP: Map<PublicKey, Party> = mapOf(
MEGA_CORP_PUBKEY to MEGA_CORP,
MINI_CORP_PUBKEY to MINI_CORP
)