Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed returnsNewTokenIdentifier interactor #1755

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions framework/snippets/src/network_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,31 @@ fn process_new_deployed_address(tx: &TransactionOnNetwork) -> Option<Address> {
}

fn process_new_issued_token_identifier(tx: &TransactionOnNetwork) -> Option<String> {
let original_tx_data = String::from_utf8(base64_decode(tx.data.as_ref().unwrap())).unwrap();

for scr in tx.smart_contract_results.iter() {
if scr.sender.to_bech32_string().unwrap() != ESDTSystemSCAddress.to_bech32_string() {
continue;
}

let Some(prev_tx) = tx
let prev_tx_data: &str = if let Some(prev_tx) = tx
.smart_contract_results
.iter()
.find(|e| e.hash == scr.prev_tx_hash)
else {
{
prev_tx.data.as_ref()
} else if &scr.prev_tx_hash == tx.hash.as_ref().unwrap() {
&original_tx_data
} else {
continue;
};

let is_issue_fungible = prev_tx.data.starts_with("issue@");
let is_issue_semi_fungible = prev_tx.data.starts_with("issueSemiFungible@");
let is_issue_non_fungible = prev_tx.data.starts_with("issueNonFungible@");
let is_register_meta_esdt = prev_tx.data.starts_with("registerMetaESDT@");
let is_issue_fungible = prev_tx_data.starts_with("issue@");
let is_issue_semi_fungible = prev_tx_data.starts_with("issueSemiFungible@");
let is_issue_non_fungible = prev_tx_data.starts_with("issueNonFungible@");
let is_register_meta_esdt = prev_tx_data.starts_with("registerMetaESDT@");
let is_register_and_set_all_roles_esdt =
prev_tx.data.starts_with("registerAndSetAllRoles@");
prev_tx_data.starts_with("registerAndSetAllRoles@");

if !is_issue_fungible
&& !is_issue_semi_fungible
Expand All @@ -135,12 +141,11 @@ fn process_new_issued_token_identifier(tx: &TransactionOnNetwork) -> Option<Stri
if scr.data.starts_with("ESDTTransfer@") {
let encoded_tid = scr.data.split('@').nth(1);
return Some(String::from_utf8(hex::decode(encoded_tid?).unwrap()).unwrap());
} else if scr.data.starts_with("@00@") {
} else if scr.data.starts_with("@00@") || scr.data.starts_with("@6f6b@") {
let encoded_tid = scr.data.split('@').nth(2);
return Some(String::from_utf8(hex::decode(encoded_tid?).unwrap()).unwrap());
}
}

None
}

Expand Down
25 changes: 25 additions & 0 deletions sdk/core/src/gateway/gateway_tx_retrieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl GatewayProxy {
let mut retries = 0;
let mut backoff_delay = Duration::from_secs_f32(INITIAL_BACKOFF_DELAY);
let start_time = Instant::now();
let mut issue_found = false;

loop {
match self.get_transaction_status(&tx_hash).await {
Expand All @@ -26,6 +27,22 @@ impl GatewayProxy {
.get_transaction_info_with_results(&tx_hash)
.await
.unwrap();

if !transaction_info_with_results
.smart_contract_results
.is_empty()
&& !issue_found
{
let first_scr =
&transaction_info_with_results.smart_contract_results[0];

if GatewayProxy::is_issue_tx(&first_scr.data) {
issue_found = true;
tokio::time::sleep(Duration::from_secs(30)).await;
continue;
}
}

info!(
"Transaction retrieved successfully, with status {}: {:#?}",
status, transaction_info_with_results
Expand Down Expand Up @@ -60,4 +77,12 @@ impl GatewayProxy {
);
TransactionOnNetwork::default()
}

fn is_issue_tx(data: &str) -> bool {
data.starts_with("issue@")
|| data.starts_with("issueSemiFungible@")
|| data.starts_with("issueNonFungible@")
|| data.starts_with("registerMetaESDT@")
|| data.starts_with("registerAndSetAllRoles@")
}
}
Loading