Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AnonymousParty superclass of Party #215

Merged
merged 1 commit into from Feb 9, 2017
Merged

Conversation

rnicoll
Copy link

@rnicoll rnicoll commented Feb 3, 2017

Add AnonymousParty superclass of Party in preparation for anonymising parties stored in
contract states.

This is a redesign of the work for #100, although there are further PRs to complete the work. I'm trying to break it into more manageable chunks this time.

@rnicoll rnicoll added this to the M9 milestone Feb 3, 2017
Copy link
Contributor

@mikehearn mikehearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good: a much smaller change. Reading it, I wondered if AnonymousParty is the right name. It's the obvious one to choose for sure, but sometimes it seems to imply that the party in question must be anonymous or is perhaps choosing to be anonymous, whereas what we really want to communicate is that the identity doesn't matter. I'm not sure what is better though. UnnamedParty? Sounds like a placeholder where any party could be put. Perhaps AnonymousParty is the best we can do.

import java.security.PublicKey

/**
* The [Party] class represents an entity on the network, which is typically identified by a legal [name] and public key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kdoc comment needs to be updated for the move, and Party needs to still have a kdoc comment as well.

@@ -23,3 +26,6 @@ interface IdentityService {
fun partyFromKey(key: CompositeKey): Party?
fun partyFromName(name: String): Party?
}

fun IdentityService.deanonymiseParty(party: AnonymousParty) = partyFromKey(party.owningKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these extension functions? Is the goal to give these functions better names? If so, let's just add the new names and deprecate the old ones.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're just nice helper methods to hide the referencing of fields inside the anonymous party. Mostly named differently because I wanted to avoid partyFromParty()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that extension functions aren't really ideal for Java users. You could also just put these in the interface itself, I think. Or add an extension to the Party class:

fun AnonymousParty.deanonymise(service: IdentityService): Party

That would probably make more sense.


Identities of parties involved in signing a transaction can be represented simply by a ``CompositeKey``, or by further
Identities of parties involved in signing a transaction can be represented simply by a ``AnonymousParty``, or by further
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This second paragraph is now a little bit duplicative with the prior: you could just lead on with something like "If, on the other hand, a verified identity is required, use the Party class".

@@ -3,13 +3,12 @@ Release notes

Here are brief summaries of what's changed between each snapshot release.

Milestone 8
Milestone 9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh? The section below this one is Milestone 7. Is the assumption that you'll rebase this onto the M8 release notes before merge?

@rnicoll rnicoll force-pushed the rnicoll-state-party-2 branch 2 times, most recently from f852531 to c165420 Compare February 6, 2017 18:35
@rnicoll
Copy link
Author

rnicoll commented Feb 7, 2017

That should be ready for re-review @mikehearn

Copy link
Contributor

@mikehearn mikehearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The only remaining niggle is the extension functions. If we put the methods in the interfaces, then at some point the Kotlin compiler will start emitting Java 8 bytecode that Java understands as default methods in interfaces too, I think. At any rate, for core APIs let's try and avoid extension functions which show up as static utility methods to Java users.

constructor(owningKey: PublicKey) : this(owningKey.composite)

/** Anonymised parties do not include any detail apart from owning key, so equality is dependent solely on the key */
override fun equals(other: Any?): Boolean = other is Party && this.owningKey == other.owningKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is Party here correct? Surely should be AnonymousParty ? With the current code no two AnonymousParty would ever be equal. e.g. Can't use them in a HashMap.

@@ -23,3 +26,6 @@ interface IdentityService {
fun partyFromKey(key: CompositeKey): Party?
fun partyFromName(name: String): Party?
}

fun IdentityService.deanonymiseParty(party: AnonymousParty) = partyFromKey(party.owningKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check if the party is a Party and do no work if so?

@rnicoll
Copy link
Author

rnicoll commented Feb 7, 2017

@rick-r3 I've changed the equality method (good catch), and had it check for the type being 'Party' and return as-is in that case.

I've also renamed the function to better fit the naming scheme used, and avoided an extension method based on Mike's feedback.

@mikehearn
Copy link
Contributor

Probably we should have a few unit tests that would have caught what Rick just spotted! Can you add some?

@rnicoll
Copy link
Author

rnicoll commented Feb 7, 2017

Tests added

@rnicoll
Copy link
Author

rnicoll commented Feb 8, 2017

Rebased to keep up to date with master. Could I get a review please @rick-r3 so I can get this merged before anything more changes? :)

Copy link
Contributor

@rick-r3 rick-r3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See minor comment. Is everyone (mostly) happy this is the direction?


/** Anonymised parties do not include any detail apart from owning key, so equality is dependent solely on the key */
override fun equals(other: Any?): Boolean = other is Party && this.owningKey == other.owningKey
override fun hashCode(): Int = owningKey.hashCode()
override fun toString() = name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. We should include the pub key in toString as well, or incorporate super.toString() in some way, since that is what AnonymousParty does. Or does it break some tests / expectations somewhere? Thinking maybe the JSON marshalling for demos assumes what toString does... in which case maybe make it a TODO. Just thinking debugging or logging will seem weird if one shows a pub key and the other shows the text name. Makes hard to understand they represent same party.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've removed assumptions about what toString() produces, earlier. Have added a commit to make the results more predictable.

Add AnonymousParty superclass of Party in preparation for anonymising parties stored in
contract states.

Signed-off-by: Ross Nicoll <ross.nicoll@r3.com>
@rnicoll rnicoll merged commit 47d2606 into master Feb 9, 2017
@rnicoll rnicoll deleted the rnicoll-state-party-2 branch February 9, 2017 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants