Skip to content

Commit

Permalink
Merge branch 'main' of github.com:freenet/locutus
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Jan 17, 2024
2 parents 1c1ef3c + 8b04584 commit 76c2fed
Show file tree
Hide file tree
Showing 41 changed files with 9,422 additions and 466 deletions.
296 changes: 148 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions apps/freenet-email-app/web/src/inbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use chacha20poly1305::{
XChaCha20Poly1305,
};
use chrono::{DateTime, Utc};
use futures::future::LocalBoxFuture;
use futures::FutureExt;
use freenet_aft_interface::{Tier, TokenAssignment, TokenAssignmentHash};
use freenet_stdlib::prelude::StateSummary;
use freenet_stdlib::{
Expand All @@ -21,6 +19,8 @@ use freenet_stdlib::{
ContractKey, State, UpdateData,
},
};
use futures::future::LocalBoxFuture;
use futures::FutureExt;
use rsa::{
pkcs1v15::SigningKey, sha2::Sha256, signature::Signer, Pkcs1v15Encrypt, RsaPrivateKey,
RsaPublicKey,
Expand Down Expand Up @@ -181,8 +181,7 @@ impl DecryptedMessage {
}
.try_into()
.map_err(|e| format!("{e}"))?;
let inbox_key =
ContractKey::from_params(INBOX_CODE_HASH, params).map_err(|e| format!("{e}"))?;
let inbox_key = !::from_params(INBOX_CODE_HASH, params).map_err(|e| format!("{e}"))?;
AftRecords::pending_assignment(delegate_key, inbox_key.clone());

PENDING_INBOXES_UPDATE.with(|map| {
Expand Down Expand Up @@ -557,7 +556,10 @@ mod tests {
minimum_tier: Tier::Hour1,
private_key,
},
key: ContractKey::from_params_and_code(&params.try_into()?, ContractCode::from([].as_slice())),
key: ContractKey::from_params_and_code(
&params.try_into()?,
ContractCode::from([].as_slice()),
),
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions apps/freenet-microblogging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ publish-webapp:
posts:
cd $(POSTS_DIR)
fdev build
hash=$$(bash -c "fdev inspect build/freenet/freenet_microblogging_posts key | grep 'code key:' | cut -d' ' -f3")
mkdir -p $(WEB_DIR)/build
echo $$hash
echo -n $$hash > $(WEB_DIR)/model_code_hash.txt

publish-posts:
cd $(POSTS_DIR)
Expand Down
86 changes: 85 additions & 1 deletion apps/freenet-microblogging/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# Freenet Microblogging
The source in this directory builds up all the contracts necessary to deploy the Freenet Microblogging site.

Freenet Microblogging App is a descentralized blog application that runs on top of Freenet.

## Introduction

This guide will walk you through the setup and launch of the microblogging application on Freenet.
Currently, Freenet is still under development, so the application will communicate with a
local node, which simulates a node on the network.

## Prerequisites

- Install the latest version of Rust and Cargo (for Windows
see [here](https://rustup.rs/)):
```bash
curl https://sh.rustup.rs -sSf | sh
```
- Install the Freeenet development tool (fdev) and a working Freenet kernel that can be used for local development. Use
cargo to install it:
```bash
cargo install freenet
cargo install fdev
```

## Prepare the Freenet microblogging contracts

### Setup the app

Prepare the microblogging app web and posts contracts.

The app is located inside the `apps/freenet-microblogging` folder:

- `freenet-core/`
- `apps/`
- `freenet-microblogging/` <-- this folder contains the microblogging app
- `contracts/` <-- this folder contains the contract source code
- `posts/` <-- this folder contains the posts contract
- `build/` <-- the generated folder that contains the compiled contract binary with version + wasm
code
- `src/` <-- this folder contains the source code of the contract
- ...
- `web/` <-- this folder contains the web app source code, web app built with node and webpack
- `build/` <-- the generated folder that contains the compiled web app binary with version + wasm
code
- `container/` <-- this folder contains the web contract container, a simple contract associated
with the web app, as the state.
- `src/` <-- this folder contains the source code of the web app
- ...
- `Makefile` <-- this file contains the build instructions for building and running the web app, and
the local node.

To build the microblogging application, go to the `apps/freenet-microblogging` folder and run the following command:

```bash
make build
```

This command will compile the posts and web contracts, generate a binary files
inside the respective `build/freenet/` folders and publish both contracts. It generates the build folder if it doesn't
exist.

After building the app, what remains is to run the local node and use browser to load the web app contract. To do
that, run the following command:

1. Run the local node:
```bash
make node
```
2. Browse to the following URL to load the microblogging web, note that the hash may be different:
```
http://127.0.0.1:50509/contract/web/9zaPEBmmMAF3eKy7NnuPUit2j1annxtVY226DWGLzEFN/
```

The hash may be different and you can get it when you run the build command.

During the development process, changes inside the web need to be recompiled and republished. To do that,
repeat the previous steps.

## Troubleshooting

### Freenet node throws an error when trying to find some contract

If any of the contracts definition change, is necessary to rebuild each of them and restart the node.
Probably the contract hash has changed and the node is trying to find the old version.

If the error persists, we recommend to make a clean build of all the contracts, and restart the node.
2 changes: 1 addition & 1 deletion apps/freenet-microblogging/contracts/posts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false

[dependencies]
byteorder = "1"
freenet-stdlib = { workspace = true }
freenet-stdlib = { workspace = true, features = ["contract"] }
rsa = { version = "0.9.2", default-features = false, features = ["serde", "pem", "sha2"] }
serde = "1"
serde_json = "1"
Expand Down
2 changes: 1 addition & 1 deletion apps/freenet-microblogging/web/container/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resolver = "2"
publish = false

[dependencies]
freenet-stdlib = { workspace = true }
freenet-stdlib = { workspace = true, features = ["contract"] }

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions apps/freenet-microblogging/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"css-loader": "6.7.1",
"jest": "28.1.3",
"postcss-loader": "7.0.1",
"raw-loader": "^4.0.2",
"sass": "1.54.5",
"sass-loader": "13.0.2",
"style-loader": "3.3.1",
Expand Down
Loading

0 comments on commit 76c2fed

Please sign in to comment.