forked from 0LNetworkCommunity/libra-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7f3440
commit 69a2970
Showing
5 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod scan; | |
pub mod warehouse_cli; | ||
pub mod extract; | ||
pub mod table_structs; | ||
pub mod load; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::table_structs::{WarehouseAccount, WarehouseState}; | ||
use anyhow::Result; | ||
use sqlx::{sqlite::SqliteQueryResult, SqlitePool}; | ||
|
||
pub async fn load_account_state(pool: &SqlitePool, accounts: Vec<WarehouseState>) -> Result<()> { | ||
// insert missing accounts | ||
for ws in accounts.iter() { | ||
insert_one_account(pool, &ws.account).await?; | ||
} | ||
|
||
// increment the balance changes | ||
Ok(()) | ||
} | ||
|
||
pub async fn insert_one_account(pool: &SqlitePool, acc: &WarehouseAccount) -> Result<SqliteQueryResult> { | ||
|
||
let res = sqlx::query(r#" | ||
INSERT INTO users (account_address, is_legacy) | ||
VALUES ($1,$2) | ||
"#) | ||
.bind(acc.address.to_string()) | ||
.bind(true) | ||
.execute(pool) | ||
.await?; | ||
|
||
Ok(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use libra_types::exports::AccountAddress; | ||
use libra_warehouse::table_structs::WarehouseAccount; | ||
use sqlx::SqlitePool; | ||
|
||
#[sqlx::test] | ||
async fn insert_one_account(pool: SqlitePool) -> anyhow::Result<()> { | ||
libra_warehouse::migrate::maybe_init(&pool).await?; | ||
let marlon = AccountAddress::random(); | ||
let acc = WarehouseAccount { | ||
address: marlon | ||
}; | ||
|
||
libra_warehouse::load::insert_one_account(&pool, &acc).await?; | ||
|
||
// second time should error if we are using the same account | ||
assert!(libra_warehouse::load::insert_one_account(&pool, &acc).await.is_err()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters