Skip to content

Commit

Permalink
Merge branch 'main' into katana/fgw-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Nov 30, 2024
2 parents fde2d2b + ebcc23d commit 94dfd6f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust
{
"name": "Rust",
"image": "ghcr.io/dojoengine/dojo-dev:v1.0.1",
"image": "ghcr.io/dojoengine/dojo-dev:v1.0.2",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
bench-katana:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
Expand All @@ -36,7 +36,7 @@ jobs:
bench-sozo:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.79.0
RUST_VERSION: 1.80.0

jobs:
build:
Expand All @@ -31,7 +31,7 @@ jobs:
needs: ensure-docker
runs-on: ubuntu-latest-32-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -56,7 +56,7 @@ jobs:
ensure-wasm:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -139,7 +139,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -154,7 +154,7 @@ jobs:
clippy:
runs-on: ubuntu-latest-4-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -163,7 +163,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -172,7 +172,7 @@ jobs:
docs:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
with:
# We have to use a PAT in order to trigger ci
token: ${{ secrets.CREATE_PR_TOKEN }}
title: "Update devcontainer image: ${{ needs.build-and-push.outputs.tag_name }}"
title: "chore(devcontainer): update image: ${{ needs.build-and-push.outputs.tag_name }}"
commit-message: "Update devcontainer image: ${{ needs.build-and-push.outputs.tag_name }}"
branch: bump-devcontainer
base: main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
contents: write
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.1
image: ghcr.io/dojoengine/dojo-dev:v1.0.2
env:
VERSION: ""
steps:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ warp = "0.3"

# gRPC
prost = "0.12"
tonic = { version = "0.11", features = [ "gzip", "tls", "tls-roots" ] }
tonic = { version = "0.11", features = [ "gzip", "tls", "tls-roots", "tls-webpki-roots" ] }
tonic-build = "0.11"
tonic-reflection = "0.11"
tonic-web = "0.11"
Expand Down
58 changes: 49 additions & 9 deletions crates/dojo/bindgen/src/plugins/typescript/generator/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cainome::parser::tokens::{CompositeType, Function, Token};
use cainome::parser::tokens::{CompositeType, Function, StateMutability, Token};
use convert_case::{Case, Casing};
use dojo_world::contracts::naming;

Expand Down Expand Up @@ -35,8 +35,9 @@ impl TsFunctionGenerator {
contract_name: &str,
token: &Function,
) -> String {
format!(
"\tconst {contract_name}_{} = async ({}) => {{
match token.state_mutability {
StateMutability::External => format!(
"\tconst {contract_name}_{} = async ({}) => {{
\t\ttry {{
\t\t\treturn await provider.execute(
\t\t\t\tsnAccount,
Expand All @@ -51,15 +52,36 @@ impl TsFunctionGenerator {
\t\t\tconsole.error(error);
\t\t}}
\t}};\n",
token.name.to_case(Case::Camel),
self.format_function_inputs(token),
token.name,
self.format_function_calldata(token)
)
token.name.to_case(Case::Camel),
self.format_function_inputs(token),
token.name,
self.format_function_calldata(token)
),
StateMutability::View => format!(
"\tconst {contract_name}_{} = async ({}) => {{
\t\ttry {{
\t\t\treturn await provider.call(\"{namespace}\", {{
\t\t\t\tcontractName: \"{contract_name}\",
\t\t\t\tentrypoint: \"{}\",
\t\t\t\tcalldata: [{}],
\t\t\t}});
\t\t}} catch (error) {{
\t\t\tconsole.error(error);
\t\t}}
\t}};\n",
token.name.to_case(Case::Camel),
self.format_function_inputs(token),
token.name,
self.format_function_calldata(token)
),
}
}

fn format_function_inputs(&self, token: &Function) -> String {
let inputs = vec!["snAccount: Account".to_owned()];
let inputs = match token.state_mutability {
StateMutability::External => vec!["snAccount: Account".to_owned()],
StateMutability::View => Vec::new(),
};
token
.inputs
.iter()
Expand Down Expand Up @@ -273,6 +295,13 @@ mod tests {
let expected = "snAccount: Account, value: BigNumberish";
assert_eq!(expected, generator.format_function_inputs(&function))
}
#[test]
fn test_format_function_inputs_view() {
let generator = TsFunctionGenerator {};
let function = create_basic_view_function();
let expected = "";
assert_eq!(expected, generator.format_function_inputs(&function))
}

#[test]
fn test_format_function_inputs_complex() {
Expand Down Expand Up @@ -408,6 +437,17 @@ mod tests {
)],
)
}

fn create_basic_view_function() -> Function {
Function {
name: "allowance".to_owned(),
state_mutability: cainome::parser::tokens::StateMutability::View,
inputs: vec![],
outputs: vec![],
named_outputs: vec![],
}
}

fn create_change_theme_function_camelized() -> Function {
create_test_function(
"changeTheme",
Expand Down

0 comments on commit 94dfd6f

Please sign in to comment.