Skip to content

Commit

Permalink
Merge pull request #519 from o1-labs/static-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Trivo25 committed Nov 8, 2022
2 parents 7ca1641 + d0d981a commit 11d6fa8
Show file tree
Hide file tree
Showing 25 changed files with 136,704 additions and 130,497 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- BREAKING CHANGE: `tx.send()` is now asynchronous: old: `send(): TransactionId` new: `send(): Promise<TransactionId>` and `tx.send()` now directly waits for the network response, as opposed to `tx.send().wait()`
- `Circuit.witness` can now be called outside circuits, where it will just directly return the callback result
- BREAKING CHANGE: Static methods of type `.fromString()`, `.fromNumber()` and `.fromBigInt()` on `Field`, `UInt64`, `UInt32` and `Int64` are not longer supported.

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions src/examples/rollup/wip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function main() {
})
.then(() =>
Mina.transaction(minaSender, () => {
const amount = UInt64.fromNumber(1000000000);
const amount = UInt64.from(1000000000);

return AccountUpdate.createSigned(depositorPrivkey).then((p) => {
p.body.delta = Int64.fromUnsigned(amount).neg();
Expand All @@ -408,7 +408,7 @@ function main() {
operatorsDb,
accountDb,
pendingDeposits,
UInt32.fromNumber(0)
UInt32.from(0)
);
});
}).send()
Expand Down Expand Up @@ -466,8 +466,8 @@ function main() {
})
.then(() => {
console.log('main', 7);
let rollupAmount = UInt64.fromNumber(10);
let rollupNonce = UInt32.fromNumber(0);
let rollupAmount = UInt64.from(10);
let rollupNonce = UInt32.from(0);
let rollupSender = depositorPubkey;
let rollupReceiver = depositorPubkey;
let rollupTransaction = new RollupTransaction(
Expand Down
2 changes: 1 addition & 1 deletion src/examples/simple_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SimpleZkapp extends SmartContract {
editState: Permissions.proofOrSignature(),
send: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
this.x.set(initialState);
}

Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/local_events_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SimpleZkapp extends SmartContract {
editState: Permissions.proofOrSignature(),
send: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
this.x.set(initialState);
}

Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/merkle_tree/merkle_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Leaderboard extends SmartContract {
...Permissions.default(),
editState: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
this.commitment.set(initialCommitment);
}

Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/set_local_preconditions_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SimpleZkapp extends SmartContract {
editState: Permissions.proofOrSignature(),
send: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
}

@method blockheightEquals(y: UInt32) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/simple_and_counter_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SimpleZkapp extends SmartContract {
editState: Permissions.proofOrSignature(),
send: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
this.x.set(initialState);
}

Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/simple_zkapp_payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SendMINAExample extends SmartContract {
editState: Permissions.proofOrSignature(),
editSequenceState: Permissions.proofOrSignature(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
}

@method sendMINA(receiverAddress: PublicKey, amount: UInt64) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/zkapps/token_with_proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TokenContract extends SmartContract {
...Permissions.default(),
send: Permissions.proof(),
});
this.balance.addInPlace(UInt64.fromNumber(initialBalance));
this.balance.addInPlace(UInt64.from(initialBalance));
}

@method tokenDeploy(deployer: PrivateKey, verificationKey: VerificationKey) {
Expand Down
7 changes: 1 addition & 6 deletions src/examples/zkapps/voting/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ export class Member extends CircuitValue {

static from(publicKey: PublicKey, tokenId: Field, balance: UInt64) {
this.count++;
return new Member(
publicKey,
tokenId,
balance,
Field.fromNumber(this.count)
);
return new Member(publicKey, tokenId, balance, Field(this.count));
}
}
2 changes: 1 addition & 1 deletion src/examples/zkapps/voting/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function testSet(

AccountUpdate.setValue(vkUpdate.update.verificationKey, {
...verificationKey,
hash: Field.fromString(verificationKey.hash),
hash: Field(verificationKey.hash),
});
},
verificationKeySet.feePayer
Expand Down
8 changes: 4 additions & 4 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,12 @@ function ignore<T>(dummy: T): OrIgnore<T> {
/**
* Ranges between all uint32 values
*/
const uint32 = () => ({ lower: UInt32.fromNumber(0), upper: UInt32.MAXINT() });
const uint32 = () => ({ lower: UInt32.from(0), upper: UInt32.MAXINT() });

/**
* Ranges between all uint64 values
*/
const uint64 = () => ({ lower: UInt64.fromNumber(0), upper: UInt64.MAXINT() });
const uint64 = () => ({ lower: UInt64.from(0), upper: UInt64.MAXINT() });

type AccountPrecondition = Preconditions['account'];
const AccountPrecondition = {
Expand Down Expand Up @@ -862,7 +862,7 @@ class AccountUpdate implements Types.AccountUpdate {
* ```ts
* \@method onlyRunsWhenBalanceIsLow() {
* let lower = UInt64.zero;
* let upper = UInt64.fromNumber(20e9);
* let upper = UInt64.from(20e9);
* AccountUpdate.assertBetween(this.self.body.preconditions.account.balance, lower, upper);
* // ...
* }
Expand Down Expand Up @@ -1078,7 +1078,7 @@ class AccountUpdate implements Types.AccountUpdate {
let amount =
initialBalance instanceof UInt64
? initialBalance
: UInt64.fromString(`${initialBalance}`);
: UInt64.from(`${initialBalance}`);
accountUpdate.balance.subInPlace(amount.add(Mina.accountCreationFee()));
}

Expand Down
20 changes: 10 additions & 10 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ function parseFetchedAccount({
return {
publicKey:
publicKey !== undefined ? PublicKey.fromBase58(publicKey) : undefined,
nonce: nonce !== undefined ? UInt32.fromString(nonce) : undefined,
balance: balance && UInt64.fromString(balance.total),
nonce: nonce !== undefined ? UInt32.from(nonce) : undefined,
balance: balance && UInt64.from(balance.total),
appState: (zkappState && zkappState.map(Field)) ?? undefined,
permissions:
permissions &&
Expand Down Expand Up @@ -497,13 +497,13 @@ function parseFetchedBlock({
return {
snarkedLedgerHash: Encoding.LedgerHash.fromBase58(snarkedLedgerHash),
// TODO: use date or utcDate?
timestamp: UInt64.fromString(utcDate),
blockchainLength: UInt32.fromString(blockHeight),
minWindowDensity: UInt32.fromString(minWindowDensity),
totalCurrency: UInt64.fromString(totalCurrency),
timestamp: UInt64.from(utcDate),
blockchainLength: UInt32.from(blockHeight),
minWindowDensity: UInt32.from(minWindowDensity),
totalCurrency: UInt64.from(totalCurrency),
// is this really `slot`?
globalSlotSinceHardFork: UInt32.fromString(slot),
globalSlotSinceGenesis: UInt32.fromString(slotSinceGenesis),
globalSlotSinceHardFork: UInt32.from(slot),
globalSlotSinceGenesis: UInt32.from(slotSinceGenesis),
nextEpochData: parseEpochData(nextEpochData),
stakingEpochData: parseEpochData(stakingEpochData),
};
Expand All @@ -519,12 +519,12 @@ function parseEpochData({
return {
ledger: {
hash: Encoding.LedgerHash.fromBase58(hash),
totalCurrency: UInt64.fromString(totalCurrency),
totalCurrency: UInt64.from(totalCurrency),
},
seed: Encoding.EpochSeed.fromBase58(seed),
startCheckpoint: Encoding.StateHash.fromBase58(startCheckpoint),
lockCheckpoint: Encoding.StateHash.fromBase58(lockCheckpoint),
epochLength: UInt32.fromString(epochLength),
epochLength: UInt32.from(epochLength),
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ describe('Field constructor', () => {
it('handles small numbers', () => {
expect(Field(5).toString()).toEqual('5');
expect(Field(1313).toString()).toEqual('1313');
expect(Field.fromNumber(5).toString()).toEqual('5');
expect(Field(5).toString()).toEqual('5');
});

it('handles large numbers 2^31 <= x < 2^53', () => {
expect(Field(2 ** 31).toString()).toEqual('2147483648');
expect(Field(Number.MAX_SAFE_INTEGER).toString()).toEqual(
String(Number.MAX_SAFE_INTEGER)
);
expect(Field.fromNumber(2 ** 31).toString()).toEqual('2147483648');
expect(Field(2 ** 31).toString()).toEqual('2147483648');
});

it('handles negative numbers', () => {
expect(Field(-1)).toEqual(Field(1).neg());
expect(Field(-(2 ** 31))).toEqual(Field(2 ** 31).neg());
expect(Field.fromNumber(-1)).toEqual(Field(1).neg());
expect(Field(-1)).toEqual(Field(1).neg());
});

it('throws on fractional numbers', () => {
expect(() => Field(0.5)).toThrow();
expect(() => Field(-1.1)).toThrow();
expect(() => Field.fromNumber(0.5)).toThrow();
expect(() => Field(0.5)).toThrow();
});

// Field(bigint), Field.fromBigInt, toBigInt

it('handles bigints', () => {
expect(Field(-1n)).toEqual(Field(1).neg());
expect(Field.fromBigInt(-1n)).toEqual(Field.fromNumber(-1));
expect(Field(-1n)).toEqual(Field(-1));
expect(Field(Field.ORDER - 1n)).toEqual(Field(1).neg());
expect(Field(1n << 64n).toString()).toEqual('18446744073709551616');
expect(Field.fromBigInt(1n << 64n)).toEqual(Field('18446744073709551616'));
expect(Field(1n << 64n)).toEqual(Field('18446744073709551616'));
});

// TODO Field(string), Field(boolean), Field(otherField)
Expand Down
Loading

0 comments on commit 11d6fa8

Please sign in to comment.