mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
# Conflicts: # adnl/adnl-query.cpp # crypto/block/block.tlb # crypto/block/mc-config.h # lite-client/lite-client.cpp # overlay/overlay-manager.h # overlay/overlay-peers.cpp # overlay/overlay.cpp # overlay/overlay.h # overlay/overlay.hpp # overlay/overlays.h # rldp-http-proxy/DNSResolver.cpp # rldp-http-proxy/rldp-http-proxy.cpp # tl/generate/scheme/ton_api.tl # tl/generate/scheme/ton_api.tlo # tl/generate/scheme/tonlib_api.tlo # ton/ton-types.h # tonlib/tonlib/ExtClient.cpp # tonlib/tonlib/ExtClient.h # tonlib/tonlib/ExtClientLazy.cpp # tonlib/tonlib/ExtClientOutbound.h # tonlib/tonlib/ExtClientRaw.h # tonlib/tonlib/TonlibClient.cpp # tonlib/tonlib/TonlibClient.h # tonlib/tonlib/tonlib-cli.cpp # validator/impl/collator.cpp # validator/impl/validate-query.cpp # validator/impl/validate-query.hpp # validator/manager.cpp # validator/state-serializer.cpp # validator/state-serializer.hpp # validator/validator-group.cpp # validator/validator-group.hpp # validator/validator.h
This commit is contained in:
commit
d652f7d706
200 changed files with 13492 additions and 2997 deletions
|
@ -68,6 +68,7 @@ liteServer.getState id:tonNode.blockIdExt = liteServer.BlockState;
|
|||
liteServer.getBlockHeader id:tonNode.blockIdExt mode:# = liteServer.BlockHeader;
|
||||
liteServer.sendMessage body:bytes = liteServer.SendMsgStatus;
|
||||
liteServer.getAccountState id:tonNode.blockIdExt account:liteServer.accountId = liteServer.AccountState;
|
||||
liteServer.getAccountStatePrunned id:tonNode.blockIdExt account:liteServer.accountId = liteServer.AccountState;
|
||||
liteServer.runSmcMethod mode:# id:tonNode.blockIdExt account:liteServer.accountId method_id:long params:bytes = liteServer.RunMethodResult;
|
||||
liteServer.getShardInfo id:tonNode.blockIdExt workchain:int shard:long exact:Bool = liteServer.ShardInfo;
|
||||
liteServer.getAllShardsInfo id:tonNode.blockIdExt = liteServer.AllShardsInfo;
|
||||
|
|
Binary file not shown.
|
@ -68,6 +68,7 @@ adnl.address.udp6 ip:int128 port:int = adnl.Address;
|
|||
//adnl.address.tcp6 ip:int128 port:int = adnl.Address;
|
||||
|
||||
adnl.address.tunnel to:int256 pubkey:PublicKey = adnl.Address;
|
||||
adnl.address.reverse = adnl.Address;
|
||||
|
||||
adnl.addressList addrs:(vector adnl.Address) version:int reinit_date:int priority:int expire_at:int = adnl.AddressList;
|
||||
|
||||
|
@ -185,8 +186,12 @@ dht.pong random_id:long = dht.Pong;
|
|||
dht.valueNotFound nodes:dht.nodes = dht.ValueResult;
|
||||
dht.valueFound value:dht.Value = dht.ValueResult;
|
||||
|
||||
dht.clientNotFound nodes:dht.nodes = dht.ReversePingResult;
|
||||
dht.reversePingOk = dht.ReversePingResult;
|
||||
|
||||
dht.stored = dht.Stored;
|
||||
dht.message node:dht.node = dht.Message;
|
||||
dht.requestReversePingCont target:adnl.Node signature:bytes client:int256 = dht.RequestReversePingCont;
|
||||
|
||||
dht.db.bucket nodes:dht.nodes = dht.db.Bucket;
|
||||
dht.db.key.bucket id:int = dht.db.Key;
|
||||
|
@ -198,6 +203,8 @@ dht.store value:dht.value = dht.Stored;
|
|||
dht.findNode key:int256 k:int = dht.Nodes;
|
||||
dht.findValue key:int256 k:int = dht.ValueResult;
|
||||
dht.getSignedAddressList = dht.Node;
|
||||
dht.registerReverseConnection node:PublicKey ttl:int signature:bytes = dht.Stored;
|
||||
dht.requestReversePing target:adnl.Node signature:bytes client:int256 k:int = dht.ReversePingResult;
|
||||
|
||||
dht.query node:dht.node = True;
|
||||
|
||||
|
@ -571,11 +578,12 @@ control.config.local priv:PrivateKey pub:int256 port:int = control.config.Local;
|
|||
config.local local_ids:(vector id.config.local) dht:(vector dht.config.Local) validators:(vector validator.config.Local) liteservers:(vector liteserver.config.Local) control:(vector control.config.local) = config.Local;
|
||||
|
||||
dht.config.global static_nodes:dht.nodes k:int a:int = dht.config.Global;
|
||||
dht.config.global_v2 static_nodes:dht.nodes k:int a:int network_id:int = dht.config.Global;
|
||||
adnl.config.global static_nodes:adnl.nodes = adnl.config.Global;
|
||||
catchain.config.global tag:int256 nodes:(vector PublicKey) = catchain.config.Global;
|
||||
dummyworkchain0.config.global zero_state_hash:int256 = dummyworkchain0.config.Global;
|
||||
validator.config.global zero_state:tonNode.blockIdExt init_block:tonNode.blockIdExt hardforks:(vector tonNode.blockIdExt) = validator.config.Global;
|
||||
config.global adnl:adnl.config.global dht:dht.config.global validator:validator.config.global = config.Global;
|
||||
config.global adnl:adnl.config.global dht:dht.config.Global validator:validator.config.global = config.Global;
|
||||
|
||||
liteserver.desc id:PublicKey ip:int port:int = liteserver.Desc;
|
||||
liteserver.descV2 id:PublicKey ip:int port:int shards:(vector tonNode.shardId) = liteserver.DescV2;
|
||||
|
@ -725,8 +733,9 @@ storage.ok = Ok;
|
|||
|
||||
storage.state will_upload:Bool want_download:Bool = storage.State;
|
||||
storage.piece proof:bytes data:bytes = storage.Piece;
|
||||
storage.torrentInfo data:bytes = storage.TorrentInfo;
|
||||
|
||||
storage.updateInit have_pieces:bytes state:storage.State = storage.Update;
|
||||
storage.updateInit have_pieces:bytes have_pieces_offset:int state:storage.State = storage.Update;
|
||||
storage.updateHavePieces piece_id:(vector int) = storage.Update;
|
||||
storage.updateState state:storage.State = storage.Update;
|
||||
|
||||
|
@ -735,10 +744,9 @@ storage.updateState state:storage.State = storage.Update;
|
|||
storage.ping session_id:long = storage.Pong;
|
||||
storage.addUpdate session_id:long seqno:int update:storage.Update = Ok;
|
||||
|
||||
storage.getTorrentInfo = storage.TorrentInfo;
|
||||
storage.getPiece piece_id:int = storage.Piece;
|
||||
|
||||
storage.queryPrefix id:int256 = Object;
|
||||
|
||||
---types---
|
||||
|
||||
http.header name:string value:string = http.Header;
|
||||
|
@ -775,4 +783,115 @@ collatorNode.generateBlockError code:int message:string = collatorNode.GenerateB
|
|||
|
||||
---functions---
|
||||
collatorNode.generateBlock workchain:int shard:long min_mc_id:tonNode.blockIdExt prev_blocks:(vector tonNode.blockIdExt)
|
||||
creator:int256 = collatorNode.GenerateBlockResult;
|
||||
creator:int256 = collatorNode.GenerateBlockResult;
|
||||
|
||||
---types---
|
||||
|
||||
storage.db.key.torrentList = storage.db.key.TorrentList;
|
||||
storage.db.key.torrent hash:int256 = storage.db.key.TorrentShort;
|
||||
storage.db.key.torrentMeta hash:int256 = storage.db.key.TorrentMeta;
|
||||
storage.db.key.priorities hash:int256 = storage.db.key.Priorities;
|
||||
storage.db.key.piecesInDb hash:int256 = storage.db.key.PiecesInDb;
|
||||
storage.db.key.pieceInDb hash:int256 idx:long = storage.db.key.PieceInDb;
|
||||
|
||||
storage.db.torrentList torrents:(vector int256) = storage.db.TorrentList;
|
||||
storage.db.torrent root_dir:string active_download:Bool = storage.db.TorrentShort;
|
||||
storage.db.priorities actions:(vector storage.PriorityAction) = storage.db.Priorities;
|
||||
storage.db.piecesInDb pieces:(vector long) = storage.db.PiecesInDb;
|
||||
|
||||
storage.priorityAction.all priority:int = storage.PriorityAction;
|
||||
storage.priorityAction.idx idx:long priority:int = storage.PriorityAction;
|
||||
storage.priorityAction.name name:string priority:int = storage.PriorityAction;
|
||||
|
||||
storage.daemon.config server_key:PublicKey cli_key_hash:int256 provider_address:string adnl_id:PublicKey dht_id:PublicKey = storage.daemon.provider.Config;
|
||||
|
||||
storage.daemon.provider.params accept_new_contracts:Bool rate_per_mb_day:string max_span:int
|
||||
minimal_file_size:long maximal_file_size:long = storage.daemon.provider.Params;
|
||||
|
||||
storage.provider.db.key.state = storage.provider.db.key.State;
|
||||
storage.provider.db.key.contractList = storage.provider.db.key.ContractList;
|
||||
storage.provider.db.key.storageContract wc:int addr:int256 = storage.provider.db.key.StorageContract;
|
||||
storage.provider.db.key.microchunkTree wc:int addr:int256 = storage.provider.db.key.MicrochunkTree;
|
||||
storage.provider.db.key.providerConfig = storage.provider.db.key.ProviderConfig;
|
||||
|
||||
storage.provider.db.state last_processed_lt:long = storage.provider.db.State;
|
||||
storage.provider.db.contractAddress wc:int addr:int256 = storage.db.ContractAddress;
|
||||
storage.provider.db.contractList contracts:(vector storage.provider.db.contractAddress) = storage.db.ContractList;
|
||||
storage.provider.db.storageContract torrent_hash:int256 microchunk_hash:int256 created_time:int state:int file_size:long
|
||||
rate:string max_span:int = storage.provider.db.StorageContract;
|
||||
storage.provider.db.microchunkTree data:bytes = storage.provider.db.MicrochunkTree;
|
||||
|
||||
storage.daemon.queryError message:string = storage.daemon.QueryError;
|
||||
storage.daemon.success = storage.daemon.Success;
|
||||
storage.daemon.torrent
|
||||
hash:int256 flags:#
|
||||
// 0 - info ready
|
||||
// 1 - header ready
|
||||
// 2 - fatal error
|
||||
total_size:flags.0?long description:flags.0?string
|
||||
files_count:flags.1?long included_size:flags.1?long dir_name:flags.1?string
|
||||
downloaded_size:long
|
||||
root_dir:string active_download:Bool completed:Bool
|
||||
download_speed:double upload_speed:double
|
||||
fatal_error:flags.2?string
|
||||
= storage.daemon.Torrent;
|
||||
storage.daemon.fileInfo
|
||||
name:string size:long
|
||||
priority:int
|
||||
downloaded_size:long
|
||||
= storage.daemon.FileInfo;
|
||||
storage.daemon.torrentFull torrent:storage.daemon.torrent files:(vector storage.daemon.fileInfo) = storage.daemon.TorrentFull;
|
||||
storage.daemon.torrentList torrents:(vector storage.daemon.torrent) = storage.daemon.TorrentList;
|
||||
storage.daemon.torrentMeta meta:bytes = storage.daemon.TorrentMeta;
|
||||
|
||||
storage.daemon.newContractParams rate:string max_span:int = storage.daemon.NewContractParams;
|
||||
storage.daemon.newContractParamsAuto provider_address:string = storage.daemon.NewContractParams;
|
||||
storage.daemon.newContractMessage body:bytes rate:string max_span:int = storage.daemon.NewContractMessage;
|
||||
|
||||
storage.daemon.peer adnl_id:int256 ip_str:string download_speed:double upload_speed:double ready_parts:long = storage.daemon.Peer;
|
||||
storage.daemon.peerList peers:(vector storage.daemon.peer) download_speed:double upload_speed:double total_parts:long = storage.daemon.PeerList;
|
||||
|
||||
storage.daemon.prioritySet = storage.daemon.SetPriorityStatus;
|
||||
storage.daemon.priorityPending = storage.daemon.SetPriorityStatus;
|
||||
|
||||
storage.daemon.keyHash key_hash:int256 = storage.daemon.KeyHash;
|
||||
|
||||
storage.daemon.providerConfig max_contracts:int max_total_size:long = storage.daemon.ProviderConfig;
|
||||
storage.daemon.contractInfo address:string state:int torrent:int256 created_time:int file_size:long downloaded_size:long
|
||||
rate:string max_span:int client_balance:string contract_balance:string = storage.daemon.ContractInfo;
|
||||
storage.daemon.providerInfo address:string balance:string config:storage.daemon.providerConfig
|
||||
contracts_count:int contracts_total_size:long
|
||||
contracts:(vector storage.daemon.contractInfo) = storage.daemon.ProviderInfo;
|
||||
storage.daemon.providerAddress address:string = storage.daemon.ProviderAddress;
|
||||
|
||||
---functions---
|
||||
storage.daemon.setVerbosity verbosity:int = storage.daemon.Success;
|
||||
storage.daemon.createTorrent path:string description:string = storage.daemon.TorrentFull;
|
||||
storage.daemon.addByHash hash:int256 root_dir:string start_download:Bool priorities:(vector storage.PriorityAction) = storage.daemon.TorrentFull;
|
||||
storage.daemon.addByMeta meta:bytes root_dir:string start_download:Bool priorities:(vector storage.PriorityAction) = storage.daemon.TorrentFull;
|
||||
storage.daemon.setActiveDownload hash:int256 active:Bool = storage.daemon.Success;
|
||||
|
||||
storage.daemon.getTorrents = storage.daemon.TorrentList;
|
||||
storage.daemon.getTorrentFull hash:int256 = storage.daemon.TorrentFull;
|
||||
storage.daemon.getTorrentMeta hash:int256 = storage.daemon.TorrentMeta;
|
||||
storage.daemon.getNewContractMessage hash:int256 query_id:long params:storage.daemon.NewContractParams = storage.daemon.NewContractMessage;
|
||||
storage.daemon.getTorrentPeers hash:int256 = storage.daemon.PeerList;
|
||||
|
||||
storage.daemon.setFilePriorityAll hash:int256 priority:int = storage.daemon.SetPriorityStatus;
|
||||
storage.daemon.setFilePriorityByIdx hash:int256 idx:long priority:int = storage.daemon.SetPriorityStatus;
|
||||
storage.daemon.setFilePriorityByName hash:int256 name:string priority:int = storage.daemon.SetPriorityStatus;
|
||||
|
||||
storage.daemon.removeTorrent hash:int256 remove_files:Bool = storage.daemon.Success;
|
||||
storage.daemon.loadFrom hash:int256 meta:bytes path:string = storage.daemon.Torrent;
|
||||
|
||||
storage.daemon.importPrivateKey key:PrivateKey = storage.daemon.KeyHash;
|
||||
storage.daemon.initProvider account_address:string = storage.daemon.Success;
|
||||
storage.daemon.deployProvider = storage.daemon.ProviderAddress;
|
||||
storage.daemon.getProviderParams address:string = storage.daemon.provider.Params;
|
||||
storage.daemon.setProviderParams params:storage.daemon.provider.params = storage.daemon.Success;
|
||||
storage.daemon.getProviderInfo with_balances:Bool with_contracts:Bool = storage.daemon.ProviderInfo;
|
||||
storage.daemon.setProviderConfig config:storage.daemon.providerConfig = storage.daemon.Success;
|
||||
storage.daemon.withdraw contract:string = storage.daemon.Success;
|
||||
storage.daemon.sendCoins address:string amount:string message:string = storage.daemon.Success;
|
||||
storage.daemon.closeStorageContract address:string = storage.daemon.Success;
|
||||
storage.daemon.removeStorageProvider = storage.daemon.Success;
|
||||
|
|
Binary file not shown.
|
@ -291,7 +291,7 @@ query.estimateFees id:int53 ignore_chksig:Bool = query.Fees;
|
|||
query.getInfo id:int53 = query.Info;
|
||||
|
||||
smc.load account_address:accountAddress = smc.Info;
|
||||
//smc.forget id:int53 = Ok;
|
||||
smc.forget id:int53 = Ok;
|
||||
smc.getCode id:int53 = tvm.Cell;
|
||||
smc.getData id:int53 = tvm.Cell;
|
||||
smc.getState id:int53 = tvm.Cell;
|
||||
|
|
Binary file not shown.
|
@ -33,7 +33,7 @@ int TD_TL_writer_java::get_max_arity() const {
|
|||
}
|
||||
|
||||
bool TD_TL_writer_java::is_built_in_simple_type(const std::string &name) const {
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Double" ||
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Int128" || name == "Int256" || name == "Double" ||
|
||||
name == "String" || name == "Bytes" || name == "SecureString" || name == "SecureBytes" || name == "Object" ||
|
||||
name == "Function";
|
||||
}
|
||||
|
@ -93,9 +93,12 @@ std::string TD_TL_writer_java::gen_base_function_class_name() const {
|
|||
}
|
||||
|
||||
std::string TD_TL_writer_java::gen_class_name(std::string name) const {
|
||||
if (name == "Object" || name == "#") {
|
||||
if (name == "Object") {
|
||||
assert(false);
|
||||
}
|
||||
if (name == "#") {
|
||||
return "int";
|
||||
}
|
||||
bool next_to_upper = true;
|
||||
std::string result;
|
||||
for (std::size_t i = 0; i < name.size(); i++) {
|
||||
|
@ -149,7 +152,7 @@ std::string TD_TL_writer_java::gen_type_name(const tl::tl_tree_type *tree_type)
|
|||
const std::string &name = t->name;
|
||||
|
||||
if (name == "#") {
|
||||
assert(false);
|
||||
return "int";
|
||||
}
|
||||
if (name == "Bool") {
|
||||
return "boolean";
|
||||
|
@ -166,7 +169,7 @@ std::string TD_TL_writer_java::gen_type_name(const tl::tl_tree_type *tree_type)
|
|||
if (name == "String" || name == "SecureString") {
|
||||
return "String";
|
||||
}
|
||||
if (name == "Bytes" || name == "SecureBytes") {
|
||||
if (name == "Bytes" || name == "SecureBytes" || name == "Int128" || name == "Int256") {
|
||||
return "byte[]";
|
||||
}
|
||||
if (name == "Object") {
|
||||
|
@ -269,9 +272,6 @@ std::string TD_TL_writer_java::gen_vars(const tl::tl_combinator *t, const tl::tl
|
|||
assert(t->args[i].type->get_type() != tl::NODE_TYPE_VAR_TYPE);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < vars.size(); i++) {
|
||||
assert(vars[i].is_type);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -286,12 +286,19 @@ std::string TD_TL_writer_java::gen_function_vars(const tl::tl_combinator *t,
|
|||
}
|
||||
|
||||
for (std::size_t i = 0; i < t->args.size(); i++) {
|
||||
assert(t->args[i].type->get_type() != tl::NODE_TYPE_VAR_TYPE);
|
||||
const tl::arg &a = t->args[i];
|
||||
|
||||
int arg_type = a.type->get_type();
|
||||
if (arg_type == tl::NODE_TYPE_VAR_TYPE) {
|
||||
const tl::tl_tree_var_type *var_type = static_cast<const tl::tl_tree_var_type *>(a.type);
|
||||
assert(a.flags & tl::FLAG_EXCL);
|
||||
assert(var_type->var_num >= 0);
|
||||
assert(!vars[var_type->var_num].is_type);
|
||||
vars[var_type->var_num].is_type = true;
|
||||
vars[var_type->var_num].function_arg_num = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < vars.size(); i++) {
|
||||
assert(vars[i].is_type);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -309,19 +316,41 @@ std::string TD_TL_writer_java::gen_field_fetch(int field_num, const tl::arg &a,
|
|||
bool flat, int parser_type) const {
|
||||
assert(parser_type >= 0);
|
||||
|
||||
assert(a.exist_var_num == -1);
|
||||
assert(a.type->get_type() != tl::NODE_TYPE_VAR_TYPE);
|
||||
if (a.type->get_type() == tl::NODE_TYPE_VAR_TYPE) {
|
||||
assert(parser_type == 1);
|
||||
|
||||
const tl::tl_tree_var_type *t = static_cast<const tl::tl_tree_var_type *>(a.type);
|
||||
assert(a.flags == tl::FLAG_EXCL);
|
||||
|
||||
assert(a.var_num == -1);
|
||||
assert(a.exist_var_num == -1);
|
||||
|
||||
assert(t->var_num >= 0);
|
||||
assert(vars[t->var_num].is_type);
|
||||
assert(!vars[t->var_num].is_stored);
|
||||
vars[t->var_num].is_stored = true;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
assert(!(a.flags & tl::FLAG_EXCL));
|
||||
assert(!(a.flags & tl::FLAG_OPT_VAR));
|
||||
|
||||
if (a.exist_var_num != -1) {
|
||||
assert(0 <= a.exist_var_num && a.exist_var_num < static_cast<int>(vars.size()));
|
||||
}
|
||||
|
||||
if (flat) {
|
||||
// TODO
|
||||
// return gen_field_fetch(const tl::arg &a, std::vector<tl::var_description> &vars, int num, bool flat);
|
||||
}
|
||||
|
||||
assert(a.var_num == -1);
|
||||
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
|
||||
if (a.var_num >= 0) {
|
||||
assert(static_cast<const tl::tl_tree_type *>(a.type)->type->id == tl::ID_VAR_NUM);
|
||||
assert(0 <= a.var_num && a.var_num < static_cast<int>(vars.size()));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace td {
|
|||
|
||||
bool TD_TL_writer_jni_cpp::is_built_in_simple_type(const std::string &name) const {
|
||||
assert(name != "function");
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Double" ||
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Int128" || name == "Int256" || name == "Double" ||
|
||||
name == "String" || name == "Bytes" || name == "SecureString" || name == "SecureBytes" || name == "Function" ||
|
||||
name == "Object";
|
||||
}
|
||||
|
@ -126,6 +126,8 @@ std::string TD_TL_writer_jni_cpp::gen_vector_fetch(std::string field_name, const
|
|||
} else if (vector_type == bytes_type) {
|
||||
std::fprintf(stderr, "Vector of Bytes is not supported\n");
|
||||
assert(false);
|
||||
} else if (vector_type == "td::Bits128" || vector_type == "td::Bits256") {
|
||||
template_type = vector_type;
|
||||
} else {
|
||||
assert(vector_type.compare(0, 10, "object_ptr") == 0);
|
||||
template_type = gen_main_class_name(t->type);
|
||||
|
@ -152,17 +154,11 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,
|
|||
assert(is_type_bare(t));
|
||||
}
|
||||
|
||||
std::string res_begin;
|
||||
if (!field_name.empty()) {
|
||||
res_begin = field_name + " = ";
|
||||
}
|
||||
|
||||
std::string res;
|
||||
assert(name != "#");
|
||||
if (field_name.empty()) {
|
||||
if (name == "Bool") {
|
||||
return "env->CallObjectMethod(p, td::jni::BooleanGetValueMethodID)";
|
||||
} else if (name == "Int32") {
|
||||
} else if (name == "Int32" || name == "#") {
|
||||
return "env->CallObjectMethod(p, td::jni::IntegerGetValueMethodID)";
|
||||
} else if (name == "Int53" || name == "Int64") {
|
||||
return "env->CallObjectMethod(p, td::jni::LongGetValueMethodID)";
|
||||
|
@ -176,12 +172,16 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,
|
|||
return "td::jni::from_jstring_secure(env, (jstring)p)";
|
||||
} else if (name == "SecureBytes") {
|
||||
return "td::jni::from_bytes_secure(env, (jbyteArray)p)";
|
||||
} else if (name == "Int128") {
|
||||
return "td::jni::from_bits<128>(env, (jbyteArray)p)";
|
||||
} else if (name == "Int256") {
|
||||
return "td::jni::from_bits<256>(env, (jbyteArray)p)";
|
||||
}
|
||||
}
|
||||
|
||||
if (name == "Bool") {
|
||||
res = "(env->GetBooleanField(p, " + field_name + "fieldID) != 0)";
|
||||
} else if (name == "Int32") {
|
||||
} else if (name == "Int32" || name == "#") {
|
||||
res = "env->GetIntField(p, " + field_name + "fieldID)";
|
||||
} else if (name == "Int53" || name == "Int64") {
|
||||
res = "env->GetLongField(p, " + field_name + "fieldID)";
|
||||
|
@ -195,6 +195,10 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,
|
|||
res = "td::jni::fetch_string_secure(env, p, " + field_name + "fieldID)";
|
||||
} else if (name == "SecureBytes") {
|
||||
res = "td::jni::from_bytes_secure(env, (jbyteArray)td::jni::fetch_object(env, p, " + field_name + "fieldID))";
|
||||
} else if (name == "Int128") {
|
||||
res = "td::jni::from_bits<128>(env, (jbyteArray)td::jni::fetch_object(env, p, " + field_name + "fieldID))";
|
||||
} else if (name == "Int256") {
|
||||
res = "td::jni::from_bits<256>(env, (jbyteArray)td::jni::fetch_object(env, p, " + field_name + "fieldID))";
|
||||
} else if (name == "Vector") {
|
||||
const tl::tl_tree_type *child = static_cast<const tl::tl_tree_type *>(tree_type->children[0]);
|
||||
res = gen_vector_fetch(field_name, child, vars, parser_type);
|
||||
|
@ -206,7 +210,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_fetch(const std::string &field_name,
|
|||
res = "td::jni::fetch_tl_object<" + gen_main_class_name(tree_type->type) + ">(env, td::jni::fetch_object(env, p, " +
|
||||
field_name + "fieldID));";
|
||||
}
|
||||
return res_begin + res;
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string TD_TL_writer_jni_cpp::gen_field_fetch(int field_num, const tl::arg &a,
|
||||
|
@ -215,7 +219,6 @@ std::string TD_TL_writer_jni_cpp::gen_field_fetch(int field_num, const tl::arg &
|
|||
assert(parser_type >= 0);
|
||||
std::string field_name = (parser_type == 0 ? (field_num == 0 ? ": " : ", ") : "res->") + gen_field_name(a.name);
|
||||
|
||||
assert(a.exist_var_num == -1);
|
||||
if (a.type->get_type() == tl::NODE_TYPE_VAR_TYPE) {
|
||||
assert(parser_type == 1);
|
||||
|
||||
|
@ -223,6 +226,7 @@ std::string TD_TL_writer_jni_cpp::gen_field_fetch(int field_num, const tl::arg &
|
|||
assert(a.flags == tl::FLAG_EXCL);
|
||||
|
||||
assert(a.var_num == -1);
|
||||
assert(a.exist_var_num == -1);
|
||||
|
||||
assert(t->var_num >= 0);
|
||||
assert(vars[t->var_num].is_type);
|
||||
|
@ -236,18 +240,52 @@ std::string TD_TL_writer_jni_cpp::gen_field_fetch(int field_num, const tl::arg &
|
|||
assert(!(a.flags & tl::FLAG_EXCL));
|
||||
assert(!(a.flags & tl::FLAG_OPT_VAR));
|
||||
|
||||
std::string res = " ";
|
||||
if (a.exist_var_num != -1) {
|
||||
assert(0 <= a.exist_var_num && a.exist_var_num < static_cast<int>(vars.size()));
|
||||
assert(vars[a.exist_var_num].is_stored);
|
||||
|
||||
res += "if (" + gen_var_name(vars[a.exist_var_num]) + " & " + int_to_string(1 << a.exist_var_bit) + ") { ";
|
||||
}
|
||||
|
||||
if (flat) {
|
||||
// TODO
|
||||
// return gen_field_fetch(const tl::arg &a, std::vector<tl::var_description> &vars, int num, bool flat);
|
||||
}
|
||||
|
||||
assert(a.var_num == -1);
|
||||
bool store_to_var_num = false;
|
||||
if (a.var_num >= 0) {
|
||||
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
|
||||
assert(static_cast<const tl::tl_tree_type *>(a.type)->type->id == tl::ID_VAR_NUM);
|
||||
assert(0 <= a.var_num && a.var_num < static_cast<int>(vars.size()));
|
||||
if (!vars[a.var_num].is_stored) {
|
||||
res += "if ((" + gen_var_name(vars[a.var_num]) + " = ";
|
||||
store_to_var_num = true;
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
vars[a.var_num].is_stored = true;
|
||||
}
|
||||
|
||||
res += field_name + (parser_type == 0 ? "(" : " = ");
|
||||
|
||||
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
|
||||
const tl::tl_tree_type *tree_type = static_cast<tl::tl_tree_type *>(a.type);
|
||||
res += gen_type_fetch(field_name, tree_type, vars, parser_type);
|
||||
if (store_to_var_num) {
|
||||
res += ") < 0) { return nullptr; }";
|
||||
} else {
|
||||
res += (parser_type == 0 ? ")" : ";");
|
||||
}
|
||||
|
||||
assert(parser_type != 0);
|
||||
return " " + gen_type_fetch(field_name, tree_type, vars, parser_type) + ";\n";
|
||||
if (a.exist_var_num >= 0) {
|
||||
res += " }";
|
||||
if (store_to_var_num) {
|
||||
res += " else { " + gen_var_name(vars[a.var_num]) + " = 0; }";
|
||||
}
|
||||
}
|
||||
res += "\n";
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string TD_TL_writer_jni_cpp::get_pretty_field_name(std::string field_name) const {
|
||||
|
@ -274,7 +312,7 @@ std::string TD_TL_writer_jni_cpp::gen_vector_store(const std::string &field_name
|
|||
assert(false); // TODO
|
||||
}
|
||||
if (vector_type == "std::int32_t" || vector_type == "std::int64_t" || vector_type == "double" ||
|
||||
vector_type == string_type || vector_type == secure_string_type ||
|
||||
vector_type == string_type || vector_type == secure_string_type || vector_type == "td::Bits128" || vector_type == "td::Bits256" ||
|
||||
vector_type.compare(0, 11, "std::vector") == 0 || vector_type.compare(0, 10, "object_ptr") == 0) {
|
||||
return "{ "
|
||||
"auto arr_tmp_ = td::jni::store_vector(env, " +
|
||||
|
@ -317,8 +355,8 @@ std::string TD_TL_writer_jni_cpp::gen_type_store(const std::string &field_name,
|
|||
}
|
||||
|
||||
std::string res;
|
||||
if (name == "Int32" || name == "Int53" || name == "Int64" || name == "Double" || name == "Bool" || name == "String" ||
|
||||
name == "SecureString") {
|
||||
if (name == "Int32" || name == "Int53" || name == "Int64" || name == "Int128" || name == "Int256" || name == "Double" || name == "Bool" || name == "String" ||
|
||||
name == "SecureString" || name == "#") {
|
||||
if (storer_type == 1) {
|
||||
res = "s.store_field(\"" + get_pretty_field_name(field_name) + "\", " + field_name + ");";
|
||||
} else if (name == "Bool") {
|
||||
|
@ -337,6 +375,16 @@ std::string TD_TL_writer_jni_cpp::gen_type_store(const std::string &field_name,
|
|||
res = "{ jstring nextString = td::jni::to_jstring_secure(env, " + field_name +
|
||||
"); if (nextString) { env->SetObjectField(s, " + field_name +
|
||||
"fieldID, nextString); env->DeleteLocalRef(nextString); } }";
|
||||
} else if (name == "Int128") {
|
||||
res = "{ jbyteArray nextBytes = td::jni::to_bits<128>(env, " + field_name +
|
||||
"); if (nextBytes) { env->SetObjectField(s, " + field_name +
|
||||
"fieldID, nextBytes); env->DeleteLocalRef(nextBytes); } }";
|
||||
} else if (name == "Int256") {
|
||||
res = "{ jbyteArray nextBytes = td::jni::to_bits<256>(env, " + field_name +
|
||||
"); if (nextBytes) { env->SetObjectField(s, " + field_name +
|
||||
"fieldID, nextBytes); env->DeleteLocalRef(nextBytes); } }";
|
||||
} else if (name == "#") {
|
||||
res = "env->SetIntField(s, " + TD_TL_writer_cpp::get_pretty_field_name(field_name) + "_fieldID, " + field_name + ");";
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
|
@ -378,12 +426,12 @@ std::string TD_TL_writer_jni_cpp::gen_field_store(const tl::arg &a, std::vector<
|
|||
std::string field_name = gen_field_name(a.name);
|
||||
std::string shift = storer_type == 1 ? " " : " ";
|
||||
|
||||
assert(a.exist_var_num == -1);
|
||||
if (a.type->get_type() == tl::NODE_TYPE_VAR_TYPE) {
|
||||
const tl::tl_tree_var_type *t = static_cast<const tl::tl_tree_var_type *>(a.type);
|
||||
assert(a.flags == tl::FLAG_EXCL);
|
||||
|
||||
assert(a.var_num == -1);
|
||||
assert(a.exist_var_num == -1);
|
||||
|
||||
assert(t->var_num >= 0);
|
||||
assert(!vars[t->var_num].is_stored);
|
||||
|
@ -397,15 +445,39 @@ std::string TD_TL_writer_jni_cpp::gen_field_store(const tl::arg &a, std::vector<
|
|||
assert(!(a.flags & tl::FLAG_EXCL));
|
||||
assert(!(a.flags & tl::FLAG_OPT_VAR));
|
||||
|
||||
if (a.exist_var_num >= 0) {
|
||||
assert(a.exist_var_num < static_cast<int>(vars.size()));
|
||||
assert(vars[a.exist_var_num].is_stored);
|
||||
|
||||
shift += "if (" + gen_var_name(vars[a.exist_var_num]) + " & " + int_to_string(1 << a.exist_var_bit) + ") { ";
|
||||
}
|
||||
|
||||
if (flat) {
|
||||
// TODO
|
||||
// return gen_field_store(const tl::arg &a, std::vector<tl::var_description> &vars, bool flat, int storer_type);
|
||||
}
|
||||
|
||||
assert(a.var_num == -1);
|
||||
if (a.var_num >= 0) {
|
||||
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
|
||||
assert(static_cast<const tl::tl_tree_type *>(a.type)->type->id == tl::ID_VAR_NUM);
|
||||
assert(a.var_num < static_cast<int>(vars.size()));
|
||||
if (!vars[a.var_num].is_stored) {
|
||||
field_name = "(" + gen_var_name(vars[a.var_num]) + " = " + field_name + ")";
|
||||
vars[a.var_num].is_stored = true;
|
||||
} else {
|
||||
assert(false); // need to check value of stored var
|
||||
field_name = gen_var_name(vars[a.var_num]);
|
||||
}
|
||||
}
|
||||
|
||||
assert(a.type->get_type() == tl::NODE_TYPE_TYPE);
|
||||
const tl::tl_tree_type *tree_type = static_cast<tl::tl_tree_type *>(a.type);
|
||||
return shift + gen_type_store(field_name, tree_type, vars, storer_type) + "\n";
|
||||
shift += gen_type_store(field_name, tree_type, vars, storer_type);
|
||||
if (a.exist_var_num >= 0) {
|
||||
shift += " }";
|
||||
}
|
||||
shift += "\n";
|
||||
return shift;
|
||||
}
|
||||
|
||||
std::string TD_TL_writer_jni_cpp::gen_get_id(const std::string &class_name, std::int32_t id, bool is_proxy) const {
|
||||
|
@ -568,11 +640,10 @@ std::string TD_TL_writer_jni_cpp::gen_type_signature(const tl::tl_tree_type *tre
|
|||
const tl::tl_type *t = tree_type->type;
|
||||
const std::string &name = t->name;
|
||||
|
||||
assert(name != "#");
|
||||
assert(name != gen_base_tl_class_name());
|
||||
if (name == "Bool") {
|
||||
return "Z";
|
||||
} else if (name == "Int32") {
|
||||
} else if (name == "Int32" || name == "#") {
|
||||
return "I";
|
||||
} else if (name == "Int53" || name == "Int64") {
|
||||
return "J";
|
||||
|
@ -580,7 +651,7 @@ std::string TD_TL_writer_jni_cpp::gen_type_signature(const tl::tl_tree_type *tre
|
|||
return "D";
|
||||
} else if (name == "String" || name == "SecureString") {
|
||||
return "Ljava/lang/String;";
|
||||
} else if (name == "Bytes" || name == "SecureBytes") {
|
||||
} else if (name == "Bytes" || name == "SecureBytes" || name == "Int128" || name == "Int256") {
|
||||
return "[B";
|
||||
} else if (name == "Vector") {
|
||||
const tl::tl_tree_type *child = static_cast<const tl::tl_tree_type *>(tree_type->children[0]);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
namespace td {
|
||||
|
||||
bool TD_TL_writer_jni_h::is_built_in_simple_type(const std::string &name) const {
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Double" ||
|
||||
return name == "Bool" || name == "Int32" || name == "Int53" || name == "Int64" || name == "Int128" || name == "Int256" || name == "Double" ||
|
||||
name == "String" || name == "Bytes" || name == "SecureString" || name == "SecureBytes" || name == "Function" ||
|
||||
name == "Object";
|
||||
}
|
||||
|
|
|
@ -30,12 +30,6 @@ namespace jni {
|
|||
|
||||
thread_local bool parse_error;
|
||||
|
||||
static jclass BooleanClass;
|
||||
static jclass IntegerClass;
|
||||
static jclass LongClass;
|
||||
static jclass DoubleClass;
|
||||
static jclass StringClass;
|
||||
static jclass ObjectClass;
|
||||
jmethodID GetConstructorID;
|
||||
jmethodID BooleanGetValueMethodID;
|
||||
jmethodID IntegerGetValueMethodID;
|
||||
|
|
|
@ -27,12 +27,19 @@
|
|||
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/SharedSlice.h"
|
||||
#include "common/bitstring.h"
|
||||
|
||||
namespace td {
|
||||
namespace jni {
|
||||
|
||||
extern thread_local bool parse_error;
|
||||
|
||||
static jclass BooleanClass;
|
||||
static jclass IntegerClass;
|
||||
static jclass LongClass;
|
||||
static jclass DoubleClass;
|
||||
static jclass StringClass;
|
||||
static jclass ObjectClass;
|
||||
extern jmethodID GetConstructorID;
|
||||
extern jmethodID BooleanGetValueMethodID;
|
||||
extern jmethodID IntegerGetValueMethodID;
|
||||
|
@ -106,6 +113,29 @@ SecureString from_bytes_secure(JNIEnv *env, jbyteArray arr);
|
|||
jbyteArray to_bytes(JNIEnv *env, Slice b);
|
||||
jbyteArray to_bytes_secure(JNIEnv *env, Slice b);
|
||||
|
||||
template<unsigned int n>
|
||||
td::BitArray<n> from_bits(JNIEnv *env, jbyteArray arr) {
|
||||
td::BitArray<n> b;
|
||||
if (arr != nullptr) {
|
||||
jsize length = env->GetArrayLength(arr);
|
||||
assert(length * 8 == n);
|
||||
env->GetByteArrayRegion(arr, 0, length, reinterpret_cast<jbyte *>(b.as_slice().begin()));
|
||||
env->DeleteLocalRef(arr);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template<unsigned int n>
|
||||
jbyteArray to_bits(JNIEnv *env, td::BitArray<n> b) {
|
||||
assert(n % 8 == 0);
|
||||
jsize length = n / 8;
|
||||
jbyteArray arr = env->NewByteArray(length);
|
||||
if (arr != nullptr) {
|
||||
env->SetByteArrayRegion(arr, 0, length, reinterpret_cast<const jbyte *>(b.data()));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
void init_vars(JNIEnv *env, const char *td_api_java_package);
|
||||
|
||||
jintArray store_vector(JNIEnv *env, const std::vector<std::int32_t> &v);
|
||||
|
@ -118,6 +148,22 @@ jobjectArray store_vector(JNIEnv *env, const std::vector<std::string> &v);
|
|||
|
||||
jobjectArray store_vector(JNIEnv *env, const std::vector<SecureString> &v);
|
||||
|
||||
template<unsigned int n>
|
||||
jobjectArray store_vector(JNIEnv *env, const std::vector<td::BitArray<n>> &v) {
|
||||
jint length = static_cast<jint>(v.size());
|
||||
jobjectArray arr = env->NewObjectArray(length, ObjectClass, jobject());
|
||||
if (arr != nullptr) {
|
||||
for (jsize i = 0; i < length; i++) {
|
||||
jbyteArray bits = to_bits<n>(env, v[i]);
|
||||
if (bits) {
|
||||
env->SetObjectArrayElement(arr, i, bits);
|
||||
env->DeleteLocalRef(bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
jobjectArray store_vector(JNIEnv *env, const std::vector<T> &v) {
|
||||
jint length = static_cast<jint>(v.size());
|
||||
|
@ -230,6 +276,26 @@ struct FetchVector<SecureString> {
|
|||
}
|
||||
};
|
||||
|
||||
template<unsigned int n>
|
||||
struct FetchVector<td::BitArray<n>> {
|
||||
static std::vector<td::BitArray<n>> fetch(JNIEnv *env, jobjectArray arr) {
|
||||
std::vector<td::BitArray<n>> result;
|
||||
if (arr != nullptr) {
|
||||
jsize length = env->GetArrayLength(arr);
|
||||
result.reserve(length);
|
||||
for (jsize i = 0; i < length; i++) {
|
||||
jbyteArray bits = (jbyteArray)env->GetObjectArrayElement(arr, i);
|
||||
result.push_back(jni::from_bits<n>(env, bits));
|
||||
if (bits) {
|
||||
env->DeleteLocalRef(bits);
|
||||
}
|
||||
}
|
||||
env->DeleteLocalRef(arr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct FetchVector<std::vector<T>> {
|
||||
static auto fetch(JNIEnv *env, jobjectArray arr) {
|
||||
|
|
|
@ -53,7 +53,8 @@ struct JsonBytes {
|
|||
};
|
||||
|
||||
inline void to_json(JsonValueScope &jv, const JsonBytes json_bytes) {
|
||||
jv << JsonString(PSLICE() << base64_encode(json_bytes.bytes));
|
||||
auto base64 = base64_encode(json_bytes.bytes);
|
||||
jv << JsonString(base64);
|
||||
}
|
||||
template <class T>
|
||||
struct JsonVectorBytesImpl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue