Skip to content

Commit

Permalink
Merge pull request #1781 from matter-labs/deniallugo-zks-739-no-symbo…
Browse files Browse the repository at this point in the history
…l-for-minted_nfts

Join tokens for correct nft symbol
  • Loading branch information
popzxc authored Jul 27, 2021
2 parents b0dd23a + 50fe2e6 commit 59a8899
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 110 deletions.
220 changes: 119 additions & 101 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1275,44 +1275,64 @@
]
}
},
"29d2ac9094d660ffa445ed8787f303e35deefc41b403b23557f6a0850cdbf4c6": {
"query": "\n SELECT * FROM nft\n WHERE creator_account_id = $1\n ",
"2e92926816053cda2de6d571867a625fab5bb9668840db94bd18c411f96dc39b": {
"query": "SELECT * FROM blocks WHERE number = $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "token_id",
"type_info": "Int4"
"name": "number",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "creator_account_id",
"type_info": "Int4"
"name": "root_hash",
"type_info": "Bytea"
},
{
"ordinal": 2,
"name": "creator_address",
"type_info": "Bytea"
"name": "fee_account_id",
"type_info": "Int8"
},
{
"ordinal": 3,
"name": "serial_id",
"type_info": "Int4"
"name": "unprocessed_prior_op_before",
"type_info": "Int8"
},
{
"ordinal": 4,
"name": "address",
"type_info": "Bytea"
"name": "unprocessed_prior_op_after",
"type_info": "Int8"
},
{
"ordinal": 5,
"name": "content_hash",
"name": "block_size",
"type_info": "Int8"
},
{
"ordinal": 6,
"name": "commit_gas_limit",
"type_info": "Int8"
},
{
"ordinal": 7,
"name": "verify_gas_limit",
"type_info": "Int8"
},
{
"ordinal": 8,
"name": "timestamp",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "commitment",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Int4"
"Int8"
]
},
"nullable": [
Expand All @@ -1321,68 +1341,57 @@
false,
false,
false,
false,
false,
false,
true,
false
]
}
},
"2e92926816053cda2de6d571867a625fab5bb9668840db94bd18c411f96dc39b": {
"query": "SELECT * FROM blocks WHERE number = $1",
"2fbf34144638328f53e4e96f0f044edc6af2724a2b5e846d2346b78d0cc7634e": {
"query": "\n SELECT nft.*, tokens.symbol FROM nft\n INNER JOIN tokens\n ON tokens.id = nft.token_id\n WHERE token_id = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "number",
"type_info": "Int8"
"name": "token_id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "root_hash",
"type_info": "Bytea"
"name": "creator_account_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "fee_account_id",
"type_info": "Int8"
"name": "creator_address",
"type_info": "Bytea"
},
{
"ordinal": 3,
"name": "unprocessed_prior_op_before",
"type_info": "Int8"
"name": "serial_id",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "unprocessed_prior_op_after",
"type_info": "Int8"
"name": "address",
"type_info": "Bytea"
},
{
"ordinal": 5,
"name": "block_size",
"type_info": "Int8"
"name": "content_hash",
"type_info": "Bytea"
},
{
"ordinal": 6,
"name": "commit_gas_limit",
"type_info": "Int8"
},
{
"ordinal": 7,
"name": "verify_gas_limit",
"type_info": "Int8"
},
{
"ordinal": 8,
"name": "timestamp",
"type_info": "Int8"
},
{
"ordinal": 9,
"name": "commitment",
"type_info": "Bytea"
"name": "symbol",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int8"
"Int4"
]
},
"nullable": [
Expand All @@ -1392,9 +1401,6 @@
false,
false,
false,
false,
false,
true,
false
]
}
Expand Down Expand Up @@ -2771,56 +2777,6 @@
"nullable": []
}
},
"72e7f8ffef6a594e659f5d0eb02e7463612d2ff4c2b6d4db120b94ebde1c314b": {
"query": "\n SELECT * FROM nft\n WHERE token_id = $1\n LIMIT 1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "token_id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "creator_account_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "creator_address",
"type_info": "Bytea"
},
{
"ordinal": 3,
"name": "serial_id",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "address",
"type_info": "Bytea"
},
{
"ordinal": 5,
"name": "content_hash",
"type_info": "Bytea"
}
],
"parameters": {
"Left": [
"Int4"
]
},
"nullable": [
false,
false,
false,
false,
false,
false
]
}
},
"73eedd4444ef5bfbfd526c319f97d75609a65517d63e88add0a864a9f7141a02": {
"query": "\n INSERT INTO block_metadata (block_number, fast_processing)\n VALUES ($1, $2)\n ",
"describe": {
Expand Down Expand Up @@ -2899,6 +2855,62 @@
"nullable": []
}
},
"77a35660d36e4b67dafa930ea4cce469b73e3f6d14a67aeda89233c7aa82206a": {
"query": "\n SELECT nft.*, tokens.symbol FROM nft\n INNER JOIN tokens\n ON tokens.id = nft.token_id\n WHERE creator_account_id = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "token_id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "creator_account_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "creator_address",
"type_info": "Bytea"
},
{
"ordinal": 3,
"name": "serial_id",
"type_info": "Int4"
},
{
"ordinal": 4,
"name": "address",
"type_info": "Bytea"
},
{
"ordinal": 5,
"name": "content_hash",
"type_info": "Bytea"
},
{
"ordinal": 6,
"name": "symbol",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int4"
]
},
"nullable": [
false,
false,
false,
false,
false,
false,
false
]
}
},
"790d46519ceaa7fbd152f1edf29b85c97ab491488b7302d8df3f57e5fc3eff55": {
"query": "\n SELECT account_id FROM account_creates\n WHERE address = $1 AND is_create = $2\n ORDER BY block_number desc\n LIMIT 1\n ",
"describe": {
Expand Down Expand Up @@ -4331,8 +4343,8 @@
"nullable": []
}
},
"ad3353e54de7447ea420b981e09af0f44894a6cad621640c7f8aac08f441ede2": {
"query": "SELECT * FROM nft",
"aca411b7ebc9a4028b4c86b71d8cd9f205f464bf19fb23fceb81210357379160": {
"query": "\n SELECT nft.*, tokens.symbol FROM nft\n INNER JOIN tokens\n ON tokens.id = nft.token_id\n ",
"describe": {
"columns": [
{
Expand Down Expand Up @@ -4364,6 +4376,11 @@
"ordinal": 5,
"name": "content_hash",
"type_info": "Bytea"
},
{
"ordinal": 6,
"name": "symbol",
"type_info": "Text"
}
],
"parameters": {
Expand All @@ -4375,6 +4392,7 @@
false,
false,
false,
false,
false
]
}
Expand Down
4 changes: 3 additions & 1 deletion core/lib/storage/src/chain/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ impl<'a, 'c> AccountSchema<'a, 'c> {
let nfts: Vec<StorageNFT> = sqlx::query_as!(
StorageNFT,
"
SELECT * FROM nft
SELECT nft.*, tokens.symbol FROM nft
INNER JOIN tokens
ON tokens.id = nft.token_id
WHERE creator_account_id = $1
",
*account_id as i32
Expand Down
23 changes: 16 additions & 7 deletions core/lib/storage/src/tokens/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,19 @@ impl<'a, 'c> TokensSchema<'a, 'c> {
/// Loads all finalized NFTs.
pub async fn load_nfts(&mut self) -> QueryResult<HashMap<TokenId, NFT>> {
let start = Instant::now();
let nfts = sqlx::query_as!(StorageNFT, "SELECT * FROM nft",)
.fetch_all(self.0.conn())
.await?
.into_iter()
.map(|nft| (TokenId(nft.token_id as u32), nft.into()))
.collect();
let nfts = sqlx::query_as!(
StorageNFT,
r#"
SELECT nft.*, tokens.symbol FROM nft
INNER JOIN tokens
ON tokens.id = nft.token_id
"#,
)
.fetch_all(self.0.conn())
.await?
.into_iter()
.map(|nft| (TokenId(nft.token_id as u32), nft.into()))
.collect();

metrics::histogram!("sql.token.load_nfts", start.elapsed());
Ok(nfts)
Expand Down Expand Up @@ -304,7 +311,9 @@ impl<'a, 'c> TokensSchema<'a, 'c> {
let db_token = sqlx::query_as!(
StorageNFT,
r#"
SELECT * FROM nft
SELECT nft.*, tokens.symbol FROM nft
INNER JOIN tokens
ON tokens.id = nft.token_id
WHERE token_id = $1
LIMIT 1
"#,
Expand Down
3 changes: 2 additions & 1 deletion core/lib/storage/src/tokens/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct StorageNFT {
pub creator_address: Vec<u8>,
pub address: Vec<u8>,
pub content_hash: Vec<u8>,
pub symbol: String,
}

#[derive(Debug, FromRow)]
Expand Down Expand Up @@ -97,7 +98,7 @@ impl From<StorageNFT> for NFT {
creator_address: Address::from_slice(val.creator_address.as_slice()),
creator_id: AccountId(val.creator_account_id as u32),
address: Address::from_slice(val.address.as_slice()),
symbol: "".to_string(),
symbol: val.symbol,
content_hash: H256::from_slice(val.content_hash.as_slice()),
}
}
Expand Down

0 comments on commit 59a8899

Please sign in to comment.