Skip to content

Commit

Permalink
Merge #1929
Browse files Browse the repository at this point in the history
1929: Add batch_id to API v0.1 endpoints r=Deniallugo a=perekopskiy



Co-authored-by: perekopskiy <[email protected]>
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2021
2 parents f4f378c + 3bdbc5e commit c164f5c
Show file tree
Hide file tree
Showing 9 changed files with 568 additions and 721 deletions.
2 changes: 2 additions & 0 deletions core/bin/zksync_api/src/api_server/rest/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn deposit_op_to_tx_by_hash(
.to_string(),
fail_reason: None,
tx: tx_json,
batch_id: None,
})
}
_ => None,
Expand Down Expand Up @@ -126,6 +127,7 @@ pub fn priority_op_to_tx_history(
commited: false,
verified: false,
created_at: current_time,
batch_id: None,
}
}

Expand Down
434 changes: 226 additions & 208 deletions core/lib/storage/sqlx-data.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions core/lib/storage/src/chain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
block_number,
success,
fail_reason,
created_at
created_at,
batch_id
FROM executed_transactions
WHERE block_number = $1
), priority_ops AS (
Expand All @@ -244,7 +245,8 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
block_number,
true as success,
Null as fail_reason,
created_at
created_at,
Null::bigint as batch_id
FROM executed_priority_operations
WHERE block_number = $1
), everything AS (
Expand All @@ -258,7 +260,8 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
op as "op!",
success as "success!",
fail_reason as "fail_reason?",
created_at as "created_at!"
created_at as "created_at!",
batch_id as "batch_id?"
FROM everything
ORDER BY created_at DESC
"#,
Expand Down
1 change: 1 addition & 0 deletions core/lib/storage/src/chain/block/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct BlockTransactionItem {
pub success: bool,
pub fail_reason: Option<String>,
pub created_at: DateTime<Utc>,
pub batch_id: Option<i64>,
}

#[derive(Debug, Serialize, Deserialize, FromRow, PartialEq)]
Expand Down
20 changes: 14 additions & 6 deletions core/lib/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
created_at,
fail_reason,
tx: tx.tx,
batch_id: tx.batch_id,
})
} else {
None
Expand Down Expand Up @@ -551,6 +552,7 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
created_at,
fail_reason: None,
tx: operation,
batch_id: None,
})
} else {
None
Expand Down Expand Up @@ -667,7 +669,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
success,
fail_reason,
block_number,
created_at
created_at,
batch_id
FROM
executed_transactions
WHERE
Expand Down Expand Up @@ -698,7 +701,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
true as success,
null as fail_reason,
block_number,
created_at
created_at,
Null::bigint as batch_id
from
executed_priority_operations
where
Expand All @@ -722,7 +726,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
fail_reason as "fail_reason?",
true as "commited!",
coalesce(verified.confirmed, false) as "verified!",
created_at as "created_at!"
created_at as "created_at!",
batch_id as "batch_id?"
from transactions
LEFT JOIN aggr_exec verified ON transactions.block_number = verified.block_number
order by transactions.block_number desc, created_at desc
Expand Down Expand Up @@ -856,7 +861,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
success,
fail_reason,
block_number,
created_at
created_at,
batch_id
from
executed_transactions
where
Expand Down Expand Up @@ -891,7 +897,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
true as success,
null as fail_reason,
block_number,
created_at
created_at,
Null::bigint as batch_id
from
executed_priority_operations
where
Expand All @@ -918,7 +925,8 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
fail_reason as "fail_reason?",
true as "commited!",
coalesce(verified.confirmed, false) as "verified!",
created_at as "created_at!"
created_at as "created_at!",
batch_id as "batch_id?"
from transactions
left join aggr_comm committed on
committed.block_number = transactions.block_number AND committed.confirmed = true
Expand Down
2 changes: 2 additions & 0 deletions core/lib/storage/src/chain/operations_ext/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct TransactionsHistoryItem {
pub commited: bool,
pub verified: bool,
pub created_at: DateTime<Utc>,
pub batch_id: Option<i64>,
}

/// Stored information resulted from executing the transaction.
Expand Down Expand Up @@ -89,6 +90,7 @@ pub struct TxByHashResponse {
pub created_at: String,
pub fail_reason: Option<String>,
pub tx: Value,
pub batch_id: Option<i64>,
}

/// Raw response of the [`get_account_transactions_receipts`] query.
Expand Down
222 changes: 28 additions & 194 deletions core/tests/ts-tests/api-types/block-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,209 +1,43 @@
interface ChangePubKeyOnchain {
type: 'Onchain';
}
import {
TransferOp,
WithdrawOp,
WithdrawNFTOp,
ChangePubKeyOp,
FullExitOp,
ForcedExitOp,
MintNFTOp,
SwapOp,
DepositOp
} from './transaction';

interface ChangePubKeyECDSA {
type: 'ECDSA';
ethSignature: string;
batchHash: string;
}

interface ChangePubKeyCREATE2 {
type: 'CREATE2';
creatorAddress: string;
saltArg: string;
codeHash: string;
}

type Transfer = {
tx_hash: string;
block_number: number;
op: {
amount: string;
fee: string;
from: string;
accountId: number;
nonce: number;
signature: {
pubKey: string;
signature: string;
};
to: string;
token: number;
type: 'Transfer';
validFrom: number;
validUntil: number;
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type Deposit = {
tx_hash: string;
block_number: number;
op: {
account_id: number;
priority_op: {
amount: string;
from: string;
to: string;
token: number;
};
type: 'Deposit';
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type ChangePubKey = {
tx_hash: string;
block_number: number;
op: {
account: string;
accountId: number;
newPkHash: string;
feeToken: number;
fee: string;
nonce: number;
ethAuthData: ChangePubKeyOnchain | ChangePubKeyECDSA | ChangePubKeyCREATE2;
ethSignature: string | null;
signature: {
pubKey: string;
signature: string;
};
type: 'ChangePubKey';
validFrom: number;
validUntil: number;
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type Withdraw = {
type PriorityOpInterface<T> = {
tx_hash: string;
block_number: number;
op: {
amount: string;
fee: string;
from: string;
accountId: number;
nonce: number;
signature: {
pubKey: string;
signature: string;
};
to: string;
token: number;
type: 'Withdraw';
fast: boolean;
validFrom: number;
validUntil: number;
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type FullExit = {
tx_hash: string;
block_number: number;
op: {
type: 'FullExit';
serial_id: number | null;
priority_op: {
token: number;
account_id: number;
eth_address: string;
};
content_hash: string | null;
creator_address: string | null;
withdraw_amount: string | null;
creator_account_id: number | null;
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type ForcedExit = {
tx_hash: string;
block_number: number;
op: {
type: 'ForcedExit';
initiatorAccountId: number;
target: string;
token: number;
fee: string;
nonce: number;
signature: {
pubKey: string;
signature: string;
};
validFrom: number;
validUntil: number;
};
success: boolean;
fail_reason: string | null;
created_at: string;
};

type WithdrawNFT = {
tx_hash: string;
block_number: number;
op: {
fee: string;
from: string;
accountId: number;
nonce: number;
signature: {
pubKey: string;
signature: string;
};
to: string;
token: number;
feeToken: number;
type: 'WithdrawNFT';
fast: boolean;
validFrom: number;
validUntil: number;
};
success: boolean;
fail_reason: string | null;
op: T;
success: true;
fail_reason: null;
created_at: string;
batch_id: null;
};

type MintNFT = {
type L2TxInterface<T> = {
tx_hash: string;
block_number: number;
op: {
fee: string;
creatorId: number;
creatorAddress: string;
nonce: number;
signature: {
pubKey: string;
signature: string;
};
recipient: string;
contentHash: string;
feeToken: number;
type: 'MintNFT';
};
op: T;
success: boolean;
fail_reason: string | null;
created_at: string;
batch_id: number | null;
};

export type Interface = (
| Deposit
| Transfer
| Withdraw
| ChangePubKey
| FullExit
| ForcedExit
| WithdrawNFT
| MintNFT
| PriorityOpInterface<DepositOp>
| PriorityOpInterface<FullExitOp>
| L2TxInterface<TransferOp>
| L2TxInterface<WithdrawOp>
| L2TxInterface<ChangePubKeyOp>
| L2TxInterface<ForcedExitOp>
| L2TxInterface<WithdrawNFTOp>
| L2TxInterface<MintNFTOp>
| L2TxInterface<SwapOp>
)[];
Loading

0 comments on commit c164f5c

Please sign in to comment.