From 6a5a7f9c3ce8a6877b6574c401724fcbb067e968 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 29 Sep 2019 13:54:49 +0200 Subject: [PATCH] First commit --- .gitmodules | 3 +++ lib | 1 + toolchain/bin/fift | 3 +++ toolchain/bin/funcompile | 3 +++ toolchain/build.sh | 27 +++++++++++++++++++++++++++ wallet-code.fc | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 .gitmodules create mode 160000 lib create mode 100755 toolchain/bin/fift create mode 100755 toolchain/bin/funcompile create mode 100755 toolchain/build.sh create mode 100644 wallet-code.fc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a31e2e1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib"] + path = lib + url = https://github.com/ton-blockchain/ton/ diff --git a/lib b/lib new file mode 160000 index 0000000..fd7a8de --- /dev/null +++ b/lib @@ -0,0 +1 @@ +Subproject commit fd7a8de9708c9ece8d802890519735b55bc99a8e diff --git a/toolchain/bin/fift b/toolchain/bin/fift new file mode 100755 index 0000000..85850ad --- /dev/null +++ b/toolchain/bin/fift @@ -0,0 +1,3 @@ +#!/bin/bash -e + +$TONLIB_HOME/build/fift "$@" diff --git a/toolchain/bin/funcompile b/toolchain/bin/funcompile new file mode 100755 index 0000000..6ba67d7 --- /dev/null +++ b/toolchain/bin/funcompile @@ -0,0 +1,3 @@ +#!/bin/bash -e + +/home/daniil/repos/ton/build/crypto/func -WRS -o "$(basename $1 .fc).fif" "$TONLIB_HOME/crypto/smartcont/stdlib.fc" "$@" diff --git a/toolchain/build.sh b/toolchain/build.sh new file mode 100755 index 0000000..e8f67d4 --- /dev/null +++ b/toolchain/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash -e + +cd "$(dirname "$0")"/.. + +git submodule update --init --recursive + +cd lib + +grep -q TONLIB_HOME $HOME/.bashrc || { + echo "export TONLIB_HOME=$PWD" >> $HOME/.bashrc + echo 'export FIFTPATH=$TONLIB_HOME/crypto/fift/lib:$TONLIB_HOME/crypto/smartcont' >> $HOME/.bashrc + echo 'export PATH=$PATH:$TONLIB_HOME/../toolchain/bin' >> $HOME/.bashrc +} + + +git pull origin master + +mkdir -p build +cd build +[ ! -f CMakeCache.txt ] && { + cmake .. +} +cmake --build . --target lite-client +cmake --build . --target fift +cmake --build . --target func + +cd ../.. diff --git a/wallet-code.fc b/wallet-code.fc new file mode 100644 index 0000000..2052fa6 --- /dev/null +++ b/wallet-code.fc @@ -0,0 +1,38 @@ +;; Simple wallet smart contract + +() recv_internal(slice in_msg) impure { + ;; do nothing for internal messages +} + +() recv_external(slice in_msg) impure { + var signature = in_msg~load_bits(512); + var cs = in_msg; + var (msg_seqno, valid_until) = (cs~load_uint(32), cs~load_uint(32)); + throw_if(35, valid_until <= now()); + var ds = get_data().begin_parse(); + var (stored_seqno, public_key) = (ds~load_uint(32), ds~load_uint(256)); + ds.end_parse(); + throw_unless(33, msg_seqno == stored_seqno); + throw_unless(34, check_signature(slice_hash(in_msg), signature, public_key)); + accept_message(); + cs~touch(); + + var op = cs~load_uint(8); + if (op == 1) { + set_code(cs~load_ref()); + } else { + while (cs.slice_refs()) { + var mode = cs~load_uint(8); + send_raw_message(cs~load_ref(), mode); + } + } + + cs.end_parse(); + set_data(begin_cell().store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell()); +} + +;; Get methods + +int seqno() method_id { + return get_data().begin_parse().preload_uint(32); +}