Skip to content

Commit

Permalink
fix indexing nft items with addr_none owner (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 authored Sep 24, 2024
1 parent 045aa68 commit b361d88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion ton-index-postgres-v2/src/InsertManagerPostgres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,12 +1327,16 @@ std::string InsertBatchPostgres::insert_nft_items(pqxx::work &txn) {
if (nft_item.collection_address) {
raw_collection_address = convert::to_raw_address(nft_item.collection_address.value());
}
std::optional<std::string> raw_owner_address;
if (nft_item.owner_address) {
raw_owner_address = convert::to_raw_address(nft_item.owner_address.value());
}
query << "("
<< txn.quote(convert::to_raw_address(nft_item.address)) << ","
<< TO_SQL_BOOL(nft_item.init) << ","
<< nft_item.index << ","
<< TO_SQL_OPTIONAL_STRING(raw_collection_address, txn) << ","
<< txn.quote(convert::to_raw_address(nft_item.owner_address)) << ","
<< TO_SQL_OPTIONAL_STRING(raw_owner_address, txn) << ","
<< (nft_item.content ? txn.quote(content_to_json_string(nft_item.content.value())) : "NULL") << ","
<< nft_item.last_transaction_lt << ","
<< txn.quote(td::base64_encode(nft_item.code_hash.as_slice())) << ","
Expand Down
2 changes: 1 addition & 1 deletion tondb-scanner/src/IndexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ struct NFTItemDataV2 {
bool init;
td::RefInt256 index;
std::optional<block::StdAddress> collection_address;
block::StdAddress owner_address;
std::optional<block::StdAddress> owner_address;
std::optional<std::map<std::string, std::string>> content;
uint64_t last_transaction_lt;
uint32_t last_transaction_now;
Expand Down
18 changes: 12 additions & 6 deletions tondb-scanner/src/smc-interfaces/Tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,19 @@ void NftItemDetectorR::start_up() {
data.collection_address = collection_address.move_as_ok();
}

auto owner_address = convert::to_std_address(stack[3].as_slice());
if (owner_address.is_error()) {
promise_.set_error(td::Status::Error("get_nft_data address parsing failed"));
stop();
return;
auto owner_addr_cs = stack[3].as_slice();
if (owner_addr_cs->size() == 2 && owner_addr_cs->prefetch_ulong(2) == 0) {
// addr_none case
data.owner_address = std::nullopt;
} else {
auto owner_address = convert::to_std_address(owner_addr_cs);
if (owner_address.is_error()) {
promise_.set_error(owner_address.move_as_error_prefix("nft owner address parsing failed: "));
stop();
return;
}
data.owner_address = owner_address.move_as_ok();
}
data.owner_address = owner_address.move_as_ok();

if (!data.collection_address) {
auto content = parse_token_data(stack[4].as_cell());
Expand Down
2 changes: 1 addition & 1 deletion tondb-scanner/src/smc-interfaces/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NftItemDetectorR: public td::actor::Actor {
bool init;
td::RefInt256 index;
std::optional<block::StdAddress> collection_address;
block::StdAddress owner_address;
std::optional<block::StdAddress> owner_address;
std::optional<std::map<std::string, std::string>> content;
};

Expand Down

0 comments on commit b361d88

Please sign in to comment.