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

Fix deploy/init, v0.7.3 #588

Merged
merged 6 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/5f20f496...HEAD)
## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/d880bd6e...HEAD)

(no unreleased changes yet)

## [0.7.3](https://github.com/o1-labs/snarkyjs/compare/5f20f496...d880bd6e)

### Fixed

- Bug in `deploy()` when initializing a contract that already exists https://github.com/o1-labs/snarkyjs/pull/588

### Deprecated

- `Mina.BerkeleyQANet` in favor of the clearer-named `Mina.Network` https://github.com/o1-labs/snarkyjs/pull/588

## [0.7.2](https://github.com/o1-labs/snarkyjs/compare/705f58d3...5f20f496)

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snarkyjs",
"description": "JavaScript bindings for SnarkyJS",
"version": "0.7.2",
"version": "0.7.3",
"license": "Apache-2.0",
"type": "module",
"main": "./dist/web/index.js",
Expand Down
4 changes: 1 addition & 3 deletions src/examples/simple_zkapp_berkeley.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class SimpleZkapp extends SmartContract {
}

// you can use this with any spec-compliant graphql endpoint
let Berkeley = Mina.BerkeleyQANet(
'https://proxy.berkeley.minaexplorer.com/graphql'
);
let Berkeley = Mina.Network('https://proxy.berkeley.minaexplorer.com/graphql');
Mina.setActiveInstance(Berkeley);

// to use this test, change this private key to an account which has enough MINA to pay fees
Expand Down
25 changes: 20 additions & 5 deletions src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Types } from 'src/index.js';
export {
createTransaction,
BerkeleyQANet,
Network,
LocalBlockchain,
currentTransaction,
CurrentTransaction,
Expand Down Expand Up @@ -546,7 +547,10 @@ function LocalBlockchain({
};
}

function RemoteBlockchain(graphqlEndpoint: string): Mina {
/**
* Represents the Mina blockchain running on a real network
*/
function Network(graphqlEndpoint: string): Mina {
let accountCreationFee = UInt64.from(defaultAccountCreationFee);
Fetch.setGraphqlEndpoint(graphqlEndpoint);
return {
Expand Down Expand Up @@ -614,17 +618,23 @@ function RemoteBlockchain(graphqlEndpoint: string): Mina {
txn.sign();

let [response, error] = await Fetch.sendZkapp(txn.toJSON());
let errors: any[] | undefined;
if (error === undefined) {
if (response!.data === null && (response as any).errors?.length > 0) {
console.log('got graphql errors', (response as any).errors);
} else {
console.log('got graphql response', response?.data);
console.log(
'got graphql errors',
JSON.stringify((response as any).errors, null, 2)
);
errors = (response as any).errors;
}
} else {
console.log('got fetch error', error);
errors = [error];
}

return {
data: response?.data,
errors,
async wait() {
console.log(
'Info: waiting for inclusion in a block is not implemented yet.'
Expand Down Expand Up @@ -662,8 +672,13 @@ function RemoteBlockchain(graphqlEndpoint: string): Mina {
};
}

/**
*
* @deprecated This is deprecated in favor of {@link Mina.Network}, which is exactly the same function.
* The name `BerkeleyQANet` was misleading because it suggested that this is specific to a particular network.
*/
function BerkeleyQANet(graphqlEndpoint: string) {
return RemoteBlockchain(graphqlEndpoint);
return Network(graphqlEndpoint);
}

let activeInstance: Mina = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ class SmartContract {
// init if this account is not yet deployed or has no verification key on it
let shouldInit =
!Mina.hasAccount(this.address) ||
Mina.getAccount(this.address).verificationKey !== undefined;
Mina.getAccount(this.address).verificationKey === undefined;
if (!shouldInit) return;
if (zkappKey) this.init(zkappKey);
else this.init();
Expand Down