mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
updated tonlib
This commit is contained in:
parent
c860ce3d1e
commit
3002321eb7
22 changed files with 576 additions and 109 deletions
|
@ -350,6 +350,7 @@ if (NOT CMAKE_CROSSCOMPILING)
|
|||
|
||||
GenFif(DEST smartcont/auto/config-code SOURCE smartcont/config-code.fc NAME config)
|
||||
GenFif(DEST smartcont/auto/wallet-code SOURCE smartcont/wallet-code.fc NAME wallet)
|
||||
GenFif(DEST smartcont/auto/wallet3-code SOURCE smartcont/wallet3-code.fc NAME wallet3)
|
||||
GenFif(DEST smartcont/auto/simple-wallet-code SOURCE smartcont/simple-wallet-code.fc NAME simple-wallet)
|
||||
GenFif(DEST smartcont/auto/highload-wallet-code SOURCE smartcont/highload-wallet-code.fc NAME highload-wallet)
|
||||
GenFif(DEST smartcont/auto/highload-wallet-v2-code SOURCE smartcont/highload-wallet-v2-code.fc NAME highoad-wallet-v2)
|
||||
|
@ -364,7 +365,9 @@ endif()
|
|||
add_library(smc-envelope ${SMC_ENVELOPE_SOURCE})
|
||||
target_include_directories(smc-envelope PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||
target_link_libraries(smc-envelope PUBLIC ton_crypto PRIVATE tdutils ton_block)
|
||||
add_dependencies(smc-envelope gen_fif)
|
||||
if (NOT CMAKE_CROSSCOMPILING)
|
||||
add_dependencies(smc-envelope gen_fif)
|
||||
endif()
|
||||
|
||||
add_executable(create-state block/create-state.cpp)
|
||||
target_include_directories(create-state PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
|
|
|
@ -534,19 +534,16 @@ td::Result<std::vector<StoragePrices>> Config::get_storage_prices() const {
|
|||
return std::move(res);
|
||||
}
|
||||
|
||||
td::Result<GasLimitsPrices> Config::get_gas_limits_prices(bool is_masterchain) const {
|
||||
td::Result<GasLimitsPrices> Config::do_get_gas_limits_prices(td::Ref<vm::Cell> cell, int id) {
|
||||
GasLimitsPrices res;
|
||||
auto id = is_masterchain ? 20 : 21;
|
||||
auto cell = get_config_param(id);
|
||||
if (cell.is_null()) {
|
||||
return td::Status::Error(PSLICE() << "configuration parameter " << id << " with gas prices is absent");
|
||||
}
|
||||
auto cs = vm::load_cell_slice(std::move(cell));
|
||||
auto cs = vm::load_cell_slice(cell);
|
||||
block::gen::GasLimitsPrices::Record_gas_flat_pfx flat;
|
||||
if (tlb::unpack(cs, flat)) {
|
||||
cs = *flat.other;
|
||||
res.flat_gas_limit = flat.flat_gas_limit;
|
||||
res.flat_gas_price = flat.flat_gas_price;
|
||||
} else {
|
||||
cs = vm::load_cell_slice(cell);
|
||||
}
|
||||
auto f = [&](const auto& r, td::uint64 spec_limit) {
|
||||
res.gas_limit = r.gas_limit;
|
||||
|
@ -570,6 +567,14 @@ td::Result<GasLimitsPrices> Config::get_gas_limits_prices(bool is_masterchain) c
|
|||
}
|
||||
return res;
|
||||
}
|
||||
td::Result<GasLimitsPrices> Config::get_gas_limits_prices(bool is_masterchain) const {
|
||||
auto id = is_masterchain ? 20 : 21;
|
||||
auto cell = get_config_param(id);
|
||||
if (cell.is_null()) {
|
||||
return td::Status::Error(PSLICE() << "configuration parameter " << id << " with gas prices is absent");
|
||||
}
|
||||
return do_get_gas_limits_prices(std::move(cell), id);
|
||||
}
|
||||
|
||||
td::Result<MsgPrices> Config::get_msg_prices(bool is_masterchain) const {
|
||||
auto id = is_masterchain ? 24 : 25;
|
||||
|
|
|
@ -540,6 +540,7 @@ class Config {
|
|||
static td::Result<std::unique_ptr<ValidatorSet>> unpack_validator_set(Ref<vm::Cell> valset_root);
|
||||
td::Result<std::vector<StoragePrices>> get_storage_prices() const;
|
||||
td::Result<GasLimitsPrices> get_gas_limits_prices(bool is_masterchain = false) const;
|
||||
static td::Result<GasLimitsPrices> do_get_gas_limits_prices(td::Ref<vm::Cell> cell, int id);
|
||||
td::Result<MsgPrices> get_msg_prices(bool is_masterchain = false) const;
|
||||
static CatchainValidatorsConfig unpack_catchain_validators_config(Ref<vm::Cell> cell);
|
||||
CatchainValidatorsConfig get_catchain_validators_config() const;
|
||||
|
|
|
@ -68,7 +68,7 @@ sym_idx_t SymTableBase::gen_lookup(std::string str, int mode, sym_idx_t idx) {
|
|||
if (!(mode & 1)) {
|
||||
return not_found;
|
||||
}
|
||||
if (def_sym >= ((long)p * 3) / 4) {
|
||||
if (def_sym >= ((long long)p * 3) / 4) {
|
||||
throw SymTableOverflow{def_sym};
|
||||
}
|
||||
sym_table[h1] = std::make_unique<Symbol>(str, idx <= 0 ? sym_idx_t(h1) : -idx);
|
||||
|
|
|
@ -163,6 +163,14 @@ slice create_new_entry(cs) inline {
|
|||
return begin_cell().store_int(false, 1).store_uint(0, 64).store_uint(0, 256).store_slice(cs).end_cell().begin_parse();
|
||||
}
|
||||
|
||||
(cell, int, int, slice) unpack_suggestion(slice cs) inline {
|
||||
return (cs~load_dict(), cs~load_uint(64), cs~load_uint(256), cs);
|
||||
}
|
||||
|
||||
builder pack_suggestion(cell voters, int sum_weight, int vset_id, slice body) inline {
|
||||
return begin_cell().store_dict(voters).store_uint(sum_weight, 64).store_uint(vset_id, 256).store_slice(body);
|
||||
}
|
||||
|
||||
cell register_vote(vote_dict, action, cs, idx, weight) {
|
||||
int hash = 0;
|
||||
var entry = null();
|
||||
|
|
63
crypto/smartcont/new-wallet-v3.fif
Normal file
63
crypto/smartcont/new-wallet-v3.fif
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/fift -s
|
||||
"TonUtil.fif" include
|
||||
"Asm.fif" include
|
||||
|
||||
{ ."usage: " @' $0 type ." <workchain-id> <wallet-id> [<filename-base>]" cr
|
||||
."Creates a new advanced wallet with unique 32-bit identifier <wallet-id> in specified workchain, with private key saved to or loaded from <filename-base>.pk" cr
|
||||
."('new-wallet.pk' by default)" cr 1 halt
|
||||
} : usage
|
||||
$# 2- -2 and ' usage if
|
||||
|
||||
$1 parse-workchain-id =: wc // set workchain id from command line argument
|
||||
$2 parse-int =: subwallet-id
|
||||
def? $3 { @' $3 } { "new-wallet" } cond constant file-base
|
||||
|
||||
."Creating new advanced v3 wallet in workchain " wc . cr
|
||||
."with unique wallet id " subwallet-id . cr
|
||||
|
||||
// Create new advanced wallet; code adapted from `auto/wallet3-code.fif`
|
||||
<{ SETCP0 DUP IFNOTRET // return if recv_internal
|
||||
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
|
||||
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
|
||||
}>
|
||||
INC 32 THROWIF // fail unless recv_external
|
||||
9 PUSHPOW2 LDSLICEX DUP 32 LDU 32 LDU 32 LDU // signature in_msg subwallet_id valid_until msg_seqno cs
|
||||
NOW s1 s3 XCHG LEQ 35 THROWIF // signature in_msg subwallet_id cs msg_seqno
|
||||
c4 PUSH CTOS 32 LDU 32 LDU 256 LDU ENDS // signature in_msg subwallet_id cs msg_seqno stored_seqno stored_subwallet public_key
|
||||
s3 s2 XCPU EQUAL 33 THROWIFNOT // signature in_msg subwallet_id cs public_key stored_seqno stored_subwallet
|
||||
s4 s4 XCPU EQUAL 34 THROWIFNOT // signature in_msg stored_subwallet cs public_key stored_seqno
|
||||
s0 s4 XCHG HASHSU // signature stored_seqno stored_subwallet cs public_key msg_hash
|
||||
s0 s5 s5 XC2PU // public_key stored_seqno stored_subwallet cs msg_hash signature public_key
|
||||
CHKSIGNU 35 THROWIFNOT // public_key stored_seqno stored_subwallet cs
|
||||
ACCEPT
|
||||
WHILE:<{
|
||||
DUP SREFS // public_key stored_seqno stored_subwallet cs _51
|
||||
}>DO<{ // public_key stored_seqno stored_subwallet cs
|
||||
8 LDU LDREF s0 s2 XCHG // public_key stored_seqno stored_subwallet cs _56 mode
|
||||
SENDRAWMSG
|
||||
}> // public_key stored_seqno stored_subwallet cs
|
||||
ENDS SWAP INC // public_key stored_subwallet seqno'
|
||||
NEWC 32 STU 32 STU 256 STU ENDC c4 POP
|
||||
}>c // >libref
|
||||
// code
|
||||
<b 0 32 u, subwallet-id 32 u,
|
||||
file-base +".pk" load-generate-keypair
|
||||
constant wallet_pk
|
||||
B,
|
||||
b> // data
|
||||
null // no libraries
|
||||
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
|
||||
dup ."StateInit: " <s csr. cr
|
||||
dup hashu wc swap 2dup 2constant wallet_addr
|
||||
."new wallet address = " 2dup .addr cr
|
||||
2dup file-base +".addr" save-address-verbose
|
||||
."Non-bounceable address (for init): " 2dup 7 .Addr cr
|
||||
."Bounceable address (for later access): " 6 .Addr cr
|
||||
<b subwallet-id 32 u, -1 32 i, 0 32 u, b>
|
||||
dup ."signing message: " <s csr. cr
|
||||
dup hashu wallet_pk ed25519_sign_uint rot
|
||||
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
|
||||
dup ."External message for initialization is " <s csr. cr
|
||||
2 boc+>B dup Bx. cr
|
||||
file-base +"-query.boc" tuck B>file
|
||||
."(Saved wallet creating query to file " type .")" cr
|
35
crypto/smartcont/wallet3-code.fc
Normal file
35
crypto/smartcont/wallet3-code.fc
Normal file
|
@ -0,0 +1,35 @@
|
|||
;; 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 (subwallet_id, valid_until, msg_seqno) = (cs~load_uint(32), cs~load_uint(32), cs~load_uint(32));
|
||||
throw_if(35, valid_until <= now());
|
||||
var ds = get_data().begin_parse();
|
||||
var (stored_seqno, stored_subwallet, public_key) = (ds~load_uint(32), ds~load_uint(32), ds~load_uint(256));
|
||||
ds.end_parse();
|
||||
throw_unless(33, msg_seqno == stored_seqno);
|
||||
throw_unless(34, subwallet_id == stored_subwallet);
|
||||
throw_unless(35, check_signature(slice_hash(in_msg), signature, public_key));
|
||||
accept_message();
|
||||
cs~touch();
|
||||
while (cs.slice_refs()) {
|
||||
var mode = cs~load_uint(8);
|
||||
send_raw_message(cs~load_ref(), mode);
|
||||
}
|
||||
set_data(begin_cell()
|
||||
.store_uint(stored_seqno + 1, 32)
|
||||
.store_uint(stored_subwallet, 32)
|
||||
.store_uint(public_key, 256)
|
||||
.end_cell());
|
||||
}
|
||||
|
||||
;; Get methods
|
||||
|
||||
int seqno() method_id {
|
||||
return get_data().begin_parse().preload_uint(32);
|
||||
}
|
|
@ -1021,9 +1021,9 @@ void CppTypeCode::generate_tag_pfx_selector(std::ostream& os, std::string nl, co
|
|||
}
|
||||
os << "};" << nl << "return ctab[1 + ";
|
||||
if (simple) {
|
||||
os << "(long)cs.prefetch_ulong(" << d << ")];";
|
||||
os << "(long long)cs.prefetch_ulong(" << d << ")];";
|
||||
} else {
|
||||
os << "(long)cs.bselect" << (d >= min_size ? "(" : "_ext(") << d << ", " << HexConstWriter{mask} << ")];";
|
||||
os << "(long long)cs.bselect" << (d >= min_size ? "(" : "_ext(") << d << ", " << HexConstWriter{mask} << ")];";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1153,7 +1153,7 @@ void CppTypeCode::generate_get_tag_body(std::ostream& os, std::string nl) {
|
|||
os << ")) {";
|
||||
for (int i = 0; i < l; i++) {
|
||||
if (A[i] != 0) {
|
||||
if ((long)A[i] > 0) {
|
||||
if ((long long)A[i] > 0) {
|
||||
int j;
|
||||
for (j = 0; j < i; j++) {
|
||||
if (A[j] == A[i]) {
|
||||
|
@ -1165,7 +1165,7 @@ void CppTypeCode::generate_get_tag_body(std::ostream& os, std::string nl) {
|
|||
}
|
||||
}
|
||||
os << nl << "case " << i << ":";
|
||||
if ((long)A[i] > 0) {
|
||||
if ((long long)A[i] > 0) {
|
||||
int j;
|
||||
for (j = i + 1; j < l; j++) {
|
||||
if (A[j] == A[i]) {
|
||||
|
|
|
@ -687,7 +687,7 @@ unsigned long long BinTrie::build_submap(int depth, unsigned long long A[]) cons
|
|||
} else {
|
||||
std::memset(A + n, 0, n * 8);
|
||||
}
|
||||
if (A[n] != A[n - 1] || (long)A[n] < 0) {
|
||||
if (A[n] != A[n - 1] || (long long)A[n] < 0) {
|
||||
r2 |= 1;
|
||||
} else {
|
||||
r2 &= ~1;
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include "vm/cellslice.h"
|
||||
#include "vm/excno.hpp"
|
||||
|
||||
#include "td/utils/Span.h"
|
||||
|
||||
namespace td {
|
||||
extern template class td::Cnt<std::string>;
|
||||
extern template class td::Ref<td::Cnt<std::string>>;
|
||||
|
@ -156,7 +158,7 @@ class StackEntry {
|
|||
|
||||
private:
|
||||
template <typename T, Type tag>
|
||||
Ref<T> dynamic_as() const & {
|
||||
Ref<T> dynamic_as() const& {
|
||||
return tp == tag ? static_cast<Ref<T>>(ref) : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
|
@ -168,7 +170,7 @@ class StackEntry {
|
|||
return tp == tag ? static_cast<Ref<T>>(std::move(ref)) : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
Ref<T> as() const & {
|
||||
Ref<T> as() const& {
|
||||
return tp == tag ? Ref<T>{td::static_cast_ref(), ref} : td::Ref<T>{};
|
||||
}
|
||||
template <typename T, Type tag>
|
||||
|
@ -189,31 +191,31 @@ class StackEntry {
|
|||
return ref;
|
||||
}
|
||||
}
|
||||
td::RefInt256 as_int() const & {
|
||||
td::RefInt256 as_int() const& {
|
||||
return as<td::CntInt256, t_int>();
|
||||
}
|
||||
td::RefInt256 as_int() && {
|
||||
return move_as<td::CntInt256, t_int>();
|
||||
}
|
||||
Ref<Cell> as_cell() const & {
|
||||
Ref<Cell> as_cell() const& {
|
||||
return as<Cell, t_cell>();
|
||||
}
|
||||
Ref<Cell> as_cell() && {
|
||||
return move_as<Cell, t_cell>();
|
||||
}
|
||||
Ref<CellBuilder> as_builder() const & {
|
||||
Ref<CellBuilder> as_builder() const& {
|
||||
return as<CellBuilder, t_builder>();
|
||||
}
|
||||
Ref<CellBuilder> as_builder() && {
|
||||
return move_as<CellBuilder, t_builder>();
|
||||
}
|
||||
Ref<CellSlice> as_slice() const & {
|
||||
Ref<CellSlice> as_slice() const& {
|
||||
return as<CellSlice, t_slice>();
|
||||
}
|
||||
Ref<CellSlice> as_slice() && {
|
||||
return move_as<CellSlice, t_slice>();
|
||||
}
|
||||
Ref<Continuation> as_cont() const &;
|
||||
Ref<Continuation> as_cont() const&;
|
||||
Ref<Continuation> as_cont() &&;
|
||||
Ref<Cnt<std::string>> as_string_ref() const {
|
||||
return as<Cnt<std::string>, t_string>();
|
||||
|
@ -228,16 +230,16 @@ class StackEntry {
|
|||
std::string as_bytes() const {
|
||||
return tp == t_bytes ? *as_bytes_ref() : "";
|
||||
}
|
||||
Ref<Box> as_box() const &;
|
||||
Ref<Box> as_box() const&;
|
||||
Ref<Box> as_box() &&;
|
||||
Ref<Tuple> as_tuple() const &;
|
||||
Ref<Tuple> as_tuple() const&;
|
||||
Ref<Tuple> as_tuple() &&;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const &;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const&;
|
||||
Ref<Tuple> as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) &&;
|
||||
Ref<Atom> as_atom() const &;
|
||||
Ref<Atom> as_atom() const&;
|
||||
Ref<Atom> as_atom() &&;
|
||||
template <class T>
|
||||
Ref<T> as_object() const & {
|
||||
Ref<T> as_object() const& {
|
||||
return dynamic_as<T, t_object>();
|
||||
}
|
||||
template <class T>
|
||||
|
@ -361,6 +363,9 @@ class Stack : public td::CntObject {
|
|||
std::vector<StackEntry>::const_iterator from_top(int offs) const {
|
||||
return stack.cend() - offs;
|
||||
}
|
||||
td::Span<StackEntry> as_span() const {
|
||||
return stack;
|
||||
}
|
||||
bool at_least(int req) const {
|
||||
return depth() >= req;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue