Skip to content

Commit b6a65ef

Browse files
committed
fix comments
1 parent ab7232c commit b6a65ef

File tree

8 files changed

+345
-196
lines changed

8 files changed

+345
-196
lines changed

api-server/api-server-common/src/storage/impls/in_memory/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use std::{
2222
sync::Arc,
2323
};
2424

25+
use itertools::Itertools as _;
26+
2527
use common::{
2628
address::Address,
2729
chain::{
@@ -40,8 +42,6 @@ use crate::storage::storage_api::{
4042
TokenTransaction, TransactionInfo, TransactionWithBlockInfo, Utxo, UtxoLock, UtxoWithExtraInfo,
4143
};
4244

43-
use itertools::Itertools as _;
44-
4545
use super::CURRENT_STORAGE_VERSION;
4646

4747
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -207,7 +207,11 @@ impl ApiServerInMemoryStorage {
207207
transactions
208208
.iter()
209209
.rev()
210-
.flat_map(|(_, txs)| txs.iter().map(|tx| &tx.0))
210+
.flat_map(|(_, txs)| {
211+
let mut txs: Vec<_> = txs.iter().map(|tx| &tx.0).collect();
212+
txs.sort_by_key(|tx| std::cmp::Reverse(tx.tx_global_index));
213+
txs
214+
})
211215
.flat_map(|tx| (tx.tx_global_index < tx_global_index).then_some(tx))
212216
.cloned()
213217
.take(len as usize)

api-server/api-server-common/src/storage/impls/postgres/queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> {
616616
r#"
617617
INSERT INTO ml.token_transactions (token_id, block_height, transaction_id, tx_global_index)
618618
VALUES ($1, $2, $3, $4)
619-
ON CONFLICT (token_id, transaction_id, block_height)
620-
DO NOTHING;
619+
ON CONFLICT (token_id, transaction_id, block_height) DO UPDATE
620+
SET tx_global_index = $4;
621621
"#,
622622
&[&token_id.encode(), &height, &transaction_id.encode(), &tx_global_index],
623623
)

api-server/api-server-common/src/storage/storage_api/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub enum ApiServerStorageError {
6868
AddressableError,
6969
#[error("Block timestamp too high: {0}")]
7070
TimestampTooHigh(BlockTimestamp),
71-
#[error("Tx global index too hight: {0}")]
71+
#[error("Tx global index too high: {0}")]
7272
TxGlobalIndexTooHigh(u64),
7373
#[error("Id creation error: {0}")]
7474
IdCreationError(#[from] IdCreationError),
@@ -619,7 +619,7 @@ pub trait ApiServerStorageRead: Sync {
619619

620620
/// Returns a page of transaction IDs that reference this `token_id`, limited to `len` entries
621621
/// and with a `tx_global_index` older than the specified value.
622-
/// The `tx_global_index` and is not continuous for a specific `token_id`.
622+
/// The `tx_global_index` is not continuous for a specific `token_id`.
623623
async fn get_token_transactions(
624624
&self,
625625
token_id: TokenId,

api-server/scanner-lib/src/blockchain_state/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ impl<S: ApiServerStorage + Send + Sync> LocalBlockchainState for BlockchainState
201201
.await
202202
.expect("Unable to set block");
203203

204-
for (i, tx_info) in transactions.iter().enumerate() {
204+
for (idx, tx_info) in transactions.iter().enumerate() {
205205
db_tx
206206
.set_transaction(
207207
tx_info.tx.transaction().get_id(),
208-
next_order_number + i as u64,
208+
next_order_number + idx as u64,
209209
block_id,
210210
tx_info,
211211
)
@@ -1054,7 +1054,7 @@ async fn update_tables_from_transaction_inputs<T: ApiServerStorageWrite>(
10541054
BTreeMap::new();
10551055
let mut transaction_tokens: BTreeSet<TokenId> = BTreeSet::new();
10561056

1057-
let update_tokens_in_transaction = |order: &Order, tokens_in_transaction: &mut BTreeSet<_>| {
1057+
let update_tokens_for_order = |order: &Order, tokens_in_transaction: &mut BTreeSet<_>| {
10581058
match order.give_currency {
10591059
CoinOrTokenId::TokenId(token_id) => {
10601060
tokens_in_transaction.insert(token_id);
@@ -1265,15 +1265,15 @@ async fn update_tables_from_transaction_inputs<T: ApiServerStorageWrite>(
12651265

12661266
db_tx.set_order_at_height(*order_id, &order, block_height).await?;
12671267

1268-
update_tokens_in_transaction(&order, &mut transaction_tokens);
1268+
update_tokens_for_order(&order, &mut transaction_tokens);
12691269
}
12701270
AccountCommand::ConcludeOrder(order_id) => {
12711271
let order = db_tx.get_order(*order_id).await?.expect("must exist");
12721272
let order = order.conclude();
12731273

12741274
db_tx.set_order_at_height(*order_id, &order, block_height).await?;
12751275

1276-
update_tokens_in_transaction(&order, &mut transaction_tokens);
1276+
update_tokens_for_order(&order, &mut transaction_tokens);
12771277
}
12781278
},
12791279
TxInput::OrderAccountCommand(cmd) => match cmd {
@@ -1283,20 +1283,21 @@ async fn update_tables_from_transaction_inputs<T: ApiServerStorageWrite>(
12831283
order.fill(&chain_config, block_height, *fill_amount_in_ask_currency);
12841284

12851285
db_tx.set_order_at_height(*order_id, &order, block_height).await?;
1286-
update_tokens_in_transaction(&order, &mut transaction_tokens);
1286+
update_tokens_for_order(&order, &mut transaction_tokens);
12871287
}
12881288
OrderAccountCommand::ConcludeOrder(order_id) => {
12891289
let order = db_tx.get_order(*order_id).await?.expect("must exist");
12901290
let order = order.conclude();
12911291

12921292
db_tx.set_order_at_height(*order_id, &order, block_height).await?;
1293-
update_tokens_in_transaction(&order, &mut transaction_tokens);
1293+
update_tokens_for_order(&order, &mut transaction_tokens);
12941294
}
12951295
OrderAccountCommand::FreezeOrder(order_id) => {
12961296
let order = db_tx.get_order(*order_id).await?.expect("must exist");
12971297
let order = order.freeze();
12981298

12991299
db_tx.set_order_at_height(*order_id, &order, block_height).await?;
1300+
update_tokens_for_order(&order, &mut transaction_tokens);
13001301
}
13011302
},
13021303
TxInput::Account(outpoint) => {

0 commit comments

Comments
 (0)