mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	Add tonlib method smc.getLibraries (#428)
Co-authored-by: ms <dungeon666master@protonmail.com>
This commit is contained in:
		
							parent
							
								
									054c5780d9
								
							
						
					
					
						commit
						6185e3b18f
					
				
					 4 changed files with 61 additions and 1 deletions
				
			
		|  | @ -180,6 +180,9 @@ smc.methodIdName name:string = smc.MethodId; | |||
| 
 | ||||
| smc.runResult gas_used:int53 stack:vector<tvm.StackEntry> exit_code:int32 = smc.RunResult; | ||||
| 
 | ||||
| smc.libraryEntry hash:int256 data:bytes = smc.LibraryEntry; | ||||
| smc.libraryResult result:(vector smc.libraryEntry) = smc.LibraryResult; | ||||
| 
 | ||||
| updateSendLiteServerQuery id:int64 data:bytes = Update; | ||||
| updateSyncState sync_state:SyncState = Update; | ||||
| 
 | ||||
|  | @ -286,6 +289,8 @@ smc.getData id:int53 = tvm.Cell; | |||
| smc.getState id:int53 = tvm.Cell; | ||||
| smc.runGetMethod id:int53 method:smc.MethodId stack:vector<tvm.StackEntry> = smc.RunResult; | ||||
| 
 | ||||
| smc.getLibraries library_list:(vector int256) = smc.LibraryResult; | ||||
| 
 | ||||
| dns.resolve account_address:accountAddress name:string category:int256 ttl:int32 = dns.Resolved; | ||||
| 
 | ||||
| pchan.signPromise input_key:InputKey promise:pchan.promise = pchan.Promise; | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							|  | @ -3438,7 +3438,7 @@ td::Result<vm::StackEntry> from_tonlib_api(tonlib_api::tvm_StackEntry& entry) { | |||
| } | ||||
| 
 | ||||
| void deep_library_search(std::set<td::Bits256>& set, std::set<vm::Cell::Hash>& visited, | ||||
|                          vm::Dictionary libs, td::Ref<vm::Cell> cell, int depth) { | ||||
|                          vm::Dictionary& libs, td::Ref<vm::Cell> cell, int depth) { | ||||
|   if (depth <= 0 || set.size() >= 16 || visited.size() >= 256) { | ||||
|     return; | ||||
|   } | ||||
|  | @ -3469,6 +3469,58 @@ void deep_library_search(std::set<td::Bits256>& set, std::set<vm::Cell::Hash>& v | |||
|   } | ||||
| } | ||||
| 
 | ||||
| td::Status TonlibClient::do_request(const tonlib_api::smc_getLibraries& request, | ||||
|                                     td::Promise<object_ptr<tonlib_api::smc_libraryResult>>&& promise) { | ||||
|   std::vector<object_ptr<tonlib_api::smc_libraryEntry>> result_entries; | ||||
|   result_entries.reserve(request.library_list_.size()); | ||||
|   std::vector<td::Bits256> not_cached_hashes; | ||||
|   for (auto& library_hash : request.library_list_) { | ||||
|     if (libraries.key_exists(library_hash)) { | ||||
|       auto library_content = vm::std_boc_serialize(libraries.lookup_ref(library_hash)).move_as_ok().as_slice().str(); | ||||
|       result_entries.push_back(tonlib_api::make_object<tonlib_api::smc_libraryEntry>(library_hash, library_content)); | ||||
|     } else { | ||||
|       not_cached_hashes.push_back(library_hash); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (not_cached_hashes.empty()) { | ||||
|     promise.set_value(tonlib_api::make_object<tonlib_api::smc_libraryResult>(std::move(result_entries))); | ||||
|     return td::Status::OK(); | ||||
|   } | ||||
| 
 | ||||
|   client_.send_query(ton::lite_api::liteServer_getLibraries(std::move(not_cached_hashes)),  | ||||
|                      promise.wrap([self=this, result_entries = std::move(result_entries)] | ||||
|                                   (td::Result<ton::lite_api::object_ptr<ton::lite_api::liteServer_libraryResult>> r_libraries) mutable | ||||
|     { | ||||
|       if (r_libraries.is_error()) { | ||||
|         LOG(WARNING) << "cannot obtain found libraries: " << r_libraries.move_as_error().to_string(); | ||||
|       } else { | ||||
|         auto libraries = r_libraries.move_as_ok(); | ||||
|         bool updated = false; | ||||
|         for (auto& lr : libraries->result_) { | ||||
|           auto contents = vm::std_boc_deserialize(lr->data_); | ||||
|           if (contents.is_ok() && contents.ok().not_null()) { | ||||
|             if (contents.ok()->get_hash().bits().compare(lr->hash_.cbits(), 256)) { | ||||
|               LOG(WARNING) << "hash mismatch for library " << lr->hash_.to_hex(); | ||||
|               continue; | ||||
|             } | ||||
|             result_entries.push_back(tonlib_api::make_object<tonlib_api::smc_libraryEntry>(lr->hash_, lr->data_.as_slice().str())); | ||||
|             self->libraries.set_ref(lr->hash_, contents.move_as_ok()); | ||||
|             updated = true; | ||||
|             LOG(DEBUG) << "registered library " << lr->hash_.to_hex(); | ||||
|           } else { | ||||
|             LOG(WARNING) << "failed to deserialize library: " << lr->hash_.to_hex(); | ||||
|           } | ||||
|           if (updated) { | ||||
|             self->store_libs_to_disk(); | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|       return tonlib_api::make_object<tonlib_api::smc_libraryResult>(std::move(result_entries)); | ||||
|     })); | ||||
|   return td::Status::OK(); | ||||
| } | ||||
| 
 | ||||
| td::Status TonlibClient::do_request(const tonlib_api::smc_runGetMethod& request, | ||||
|                                     td::Promise<object_ptr<tonlib_api::smc_runResult>>&& promise) { | ||||
|   auto it = smcs_.find(request.id_); | ||||
|  |  | |||
|  | @ -311,6 +311,9 @@ class TonlibClient : public td::actor::Actor { | |||
|   td::Status do_request(const tonlib_api::smc_runGetMethod& request, | ||||
|                         td::Promise<object_ptr<tonlib_api::smc_runResult>>&& promise); | ||||
| 
 | ||||
|   td::Status do_request(const tonlib_api::smc_getLibraries& request, | ||||
|                         td::Promise<object_ptr<tonlib_api::smc_libraryResult>>&& promise); | ||||
| 
 | ||||
|   td::Status do_request(const tonlib_api::dns_resolve& request, | ||||
|                         td::Promise<object_ptr<tonlib_api::dns_resolved>>&& promise); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue