-
Notifications
You must be signed in to change notification settings - Fork 118
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 send
API to zkApp and Party classes
#325
Conversation
0e3a3f6
to
6eb3b73
Compare
src/lib/party.ts
Outdated
@@ -670,6 +671,21 @@ class Party implements Types.Party { | |||
}; | |||
} | |||
|
|||
send({ to, amount }: Omit<SendParams, 'from'>) { | |||
let party = this; | |||
let receiverParty = Party.createUnsigned(to); |
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.
If the this
party has a non-default token id, then this method could be used to send tokens (e.g., inside the smart contract callback we give to a token contract). This would be cool functionality! However, for this to work, the receiver party must get the same token id. (The current implementation would add Mina on the receiver party but subtract tokens from the this
party, which would just make the txn fail)
So, I suggest to add the following line here:
receiverParty.body.tokenId = party.body.tokenId
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.
Another thing: We should think about whether we want to make the receiverParty the child of the sender here, by default. Otherwise, the receiver is not linked to the circuit, so I'm scared that a user would add checks on the receiver which would do nothing, and they'd have a security hole that could be exploited
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.
Ahh, that's a good point I didn't think about. When you say by default, is there a case that the receiverParty wouldn't want to be a child in this case? Seems like we would always want to link the receiver to the circuit to verify its correctness instead of inserting a constant value. :/
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.
Yeah let's do it always for now! I think it might make our lives a little harder when doing the token proofs authorization thing, but we'll figure it out then
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.
Gotcha, done! :D
src/examples/simple-zkapp-payment.ts
Outdated
@@ -0,0 +1,131 @@ | |||
import { |
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.
@MartinMinkov @mitschabaude do you have an opinion if we should be adding examples like these in the src/examples/zkapps
directory or keep them in src/examples
? I noticed apps like composability
and simple_and_counter
were added to the zkapps directory and others to examples. It's not a big deal either way as long as we are in agreement.
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.
good point, I think we'll accumulate more & more of those, so I'd add most of them to /src/examples/zkapps
and reserve /src/examples
for the most fundamental examples, to not overwhelm a user who explores these
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.
Sure thing, I'll move it over
Implements #281
Adds the
.send()
method on both the Party and zkApp classes. Additionally added a test script to verify correct behavior.