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

update: Disable Motoko code execution #3502

Merged
merged 2 commits into from
Sep 20, 2024
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
4 changes: 2 additions & 2 deletions blog/news-and-updates/2024-03-06-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In the newest version of Motoko, the type system has been revised to detect and

For example, in previous Motoko versions, the following code snippet could be used:

```motoko
```motoko no-repl
func splitCycles() {
let amount = ExperimentalCycles.balance() / 2;
ExperimentalCycles.add(amount); // new error
Expand All @@ -47,7 +47,7 @@ In Motoko v0.11.0 and newer, this code will throw a compiler error:

To support the new changes, the previous code should be rewritten to include the `system` type parameter:

```motoko
```motoko no-repl
func splitCycles<system>() {
let amount = ExperimentalCycles.balance() / 2;
ExperimentalCycles.add(amount); // warning
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/defi/nfts/nft-collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dfx canister call icrc7 init

This command will initialize an NFT collection using the parameters set in the project's `example/initial_state/icrc7.mo` file:

```motoko
```motoko no-repl
import ICRC7 "mo:icrc7-mo";

module{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ can have multiple UTXOs associated with it.
<Tabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

let own_utxos = (await BitcoinApi.get_utxos(network, own_address)).utxos;

Expand Down Expand Up @@ -65,7 +65,7 @@ An UTXO has the following structure:
<Tabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

/// An unspent transaction output.
public type Utxo = {
Expand Down Expand Up @@ -127,7 +127,7 @@ using the `bitcoin_get_current_fee_percentiles` API endpoint and choosing the
<Tabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

// Get fee percentiles from previous transactions to estimate our own fee.
let fee_percentiles = await BitcoinApi.get_current_fee_percentiles(network);
Expand Down Expand Up @@ -187,7 +187,7 @@ transaction and requires a signature.
<Tabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

// Builds a transaction to send the given `amount` of satoshis to the
// destination address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ demonstrates how to generate a `P2PKH` address from a canister's public key.
<Tabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

/// Returns the P2PKH address of this canister at the given derivation path.
public func get_p2pkh_address(network : Network, key_name : Text, derivation_path : [[Nat8]]) : async BitcoinAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To read unspent transaction outputs from the Bitcoin network, make a call to the
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
type ManagementCanisterActor = actor {
bitcoin_get_utxos : GetUtxosRequest -> async GetUtxosResponse;
};
Expand Down Expand Up @@ -103,7 +103,7 @@ To read the current balance of a Bitcoin address, make a call to the `bitcoin_ge
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
type ManagementCanisterActor = actor {
bitcoin_get_balance : GetBalanceRequest -> async Satoshi;
};
Expand Down Expand Up @@ -168,7 +168,7 @@ The function returns 101 numbers that are fees measured in millisatoshi per virt
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
type ManagementCanisterActor = actor {
bitcoin_get_current_fee_percentiles : GetCurrentFeePercentilesRequest -> async [MillisatoshiPerVByte];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following snippet shows a simplified example of how to sign a Bitcoin transa
<Tabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
public func sign_transaction(
own_public_key : [Nat8],
own_address : BitcoinAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The following snippet shows how to send a signed transaction to the Bitcoin netw
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
type ManagementCanisterActor = actor {
bitcoin_send_transaction : SendTransactionRequest -> async ();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ Once you have determined how many cycles your call will need, you can send them
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko

```motoko no-repl
import EvmRpc "canister:evm_rpc";
import Cycles "mo:base/ExperimentalCycles";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Note that when deploying your own canister, you may encounter API rate limits. R
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -232,7 +232,7 @@ This example use case displays a caveat that comes with mapping the `eth_getLogs
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -320,7 +320,7 @@ dfx canister call evm_rpc eth_getBlockByNumber "(variant {$RPC_SOURCE}, $RPC_CON
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -487,7 +487,7 @@ pub async fn eth_call(
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -587,7 +587,7 @@ dfx canister call evm_rpc eth_getTransactionCount "(variant {$RPC_SOURCE}, $RPC_
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -703,7 +703,7 @@ The EVM RPC canister can also be used to send raw transactions to the Ethereum a
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -818,7 +818,7 @@ Note that even if an error is returned, you should assume that your transaction
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
import EvmRpc "canister:evm_rpc";

import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -909,7 +909,7 @@ dfx canister call evm_rpc request "(variant {$JSON_RPC_SOURCE}, "'"{ \"jsonrpc\"
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
let services = #EthMainnet;
let config = null;
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ To create an ETH address for your canister, first you will need to obtain an ECD
<AdornedTabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
// Declare "ic" to be the management canister, which is evoked by `actor("aaaaa-aa")`.:
let ic : IC = actor("aaaaa-aa");
```motoko no-repl
// Declare "ic" to be the management canister, which is evoked by `actor("aaaaa-aa")`.:
let ic : IC = actor("aaaaa-aa");

public shared (msg) func public_key() : async { #Ok : { public_key: Blob }; #Err : Text } {
let caller = Principal.toBlob(msg.caller);
public shared (msg) func public_key() : async { #Ok : { public_key: Blob }; #Err : Text } {
let caller = Principal.toBlob(msg.caller);

try {
try {

// Make a call to the management canister to request an ECDSA public key:
let { public_key } = await ic.ecdsa_public_key({
canister_id = null;
derivation_path = [ caller ];
key_id = { curve = #secp256k1; name = "test_key_1" };
});
// Make a call to the management canister to request an ECDSA public key:
let { public_key } = await ic.ecdsa_public_key({
canister_id = null;
derivation_path = [ caller ];
key_id = { curve = #secp256k1; name = "test_key_1" };
});

#Ok({ public_key })
#Ok({ public_key })

} catch (err) {
} catch (err) {

#Err(Error.message(err))
#Err(Error.message(err))

}
}

};
};
```

</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ HTTP `GET` requests are used to retrieve and return existing data from an endpoi

In Motoko, a `case` configuration can be used to return different `GET` responses based on the endpoint:

```motoko
```motoko no-repl
import FHM "mo:StableHashMap/FunctionalStableHashMap";
import SHA256 "mo:motoko-sha/SHA256";
import CertTree "mo:ic-certification/CertTree";
Expand Down Expand Up @@ -393,7 +393,7 @@ HTTP `POST` requests are used to send data to an endpoint with the intention of

In Motoko, a `case` configuration can be used to return different `POST` responses based on the endpoint:

```motoko
```motoko no-repl
import FHM "mo:StableHashMap/FunctionalStableHashMap";
import SHA256 "mo:motoko-sha/SHA256";
import CertTree "mo:ic-certification/CertTree";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Before you dive in, here is the structure of the code you will touch:
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

//Import some custom types from `src/backend_canister/Types.mo` file
import Types "Types";
Expand Down Expand Up @@ -95,7 +95,7 @@ actor {

You will also create some custom types in `Types.mo`. It will look like this:

```motoko
```motoko no-repl
module Types {

//type declarations for s, HTTP responses, management canister, etc...
Expand Down Expand Up @@ -180,7 +180,7 @@ rustup target add wasm32-unknown-unknown

Open the `src/send_http_get_motoko_backend/main.mo` file in a text editor and replace content with:

```motoko title="src/send_http_get_motoko_backend/main.mo"
```motoko no-repl title="src/send_http_get_motoko_backend/main.mo"
import Debug "mo:base/Debug";
import Blob "mo:base/Blob";
import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -534,7 +534,7 @@ fn transform(raw: TransformArgs) -> HttpResponse {

Open the `src/send_http_get_motoko_backend/Types.mo` file in a text editor and replace content with:

```motoko title="src/send_http_get_motoko_backend/Types.mo"
```motoko no-repl title="src/send_http_get_motoko_backend/Types.mo"
module Types {

public type Timestamp = Nat64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Before you dive in, here is the structure of the code you will touch:
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl

//Import some custom types from `src/backend_canister/Types.mo` file
import Types "Types";
Expand Down Expand Up @@ -97,7 +97,7 @@ actor {

You will also create some custom types in `Types.mo`. This will look like this:

```motoko
```motoko no-repl
module Types {

//type declarations for HTTP requests, HTTP responses, management canister, etc...
Expand Down Expand Up @@ -176,7 +176,7 @@ rustup target add wasm32-unknown-unknown

Open the `src/send_http_post_motoko_backend/main.mo` file in a text editor and replace content with:

```motoko title="src/send_http_post_motoko_backend/main.mo"
```motoko no-repl title="src/send_http_post_motoko_backend/main.mo"
import Debug "mo:base/Debug";
import Blob "mo:base/Blob";
import Cycles "mo:base/ExperimentalCycles";
Expand Down Expand Up @@ -531,7 +531,7 @@ fn transform(raw: TransformArgs) -> HttpResponse {

Create the `src/send_http_post_motoko_backend/Types.mo` file in a text editor and replace content with:

```motoko title="src/send_http_post_motoko_backend/Types.mo"
```motoko no-repl title="src/send_http_post_motoko_backend/Types.mo"
module Types {

//1. Type that describes the Request arguments for an HTTPS outcall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Here are some examples calling the management canister:
<AdornedTabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
actor {
let ic = actor "aaaaa-aa" : IC.Self;
public func createCanister(settings: ?canister_settings) : async () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For the code composability reasons, i.e. to be able to use different libraries w
<AdornedTabs groupId="languages">
<TabItem value="motoko" label="Motoko" default>

```motoko
```motoko no-repl
system func timer(setGlobalTimer : Nat64 -> ()) : async () {
let next = Nat64.fromIntWrap(Time.now()) + 20_000_000_000;
setGlobalTimer(next); // absolute time in nanoseconds
Expand Down Expand Up @@ -200,7 +200,7 @@ To use multiple timers in a canister, simply create multiple timer definitions:
In Motoko, call the `recurringTimer` function multiple times, setting different durations and callback functions for each timer:


```motoko
```motoko no-repl
import { print } = "mo:base/Debug";
import { recurringTimer } = "mo:base/Timer";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Your canister can programmatically get system time to be used within your applic
<AdornedTabs groupId="language">
<TabItem value="motoko" label="Motoko">

```motoko
```motoko no-repl
import { now } = "mo:base/Time";
import Debug "mo:base/Debug";

Expand Down Expand Up @@ -106,7 +106,7 @@ Below are examples showing how to convert Unix timestamps to DateTime format.
<AdornedTabs groupId="language">
<TabItem value="motoko" label="Motoko">

```motoko
```motoko no-repl
import Time "mo:time/time";
import DateTime "mo:datetime/DateTime";
import Debug "mo:base/Debug";
Expand Down Expand Up @@ -155,7 +155,7 @@ fn to_date(timestamp: &u64) -> OffsetDateTime {

For some applications, it may be useful to calculate the time that has passed between two timestamps. Below is an example canister written in Motoko that demonstrates how to use [timers](periodic-tasks.mdx) to generate two timestamps, then creates a function that can be used to calculate the difference:

```motoko
```motoko no-repl
import Debug "mo:base/Debug";
import { setTimer; recurringTimer } = "mo:base/Timer";
import Time "mo:time/time";
Expand Down
Loading
Loading