2023-02-02 07:03:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include "crypto/common/refcnt.hpp"
|
|
|
|
#include "ton/ton-types.h"
|
|
|
|
#include "crypto/vm/cells.h"
|
|
|
|
#include "block/transaction.h"
|
|
|
|
#include "block/block-auto.h"
|
|
|
|
#include "block/block-parse.h"
|
|
|
|
#include "block/mc-config.h"
|
|
|
|
|
|
|
|
namespace emulator {
|
|
|
|
class TransactionEmulator {
|
|
|
|
block::Config config_;
|
|
|
|
vm::Dictionary libraries_;
|
|
|
|
int vm_log_verbosity_;
|
|
|
|
ton::UnixTime unixtime_;
|
|
|
|
ton::LogicalTime lt_;
|
|
|
|
td::BitArray<256> rand_seed_;
|
|
|
|
bool ignore_chksig_;
|
2023-04-02 14:28:18 +00:00
|
|
|
bool debug_enabled_;
|
2023-02-02 07:03:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
TransactionEmulator(block::Config&& config, int vm_log_verbosity = 0) :
|
|
|
|
config_(std::move(config)), libraries_(256), vm_log_verbosity_(vm_log_verbosity),
|
2023-04-02 14:28:18 +00:00
|
|
|
unixtime_(0), lt_(0), rand_seed_(td::BitArray<256>::zero()), ignore_chksig_(false), debug_enabled_(false) {
|
2023-02-02 07:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct EmulationResult {
|
|
|
|
std::string vm_log;
|
2023-03-07 16:51:09 +00:00
|
|
|
double elapsed_time;
|
2023-02-02 07:03:45 +00:00
|
|
|
|
2023-03-07 16:51:09 +00:00
|
|
|
EmulationResult(std::string vm_log_, double elapsed_time_) : vm_log(vm_log_), elapsed_time(elapsed_time_) {}
|
2023-02-02 07:03:45 +00:00
|
|
|
virtual ~EmulationResult() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EmulationSuccess: EmulationResult {
|
|
|
|
td::Ref<vm::Cell> transaction;
|
|
|
|
block::Account account;
|
2023-03-07 16:51:09 +00:00
|
|
|
td::Ref<vm::Cell> actions;
|
2023-02-02 07:03:45 +00:00
|
|
|
|
2023-03-07 16:51:09 +00:00
|
|
|
EmulationSuccess(td::Ref<vm::Cell> transaction_, block::Account account_, std::string vm_log_, td::Ref<vm::Cell> actions_, double elapsed_time_) :
|
|
|
|
EmulationResult(vm_log_, elapsed_time_), transaction(transaction_), account(account_) , actions(actions_)
|
2023-02-02 07:03:45 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EmulationExternalNotAccepted: EmulationResult {
|
|
|
|
int vm_exit_code;
|
|
|
|
|
2023-03-07 16:51:09 +00:00
|
|
|
EmulationExternalNotAccepted(std::string vm_log_, int vm_exit_code_, double elapsed_time_) :
|
|
|
|
EmulationResult(vm_log_, elapsed_time_), vm_exit_code(vm_exit_code_)
|
2023-02-02 07:03:45 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EmulationChain {
|
|
|
|
std::vector<td::Ref<vm::Cell>> transactions;
|
|
|
|
block::Account account;
|
|
|
|
};
|
|
|
|
|
|
|
|
const block::Config& get_config() {
|
|
|
|
return config_;
|
|
|
|
}
|
|
|
|
|
2023-05-24 09:40:04 +00:00
|
|
|
ton::UnixTime get_unixtime() {
|
|
|
|
return unixtime_;
|
|
|
|
}
|
|
|
|
|
2023-02-02 07:03:45 +00:00
|
|
|
td::Result<std::unique_ptr<EmulationResult>> emulate_transaction(
|
|
|
|
block::Account&& account, td::Ref<vm::Cell> msg_root, ton::UnixTime utime, ton::LogicalTime lt, int trans_type);
|
|
|
|
|
|
|
|
td::Result<EmulationSuccess> emulate_transaction(block::Account&& account, td::Ref<vm::Cell> original_trans);
|
|
|
|
td::Result<EmulationChain> emulate_transactions_chain(block::Account&& account, std::vector<td::Ref<vm::Cell>>&& original_transactions);
|
|
|
|
|
|
|
|
void set_unixtime(ton::UnixTime unixtime);
|
|
|
|
void set_lt(ton::LogicalTime lt);
|
|
|
|
void set_rand_seed(td::BitArray<256>& rand_seed);
|
|
|
|
void set_ignore_chksig(bool ignore_chksig);
|
|
|
|
void set_config(block::Config &&config);
|
|
|
|
void set_libs(vm::Dictionary &&libs);
|
2023-04-02 14:28:18 +00:00
|
|
|
void set_debug_enabled(bool debug_enabled);
|
2023-02-02 07:03:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool check_state_update(const block::Account& account, const block::gen::Transaction::Record& trans);
|
|
|
|
|
|
|
|
td::Result<std::unique_ptr<block::transaction::Transaction>> create_transaction(
|
|
|
|
td::Ref<vm::Cell> msg_root, block::Account* acc,
|
|
|
|
ton::UnixTime utime, ton::LogicalTime lt, int trans_type,
|
|
|
|
block::StoragePhaseConfig* storage_phase_cfg,
|
|
|
|
block::ComputePhaseConfig* compute_phase_cfg,
|
|
|
|
block::ActionPhaseConfig* action_phase_cfg);
|
|
|
|
};
|
|
|
|
} // namespace emulator
|