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

[INDEXER_CLIENT] model incompatibility with non Tari engine (wasm) environment #1259

Open
humb1t opened this issue Jan 22, 2025 · 0 comments

Comments

@humb1t
Copy link
Contributor

humb1t commented Jan 22, 2025

Describe the bug

Indexer uses types from dan_layer/template_lib/src/models to return results. These models depend on Tari engine and do not have implementations for non-wasm environments.

To Reproduce
Steps to reproduce the behavior:

  1. Create a component with some Vaults inside main state:
    #[derive(Debug, Clone, Serialize, Deserialize)]
    struct LiquidityPool {
        a: Vault,
        b: Vault,
        lp_resource: ResourceAddress,
        fees_collected: HashMap<String, f64>,
    }
  1. Get list of component's substates:
    let substate_ids = client
        .list_substates(ListSubstatesRequest {
            filter_by_template: Some(template_address),
            filter_by_type: None,
            limit: None,
            offset: None,
        })
        .await?
        .substates
        .into_iter()
        .map(|list_item| (list_item.substate_id, list_item.version));
    let mut result = Vec::with_capacity(substate_ids.len());
    let mut tasks = Vec::with_capacity(substate_ids.len());
    for (substate_id, version) in substate_ids {
        let mut client_clone = client.clone();
        tasks.push(tokio::spawn(async move {
            client_clone
                .get_substate(GetSubstateRequest {
                    address: substate_id,
                    version: Some(1),
                    local_search_only: false,
                })
                .await
                .map(|response| response.substate)
        }));
    }
    for task in tasks {
        result.push(task.await??);
    }
  1. Try to use them outside of Tari engine:
    impl From<LiquidityPool> for tari_exchange::LiquidityPool {
        fn from(value: LiquidityPool) -> Self {
            Self {
                a: value.a.balance().0,
                b: value.b.balance().0,
                lp_resource: value.lp_resource,
                //TODO:
                fees_collected: HashMap::new(),
            }
        }
    }

Expected behavior

Developers of non-engine integrations will need a way to receive the "deep" substate, where Vaults will be represented not by Id's, but by real values. Otherwise they will need to put the logic of transformations inside the component itself or create wrappers around indexer to transform Vault(VaultId) into Vault(RealValue).

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS & Version: [e.g. iOS 10.2.1]
  • Browser & Version [e.g. chrome v71.0.12345]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser & Version [e.g. stock browser v0.1.2]

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant