Skip to content

Commit

Permalink
Merge #1874
Browse files Browse the repository at this point in the history
1874: Return backward compatibility in tokens r=Deniallugo a=Deniallugo

Signed-off-by: deniallugo <deniallugo@gmail.com>

Co-authored-by: deniallugo <deniallugo@gmail.com>
  • Loading branch information
bors-matterlabs-dev[bot] and Deniallugo authored Aug 24, 2021
2 parents a40d1cc + 0f376e4 commit f59e154
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 114 deletions.
14 changes: 7 additions & 7 deletions core/bin/data_restore/src/data_restore_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ where
);

interactor
.save_special_token(Token {
id: NFT_TOKEN_ID,
symbol: "SPECIAL".to_string(),
address: *NFT_STORAGE_ACCOUNT_ADDRESS,
decimals: 18,
kind: TokenKind::NFT,
})
.save_special_token(Token::new(
NFT_TOKEN_ID,
*NFT_STORAGE_ACCOUNT_ADDRESS,
"SPECIAL",
18,
TokenKind::NFT,
))
.await;
vlog::info!("Special token added");

Expand Down
14 changes: 7 additions & 7 deletions core/bin/data_restore/src/database_storage_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ impl StorageInteractor for DatabaseStorageInteractor<'_> {
async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) {
self.storage
.tokens_schema()
.store_token(Token {
id: token_id,
symbol: token.symbol,
address: token.address,
decimals: token.decimals,
kind: TokenKind::ERC20,
})
.store_token(Token::new(
token_id,
token.address,
&token.symbol,
token.decimals,
TokenKind::ERC20,
))
.await
.expect("failed to store token");
}
Expand Down
16 changes: 9 additions & 7 deletions core/bin/data_restore/src/inmemory_storage_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ impl StorageInteractor for InMemoryStorageInteractor {
}

async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) {
let token = Token {
id: token_id,
symbol: token.symbol,
address: token.address,
decimals: token.decimals,
kind: TokenKind::ERC20,
};
let token = Token::new(
token_id,
token.address,
&token.symbol,
token.decimals,
TokenKind::ERC20,
);
self.tokens.insert(token_id, token);
}

Expand All @@ -98,6 +98,7 @@ impl StorageInteractor for InMemoryStorageInteractor {
symbol: format!("ERC20-{}", *id),
decimals: 18,
kind: TokenKind::ERC20,
is_nft: false,
},
);
}
Expand Down Expand Up @@ -277,6 +278,7 @@ impl InMemoryStorageInteractor {
symbol: token.symbol.clone(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
},
);
}
Expand Down
12 changes: 6 additions & 6 deletions core/bin/zksync_api/src/api_server/admin_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ async fn add_token(
}
};

let token = tokens::Token {
let token = tokens::Token::new(
id,
address: token_request.address,
symbol: token_request.symbol.clone(),
decimals: token_request.decimals,
kind: TokenKind::ERC20,
};
token_request.address,
&token_request.symbol,
token_request.decimals,
TokenKind::ERC20,
);

storage
.tokens_schema()
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/fee_ticker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ async fn test_error_coingecko_api() {
symbol: String::from("DAI"),
decimals: 18,
kind: TokenKind::ERC20,
is_nft: false,
};
let (address, handler) = run_server(token.address);
let client = reqwest::ClientBuilder::new()
Expand Down
14 changes: 7 additions & 7 deletions core/bin/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ pub async fn genesis_init(config: &ZkSyncConfig) {
.await
.expect("failed to access db")
.tokens_schema()
.store_token(Token {
id: TokenId(id as u32),
symbol: token.symbol,
address: token.address,
decimals: token.decimals,
kind: TokenKind::ERC20,
})
.store_token(Token::new(
TokenId(id as u32),
token.address,
&token.symbol,
token.decimals,
TokenKind::ERC20,
))
.await
.expect("failed to store token");
}
Expand Down
14 changes: 7 additions & 7 deletions core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,13 @@ impl ZkSyncStateKeeper {
vlog::info!("Adding special token");
transaction
.tokens_schema()
.store_token(Token {
id: NFT_TOKEN_ID,
symbol: "SPECIAL".to_string(),
address: *NFT_STORAGE_ACCOUNT_ADDRESS,
decimals: 18,
kind: TokenKind::NFT,
})
.store_token(Token::new(
NFT_TOKEN_ID,
*NFT_STORAGE_ACCOUNT_ADDRESS,
"SPECIAL",
18,
TokenKind::NFT,
))
.await
.expect("failed to store special token");
vlog::info!("Special token added");
Expand Down
36 changes: 18 additions & 18 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2728,24 +2728,6 @@
"nullable": []
}
},
"66dddd41e83db60b333ea6f5697d4507fb090021f4e4b22dbb4496d0999e17f1": {
"query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"'\n ORDER BY nonce\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "tx",
"type_info": "Jsonb"
}
],
"parameters": {
"Left": []
},
"nullable": [
false
]
}
},
"681359f99d0e4bafdd3109f67c7af4d235dc1197ba88cd0d6148f632ae0cdf8f": {
"query": "SELECT * FROM aggregated_proofs WHERE first_block = $1 and last_block = $2",
"describe": {
Expand Down Expand Up @@ -7174,6 +7156,24 @@
]
}
},
"f7a49b80724c8deb1f8af7016e92937fd04f9c5df474986ab61ad201ec41bdb4": {
"query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"' AND success = true\n ORDER BY nonce\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "tx",
"type_info": "Jsonb"
}
],
"parameters": {
"Left": []
},
"nullable": [
false
]
}
},
"f8f2208c71cbf2d42de633222bb888c773a47b82dd0095b76ad38f535d74fdce": {
"query": "SELECT created_at, block_number FROM executed_transactions\n WHERE tx_hash = $1",
"describe": {
Expand Down
3 changes: 3 additions & 0 deletions core/lib/storage/src/tests/chain/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer
symbol: "NFT".to_string(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
})
.await?;
storage
Expand All @@ -340,6 +341,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer
symbol: "SPECIAL".to_string(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
})
.await?;

Expand Down Expand Up @@ -458,6 +460,7 @@ async fn test_get_nft_owner(mut storage: StorageProcessor<'_>) -> QueryResult<()
symbol: "NFT".to_string(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
})
.await?;
storage
Expand Down
4 changes: 4 additions & 0 deletions core/lib/storage/src/tests/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
symbol: "ETH".into(),
decimals: 18,
kind: TokenKind::ERC20,
is_nft: false,
};
assert_eq!(tokens[&TokenId(0)], eth_token);

Expand All @@ -48,20 +49,23 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
symbol: "ABC".into(),
decimals: 9,
kind: TokenKind::ERC20,
is_nft: false,
};
let token_b = Token {
id: TokenId(2),
address: "0000000000000000000000000000000000000002".parse().unwrap(),
symbol: "DEF".into(),
decimals: 6,
kind: TokenKind::None,
is_nft: false,
};
let nft = Token {
id: TokenId(MIN_NFT_TOKEN_ID),
address: "0000000000000000000000000000000000000005".parse().unwrap(),
symbol: "NFT".into(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
};

TokensSchema(&mut storage)
Expand Down
14 changes: 7 additions & 7 deletions core/lib/storage/src/tokens/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ impl From<Token> for DbToken {

impl From<DbToken> for Token {
fn from(val: DbToken) -> Token {
Token {
id: TokenId(val.id as u32),
address: stored_str_address_to_address(&val.address),
symbol: val.symbol,
decimals: val.decimals as u8,
kind: val.kind.into(),
}
Token::new(
TokenId(val.id as u32),
stored_str_address_to_address(&val.address),
&val.symbol,
val.decimals as u8,
val.kind.into(),
)
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/lib/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct Token {
/// Token precision (e.g. 18 for "ETH" so "1.0" ETH = 10e18 as U256 number)
pub decimals: u8,
pub kind: TokenKind,
pub is_nft: bool,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
Expand All @@ -121,6 +122,7 @@ impl Token {
symbol: symbol.to_string(),
decimals,
kind,
is_nft: matches!(kind, TokenKind::NFT),
}
}

Expand All @@ -131,6 +133,7 @@ impl Token {
symbol: symbol.to_string(),
decimals: 0,
kind: TokenKind::NFT,
is_nft: true,
}
}
}
Expand Down
Loading

0 comments on commit f59e154

Please sign in to comment.