Skip to content

Commit 2c0efa3

Browse files
authored
Merge pull request #1598 from o1-labs/feature/remove-account
Remove Account constructor
2 parents f9286db + da1cd44 commit 2c0efa3

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3838
- Improved functionality of `MerkleList` and `MerkleListIterator` for easier traversal of `MerkleList`s. https://github.com/o1-labs/o1js/pull/1562
3939
- Simplified internal logic of reducer. https://github.com/o1-labs/o1js/pull/1577
4040
- `contract.getActions()` now returns a `MerkleList`
41+
- Add `toValue()` and `fromValue()` interface to `Provable<T>` to encode how provable types map to plain JS values https://github.com/o1-labs/o1js/pull/1271
42+
- You can now return the plain value from a `Provable.witness()` callback, and it will be transformed into the provable type
43+
- Remove `Account()` constructor which was no different from `AccountUpdate.create().account`, and export `Account` type instead. https://github.com/o1-labs/o1js/pull/1598
4144

4245
### Added
4346

src/examples/zkapps/dex/dex-with-actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class Dex extends TokenContract {
146146
*/
147147
async supplyLiquidity(dx: UInt64) {
148148
// calculate dy outside circuit
149-
let x = Account(this.address, TokenId.derive(this.tokenX)).balance.get();
150-
let y = Account(this.address, TokenId.derive(this.tokenY)).balance.get();
149+
let x = Mina.getAccount(this.address, TokenId.derive(this.tokenX)).balance;
150+
let y = Mina.getAccount(this.address, TokenId.derive(this.tokenY)).balance;
151151
if (x.value.isConstant() && x.value.equals(0).toBoolean()) {
152152
throw Error(
153153
'Cannot call `supplyLiquidity` when reserves are zero. Use `supplyLiquidityBase`.'

src/examples/zkapps/dex/dex.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,14 @@ function createDex({
126126
*/
127127
async supplyLiquidity(dx: UInt64) {
128128
// calculate dy outside circuit
129-
let x = Account(this.address, TokenId.derive(this.tokenX)).balance.get();
130-
let y = Account(this.address, TokenId.derive(this.tokenY)).balance.get();
129+
let x = Mina.getAccount(
130+
this.address,
131+
TokenId.derive(this.tokenX)
132+
).balance;
133+
let y = Mina.getAccount(
134+
this.address,
135+
TokenId.derive(this.tokenY)
136+
).balance;
131137
if (x.value.isConstant() && x.value.equals(0).toBoolean()) {
132138
throw Error(
133139
'Cannot call `supplyLiquidity` when reserves are zero. Use `supplyLiquidityBase`.'

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export {
6363
SmartContract,
6464
method,
6565
declareMethods,
66-
Account,
6766
Reducer,
6867
} from './lib/mina/zkapp.js';
6968
export { state, State, declareState } from './lib/mina/state.js';
@@ -80,6 +79,7 @@ export {
8079
} from './lib/proof-system/zkprogram.js';
8180
export { Cache, CacheHeader } from './lib/proof-system/cache.js';
8281

82+
export { Account } from './lib/mina/account.js';
8383
export {
8484
TokenId,
8585
AccountUpdate,

src/lib/mina/zkapp.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import { ProvablePure } from '../provable/types/provable-intf.js';
7777
import { MerkleList } from '../provable/merkle-list.js';
7878

7979
// external API
80-
export { SmartContract, method, DeployArgs, declareMethods, Account, Reducer };
80+
export { SmartContract, method, DeployArgs, declareMethods, Reducer };
8181

8282
const reservedPropNames = new Set(['_methods', '_']);
8383
type AsyncFunction = (...args: any) => Promise<any>;
@@ -1478,14 +1478,6 @@ type DeployArgs =
14781478
| { verificationKey?: { data: string; hash: string | Field } }
14791479
| undefined;
14801480

1481-
function Account(address: PublicKey, tokenId?: Field) {
1482-
if (smartContractContext.get()) {
1483-
return AccountUpdate.create(address, tokenId).account;
1484-
} else {
1485-
return AccountUpdate.defaultAccountUpdate(address, tokenId).account;
1486-
}
1487-
}
1488-
14891481
// alternative API which can replace decorators, works in pure JS
14901482

14911483
/**

0 commit comments

Comments
 (0)