Skip to content

Commit 9b92d33

Browse files
committed
fixes empty token field
1 parent a8be3c4 commit 9b92d33

6 files changed

Lines changed: 87 additions & 187 deletions

File tree

zetachain-cctx/zetachain-cctx-logic/src/database.rs

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ impl ZetachainCctxDatabase {
660660
root_id: r.try_get_by_index(2)?,
661661
depth: r.try_get_by_index(3)?,
662662
retries_number: r.try_get_by_index(4)?,
663+
token_id: r.try_get_by_index(5)?,
663664
})
664665
})
665666
.collect::<Result<Vec<CctxShort>, sea_orm::DbErr>>();
@@ -739,6 +740,7 @@ impl ZetachainCctxDatabase {
739740
root_id: r.try_get_by_index(2)?,
740741
depth: r.try_get_by_index(3)?,
741742
retries_number: r.try_get_by_index(4)?,
743+
token_id: r.try_get_by_index(5)?,
742744
})
743745
})
744746
.collect::<Result<Vec<CctxShort>, sea_orm::DbErr>>();
@@ -849,69 +851,69 @@ impl ZetachainCctxDatabase {
849851
#[instrument(,level="trace",skip_all)]
850852
pub async fn update_cctx_status(
851853
&self,
852-
cctx_id: i32,
854+
cctx: &CctxShort,
853855
fetched_cctx: CrossChainTx,
854-
) -> anyhow::Result<Option<CctxListItemProto>> {
855-
let mut cctx_list_item: Option<CctxListItemProto> = None;
856+
) -> anyhow::Result<CctxListItemProto> {
856857
let tx = self.db.begin().await?;
857-
if let Some(cctx_status_row) = cctx_status::Entity::find()
858-
.filter(cctx_status::Column::CrossChainTxId.eq(cctx_id))
859-
.one(self.db.as_ref())
860-
.await?
861-
{
862-
let new_status =
863-
CctxStatusProto::from_str_name(&fetched_cctx.cctx_status.status).unwrap();
864-
cctx_status::Entity::update(cctx_status::ActiveModel {
865-
id: ActiveValue::Set(cctx_status_row.id),
866-
status: ActiveValue::Set(
867-
CctxStatusStatus::try_from(fetched_cctx.cctx_status.status.clone())
868-
.map_err(|e| anyhow::anyhow!(e))?,
869-
),
870-
last_update_timestamp: ActiveValue::Set(
871-
chrono::DateTime::from_timestamp(
872-
fetched_cctx
873-
.cctx_status
874-
.last_update_timestamp
875-
.parse::<i64>()
876-
.unwrap_or(0),
877-
0,
878-
)
879-
.ok_or(anyhow::anyhow!("Invalid timestamp"))?
880-
.naive_utc(),
881-
),
882-
..Default::default()
883-
})
884-
.filter(cctx_status::Column::Id.eq(cctx_status_row.id))
885-
.exec(self.db.as_ref())
886-
.await?;
887858

888-
let first_outbound_params = fetched_cctx.outbound_params.first().unwrap();
889-
let token = self.calculate_token(&fetched_cctx).await?;
859+
let new_status = CctxStatusProto::from_str_name(&fetched_cctx.cctx_status.status).unwrap();
860+
cctx_status::Entity::update(cctx_status::ActiveModel {
861+
id: ActiveValue::Set(cctx.id),
862+
status: ActiveValue::Set(
863+
CctxStatusStatus::try_from(fetched_cctx.cctx_status.status.clone())
864+
.map_err(|e| anyhow::anyhow!(e))?,
865+
),
866+
last_update_timestamp: ActiveValue::Set(
867+
chrono::DateTime::from_timestamp(
868+
fetched_cctx
869+
.cctx_status
870+
.last_update_timestamp
871+
.parse::<i64>()
872+
.unwrap_or(0),
873+
0,
874+
)
875+
.ok_or(anyhow::anyhow!("Invalid timestamp"))?
876+
.naive_utc(),
877+
),
878+
..Default::default()
879+
})
880+
.filter(cctx_status::Column::Id.eq(cctx.id))
881+
.exec(self.db.as_ref())
882+
.await?;
890883

891-
cctx_list_item = Some(CctxListItemProto {
892-
index: fetched_cctx.index,
893-
status: new_status.into(),
894-
status_reduced: reduce_status(new_status).into(),
895-
amount: fetched_cctx.inbound_params.amount,
896-
created_timestamp: fetched_cctx.cctx_status.created_timestamp.parse::<i64>()?,
897-
last_update_timestamp: fetched_cctx
898-
.cctx_status
899-
.last_update_timestamp
900-
.parse::<i64>()?,
901-
source_chain_id: fetched_cctx.inbound_params.sender_chain_id.parse::<i32>()?,
902-
target_chain_id: first_outbound_params.receiver_chain_id.parse::<i32>()?,
903-
sender_address: fetched_cctx.inbound_params.sender,
904-
receiver_address: first_outbound_params.receiver.clone(),
905-
asset: fetched_cctx.inbound_params.asset,
906-
coin_type: token
907-
.as_ref()
908-
.map(|t| t.coin_type.clone().into())
909-
.unwrap_or_default(),
910-
token_symbol: token.as_ref().map(|t| t.symbol.clone()),
911-
zrc20_contract_address: token.as_ref().map(|t| t.zrc20_contract_address.clone()),
912-
decimals: token.as_ref().map(|t| t.decimals as i64),
913-
});
914-
}
884+
let first_outbound_params = fetched_cctx.outbound_params.first().unwrap();
885+
let token = if let Some(token_id) = cctx.token_id {
886+
TokenEntity::Entity::find()
887+
.filter(TokenEntity::Column::Id.eq(token_id))
888+
.one(self.db.as_ref())
889+
.await?
890+
} else {
891+
None
892+
};
893+
894+
let cctx_list_item = CctxListItemProto {
895+
index: fetched_cctx.index,
896+
status: new_status.into(),
897+
status_reduced: reduce_status(new_status).into(),
898+
amount: fetched_cctx.inbound_params.amount,
899+
created_timestamp: fetched_cctx.cctx_status.created_timestamp.parse::<i64>()?,
900+
last_update_timestamp: fetched_cctx
901+
.cctx_status
902+
.last_update_timestamp
903+
.parse::<i64>()?,
904+
source_chain_id: fetched_cctx.inbound_params.sender_chain_id.parse::<i32>()?,
905+
target_chain_id: first_outbound_params.receiver_chain_id.parse::<i32>()?,
906+
sender_address: fetched_cctx.inbound_params.sender,
907+
receiver_address: first_outbound_params.receiver.clone(),
908+
asset: fetched_cctx.inbound_params.asset,
909+
coin_type: token
910+
.as_ref()
911+
.map(|t| t.coin_type.clone().into())
912+
.unwrap_or_default(),
913+
token_symbol: token.as_ref().map(|t| t.symbol.clone()),
914+
zrc20_contract_address: token.as_ref().map(|t| t.zrc20_contract_address.clone()),
915+
decimals: token.as_ref().map(|t| t.decimals as i64),
916+
};
915917

916918
//commit transaction
917919
tx.commit().await?;

zetachain-cctx/zetachain-cctx-logic/src/indexer.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ async fn refresh_cctx_status(
5757
database: Arc<ZetachainCctxDatabase>,
5858
client: &Client,
5959
cctx: &CctxShort,
60-
) -> anyhow::Result<Option<CctxListItemProto>> {
60+
) -> anyhow::Result<CctxListItemProto> {
6161
let fetched_cctx = client
6262
.fetch_cctx(&cctx.index)
6363
.await
6464
.map_err(|e| anyhow::anyhow!(format!("Failed to fetch cctx: {}", e)))?;
6565
let updated = database
66-
.update_cctx_status(cctx.id, fetched_cctx)
66+
.update_cctx_status(cctx, fetched_cctx)
6767
.await
6868
.map_err(|e| anyhow::anyhow!(format!("Failed to update cctx status: {}", e)))?;
6969
Ok(updated)
@@ -174,16 +174,15 @@ async fn refresh_status_and_link_related(
174174
job_id: Uuid,
175175
channel_broadcaster: &ChannelBroadcaster,
176176
) -> anyhow::Result<()> {
177-
if let Some(updated) = refresh_cctx_status(database.clone(), client, cctx)
177+
let updated = refresh_cctx_status(database.clone(), client, cctx)
178178
.await
179-
.map_err(|e| anyhow::format_err!("Failed to refresh cctx status: {}", e))?
180-
{
181-
channel_broadcaster.broadcast(ChannelEvent::new(
182-
CCTX_STATUS_UPDATE_TOPIC,
183-
updated.index.clone(),
184-
&updated,
185-
));
186-
}
179+
.map_err(|e| anyhow::format_err!("Failed to refresh cctx status: {}", e))?;
180+
channel_broadcaster.broadcast(ChannelEvent::new(
181+
CCTX_STATUS_UPDATE_TOPIC,
182+
updated.index.clone(),
183+
&updated,
184+
));
185+
187186
let inserted = update_cctx_relations(database.clone(), client, cctx, job_id)
188187
.await
189188
.map_err(|e| anyhow::format_err!("Failed to update cctx relations: {}", e))?;

zetachain-cctx/zetachain-cctx-logic/src/models.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub struct CctxShort {
8181
pub root_id: Option<i32>,
8282
pub depth: i32,
8383
pub retries_number: i32,
84+
pub token_id: Option<i32>,
8485
}
8586

8687
#[derive(Debug, Serialize, Deserialize)]

zetachain-cctx/zetachain-cctx-logic/src/query_for_update.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ WHERE
2929
cctx.index,
3030
cctx.root_id,
3131
cctx.depth,
32-
cctx.retries_number;
32+
cctx.retries_number,
33+
cctx.token_id;

zetachain-cctx/zetachain-cctx-logic/tests/complete_cctx.rs

Lines changed: 12 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async fn test_get_complete_cctx() {
9696
"revert_address": "tb1quegm9lg6nd0v2xncl8ldkvfkghhe8mns3ftvca",
9797
"call_on_revert": false,
9898
"abort_address": "",
99-
"revert_message": null,
99+
"revert_message": "dummy revert message",
100100
"revert_gas_limit": "0"
101101
}
102102
}
@@ -137,119 +137,15 @@ async fn test_get_complete_cctx() {
137137
assert_eq!(cctx.zeta_fees, "0");
138138
assert_eq!(cctx.relayed_message, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000076465706f73697400000000000000000000000000000000000000000000000000");
139139
assert_eq!(cctx.token_symbol, Some("sBTC.BTC".to_string()));
140+
assert!(cctx.revert_options.is_some());
141+
assert!(cctx
142+
.revert_options
143+
.clone()
144+
.unwrap()
145+
.revert_message
146+
.is_some());
147+
assert_eq!(
148+
cctx.revert_options.clone().unwrap().revert_message.unwrap(),
149+
"dummy revert message"
150+
);
140151
}
141-
142-
#[tokio::test]
143-
async fn test_revert_message_is_base64_encoded() {
144-
let db = crate::helpers::init_db("test", "indexer_revert_message_is_base64_encoded").await;
145-
let database = ZetachainCctxDatabase::new(db.client().clone(), 7001);
146-
database.setup_db().await.unwrap();
147-
148-
let cctx_response = json!({
149-
"CrossChainTx": {
150-
"creator": "",
151-
"index": "0xa99eee254efce80d23caf1d4691c46b6e9965bd7b8923435fcc669fd3c032246",
152-
"zeta_fees": "0",
153-
"relayed_message": "00000000000000000000000050753ca349636ca8732762e8ccf057d3999891a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000005098e1b2e8ec00000000000000000000000050753ca349636ca8732762e8ccf057d3999891a0000000000000000000000000000000000000000000000000000000000000002868747470733a2f2f6170692e6578616d706c652e636f6d2f6d657461646174612f2f312e6a736f6e000000000000000000000000000000000000000000000000",
154-
"cctx_status": {
155-
"status": "Aborted",
156-
"status_message": "outbound failed and revert failed",
157-
"error_message": "{\"type\":\"internal_error\",\"message\":\"outbound tx failed to be executed on connected chain\"}",
158-
"lastUpdate_timestamp": "1756282428",
159-
"isAbortRefunded": false,
160-
"created_timestamp": "1756282335",
161-
"error_message_revert": "{\"type\":\"contract_call_error\",\"message\":\"contract call failed when calling EVM with data\",\"error\":\"revert transaction reverted:execution reverted: ret 0x7e2732890000000000000000000000000000000000000000000000000000000000000001: evm transaction execution failed\",\"method\":\"depositAndRevert\",\"contract\":\"0x6c533f7fE93fAE114d0954697069Df33C9B74fD7\",\"args\":\"[0x236b0DE675cC8F46AE186897fCCeFe3370C9eDeD 88617551849708 0xCf726D8D25aB1BEB67362cD42Bf57AE5f0941246 {0xCf726D8D25aB1BEB67362cD42Bf57AE5f0941246 0x236b0DE675cC8F46AE186897fCCeFe3370C9eDeD 88617551849708 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 96 0 0 0 0 0 0 0 0 0 0 0 0 80 117 60 163 73 99 108 168 115 39 98 232 204 240 87 211 153 152 145 160 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 40 104 116 116 112 115 58 47 47 97 112 105 46 101 120 97 109 112 108 101 46 99 111 109 47 109 101 116 97 100 97 116 97 47 47 49 46 106 115 111 110 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}]\"}",
162-
"error_message_abort": "failed to process abort: {\"type\":\"contract_call_error\",\"message\":\"contract call failed when calling EVM with data\",\"error\":\"execution reverted: ret 0xd92e233d: evm transaction execution failed\",\"method\":\"deposit\",\"contract\":\"0x236b0DE675cC8F46AE186897fCCeFe3370C9eDeD\",\"args\":\"[0x0000000000000000000000000000000000000000 88617551849708]\"}"
163-
},
164-
"inbound_params": {
165-
"sender": "0xCf726D8D25aB1BEB67362cD42Bf57AE5f0941246",
166-
"sender_chain_id": "7001",
167-
"tx_origin": "0x62dFD544f6f9bC3279D9762d7AeA4719a2559B0d",
168-
"coin_type": "Gas",
169-
"asset": "",
170-
"amount": "88617551849708",
171-
"observed_hash": "0x96304e7ff9c454ad19c61575dfcd512ed62c8187a57bbf2ac1635375701628d2",
172-
"observed_external_height": "12350146",
173-
"ballot_index": "0xa99eee254efce80d23caf1d4691c46b6e9965bd7b8923435fcc669fd3c032246",
174-
"finalized_zeta_height": "0",
175-
"tx_finalization_status": "NotFinalized",
176-
"is_cross_chain_call": true,
177-
"status": "SUCCESS",
178-
"confirmation_mode": "SAFE"
179-
},
180-
"outbound_params": [
181-
{
182-
"receiver": "0x62dFD544f6f9bC3279D9762d7AeA4719a2559B0d",
183-
"receiver_chainId": "84532",
184-
"coin_type": "Gas",
185-
"amount": "88617551849708",
186-
"tss_nonce": "962",
187-
"gas_limit": "0",
188-
"gas_price": "1217762",
189-
"gas_priority_fee": "0",
190-
"hash": "0x05b3312c4d88d5c2976a865f8a1e43c34bfbdc25909a4db80f210931a3425699",
191-
"ballot_index": "0x7fbbf69dfbfc793cbe717a25746cb98505ffd9f02d70300d1b2d3c490c0d4eaa",
192-
"observed_external_height": "30257033",
193-
"gas_used": "74505",
194-
"effective_gas_price": "1217762",
195-
"effective_gas_limit": "1000000",
196-
"tss_pubkey": "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p",
197-
"tx_finalization_status": "Executed",
198-
"call_options": {
199-
"gas_limit": "1000000",
200-
"is_arbitrary_call": false
201-
},
202-
"confirmation_mode": "SAFE"
203-
},
204-
{
205-
"receiver": "0xCf726D8D25aB1BEB67362cD42Bf57AE5f0941246",
206-
"receiver_chainId": "7001",
207-
"coin_type": "Gas",
208-
"amount": "88617551849708",
209-
"tss_nonce": "0",
210-
"gas_limit": "0",
211-
"gas_price": "",
212-
"gas_priority_fee": "",
213-
"hash": "",
214-
"ballot_index": "",
215-
"observed_external_height": "0",
216-
"gas_used": "0",
217-
"effective_gas_price": "0",
218-
"effective_gas_limit": "0",
219-
"tss_pubkey": "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p",
220-
"tx_finalization_status": "NotFinalized",
221-
"call_options": {
222-
"gas_limit": "1500000",
223-
"is_arbitrary_call": false
224-
},
225-
"confirmation_mode": "SAFE"
226-
}
227-
],
228-
"protocol_contract_version": "V2",
229-
"revert_options": {
230-
"revert_address": "0xCf726D8D25aB1BEB67362cD42Bf57AE5f0941246",
231-
"call_on_revert": true,
232-
"abort_address": "0x0000000000000000000000000000000000000000",
233-
"revert_message": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAFB1PKNJY2yocydi6MzwV9OZmJGgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAChodHRwczovL2FwaS5leGFtcGxlLmNvbS9tZXRhZGF0YS8vMS5qc29uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
234-
"revert_gas_limit": "0"
235-
}
236-
}
237-
});
238-
let cctx = cctx_response.get("CrossChainTx").unwrap();
239-
let cctx: CrossChainTx = serde_json::from_value(cctx.clone()).unwrap();
240-
let tx = db.client().begin().await.unwrap();
241-
database
242-
.batch_insert_transactions(Uuid::new_v4(), &vec![cctx], &tx, None)
243-
.await
244-
.unwrap();
245-
tx.commit().await.unwrap();
246-
let cctx = database
247-
.get_complete_cctx(
248-
"0xa99eee254efce80d23caf1d4691c46b6e9965bd7b8923435fcc669fd3c032246".to_string(),
249-
)
250-
.await
251-
.unwrap();
252-
assert!(cctx.is_some());
253-
let cctx = cctx.unwrap();
254-
assert_eq!(cctx.revert_options.unwrap().revert_message, Some("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAAFB1PKNJY2yocydi6MzwV9OZmJGgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAChodHRwczovL2FwaS5leGFtcGxlLmNvbS9tZXRhZGF0YS8vMS5qc29uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".to_string()));
255-
}

zetachain-cctx/zetachain-cctx-logic/tests/traverse_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ async fn test_traverse_and_update_tree_relationships() {
116116
root_id: None,
117117
depth: 0,
118118
retries_number: 0,
119+
token_id: Some(1),
119120
};
120121

121122
let job_id = Uuid::new_v4();

0 commit comments

Comments
 (0)