1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

updated tonlib + fixes in vm

This commit is contained in:
ton 2020-02-20 19:56:18 +04:00
parent 28735ddc9e
commit efd47af432
42 changed files with 750 additions and 307 deletions

View file

@ -81,7 +81,7 @@ td::Ref<vm::Cell> HighloadWallet::make_a_gift_message(const td::Ed25519::Private
}
td::Ref<vm::Cell> HighloadWallet::get_init_code() noexcept {
return SmartContractCode::highload_wallet();
return SmartContractCode::get_code(SmartContractCode::HighloadWalletV1);
}
vm::CellHash HighloadWallet::get_init_code_hash() noexcept {

View file

@ -104,7 +104,7 @@ td::Ref<vm::Cell> HighloadWalletV2::make_a_gift_message(const td::Ed25519::Priva
}
td::Ref<vm::Cell> HighloadWalletV2::get_init_code(td::int32 revision) noexcept {
return SmartContractCode::highload_wallet_v2(revision);
return SmartContractCode::get_code(SmartContractCode::HighloadWalletV2, revision);
}
vm::CellHash HighloadWalletV2::get_init_code_hash() noexcept {

View file

@ -178,15 +178,17 @@ td::Result<std::vector<DnsInterface::Entry>> DnsInterface::resolve(td::Slice nam
*/
// creation
td::Ref<ManualDns> ManualDns::create(td::Ref<vm::Cell> data, int revision) {
return td::Ref<ManualDns>(true, State{ton::SmartContractCode::dns_manual(revision), std::move(data)});
return td::Ref<ManualDns>(
true, State{ton::SmartContractCode::get_code(ton::SmartContractCode::ManualDns, revision), std::move(data)});
}
td::Ref<ManualDns> ManualDns::create(const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id, int revision) {
return create(create_init_data_fast(public_key, wallet_id), revision);
}
td::optional<td::int32> ManualDns::guess_revision(const vm::Cell::Hash& code_hash) {
for (auto i : {-1, 1}) {
if (ton::SmartContractCode::dns_manual(i)->get_hash() == code_hash) {
for (auto i : ton::SmartContractCode::get_revisions(ton::SmartContractCode::ManualDns)) {
if (ton::SmartContractCode::get_code(ton::SmartContractCode::ManualDns, i)->get_hash() == code_hash) {
return i;
}
}

View file

@ -48,7 +48,8 @@ td::Ref<vm::Cell> MultisigWallet::QueryBuilder::create(td::int32 id, td::Ed25519
}
td::Ref<MultisigWallet> MultisigWallet::create(td::Ref<vm::Cell> data) {
return td::Ref<MultisigWallet>(true, State{ton::SmartContractCode::multisig(), std::move(data)});
return td::Ref<MultisigWallet>(
true, State{ton::SmartContractCode::get_code(ton::SmartContractCode::Multisig), std::move(data)});
}
int MultisigWallet::processed(td::uint64 query_id) const {

View file

@ -96,19 +96,6 @@ const auto& get_map() {
"FwCEMQLTAAHAAZPUAdCY0wUBqgLXGAHiINdJwg/"
"ypiB41yLXCwfyaHBTEddJqTYCmNMHAcAAEqEB5DDIywYBzxbJ0FADACBZ9KhvpSCUAvQEMJIybeICACg0A4AQ9FqZECOECUBE8AEBkjAx4gBmM"
"SLAFZwy9AQQI4QJUELwAQHgIsAWmDIChAn0czAB4DAyIMAfkzD0BODAIJJtAeDyLG0B");
//auto check_revision = [&](td::Slice name, td::int32 default_revision) {
//auto it = map.find(name);
//CHECK(it != map.end());
//auto other_it = map.find(PSLICE() << name << "-r" << default_revision);
//CHECK(other_it != map.end());
//CHECK(it->second->get_hash() == other_it->second->get_hash());
//};
//check_revision("highload-wallet", HIGHLOAD_WALLET_REVISION);
//check_revision("highload-wallet-v2", HIGHLOAD_WALLET2_REVISION);
//check_revision("simple-wallet", WALLET_REVISION);
//check_revision("wallet", WALLET2_REVISION);
//check_revision("wallet3", WALLET3_REVISION);
return map;
}();
return map;
@ -123,60 +110,93 @@ td::Result<td::Ref<vm::Cell>> SmartContractCode::load(td::Slice name) {
}
return it->second;
}
td::Ref<vm::Cell> SmartContractCode::multisig() {
auto res = load("multisig").move_as_ok();
return res;
}
td::Ref<vm::Cell> SmartContractCode::wallet3(int revision) {
if (revision == 0) {
revision = WALLET3_REVISION;
td::Span<int> SmartContractCode::get_revisions(Type type) {
switch (type) {
case Type::WalletV1: {
static int res[] = {1, 2};
return res;
}
case Type::WalletV2: {
static int res[] = {1, 2};
return res;
}
case Type::WalletV3: {
static int res[] = {1, 2};
return res;
}
case Type::WalletV1Ext: {
static int res[] = {-1};
return res;
}
case Type::HighloadWalletV1: {
static int res[] = {-1, 1, 2};
return res;
}
case Type::HighloadWalletV2: {
static int res[] = {-1, 1, 2};
return res;
}
case Type::Multisig: {
static int res[] = {-1};
return res;
}
case Type::ManualDns: {
static int res[] = {-1, 1};
return res;
}
}
auto res = load(PSLICE() << "wallet3-r" << revision).move_as_ok();
return res;
UNREACHABLE();
return {};
}
td::Ref<vm::Cell> SmartContractCode::wallet(int revision) {
if (revision == 0) {
revision = WALLET2_REVISION;
}
auto res = load(PSLICE() << "wallet-r" << revision).move_as_ok();
return res;
}
td::Ref<vm::Cell> SmartContractCode::simple_wallet(int revision) {
if (revision == 0) {
revision = WALLET_REVISION;
}
auto res = load(PSLICE() << "simple-wallet-r" << revision).move_as_ok();
return res;
}
td::Ref<vm::Cell> SmartContractCode::simple_wallet_ext() {
static auto res = load("simple-wallet-ext").move_as_ok();
return res;
}
td::Ref<vm::Cell> SmartContractCode::highload_wallet(int revision) {
td::Result<int> SmartContractCode::validate_revision(Type type, int revision) {
auto revisions = get_revisions(type);
if (revision == -1) {
return load("highload-wallet").move_as_ok();
if (revisions[0] == -1) {
return -1;
}
return revisions[revisions.size() - 1];
}
if (revision == 0) {
revision = HIGHLOAD_WALLET_REVISION;
return revisions[revisions.size() - 1];
}
return load(PSLICE() << "highload-wallet-r" << revision).move_as_ok();
for (auto x : revisions) {
if (x == revision) {
return revision;
}
}
return td::Status::Error("No such revision");
}
td::Ref<vm::Cell> SmartContractCode::highload_wallet_v2(int revision) {
td::Ref<vm::Cell> SmartContractCode::get_code(Type type, int ext_revision) {
auto revision = validate_revision(type, ext_revision).move_as_ok();
auto basename = [](Type type) -> td::Slice {
switch (type) {
case Type::WalletV1:
return "simple-wallet";
case Type::WalletV2:
return "wallet";
case Type::WalletV3:
return "wallet3";
case Type::WalletV1Ext:
return "simple-wallet-ext";
case Type::HighloadWalletV1:
return "highload-wallet";
case Type::HighloadWalletV2:
return "highload-wallet-v2";
case Type::Multisig:
return "multisig";
case Type::ManualDns:
return "dns-manual";
}
UNREACHABLE();
return "";
}(type);
if (revision == -1) {
return load("highload-wallet-v2").move_as_ok();
return load(basename).move_as_ok();
}
if (revision == 0) {
revision = HIGHLOAD_WALLET2_REVISION;
}
return load(PSLICE() << "highload-wallet-v2-r" << revision).move_as_ok();
}
td::Ref<vm::Cell> SmartContractCode::dns_manual(int revision) {
if (revision == -1) {
return load("dns-manual").move_as_ok();
}
if (revision == 0) {
revision = DNS_REVISION;
}
return load(PSLICE() << "dns-manual-r" << revision).move_as_ok();
return load(PSLICE() << basename << "-r" << revision).move_as_ok();
}
} // namespace ton

View file

@ -18,17 +18,16 @@
*/
#include "vm/cells.h"
#include "td/utils/Span.h"
namespace ton {
class SmartContractCode {
public:
static td::Result<td::Ref<vm::Cell>> load(td::Slice name);
static td::Ref<vm::Cell> multisig();
static td::Ref<vm::Cell> wallet3(int revision = 0);
static td::Ref<vm::Cell> wallet(int revision = 0);
static td::Ref<vm::Cell> simple_wallet(int revision = 0);
static td::Ref<vm::Cell> simple_wallet_ext();
static td::Ref<vm::Cell> highload_wallet(int revision = 0);
static td::Ref<vm::Cell> highload_wallet_v2(int revision = 0);
static td::Ref<vm::Cell> dns_manual(int revision = 0);
enum Type { WalletV1 = 1, WalletV1Ext, WalletV2, WalletV3, HighloadWalletV1, HighloadWalletV2, ManualDns, Multisig };
static td::Span<int> get_revisions(Type type);
static td::Result<int> validate_revision(Type type, int revision);
static td::Ref<vm::Cell> get_code(Type type, int revision = 0);
};
} // namespace ton

View file

@ -64,7 +64,7 @@ td::Ref<vm::Cell> TestWallet::make_a_gift_message_static(const td::Ed25519::Priv
}
td::Ref<vm::Cell> TestWallet::get_init_code(td::int32 revision) noexcept {
return ton::SmartContractCode::simple_wallet(revision);
return ton::SmartContractCode::get_code(ton::SmartContractCode::WalletV1, revision);
}
vm::CellHash TestWallet::get_init_code_hash() noexcept {

View file

@ -70,7 +70,7 @@ td::Ref<vm::Cell> Wallet::make_a_gift_message(const td::Ed25519::PrivateKey& pri
}
td::Ref<vm::Cell> Wallet::get_init_code(td::int32 revision) noexcept {
return SmartContractCode::wallet(revision);
return SmartContractCode::get_code(ton::SmartContractCode::WalletV2, revision);
}
vm::CellHash Wallet::get_init_code_hash() noexcept {

View file

@ -80,7 +80,7 @@ td::Ref<vm::Cell> WalletV3::make_a_gift_message(const td::Ed25519::PrivateKey& p
}
td::Ref<vm::Cell> WalletV3::get_init_code(td::int32 revision) noexcept {
return SmartContractCode::wallet3(revision);
return SmartContractCode::get_code(ton::SmartContractCode::WalletV3, revision);
}
vm::CellHash WalletV3::get_init_code_hash() noexcept {