-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Create new index for tracking Asset metadata #2445
Draft
maschad
wants to merge
18
commits into
master
Choose a base branch
from
mc/feat/index-asset-ids
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
610fd37
feat: add indexing for asset id metadata for gql endpoint
maschad 54375c3
feat: add gql endpoint to retrieve from off-chain db
maschad 1dc6932
feat: updated GQL structs
maschad 246eae3
lint: formatting
maschad 684361d
docs: added changelog
maschad d750c73
Merge branch 'master' into mc/feat/index-asset-ids
maschad ab09b8d
fix: increase based on burn/mint amount
maschad 07fa5e5
test: add test for checking totals
maschad b2abf4d
fix: remove unused method
maschad 3b56332
Merge branch 'master' into mc/feat/index-asset-ids
maschad 0cb04fd
Merge branch 'master' into mc/feat/index-asset-ids
maschad 6ae2051
chore: handle unindexed asset events
maschad 098b031
Fix the indexation and rework the tests
AurelienFT 630da0d
Add GWT in test
AurelienFT ef2e9ce
Merge branch 'master' into mc/feat/index-asset-ids
AurelienFT 5ae7e63
Merge branch 'master' into mc/feat/index-asset-ids
AurelienFT 1bc7ddd
Merge remote-tracking branch 'refs/remotes/origin/master' into mc/fea…
xgreenx 319d32d
Applied comments from the PR.
xgreenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::client::schema::{ | ||
schema, | ||
AssetId, | ||
ContractId, | ||
SubId, | ||
U128, | ||
}; | ||
|
||
#[derive(cynic::QueryVariables, Debug)] | ||
pub struct AssetInfoArg { | ||
pub id: AssetId, | ||
} | ||
|
||
#[derive(cynic::QueryFragment, Clone, Debug)] | ||
#[cynic( | ||
schema_path = "./assets/schema.sdl", | ||
graphql_type = "Query", | ||
variables = "AssetInfoArg" | ||
)] | ||
pub struct AssetInfoQuery { | ||
#[arguments(id: $id)] | ||
pub asset_details: AssetInfoDetails, | ||
} | ||
|
||
#[derive(cynic::QueryFragment, Clone, Debug)] | ||
#[cynic(schema_path = "./assets/schema.sdl")] | ||
pub struct AssetInfoDetails { | ||
pub sub_id: SubId, | ||
pub contract_id: ContractId, | ||
pub total_supply: U128, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::client::schema; | ||
use fuel_core_types::{ | ||
fuel_tx::Bytes32, | ||
fuel_types::ContractId, | ||
}; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct AssetDetail { | ||
pub contract_id: ContractId, | ||
pub sub_id: Bytes32, | ||
pub total_supply: u128, | ||
} | ||
|
||
// GraphQL Translation | ||
|
||
impl From<schema::assets::AssetInfoDetails> for AssetDetail { | ||
fn from(value: schema::assets::AssetInfoDetails) -> Self { | ||
AssetDetail { | ||
contract_id: value.contract_id.into(), | ||
sub_id: value.sub_id.into(), | ||
total_supply: value.total_supply.into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use fuel_core_storage::{ | ||
blueprint::plain::Plain, | ||
codec::{ | ||
postcard::Postcard, | ||
raw::Raw, | ||
}, | ||
structured_storage::TableWithBlueprint, | ||
Mappable, | ||
}; | ||
use fuel_core_types::fuel_tx::{ | ||
AssetId, | ||
Bytes32, | ||
ContractId, | ||
}; | ||
|
||
/// Asset info table to store information about the asset like total minted amounts, | ||
/// source contract, original sub id, etc. | ||
pub struct AssetsInfo; | ||
|
||
#[derive(Default, Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
pub struct AssetDetails { | ||
pub contract_id: ContractId, | ||
pub sub_id: Bytes32, | ||
pub total_supply: u128, | ||
} | ||
|
||
impl Mappable for AssetsInfo { | ||
type Key = AssetId; | ||
type OwnedKey = Self::Key; | ||
type Value = Self::OwnedValue; | ||
type OwnedValue = AssetDetails; | ||
} | ||
|
||
impl TableWithBlueprint for AssetsInfo { | ||
type Blueprint = Plain<Raw, Postcard>; | ||
type Column = super::Column; | ||
|
||
fn column() -> Self::Column { | ||
Self::Column::AssetsInfo | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
fuel_core_storage::basic_storage_tests!( | ||
AssetsInfo, | ||
<AssetsInfo as Mappable>::Key::default(), | ||
<AssetsInfo as Mappable>::Value::default() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod assets; | ||
mod balance; | ||
mod blob; | ||
mod block; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::{ | ||
fuel_core_graphql_api::database::ReadView, | ||
graphql_api::storage::assets::AssetDetails, | ||
}; | ||
use fuel_core_storage::{ | ||
not_found, | ||
Result as StorageResult, | ||
}; | ||
use fuel_core_types::fuel_tx::AssetId; | ||
|
||
impl ReadView { | ||
pub fn get_asset_details(&self, id: &AssetId) -> StorageResult<AssetDetails> { | ||
let asset = self | ||
.off_chain | ||
.asset_info(id)? | ||
.ok_or(not_found!(AssetDetails))?; | ||
Ok(asset) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please enumerate all variants explicitly to avoid surprises when new variant is added in the future.