fuel
September 15, 2023, 7:13pm
1
Hi guys, I’m trying to create uid
based on Address and AssetId in the indexer lib file, it works well like uid(event.address)
and uid(event.asset_id.0)
but how to make it together?
I’m trying to store data like this:
storage {
user_collateral: StorageMap<(Address, AssetId), u64> = StorageMap {},
}
Toolchain latest and indexer v0.20.8
Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup
installed toolchains
--------------------
beta-3-aarch64-apple-darwin
beta-4-rc.2-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
hotfix
my-custom-toolchain
active toolchain
-----------------
latest-aarch64-apple-darwin (default)
forc : 0.44.1
- forc-client
- forc-deploy : 0.44.1
- forc-run : 0.44.1
- forc-doc : 0.44.1
- forc-explore : 0.28.1
- forc-fmt : 0.44.1
- forc-index : 0.20.8
- forc-lsp : 0.44.1
- forc-tx : 0.44.1
- forc-wallet : 0.3.0
fuel-core : 0.20.4
fuel-core-keygen : Error getting version string
fuel-indexer : 0.20.8
fuels versions
---------------
forc : 0.45
forc-wallet : 0.45
Source code
extern crate alloc;
use fuel_indexer_utils::prelude::*;
#[indexer(manifest = "swaylend_indexer.manifest.yaml")]
pub mod swaylend_indexer_index_mod {
fn handle_block(block: BlockData) {
let height = block.height;
let txs = block.transactions.len();
info!("🧱 Block height: {height} | transacrions: {txs}");
}
fn handle_asset_collateral_event(event: AssetCollateralEvent) {
let entry = CollateralConfigurationEntity {
id: uid(&event.configuration.asset_id.0),
asset_id: event.configuration.asset_id.0.into(),
price_feed: event.configuration.price_feed,
decimals: event.configuration.decimals,
borrow_collateral_factor: event.configuration.borrow_collateral_factor,
liquidate_collateral_factor: event.configuration.liquidate_collateral_factor,
This file has been truncated. show original
Voxelot
September 15, 2023, 7:47pm
2
The uid function expects a contiguous slice of bytes.
The following is not a valid way to join two separate byte arrays together in rust, as it just creates a slice of two nested slices:
[..event.address, ..event.asset_id.0]
To create a flattened byte slice from two separate slices you’ll need to concat them.
Playground example → Rust Playground
fuel
September 15, 2023, 10:32pm
3
Oh, sorry, stupid question, that works for me