Skip to content

Commit

Permalink
Merged migrations into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Oct 24, 2023
1 parent 0246c44 commit f58933d
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 43 deletions.
59 changes: 37 additions & 22 deletions crates/erc20_payment_lib/migrations/20221026000000_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ CREATE TABLE "tx"
to_addr TEXT NOT NULL,
chain_id INTEGER NOT NULL,
gas_limit INTEGER NULL,
max_fee_per_gas TEXT NOT NULL,
priority_fee TEXT NOT NULL,
max_fee_per_gas TEXT NULL,
priority_fee TEXT NULL,
val TEXT NOT NULL,
nonce INTEGER NULL,
processing INTEGER NOT NULL,
call_data TEXT NULL,
created_date DATETIME NOT NULL,
first_processed DATETIME NULL,
created_date TEXT NOT NULL,
first_processed TEXT NULL,
tx_hash TEXT NULL,
signed_raw_data TEXT NULL,
signed_date DATETIME NULL,
broadcast_date DATETIME NULL,
signed_date TEXT NULL,
broadcast_date TEXT NULL,
broadcast_count INTEGER NOT NULL,
confirm_date DATETIME NULL,
confirm_date TEXT NULL,
block_number INTEGER NULL,
chain_status INTEGER NULL,
fee_paid TEXT NULL,
error TEXT NULL
);
error TEXT NULL,
orig_tx_id INTEGER NULL
) strict;

CREATE INDEX "idx_tx_created_date" ON "tx" (created_date);
CREATE INDEX "idx_tx_first_processed" ON "tx" (first_processed);
Expand All @@ -43,14 +44,15 @@ CREATE TABLE "chain_tx"
priority_fee TEXT NULL,
val TEXT NOT NULL,
nonce INTEGER NOT NULL,
checked_date DATETIME NOT NULL,
blockchain_date DATETIME NOT NULL,
checked_date TEXT NOT NULL,
blockchain_date TEXT NOT NULL,
block_number INTEGER NOT NULL,
chain_status INTEGER NOT NULL,
fee_paid TEXT NULL,
error TEXT NULL
);

error TEXT NULL,
balance_eth TEXT NULL,
balance_glm TEXT NULL
) strict;

CREATE TABLE "token_transfer"
(
Expand All @@ -61,12 +63,13 @@ CREATE TABLE "token_transfer"
chain_id INTEGER NOT NULL,
token_addr TEXT NULL,
token_amount TEXT NOT NULL,
create_date DATETIME NOT NULL,
create_date TEXT NOT NULL,
paid_date TEXT NULL,
tx_id INTEGER NULL,
fee_paid TEXT NULL,
error TEXT NULL,
CONSTRAINT "fk_token_transfer_tx" FOREIGN KEY ("tx_id") REFERENCES "tx" ("id")
);
) strict;

CREATE TABLE "transfer_in"
(
Expand All @@ -78,9 +81,9 @@ CREATE TABLE "transfer_in"
token_addr TEXT NULL,
token_amount TEXT NOT NULL,
tx_hash TEXT NULL,
requested_date DATETIME NOT NULL,
received_date DATETIME NULL
);
requested_date TEXT NOT NULL,
received_date TEXT NULL
) strict;

CREATE TABLE "chain_transfer"
(
Expand All @@ -91,8 +94,10 @@ CREATE TABLE "chain_transfer"
token_addr TEXT NULL,
token_amount TEXT NOT NULL,
chain_tx_id INTEGER NOT NULL,
fee_paid TEXT NOT NULL,
blockchain_date TEXT NOT NULL,
CONSTRAINT "fk_chain_transfer_tx" FOREIGN KEY ("chain_tx_id") REFERENCES "chain_tx" ("id")
);
) strict;

CREATE TABLE "allowance"
(
Expand All @@ -104,10 +109,20 @@ CREATE TABLE "allowance"
chain_id INTEGER NOT NULL,
tx_id INTEGER NULL,
fee_paid TEXT NULL,
confirm_date DATETIME NULL,
confirm_date TEXT NULL,
error TEXT NULL,
CONSTRAINT "fk_allowance_tx" FOREIGN KEY ("tx_id") REFERENCES "tx" ("id")
);
) strict;

CREATE TABLE "scan_info"
(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
chain_id INTEGER NOT NULL,
filter TEXT NOT NULL,
start_block INTEGER NOT NULL,
last_block INTEGER NOT NULL

) strict;

CREATE UNIQUE INDEX "idx_scan_info_chain_id" ON "scan_info" ("chain_id", "filter");

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions crates/erc20_payment_lib/migrations/20231019000000_scan.sql

This file was deleted.

3 changes: 0 additions & 3 deletions crates/erc20_payment_lib/migrations/20231023000000_chain.sql

This file was deleted.

2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/src/db/model/tx_dao.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use serde::Serialize;

#[derive(Serialize, sqlx::FromRow, Debug, Clone)]
#[derive(Serialize, sqlx::FromRow, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TxDao {
pub id: i64,
Expand Down
52 changes: 52 additions & 0 deletions crates/erc20_payment_lib/src/db/ops/tx_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,55 @@ WHERE id = $1
.await?;
Ok(tx.clone())
}

#[tokio::test]
async fn tx_test() -> sqlx::Result<()> {
println!("Start tx_test...");

use crate::db::create_sqlite_connection;
let conn = create_sqlite_connection(None, None, false, true)
.await
.unwrap();

println!("In memory DB created");

let mut tx_to_insert = TxDao {
id: -1,
tx_hash: Some("0x13d8a54dec1c0a30f1cd5129f690c3e27b9aadd59504957bad4d247966dadae7".to_string()),
signed_raw_data: None,
signed_date: Some(chrono::Utc::now()),
broadcast_date: Some(chrono::Utc::now()),
broadcast_count: 0,
method: "".to_string(),
from_addr: "0x001066290077e38f222cc6009c0c7a91d5192303".to_string(),
to_addr: "0xbcfe9736a4f5bf2e43620061ff3001ea0d003c0f".to_string(),
chain_id: 987789,
gas_limit: Some(100000),
max_fee_per_gas: "110000000000".to_string(),
priority_fee: "5110000000000".to_string(),
val: "0".to_string(),
nonce: Some(1),
processing: 0,
call_data: None,
created_date: chrono::Utc::now(),
block_number: Some(119677),
chain_status: Some(1),
fee_paid: Some("83779300533141".to_string()),
error: Some("Test error message".to_string()),
orig_tx_id: None,
engine_message: None,
engine_error: None,
first_processed: None,
confirm_date: None
};

let tx_from_insert = insert_tx(&conn, &tx_to_insert).await?;
tx_to_insert.id = tx_from_insert.id;
let tx_from_dao = get_transaction(&conn, tx_from_insert.id).await?;

//all three should be equal
assert_eq!(tx_to_insert, tx_from_dao);
assert_eq!(tx_from_insert, tx_from_dao);

Ok(())
}

0 comments on commit f58933d

Please sign in to comment.