Skip to content

Commit d605d5a

Browse files
authored
fix(template): bump ckb-script-templates and frontend deps (#220)
* fix(template): bump ckb-script-templates and frontend deps * chore: fmt
1 parent ccf05cd commit d605d5a

27 files changed

Lines changed: 2246 additions & 902 deletions

File tree

templates/v3/next-js-template/Cargo.lock

Lines changed: 976 additions & 255 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/v3/next-js-template/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ members = [
1111

1212
[profile.release]
1313
overflow-checks = true
14-
strip = true
14+
strip = false
1515
codegen-units = 1
16+
debug = true

templates/v3/next-js-template/Makefile

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# We cannot use $(shell pwd), which will return unix path format on Windows,
22
# making it hard to use.
3-
cur_dir = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
3+
cur_dir = $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
44

55
TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# Additional cargo args to append here. For example, one can use
1111
# make test CARGO_ARGS="-- --nocapture" so as to inspect data emitted to
1212
# stdout in unit tests
@@ -23,6 +23,10 @@ CONTRACT :=
2323
CLEAN_BUILD_DIR_FIRST := true
2424
BUILD_DIR := build/$(MODE)
2525

26+
ifeq (release,$(MODE))
27+
MODE_ARGS := --release
28+
endif
29+
2630
# Pass setups to child make processes
2731
export CUSTOM_RUSTFLAGS
2832
export TOP
@@ -44,9 +48,16 @@ build:
4448
for contract in $(wildcard contracts/*); do \
4549
$(MAKE) -e -C $$contract build; \
4650
done; \
51+
for crate in $(wildcard crates/*); do \
52+
cargo build -p $$(basename $$crate) $(MODE_ARGS) $(CARGO_ARGS); \
53+
done; \
54+
for sim in $(wildcard native-simulators/*); do \
55+
cargo build -p $$(basename $$sim) $(CARGO_ARGS); \
56+
done; \
4757
else \
4858
$(MAKE) -e -C contracts/$(CONTRACT) build; \
49-
fi
59+
cargo build -p $(CONTRACT)-sim; \
60+
fi;
5061

5162
# Run a single make task for a specific contract. For example:
5263
#
@@ -91,6 +102,7 @@ DESTINATION := contracts
91102
generate:
92103
@set -eu; \
93104
if [ "x$(CRATE)" = "x" ]; then \
105+
mkdir -p $(DESTINATION); \
94106
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
95107
--destination $(DESTINATION); \
96108
GENERATED_DIR=$$(ls -dt $(DESTINATION)/* | head -n 1); \
@@ -101,6 +113,7 @@ generate:
101113
sed "s,@@INSERTION_POINT@@,@@INSERTION_POINT@@\n \"$$GENERATED_DIR\"\,," Cargo.toml > Cargo.toml.new; \
102114
mv Cargo.toml.new Cargo.toml; \
103115
else \
116+
mkdir -p $(DESTINATION); \
104117
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
105118
--destination $(DESTINATION) \
106119
--name $(CRATE); \
@@ -110,7 +123,24 @@ generate:
110123
fi; \
111124
sed '/@@INSERTION_POINT@@/s/$$/\n "$(DESTINATION)\/$(CRATE)",/' Cargo.toml > Cargo.toml.new; \
112125
mv Cargo.toml.new Cargo.toml; \
113-
fi
126+
fi;
127+
128+
generate-native-simulator:
129+
@set -eu; \
130+
if [ -z "$(CRATE)" ]; then \
131+
echo "Error: Must have CRATE=<Contract Name>"; \
132+
exit 1; \
133+
fi; \
134+
mkdir -p native-simulators; \
135+
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) native-simulator \
136+
-n $(CRATE)-sim \
137+
--destination native-simulators; \
138+
sed '/@@INSERTION_POINT@@/s/$$/\n "native-simulators\/$(CRATE)-sim",/' Cargo.toml > Cargo.toml.new; \
139+
mv Cargo.toml.new Cargo.toml; \
140+
if [ ! -f "contracts/$(CRATE)/Cargo.toml" ]; then \
141+
echo "Warning: This is a non-existent contract and needs to be processed manually"; \
142+
echo " Otherwise compilation may fail."; \
143+
fi;
114144

115145
prepare:
116146
rustup target add riscv64imac-unknown-none-elf
Lines changed: 4 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,7 @@
1-
# offckb-template
1+
# next-js-template-1
22

3-
This is a Minimal Template for CKB Full-Stack Dapps generated by [offckb](https://github.com/RetricSu/offckb).
3+
TODO: Write this readme
44

5-
Offckb does not do the magic. It just wraps the new CKB smart contract template and the CKB javascript Dapp framework into one mono-repo. Under the hook, it uses:
5+
_This project was bootstrapped with [ckb-script-templates]._
66

7-
- [ckb-scripts-template](https://github.com/cryptape/ckb-script-templates) for smart contract development
8-
- [next-js](https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app) and [Lumos](https://github.com/ckb-js/lumos) for frontend development
9-
10-
## Smart contract development
11-
12-
By default, this template comes with a single simple smart contract `hello-world`: `contracts/hello-world/src/main.rs`.
13-
14-
The smart contract is written in Rust lang. In order to develop, the following dependencies are required:
15-
16-
- `git`, `make`, `sed`, `bash`, `sha256sum` and others Unix utilities.
17-
- `Rust` with `riscv64 target`: `rustup target add riscv64imac-unknown-none-elf`
18-
- `Clang 16+`
19-
- `cargo-generate`
20-
21-
Check out the ckb-script-templates for more [detail](https://github.com/cryptape/ckb-script-templates/blob/main/README.md#dependencies)
22-
23-
### Usage
24-
25-
add a new smart-contract:
26-
27-
```sh
28-
make generate
29-
```
30-
31-
build smart-contract:
32-
33-
```sh
34-
make build
35-
```
36-
37-
run test:
38-
39-
```sh
40-
make test
41-
```
42-
43-
For more detail, check out [ckb-script-templates](https://github.com/cryptape/ckb-script-templates)
44-
45-
## dApp frontend development
46-
47-
first, enter the frontend workspace:
48-
49-
```sh
50-
cd frontend
51-
```
52-
53-
start the app:
54-
55-
```sh
56-
npm i && npm run dev
57-
```
58-
59-
change the CKB blockchain network:
60-
61-
edit `.env` file:
62-
63-
```bash
64-
NEXT_PUBLIC_NETWORK=devnet # devnet, testnet or mainnet
65-
```
66-
67-
## Deploy to devnet/testnet with offckb
68-
69-
Once you build your smart contracts, you can deploy them to CKB blockchain with [ckb-cli](https://github.com/nervosnetwork/ckb-cli) or any other tools.
70-
71-
If you want to test them in devnet/testnet blockchain, then `offckb` might be the ideal selection.
72-
73-
`offckb` will look for the `offckb.config.ts` file to read config information. so you will need to enter the frontend workspace to do the instruction:
74-
75-
```sh
76-
cd frontend
77-
offckb deploy --network devnet
78-
```
79-
80-
If successfully deployed, you will see the deploy script info for your smart contract recorded in the `offckb.config.ts` file. You can then directly import and use your smart contract in your frontend Dapp like this:
81-
82-
```ts
83-
import offckb from 'offckb.config';
84-
import { CellDep } from '@ckb-lumos/lumos';
85-
86-
const lumosConfig = offckb.lumosConfig;
87-
const myContractDep: CellDep = {
88-
outPoint: {
89-
txHash: lumosConfig.SCRIPTS.YOUR_SCRIPT_NAME!.TX_HASH,
90-
index: lumosConfig.SCRIPTS.YOUR_SCRIPT_NAME!.INDEX,
91-
},
92-
depType: lumosConfig.SCRIPTS.YOUR_SCRIPT_NAME!.DEP_TYPE,
93-
};
94-
```
95-
96-
Every time you deploy a new version of your smart contracts, those script infos will be updated by `offckb` in the `offckb.config.ts` and work out-of-box in your frontend.
97-
98-
You can also deploy smart contracts to the CKB Testnet like this:
99-
100-
```sh
101-
cd frontend
102-
offckb deploy --network testnet
103-
```
104-
105-
and start your frontend Dapp targeting Testnet:
106-
107-
edit `.env` file:
108-
109-
```bash
110-
NEXT_PUBLIC_NETWORK=testnet # devnet, testnet or mainnet
111-
```
112-
113-
```bash
114-
cd frontend
115-
npm run dev
116-
```
117-
118-
Note that the `mainnet` network is not supported in `offckb` since `offckb` is focusing on building a friendly development environment for CKB. To gain better security, it is recommended to use production tools like [ckb-cli](https://github.com/nervosnetwork/ckb-cli) to deploy smart contracts and do transactions for the CKB mainnet.
7+
[ckb-script-templates]: https://github.com/cryptape/ckb-script-templates

templates/v3/next-js-template/contracts/hello-world/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ckb-std = "0.15.1"
7+
ckb-std = "0.17.0"
8+
9+
[features]
10+
library = []
11+
native-simulator = ["library", "ckb-std/native-simulator"]

templates/v3/next-js-template/contracts/hello-world/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# We cannot use $(shell pwd), which will return unix path format on Windows,
22
# making it hard to use.
3-
cur_dir = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
3+
cur_dir = $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
44

55
TOP := $(cur_dir)
66
# RUSTFLAGS that are likely to be tweaked by developers. For example,
77
# while we enable debug logs by default here, some might want to strip them
88
# for minimal code size / consumed cycles.
9-
CUSTOM_RUSTFLAGS := --cfg debug_assertions
9+
CUSTOM_RUSTFLAGS := -C debug-assertions
1010
# RUSTFLAGS that are less likely to be tweaked by developers. Most likely
1111
# one would want to keep the default values here.
12-
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs $(CUSTOM_RUSTFLAGS)
12+
FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS)
1313
# Additional cargo args to append here. For example, one can use
1414
# make test CARGO_ARGS="-- --nocapture" so as to inspect data emitted to
1515
# stdout in unit tests
@@ -19,6 +19,7 @@ MODE := release
1919
# we use a bash script with somes heuristics to find clang in current system.
2020
CLANG := $(shell $(TOP)/scripts/find_clang)
2121
AR := $(subst clang,llvm-ar,$(CLANG))
22+
OBJCOPY := $(subst clang,llvm-objcopy,$(CLANG))
2223
# When this is set to some value, the generated binaries will be copied over
2324
BUILD_DIR :=
2425
# Generated binaries to copy. By convention, a Rust crate's directory name will
@@ -41,6 +42,8 @@ build:
4142
for binary in $(BINARIES); do \
4243
echo "Copying binary $$binary to build directory"; \
4344
cp $(TOP)/target/riscv64imac-unknown-none-elf/$(MODE)/$$binary $(TOP)/$(BUILD_DIR); \
45+
cp $(TOP)/$(BUILD_DIR)/$$binary $(TOP)/$(BUILD_DIR)/$$binary.debug; \
46+
$(OBJCOPY) --strip-debug --strip-all $(TOP)/$(BUILD_DIR)/$$binary; \
4447
done \
4548
fi
4649

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![cfg_attr(not(feature = "library"), no_std)]
2+
#![allow(special_module_name)]
3+
#![allow(unused_attributes)]
4+
#[cfg(feature = "library")]
5+
mod main;
6+
#[cfg(feature = "library")]
7+
pub use main::program_entry;
8+
9+
extern crate alloc;
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
#![no_std]
1+
#![cfg_attr(not(any(feature = "library", test)), no_std)]
22
#![cfg_attr(not(test), no_main)]
33

4-
#[cfg(test)]
4+
#[cfg(any(feature = "library", test))]
55
extern crate alloc;
66

7-
#[cfg(not(test))]
8-
use ckb_std::default_alloc;
9-
#[cfg(not(test))]
7+
#[cfg(not(any(feature = "library", test)))]
108
ckb_std::entry!(program_entry);
11-
#[cfg(not(test))]
12-
default_alloc!();
9+
#[cfg(not(any(feature = "library", test)))]
10+
// By default, the following heap configuration is used:
11+
// * 16KB fixed heap
12+
// * 1.2MB(rounded up to be 16-byte aligned) dynamic heap
13+
// * Minimal memory block in dynamic heap is 64 bytes
14+
// For more details, please refer to ckb-std's default_alloc macro
15+
// and the buddy-alloc alloc implementation.
16+
ckb_std::default_alloc!(16384, 1258306, 64);
1317

1418
pub fn program_entry() -> i8 {
15-
ckb_std::debug!("Hello world! This is a sample contract!");
19+
ckb_std::debug!("This is a sample contract!");
1620

1721
0
1822
}

0 commit comments

Comments
 (0)