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

updated func and tonlib

This commit is contained in:
ton 2020-02-15 20:03:17 +04:00
parent 493ae2410c
commit a73d202ba2
50 changed files with 1340 additions and 271 deletions

View file

@ -177,11 +177,30 @@ td::Result<std::vector<DnsInterface::Entry>> DnsInterface::resolve(td::Slice nam
[UInt<256b>:new_public_key]
*/
// creation
td::Ref<ManualDns> ManualDns::create(td::Ref<vm::Cell> data) {
return td::Ref<ManualDns>(true, State{ton::SmartContractCode::dns_manual(), std::move(data)});
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)});
}
td::Ref<ManualDns> ManualDns::create(const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id) {
return create(create_init_data_fast(public_key, wallet_id));
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) {
return i;
}
}
return {};
}
td::optional<td::int32> ManualDns::guess_revision(const block::StdAddress& address,
const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id) {
for (auto i : {-1, 1}) {
auto dns = ton::ManualDns::create(public_key, wallet_id, i);
if (dns->get_address() == address) {
return i;
}
}
return {};
}
td::Result<td::uint32> ManualDns::get_wallet_id() const {

View file

@ -180,14 +180,18 @@ class ManualDns : public ton::SmartContract, public DnsInterface {
static td::Ref<ManualDns> create(State state) {
return td::Ref<ManualDns>(true, std::move(state));
}
static td::Ref<ManualDns> create(td::Ref<vm::Cell> data = {});
static td::Ref<ManualDns> create(const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id);
static td::Ref<ManualDns> create(td::Ref<vm::Cell> data = {}, int revision = 0);
static td::Ref<ManualDns> create(const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id, int revision = 0);
static std::string serialize_data(const EntryData& data);
static td::Result<td::optional<ManualDns::EntryData>> parse_data(td::Slice cmd);
static td::Result<ManualDns::ActionExt> parse_line(td::Slice cmd);
static td::Result<std::vector<ManualDns::ActionExt>> parse(td::Slice cmd);
static td::optional<td::int32> guess_revision(const vm::Cell::Hash& code_hash);
static td::optional<td::int32> guess_revision(const block::StdAddress& address,
const td::Ed25519::PublicKey& public_key, td::uint32 wallet_id);
td::Ref<vm::Cell> create_init_data(const td::Ed25519::PublicKey& public_key, td::uint32 valid_until) const {
return create_init_data_fast(public_key, valid_until);
}

View file

@ -30,6 +30,7 @@ constexpr static int WALLET2_REVISION = 2;
constexpr static int WALLET3_REVISION = 2;
constexpr static int HIGHLOAD_WALLET_REVISION = 2;
constexpr static int HIGHLOAD_WALLET2_REVISION = 2;
constexpr static int DNS_REVISION = 1;
const auto& get_map() {
static auto map = [] {
std::map<std::string, td::Ref<vm::Cell>, std::less<>> map;
@ -80,15 +81,30 @@ const auto& get_map() {
with_tvm_code("wallet3-r2",
"te6ccgEBAQEAcQAA3v8AIN0gggFMl7ohggEznLqxn3Gw7UTQ0x/THzHXC//jBOCk8mCDCNcYINMf0x/TH/gjE7vyY+1E0NMf0x/"
"T/9FRMrryoVFEuvKiBPkBVBBV+RDyo/gAkyDXSpbTB9QC+wDo0QGkyMsfyx/L/8ntVA==");
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);
with_tvm_code(
"dns-manual-r1",
"te6ccgECGAEAAtAAART/APSkE/S88sgLAQIBIAIDAgFIBAUC7PLbPAWDCNcYIPkBAdMf0z/"
"4I6ofUyC58mNTKoBA9A5voTHyYFKUuvKiVBNG+RDyo/gAItcLBcAzmDQBdtch0/"
"8wjoVa2zxAA+"
"IDgyWhyEAHgED0Q44aIIBA9JZvpTJREJQwUwe53iCTMzUBkjIw4rPmNVUD8AQREgICxQYHAgEgDA0CAc8ICQAIqoJfAwIBSAoLACHWQK5Y+"
"J5Z/l//oAegBk9qpAAFF8DgABcyPQAydBBM/Rw8qGAAF72c52omhpr5jrhf/"
"AIBIA4PABG7Nz7UTQ1wsfgD+"
"7owwh10kglF8DcG3hIHew8l4ieNci1wsHnnDIUATPFhPLB8nQAqYI3iDACJRfA3Bt4Ns8FF8EI3ADqwKY0wcBwAAToQLkIG2OnF8DIcjLBiTPF"
"snQhAlUQgHbPAWlFbIgwQEVQzDmMzUilF8FcG3hMgHHAJMxfwHfAtdJpvmBEVEAAYIcAAkjEB4AKAEPRqABztRNDTH9M/0//"
"0BPQE0QE2cFmOlNs8IMcBnCDXSpPUMNCTMn8C4t4i5jAxEwT20wUhwQqOLCGRMeEhwAGXMdMH1AL7AOABwAmOFNQh+wTtQwLQ7R7tU1RiA/"
"EGgvIA4PIt4HAiwRSUMNIPAd5tbSTBHoreJMEUjpElhAkj2zwzApUyxwDyo5Fb4t4kwAuOEzQC9ARQJIAQ9G4wECOECVnwAQHgJMAMiuAwFBUW"
"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);
@ -137,21 +153,30 @@ td::Ref<vm::Cell> SmartContractCode::simple_wallet_ext() {
return res;
}
td::Ref<vm::Cell> SmartContractCode::highload_wallet(int revision) {
if (revision == -1) {
return load("highload-wallet").move_as_ok();
}
if (revision == 0) {
revision = HIGHLOAD_WALLET_REVISION;
}
auto res = load(PSLICE() << "highload-wallet-r" << revision).move_as_ok();
return res;
return load(PSLICE() << "highload-wallet-r" << revision).move_as_ok();
}
td::Ref<vm::Cell> SmartContractCode::highload_wallet_v2(int revision) {
if (revision == -1) {
return load("highload-wallet-v2").move_as_ok();
}
if (revision == 0) {
revision = HIGHLOAD_WALLET2_REVISION;
}
auto res = load(PSLICE() << "highload-wallet-v2-r" << revision).move_as_ok();
return res;
return load(PSLICE() << "highload-wallet-v2-r" << revision).move_as_ok();
}
td::Ref<vm::Cell> SmartContractCode::dns_manual() {
static auto res = load("dns-manual").move_as_ok();
return res;
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();
}
} // namespace ton

View file

@ -29,6 +29,6 @@ class SmartContractCode {
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();
static td::Ref<vm::Cell> dns_manual(int revision = 0);
};
} // namespace ton