-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/lookup-runtime-tables
- Loading branch information
Showing
24 changed files
with
953 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Check Changelog for changes | ||
on: | ||
pull_request: | ||
types: [assigned, opened, synchronize, reopened, labeled, unlabeled] | ||
branches: | ||
- main | ||
jobs: | ||
Check-Changelog: | ||
name: Check Changelog Action | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: tarides/changelog-check-action@v2 | ||
with: | ||
changelog: CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule bindings
updated
12 files
+1 −1 | MINA_COMMIT | |
+70,960 −70,954 | compiled/node_bindings/o1js_node.bc.cjs | |
+1 −1 | compiled/node_bindings/o1js_node.bc.map | |
+1,417 −1,414 | compiled/node_bindings/plonk_wasm.cjs | |
+348 −348 | compiled/node_bindings/plonk_wasm.d.cts | |
+ − | compiled/node_bindings/plonk_wasm_bg.wasm | |
+416 −416 | compiled/node_bindings/plonk_wasm_bg.wasm.d.ts | |
+12 −12 | compiled/web_bindings/o1js_web.bc.js | |
+939 −939 | compiled/web_bindings/plonk_wasm.d.ts | |
+1,635 −1,634 | compiled/web_bindings/plonk_wasm.js | |
+ − | compiled/web_bindings/plonk_wasm_bg.wasm | |
+348 −348 | compiled/web_bindings/plonk_wasm_bg.wasm.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/lib/mina/actions/offchain-contract-tests/ExampleContract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
SmartContract, | ||
method, | ||
state, | ||
PublicKey, | ||
UInt64, | ||
Experimental, | ||
} from '../../../../index.js'; | ||
|
||
export { offchainState, StateProof, ExampleContract }; | ||
|
||
const { OffchainState } = Experimental; | ||
|
||
const offchainState = OffchainState( | ||
{ | ||
accounts: OffchainState.Map(PublicKey, UInt64), | ||
totalSupply: OffchainState.Field(UInt64), | ||
}, | ||
{ logTotalCapacity: 10, maxActionsPerProof: 5 } | ||
); | ||
|
||
class StateProof extends offchainState.Proof {} | ||
|
||
// example contract that interacts with offchain state | ||
class ExampleContract extends SmartContract { | ||
@state(OffchainState.Commitments) offchainStateCommitments = | ||
offchainState.emptyCommitments(); | ||
|
||
// o1js memoizes the offchain state by contract address so that this pattern works | ||
offchainState = offchainState.init(this); | ||
|
||
@method | ||
async createAccount(address: PublicKey, amountToMint: UInt64) { | ||
// setting `from` to `undefined` means that the account must not exist yet | ||
this.offchainState.fields.accounts.update(address, { | ||
from: undefined, | ||
to: amountToMint, | ||
}); | ||
|
||
// TODO using `update()` on the total supply means that this method | ||
// can only be called once every settling cycle | ||
let totalSupplyOption = await this.offchainState.fields.totalSupply.get(); | ||
let totalSupply = totalSupplyOption.orElse(0n); | ||
|
||
this.offchainState.fields.totalSupply.update({ | ||
from: totalSupplyOption, | ||
to: totalSupply.add(amountToMint), | ||
}); | ||
} | ||
|
||
@method | ||
async transfer(from: PublicKey, to: PublicKey, amount: UInt64) { | ||
let fromOption = await this.offchainState.fields.accounts.get(from); | ||
let fromBalance = fromOption.assertSome('sender account exists'); | ||
|
||
let toOption = await this.offchainState.fields.accounts.get(to); | ||
let toBalance = toOption.orElse(0n); | ||
|
||
/** | ||
* Update both accounts atomically. | ||
* | ||
* This is safe, because both updates will only be accepted if both previous balances are still correct. | ||
*/ | ||
this.offchainState.fields.accounts.update(from, { | ||
from: fromOption, | ||
to: fromBalance.sub(amount), | ||
}); | ||
|
||
this.offchainState.fields.accounts.update(to, { | ||
from: toOption, | ||
to: toBalance.add(amount), | ||
}); | ||
} | ||
|
||
@method.returns(UInt64) | ||
async getSupply() { | ||
return (await this.offchainState.fields.totalSupply.get()).orElse(0n); | ||
} | ||
|
||
@method.returns(UInt64) | ||
async getBalance(address: PublicKey) { | ||
return (await this.offchainState.fields.accounts.get(address)).orElse(0n); | ||
} | ||
|
||
@method | ||
async settle(proof: StateProof) { | ||
await this.offchainState.settle(proof); | ||
} | ||
} |
Oops, something went wrong.