1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-12 11:12:16 +00:00
ton/crypto/vm/tonops.h
EmelyanenkoK 9d05696452
Add infrastructure for precompiled smartcontracts (#927)
* Utils for writing precompiled contracts

* Precompiled contracts in config, override gas_usage for them

* Add base class for precompiled contracts

* Improve utils for precompiled smc

* Implement GETPRECOMPILEDGAS

* Enable precompiles by flag

* Process null data in PrecompiledSmartContract

* Fix ton_block wasm build

* Fix vm::util::store_(u)long

---------

Co-authored-by: SpyCheese <mikle98@yandex.ru>
2024-03-05 16:54:49 +03:00

56 lines
2.4 KiB
C++

/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#pragma once
#include "vm/vm.h"
#include "ton/ton-types.h"
#include "mc-config.h"
namespace vm {
class OpcodeTable;
void register_ton_ops(OpcodeTable& cp0);
namespace util {
// "_q" functions throw on error if not quiet, return false if quiet (leaving cs unchanged)
bool load_var_integer_q(CellSlice& cs, td::RefInt256& res, int len_bits, bool sgnd, bool quiet);
bool load_coins_q(CellSlice& cs, td::RefInt256& res, bool quiet);
bool load_msg_addr_q(CellSlice& cs, CellSlice& res, bool quiet);
bool parse_std_addr_q(CellSlice cs, ton::WorkchainId& res_wc, ton::StdSmcAddress& res_addr, bool quiet);
// Non-"_q" functions throw on error
td::RefInt256 load_var_integer(CellSlice& cs, int len_bits, bool sgnd);
td::RefInt256 load_coins(CellSlice& cs);
CellSlice load_msg_addr(CellSlice& cs);
std::pair<ton::WorkchainId, ton::StdSmcAddress> parse_std_addr(CellSlice cs);
// store_... functions throw on error if not quiet, return false if quiet (leaving cb unchanged)
bool store_var_integer(CellBuilder& cb, const td::RefInt256& x, int len_bits, bool sgnd, bool quiet = false);
bool store_coins(CellBuilder& cb, const td::RefInt256& x, bool quiet = false);
block::GasLimitsPrices get_gas_prices(const td::Ref<Tuple>& unpacked_config, bool is_masterchain);
block::MsgPrices get_msg_prices(const td::Ref<Tuple>& unpacked_config, bool is_masterchain);
td::optional<block::StoragePrices> get_storage_prices(const td::Ref<Tuple>& unpacked_config);
td::RefInt256 calculate_storage_fee(const td::optional<block::StoragePrices>& maybe_prices, bool is_masterchain,
td::uint64 delta, td::uint64 bits, td::uint64 cells);
} // namespace util
} // namespace vm