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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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".
docs/source/release-notes.rst
Outdated
@@ -3,13 +3,12 @@ Release notes | |||
|
|||
Here are brief summaries of what's changed between each snapshot release. | |||
|
|||
Milestone 8 | |||
Milestone 9 |
There was a problem hiding this comment.
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?
f852531
to
c165420
Compare
That should be ready for re-review @mikehearn |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
c165420
to
b2aebde
Compare
@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. |
Probably we should have a few unit tests that would have caught what Rick just spotted! Can you add some? |
Tests added |
1f69117
to
36c8339
Compare
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? :) |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
eb90d78
to
9785cd9
Compare
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.