Skip to content

Commit

Permalink
Web4 scripts from socialdb (#148)
Browse files Browse the repository at this point in the history
Preview URL: https://devhubweb4.testnet.page/

Notice that the served index.html is referencing `web4browserclient.js`
with a `blockHeight` parameter. The block height of the latest deployed
`web4browserclient.js` is obtained to a preload call to socialdb. This
ensures that the browser will always load the latest version of the
script, and allow local caching as long as there are no changes.

<img width="1249" alt="image"
src="https://github.com/user-attachments/assets/468e78a2-7393-4fd0-9db3-e4c55ac1a6c5">

The javascript file, which is stored in socialdb, can then be loaded
from this URL:
https://devhubweb4.testnet.page/resources/devhub.near/web4browserclient.js?blockHeight=127582922

This will query socialdb for the latest block height of the javascript
referenced in the web4 deployment, and reference the script in the
served index.html. The script will also served through web4. Having the
blockheight in the query string when referencing the script, ensure that
it's always the latest script being loaded, but also enables caching in
the browser as long as there are no changes. This is a good alternative
to referencing a CDN where you often don't have the same opportunity to
check which version is the latest, and also we can reduce the number of
dependencies this way. Both when it comes to referencing the script, as
we now only can use the web4 gateway, and also in deployment, where
everything can be deployed to socialdb.

Resolves #146
  • Loading branch information
petersalomonsen authored Sep 11, 2024
1 parent 7673833 commit 093e9d5
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 97 deletions.
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"image": "ghcr.io/near/near-devcontainer:latest",
"features": {
"ghcr.io/devcontainers/features/rust:1": {},
},
"customizations": {
"vscode": {
"extensions": [
"dtsvet.vscode-wasm",
"rust-lang.rust-analyzer",
"github.vscode-github-actions"
"github.vscode-github-actions",
"vadimcn.vscode-lldb"
]
}
},
"postCreateCommand": "./.devcontainer/post-create.sh"
}
}
11 changes: 7 additions & 4 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

(cd discussions && cargo near build)
(cd community && cargo near build)
(cd community-factory && cargo near build)
cargo near build
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
(cd discussions && cargo near build --no-docker)
(cd community && cargo near build --no-docker)
(cd community-factory && cargo near build --no-docker)
cargo near build --no-docker
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- name: Install cargo-near
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
- name: Build discussions contract
run: cd discussions && cargo near build
run: cd discussions && cargo near build --no-docker
- name: Build community contract
run: cd community && cargo near build
run: cd community && cargo near build --no-docker
- name: Build community factory contract
run: cd community-factory && cargo near build
run: cd community-factory && cargo near build --no-docker
- name: Build devhub contract
run: cargo near build
run: cargo near build --no-docker
- name: Unit tests
run: cargo test
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
- name: Install cargo-near
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
- name: Build discussions contract
run: cd discussions && cargo near build
run: cd discussions && cargo near build --no-docker
- name: Build community contract
run: cd community && cargo near build
run: cd community && cargo near build --no-docker
- name: Build community factory contract
run: cd community-factory && cargo near build
run: cd community-factory && cargo near build --no-docker
- name: Build devhub contract
run: cargo near build
run: cargo near build --no-docker
- name: Install near CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.3.1/near-cli-rs-v0.3.1-installer.sh | sh
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "devhub"
version = "0.2.0"
authors = ["NEAR DevHub <neardevhub.org>"]
edition = "2021"
repository = "https://github.com/NEAR-DevHub/neardevhub-contract"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions community-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "devhub-community-factory"
version = "0.1.0"
authors = ["NEAR DevHub <neardevhub.org>"]
edition = "2021"
repository = "https://github.com/NEAR-DevHub/neardevhub-contract"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions community/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "devhub-community"
version = "0.1.0"
authors = ["NEAR DevHub <neardevhub.org>"]
edition = "2021"
repository = "https://github.com/NEAR-DevHub/neardevhub-contract"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions discussions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "devhub-discussions"
version = "0.1.0"
authors = ["NEAR DevHub <neardevhub.org>"]
edition = "2021"
repository = "https://github.com/NEAR-DevHub/neardevhub-contract"

[lib]
crate-type = ["cdylib"]
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ impl Contract {
let author_id = env::predecessor_account_id();
let editor_id = author_id.clone();

let current_block_height = env::block_height();

if let Some(accepted_terms_and_conditions_version) = accepted_terms_and_conditions_version {
// require!(
// accepted_terms_and_conditions_version + 10000 >= current_block_height,
// "Terms and conditions version is too old"
// );
require!(
accepted_terms_and_conditions_version <= env::block_height(),
"Terms and conditions version cannot be from the future"
Expand Down
Loading

0 comments on commit 093e9d5

Please sign in to comment.