From 90b99c928f16df0c23edffae24730a532be3e9e4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 17 Oct 2023 12:02:32 +0000 Subject: [PATCH] docs using test contract for unencrypted logs --- docs/docs/dev_docs/contracts/syntax/events.md | 4 ++-- .../tutorials/writing_dapp/contract_interaction.md | 14 +------------- .../src/contracts/test_contract/src/main.nr | 9 ++++++--- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/docs/docs/dev_docs/contracts/syntax/events.md b/docs/docs/dev_docs/contracts/syntax/events.md index 5a04e6f0541..d3f3f6c192b 100644 --- a/docs/docs/dev_docs/contracts/syntax/events.md +++ b/docs/docs/dev_docs/contracts/syntax/events.md @@ -100,11 +100,11 @@ They can be emitted by both public and private functions. To emit unencrypted logs first import the `emit_unencrypted_log` utility function inside your contract: -#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust +#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr rust Then you can call the function: -#include_code unencrypted_log /yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust +#include_code emit_unencrypted /yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr rust Once emitted, unencrypted events are stored in AztecNode and can be queried by anyone: diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md index 535620bcd21..6cc2e502d11 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md @@ -21,7 +21,7 @@ import { readFileSync } from "fs"; import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; ``` -And then add the following code for initialising the `Contract` instances: +And then add the following code for initializing the `Contract` instances: #include_code get-tokens yarn-project/end-to-end/src/sample-dapp/contracts.mjs javascript @@ -122,18 +122,6 @@ Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0 Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 ``` -Public functions can emit [unencrypted logs](../../contracts/syntax/events.md#unencrypted-events), which can be queried via the PXE interface. In particular, the token contract emits a generic `Public tokens minted` whenever the `mint_public` method is called: - -#include_code unencrypted_log yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr rust - -We can extend our code by querying the logs emitted on the last block when the minting transaction is mined: - -#include_code showLogs yarn-project/end-to-end/src/sample-dapp/index.mjs javascript - -:::info -At the time of this writing, there is no event-based mechanism in the `aztec.js` library to subscribe to events. The only option to consume them is to poll on every new block detected. This will change in a future version. -::: - ## Next steps In the next and final section, we'll [set up automated tests for our application](./testing.md). diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index ddb28b85fda..82a276afddb 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -1,5 +1,9 @@ // A contract used for testing a random hodgepodge of small features from simulator and end-to-end tests. contract Test { + // docs:start:unencrypted_import + use dep::aztec::log::emit_unencrypted_log; + // docs:end:unencrypted_import + use dep::aztec::{ abi, abi::PrivateContextInputs, @@ -9,7 +13,6 @@ contract Test { context::get_portal_address, rand::rand }, - log::emit_unencrypted_log, types::vec::BoundedVec, constants_gen::EMPTY_NULLIFIED_COMMITMENT, }; @@ -130,15 +133,15 @@ contract Test { } // docs:end:is-time-equal - // docs:start:emit_unencrypted_log #[aztec(public)] fn emit_unencrypted( value: Field ) -> Field { + // docs:start:emit_unencrypted emit_unencrypted_log(&mut context, value); + // docs:end:emit_unencrypted 0 } - // docs:end:emit_unencrypted_log #[aztec(public)] fn consume_mint_public_message(