Skip to main content

Synchronizer

The Synchronizer helps you synchronize on-chain data to the local environment.

Data Structure

SynchronizerStatus

PropertyTypeDescription
chainsVec<ChainStatus>
The list of ChainStatus

ChainStatus

PropertyTypeDescription
chain_idu64
Chain id
synced_blocku64
Synced block number
target_blocku64
Target block number
contractsVec<ContractStatus>
The list of ContractStatus

ContractStatus

PropertyTypeDescription
contract_addressString
Contract address
synced_blocku64
Synced block number

chain_synced_block

Sync block data according to chain id.

use mystiko_protos::api::synchronizer::v1::{ChainSyncedBlockRequest, ChainSyncedBlockResponse};
use mystiko_lib::synchronizer::chain_synced_block;
use mystiko_protos::api::v1::api_response;

let request = ChainSyncedBlockRequest::builder().chain_id(11155111u64).build()
let response = chain_synced_block(request);
let result = match response.result {
Some(api_response::Result::Data(data)) => match ChainSyncedBlockResponse::try_from(data) {
Ok(result) => result,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};

contract_synced_block

Sync block data according to chain id and contract address.

use mystiko_protos::api::synchronizer::v1::{ContractSyncedBlockRequest, ContractSyncedBlockResponse};
use mystiko_lib::synchronizer::contract_synced_block;
use mystiko_protos::api::v1::api_response;

let request = ContractSyncedBlockRequest::builder()
.chain_id(11155111u64)
.contract_address("0xAE77941b3bd4d2293E13A9a69E64A0ACFf5bBC55")
.build()
let response = contract_synced_block(request);
let result = match response.result {
Some(api_response::Result::Data(data)) => match ContractSyncedBlockResponse::try_from(data) {
Ok(result) => result,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};

status

Check the Sync Status.

Parameter: withContracts Indicates whether to include contract-related data in the synchronization status.

use mystiko_protos::api::synchronizer::v1::{SynchronizerStatusRequest, SynchronizerStatusResponse};
use mystiko_lib::synchronizer::status;
use mystiko_protos::api::v1::api_response;

let request = SynchronizerStatusRequest::builder().with_contracts(false).build();
let response = status(request);
let result = match response.result {
Some(api_response::Result::Data(data)) => match SynchronizerStatusResponse::try_from(data) {
Ok(result) => result,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};

sync

Synchronize the transaction data for the Mystiko contract.

use mystiko_protos::api::synchronizer::v1::{SynchronizerSyncRequest, SynchronizerSyncResponse};
use mystiko_protos::core::synchronizer::v1::SynchronizerSyncOptions;
use mystiko_lib::synchronizer::sync;
use mystiko_protos::api::v1::api_response;

let options = SynchronizerSyncOptions::builder().chain_ids(vec![1u64]).build();
let request = SynchronizerSyncRequest::builder().options(options).build();
let response = sync(request);
let result = match response.result {
Some(api_response::Result::Data(data)) => match SynchronizerSyncResponse::try_from(data) {
Ok(result) => result,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};

The parameter list for SynchronizerSyncOptions:

ParameterRequiredDescription
disable_datapacker_fetcherfalse
Disable the datapacker fetcher.
enable_datapacker_fetcher_validatefalse
Enable the datapacker fetcher validate.
disable_sequencer_fetcherfalse
Disable the sequencer fetcher.
enable_sequencer_fetcher_validatefalse
Enable the sequencer fetcher validate.
disable_provider_fetcherfalse
Disable the provider fetcher.
disable_provider_fetcher_validatefalse
Disable the provider fetcher validate.
disable_rule_validatorfalse
Disable the rule validator.
disable_rule_validator_integrity_checkfalse
Disable the rule validator integrity check.
disable_rule_validator_sequence_checkfalse
Disable the rule validator sequence check.
disable_rule_validator_counter_checkfalse
Disable the rule validator counter check.
disable_rule_validator_treecheckfalse
Disable the rule validator tree check.
fetcher_fetch_timeout_msfalse
The fetcher fetch timeout in milliseconds.
fetcher_query_loaded_block_timeout_msfalse
The fetcher query loaded block timeout in milliseconds.
validator_validate_concurrencyfalse
The validator validate concurrency, enforced to 1 in the SDK.
chain_idsfalse
The list of chain ids.

reset

Reset the synchronization data.

use mystiko_protos::api::synchronizer::v1::{SynchronizerResetRequest, SynchronizerResetResponse};
use mystiko_protos::core::synchronizer::v1::{SynchronizerResetOptions, ResetChainOptions};
use mystiko_lib::synchronizer::reset;
use mystiko_protos::api::v1::api_response;

let chain = ResetChainOptions::builder().chain_id(1u64).build();
let options = SynchronizerResetOptions::builder().chains(vec![chain]).build();
let request = SynchronizerResetRequest::builder().options(options).build();
let response = reset(request);
let result = match response.result {
Some(api_response::Result::Data(data)) => match SynchronizerResetResponse::try_from(data) {
Ok(result) => result,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};

The parameter list for SynchronizerResetOptions:

ParameterRequiredDescription
chainsfalse
The list of ResetChainOptions.

ResetChainOptions:

ParameterRequiredDescription
chain_idtrue
The chain id.
contract_addressesfalse
The contract addresses.
block_numberfalse
The block number.