-
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
Open
maschad
wants to merge
9
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.
Open
Changes from all commits
Commits
Show all changes
9 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 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,30 @@ | ||
use crate::client::schema::{ | ||
schema, | ||
AssetId, | ||
HexString, | ||
U64, | ||
}; | ||
|
||
#[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: Option<AssetInfoDetails>, | ||
} | ||
|
||
#[derive(cynic::QueryFragment, Clone, Debug)] | ||
#[cynic(schema_path = "./assets/schema.sdl")] | ||
pub struct AssetInfoDetails { | ||
pub sub_id: HexString, | ||
pub contract_id: HexString, | ||
pub total_supply: U64, | ||
} |
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,48 @@ | ||
use fuel_core_storage::{ | ||
blueprint::plain::Plain, | ||
codec::{ | ||
postcard::Postcard, | ||
raw::Raw, | ||
}, | ||
structured_storage::TableWithBlueprint, | ||
Mappable, | ||
}; | ||
use fuel_core_types::{ | ||
fuel_merkle::common::Bytes32, | ||
fuel_tx::{ | ||
AssetId, | ||
ContractId, | ||
}, | ||
}; | ||
|
||
/// Contract info | ||
pub struct AssetsInfo; | ||
|
||
pub type AssetDetails = (ContractId, Bytes32, u64); // (contract_id, sub_id, total_amount) | ||
|
||
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) | ||
} | ||
} |
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
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.
You need to increase/decrease based on the minted/burned amount=)
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.
Good catch 😄 ab09b8d