Skip to content
Merged

Suifix #5368

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
11 changes: 7 additions & 4 deletions voyager/modules/state/sui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ pub struct Module {

pub ibc_store: ObjectID,

pub ibc_contract: ObjectID,
pub initial_ibc_contract: ObjectID,

pub latest_ibc_contract: ObjectID,

pub ibc_store_initial_seq: SequenceNumber,
}
Expand Down Expand Up @@ -174,7 +176,7 @@ impl Module {
.expect("there must be some events exist")
.into_iter()
.find_map(|e| {
if e.type_.address == self.ibc_contract.into()
if e.type_.address == self.initial_ibc_contract.into()
&& e.type_.module.as_str() == "events"
&& e.type_.name.as_str() == "PacketSend"
{
Expand Down Expand Up @@ -255,7 +257,8 @@ impl StateModule<IbcUnion> for Module {
sui_client,
rpc_url: config.rpc_url,
ibc_store: config.ibc_store,
ibc_contract,
initial_ibc_contract: config.ibc_contract,
latest_ibc_contract: ibc_contract,
ibc_store_initial_seq,
})
}
Expand Down Expand Up @@ -306,7 +309,7 @@ impl StateModuleServer<IbcUnion> for Module {
) -> RpcResult<Value> {
let query = SuiQuery::new_with_store(
&self.sui_client,
self.ibc_contract,
self.latest_ibc_contract,
self.ibc_store,
self.ibc_store_initial_seq,
)
Expand Down
48 changes: 29 additions & 19 deletions voyager/plugins/client-update/sui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sui_sdk::{
base_types::ObjectID, committee::EpochId, full_checkpoint_content::CheckpointTransaction,
},
};
use tracing::instrument;
use tracing::{info, instrument};
use unionlabs::ibc::core::client::height::Height;
use voyager_sdk::{
DefaultCmd, anyhow,
Expand Down Expand Up @@ -177,26 +177,36 @@ impl Module {
let mut headers = vec![];

let mut is_first = true;
for epoch in from..to {
let query = json!({
"query": "query ($epoch_id: UInt53) { epoch(epochId: $epoch_id) { checkpoints(last: 1) { edges { node { sequenceNumber } } } } }",
"variables": { "epoch_id": epoch }
});

let resp = client
.try_clone()
.expect("no body, so this will work")
.body(query.to_string())
.send()
.await
.unwrap()
.text()
.await
.unwrap();
let epoch_ids: Vec<u64> = (from..to).collect();
let query = json!({
"query": "query ($epoch_ids: [UInt53]) { multiGetEpochs(keys: $epoch_ids) { checkpoints(last: 1) { edges { node { sequenceNumber } } } } }",
"variables": { "epoch_ids": epoch_ids}
});

let resp = client
.try_clone()
.expect("no body, so this will work")
.body(query.to_string())
.send()
.await
.map_err(RpcError::retryable("error fetching epoch checkpoint"))?
.error_for_status()
.map_err(RpcError::retryable(
"error fetching epoch checkpoint: error status",
))?
.text()
.await
.map_err(RpcError::retryable(
"error fetching epoch checkpoint: error reading text from body",
))?;

info!(%resp);

let v: serde_json::Value = serde_json::from_str(&resp).unwrap();
let v: &serde_json::Value =
&serde_json::from_str::<serde_json::Value>(&resp).unwrap()["data"]["multiGetEpochs"];

let update_to = v["data"]["epoch"]["checkpoints"]["edges"][0]["node"]["sequenceNumber"]
for (i, _) in (from..to).enumerate() {
let update_to = v[i]["checkpoints"]["edges"][0]["node"]["sequenceNumber"]
.as_u64()
.unwrap();

Expand Down
Loading