-
Notifications
You must be signed in to change notification settings - Fork 105
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
Transaction Construction, Pt 1. @method
and compile()
#115
Changes from all commits
cf38c10
600fda7
c83487e
fb0fd03
5efc7b5
0e2efd8
e62abc3
11602fa
6448325
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,8 @@ class SimpleSnapp extends SmartContract { | |
this.x.set(x); | ||
} | ||
|
||
@method async update(y: Field) { | ||
let x = await this.x.get(); | ||
@method update(y: Field) { | ||
let x = this.x.get(); | ||
this.x.set(x.add(y)); | ||
} | ||
} | ||
|
@@ -37,6 +37,12 @@ const account2 = Local.testAccounts[1].privateKey; | |
const snappPrivKey = PrivateKey.random(); | ||
const snappPubKey = snappPrivKey.toPublicKey(); | ||
|
||
console.log('compile'); | ||
let { | ||
provers: [updateProver], | ||
} = SimpleSnapp.compile(snappPubKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should references of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's in a future PR :P |
||
|
||
console.log('deploy'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the console logs are removed in further PRs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They aren't! Are you against logging out what's happening in examples? I tend to find that helpful, especially logging the initial and final states here helps developers confirm that it's working There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's fair -- these seem okay to keep. I think we should do something more fancy in the future, but we can do that later. |
||
await Mina.transaction(account1, async () => { | ||
let snapp = new SimpleSnapp(snappPubKey); | ||
|
||
|
@@ -49,6 +55,11 @@ await Mina.transaction(account1, async () => { | |
.send() | ||
.wait(); | ||
|
||
console.log('prove'); | ||
let proof = updateProver(Field(1)); | ||
console.log({ proof }); | ||
|
||
console.log('update'); | ||
let snappState = (await Mina.getAccount(snappPubKey)).snapp.appState[0]; | ||
console.log('initial state: ' + snappState); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,3 +239,26 @@ export function circuitMain( | |
Array.from(publicIndexSet).map((i) => paramTypes[i]) | ||
); | ||
} | ||
|
||
export function toFieldsMagic(thing: any): Field[] { | ||
if (typeof thing == 'object') { | ||
if (thing.toFields) { | ||
// console.log('toFields'); | ||
return thing.toFields(); | ||
} | ||
|
||
if (Array.isArray(thing)) { | ||
// console.log('array', thing.length); | ||
return thing.map((x) => toFieldsMagic(x)).flat(); | ||
} | ||
|
||
let fields = [] as Field[]; | ||
let keys = Object.keys(thing).sort(); | ||
for (let key of keys) { | ||
// console.log({ key }); | ||
fields.push(...toFieldsMagic(thing[key])); | ||
} | ||
return fields; | ||
} | ||
return []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it less surprising for this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function isn't used right now, but being able to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accumulating the skipped data could be an option! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to remove the function instead of changing it (b80d39f), since it's unused and most likely won't be useful, because if we want to compute hash inputs we'll have to conform to the more elaborate system used in Mina. |
||
} |
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.
How will the
.get
function work synchronously? I figured that it would eventually make a network call to get the state of a contract on the chain, and that would need to be async?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 laid out here how I think it will work: #113
The only alternative I see would be to refactor Pickles so that it can handle async circuits. This would be better for users (enables them to make their methods async, which adds a lot of flexibility), but is probably much harder to implement.