Skip to content

Commit

Permalink
add xudt
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Apr 12, 2024
1 parent f7e6606 commit fd496e9
Show file tree
Hide file tree
Showing 11 changed files with 3,365 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
[submodule "third-party/ckb-c-stdlib"]
path = third-party/ckb-c-stdlib
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
# [submodule "third-party/secp256k1"]
# path = third-party/secp256k1
# url = https://github.com/nervosnetwork/secp256k1
# branch = master
[submodule "third-party/sparse-merkle-tree"]
path = third-party/sparse-merkle-tree
url = https://github.com/nervosnetwork/sparse-merkle-tree.git
branch = master
# [submodule "third-party/mbedtls"]
# path = third-party/mbedtls
# url = https://github.com/nervosnetwork/mbedtls.git
# [submodule "third-party/ckb-c-stdlib-20210413"]
# path = third-party/ckb-c-stdlib-20210413
# url = https://github.com/nervosnetwork/ckb-c-stdlib.git
# [submodule "third-party/secp256k1-20210801"]
# path = third-party/secp256k1-20210801
# url = https://github.com/nervosnetwork/secp256k1.git
# branch = schnorr
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ sudt-c:
-o sudt-c && \
cp sudt-c ../..
@echo " >>> sussecfully build sudt-c"
xudt-c:
cd third-party/xudt && \
moleculec --language c --schema-file xudt_rce.mol > xudt_rce_mol.h
# moleculec --language - --schema-file xudt_rce.mol --format json > blockchain_mol2.json
# moleculec-c2 --input blockchain_mol2.json | clang-format -style=Google > xudt_rce_mol2.h
cd third-party && \
clang --target=riscv64 \
-march=rv64imc \
-nostdlib \
-Wall -Werror -Wextra -Wno-unused-parameter -Wno-nonnull -fno-builtin-printf -fno-builtin-memcmp -O3 -fdata-sections -ffunction-sections \
-I ckb-c-stdlib/libc \
-I ckb-c-stdlib/molecule \
-I ckb-c-stdlib \
-I sparse-merkle-tree/c \
xudt/*.c \
-o xudt-c && \
cp xudt-c ..
@echo " >>> sussecfully build xudt-c"
ckb-libc: ckb-libc-debug ckb-libc-release
ckb-libc-debug:
@echo " >>> build libdummylibc-debug.a"
Expand Down Expand Up @@ -95,7 +113,7 @@ test/example:
${CELL} -t riscv tests/examples/cell-data.cell && ckb-debugger --bin cell-data
${CELL} -t riscv tests/examples/inputs.cell && ckb-debugger --bin inputs
${CELL} -t riscv tests/examples/outputs.cell && ckb-debugger --bin outputs
${CELL} -t riscv tests/examples/sudt.cell && ckb-debugger --bin sudt
${CELL} -t riscv tests/examples/sudt.cell && ckb-debugger --bin sudt || true

${CELL} -t riscv tests/examples/multi-files && ckb-debugger --bin multi-files
${CELL} -t riscv tests/examples/import-package && ckb-debugger --bin import-package
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ cell <file>.cell
cargo install --git https://github.com/nervosnetwork/ckb-standalone-debugger ckb-debugger
ckb-debugger --bin <file>
```
## To develop xUDT

ckb-c-stdlib use molecule 0.7.1
```
cargo install moleculec@0.7.1 --locked
```

## How to Deploy?
```
Expand Down
1 change: 1 addition & 0 deletions third-party/sparse-merkle-tree
Submodule sparse-merkle-tree added at 5739f3
108 changes: 108 additions & 0 deletions third-party/xudt/blockchain.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* Basic Types */

array Uint32 [byte; 4];
array Uint64 [byte; 8];
array Uint128 [byte; 16];
array Byte32 [byte; 32];
array Uint256 [byte; 32];

vector Bytes <byte>;
option BytesOpt (Bytes);

vector BytesVec <Bytes>;
vector Byte32Vec <Byte32>;

/* Types for Chain */

option ScriptOpt (Script);

array ProposalShortId [byte; 10];

vector UncleBlockVec <UncleBlock>;
vector TransactionVec <Transaction>;
vector ProposalShortIdVec <ProposalShortId>;
vector CellDepVec <CellDep>;
vector CellInputVec <CellInput>;
vector CellOutputVec <CellOutput>;

table Script {
code_hash: Byte32,
hash_type: byte,
args: Bytes,
}

struct OutPoint {
tx_hash: Byte32,
index: Uint32,
}

struct CellInput {
since: Uint64,
previous_output: OutPoint,
}

table CellOutput {
capacity: Uint64,
lock: Script,
type_: ScriptOpt,
}

struct CellDep {
out_point: OutPoint,
dep_type: byte,
}

table RawTransaction {
version: Uint32,
cell_deps: CellDepVec,
header_deps: Byte32Vec,
inputs: CellInputVec,
outputs: CellOutputVec,
outputs_data: BytesVec,
}

table Transaction {
raw: RawTransaction,
witnesses: BytesVec,
}

struct RawHeader {
version: Uint32,
compact_target: Uint32,
timestamp: Uint64,
number: Uint64,
epoch: Uint64,
parent_hash: Byte32,
transactions_root: Byte32,
proposals_hash: Byte32,
uncles_hash: Byte32,
dao: Byte32,
}

struct Header {
raw: RawHeader,
nonce: Uint128,
}

table UncleBlock {
header: Header,
proposals: ProposalShortIdVec,
}

table Block {
header: Header,
uncles: UncleBlockVec,
transactions: TransactionVec,
proposals: ProposalShortIdVec,
}

table CellbaseWitness {
lock: Script,
message: Bytes,
}

table WitnessArgs {
lock: BytesOpt, // Lock args
input_type: BytesOpt, // Type args for input
output_type: BytesOpt, // Type args for output
}
Loading

0 comments on commit fd496e9

Please sign in to comment.