Skip to content

Commit f59e154

Browse files
Merge #1874
1874: Return backward compatibility in tokens r=Deniallugo a=Deniallugo Signed-off-by: deniallugo <[email protected]> Co-authored-by: deniallugo <[email protected]>
2 parents a40d1cc + 0f376e4 commit f59e154

File tree

13 files changed

+129
-114
lines changed

13 files changed

+129
-114
lines changed

core/bin/data_restore/src/data_restore_driver.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ where
176176
);
177177

178178
interactor
179-
.save_special_token(Token {
180-
id: NFT_TOKEN_ID,
181-
symbol: "SPECIAL".to_string(),
182-
address: *NFT_STORAGE_ACCOUNT_ADDRESS,
183-
decimals: 18,
184-
kind: TokenKind::NFT,
185-
})
179+
.save_special_token(Token::new(
180+
NFT_TOKEN_ID,
181+
*NFT_STORAGE_ACCOUNT_ADDRESS,
182+
"SPECIAL",
183+
18,
184+
TokenKind::NFT,
185+
))
186186
.await;
187187
vlog::info!("Special token added");
188188

core/bin/data_restore/src/database_storage_interactor.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ impl StorageInteractor for DatabaseStorageInteractor<'_> {
119119
async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) {
120120
self.storage
121121
.tokens_schema()
122-
.store_token(Token {
123-
id: token_id,
124-
symbol: token.symbol,
125-
address: token.address,
126-
decimals: token.decimals,
127-
kind: TokenKind::ERC20,
128-
})
122+
.store_token(Token::new(
123+
token_id,
124+
token.address,
125+
&token.symbol,
126+
token.decimals,
127+
TokenKind::ERC20,
128+
))
129129
.await
130130
.expect("failed to store token");
131131
}

core/bin/data_restore/src/inmemory_storage_interactor.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ impl StorageInteractor for InMemoryStorageInteractor {
6666
}
6767

6868
async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) {
69-
let token = Token {
70-
id: token_id,
71-
symbol: token.symbol,
72-
address: token.address,
73-
decimals: token.decimals,
74-
kind: TokenKind::ERC20,
75-
};
69+
let token = Token::new(
70+
token_id,
71+
token.address,
72+
&token.symbol,
73+
token.decimals,
74+
TokenKind::ERC20,
75+
);
7676
self.tokens.insert(token_id, token);
7777
}
7878

@@ -98,6 +98,7 @@ impl StorageInteractor for InMemoryStorageInteractor {
9898
symbol: format!("ERC20-{}", *id),
9999
decimals: 18,
100100
kind: TokenKind::ERC20,
101+
is_nft: false,
101102
},
102103
);
103104
}
@@ -277,6 +278,7 @@ impl InMemoryStorageInteractor {
277278
symbol: token.symbol.clone(),
278279
decimals: 0,
279280
kind: TokenKind::NFT,
281+
is_nft: true,
280282
},
281283
);
282284
}

core/bin/zksync_api/src/api_server/admin_server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ async fn add_token(
116116
}
117117
};
118118

119-
let token = tokens::Token {
119+
let token = tokens::Token::new(
120120
id,
121-
address: token_request.address,
122-
symbol: token_request.symbol.clone(),
123-
decimals: token_request.decimals,
124-
kind: TokenKind::ERC20,
125-
};
121+
token_request.address,
122+
&token_request.symbol,
123+
token_request.decimals,
124+
TokenKind::ERC20,
125+
);
126126

127127
storage
128128
.tokens_schema()

core/bin/zksync_api/src/fee_ticker/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ async fn test_error_coingecko_api() {
565565
symbol: String::from("DAI"),
566566
decimals: 18,
567567
kind: TokenKind::ERC20,
568+
is_nft: false,
568569
};
569570
let (address, handler) = run_server(token.address);
570571
let client = reqwest::ClientBuilder::new()

core/bin/zksync_core/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ pub async fn genesis_init(config: &ZkSyncConfig) {
7474
.await
7575
.expect("failed to access db")
7676
.tokens_schema()
77-
.store_token(Token {
78-
id: TokenId(id as u32),
79-
symbol: token.symbol,
80-
address: token.address,
81-
decimals: token.decimals,
82-
kind: TokenKind::ERC20,
83-
})
77+
.store_token(Token::new(
78+
TokenId(id as u32),
79+
token.address,
80+
&token.symbol,
81+
token.decimals,
82+
TokenKind::ERC20,
83+
))
8484
.await
8585
.expect("failed to store token");
8686
}

core/bin/zksync_core/src/state_keeper/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,13 @@ impl ZkSyncStateKeeper {
525525
vlog::info!("Adding special token");
526526
transaction
527527
.tokens_schema()
528-
.store_token(Token {
529-
id: NFT_TOKEN_ID,
530-
symbol: "SPECIAL".to_string(),
531-
address: *NFT_STORAGE_ACCOUNT_ADDRESS,
532-
decimals: 18,
533-
kind: TokenKind::NFT,
534-
})
528+
.store_token(Token::new(
529+
NFT_TOKEN_ID,
530+
*NFT_STORAGE_ACCOUNT_ADDRESS,
531+
"SPECIAL",
532+
18,
533+
TokenKind::NFT,
534+
))
535535
.await
536536
.expect("failed to store special token");
537537
vlog::info!("Special token added");

core/lib/storage/sqlx-data.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -2728,24 +2728,6 @@
27282728
"nullable": []
27292729
}
27302730
},
2731-
"66dddd41e83db60b333ea6f5697d4507fb090021f4e4b22dbb4496d0999e17f1": {
2732-
"query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"'\n ORDER BY nonce\n ",
2733-
"describe": {
2734-
"columns": [
2735-
{
2736-
"ordinal": 0,
2737-
"name": "tx",
2738-
"type_info": "Jsonb"
2739-
}
2740-
],
2741-
"parameters": {
2742-
"Left": []
2743-
},
2744-
"nullable": [
2745-
false
2746-
]
2747-
}
2748-
},
27492731
"681359f99d0e4bafdd3109f67c7af4d235dc1197ba88cd0d6148f632ae0cdf8f": {
27502732
"query": "SELECT * FROM aggregated_proofs WHERE first_block = $1 and last_block = $2",
27512733
"describe": {
@@ -7174,6 +7156,24 @@
71747156
]
71757157
}
71767158
},
7159+
"f7a49b80724c8deb1f8af7016e92937fd04f9c5df474986ab61ad201ec41bdb4": {
7160+
"query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"' AND success = true\n ORDER BY nonce\n ",
7161+
"describe": {
7162+
"columns": [
7163+
{
7164+
"ordinal": 0,
7165+
"name": "tx",
7166+
"type_info": "Jsonb"
7167+
}
7168+
],
7169+
"parameters": {
7170+
"Left": []
7171+
},
7172+
"nullable": [
7173+
false
7174+
]
7175+
}
7176+
},
71777177
"f8f2208c71cbf2d42de633222bb888c773a47b82dd0095b76ad38f535d74fdce": {
71787178
"query": "SELECT created_at, block_number FROM executed_transactions\n WHERE tx_hash = $1",
71797179
"describe": {

core/lib/storage/src/tests/chain/accounts.rs

+3
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer
330330
symbol: "NFT".to_string(),
331331
decimals: 0,
332332
kind: TokenKind::NFT,
333+
is_nft: true,
333334
})
334335
.await?;
335336
storage
@@ -340,6 +341,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer
340341
symbol: "SPECIAL".to_string(),
341342
decimals: 0,
342343
kind: TokenKind::NFT,
344+
is_nft: true,
343345
})
344346
.await?;
345347

@@ -458,6 +460,7 @@ async fn test_get_nft_owner(mut storage: StorageProcessor<'_>) -> QueryResult<()
458460
symbol: "NFT".to_string(),
459461
decimals: 0,
460462
kind: TokenKind::NFT,
463+
is_nft: true,
461464
})
462465
.await?;
463466
storage

core/lib/storage/src/tests/tokens.rs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
3838
symbol: "ETH".into(),
3939
decimals: 18,
4040
kind: TokenKind::ERC20,
41+
is_nft: false,
4142
};
4243
assert_eq!(tokens[&TokenId(0)], eth_token);
4344

@@ -48,20 +49,23 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
4849
symbol: "ABC".into(),
4950
decimals: 9,
5051
kind: TokenKind::ERC20,
52+
is_nft: false,
5153
};
5254
let token_b = Token {
5355
id: TokenId(2),
5456
address: "0000000000000000000000000000000000000002".parse().unwrap(),
5557
symbol: "DEF".into(),
5658
decimals: 6,
5759
kind: TokenKind::None,
60+
is_nft: false,
5861
};
5962
let nft = Token {
6063
id: TokenId(MIN_NFT_TOKEN_ID),
6164
address: "0000000000000000000000000000000000000005".parse().unwrap(),
6265
symbol: "NFT".into(),
6366
decimals: 0,
6467
kind: TokenKind::NFT,
68+
is_nft: true,
6569
};
6670

6771
TokensSchema(&mut storage)

core/lib/storage/src/tokens/records.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ impl From<Token> for DbToken {
6565

6666
impl From<DbToken> for Token {
6767
fn from(val: DbToken) -> Token {
68-
Token {
69-
id: TokenId(val.id as u32),
70-
address: stored_str_address_to_address(&val.address),
71-
symbol: val.symbol,
72-
decimals: val.decimals as u8,
73-
kind: val.kind.into(),
74-
}
68+
Token::new(
69+
TokenId(val.id as u32),
70+
stored_str_address_to_address(&val.address),
71+
&val.symbol,
72+
val.decimals as u8,
73+
val.kind.into(),
74+
)
7575
}
7676
}
7777

core/lib/types/src/tokens.rs

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct Token {
104104
/// Token precision (e.g. 18 for "ETH" so "1.0" ETH = 10e18 as U256 number)
105105
pub decimals: u8,
106106
pub kind: TokenKind,
107+
pub is_nft: bool,
107108
}
108109

109110
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
@@ -121,6 +122,7 @@ impl Token {
121122
symbol: symbol.to_string(),
122123
decimals,
123124
kind,
125+
is_nft: matches!(kind, TokenKind::NFT),
124126
}
125127
}
126128

@@ -131,6 +133,7 @@ impl Token {
131133
symbol: symbol.to_string(),
132134
decimals: 0,
133135
kind: TokenKind::NFT,
136+
is_nft: true,
134137
}
135138
}
136139
}

0 commit comments

Comments
 (0)