Going somewhere.
This commit is contained in:
1 parent
fc13cf7f99
commit
3dc963cdea
5 files changed
+63
-62
No files matched your search
Generated
+15
-15
@@ -138,6 +138,21 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "escarmouche-ledger"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"clap-verbosity-flag",
|
||||||
|
"home",
|
||||||
|
"log",
|
||||||
|
"rusqlite",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
|
"simple_logger",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fallible-iterator"
|
name = "fallible-iterator"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -251,21 +266,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "machine"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
"clap-verbosity-flag",
|
|
||||||
"home",
|
|
||||||
"log",
|
|
||||||
"rusqlite",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"simple_logger",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_threads"
|
name = "num_threads"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "machine"
|
name = "escarmouche-ledger"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -1,10 +1,9 @@
|
|||||||
use std::any::Any;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
||||||
use serde::{Serialize};
|
use serde::{Serialize};
|
||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, info};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use simple_logger::SimpleLogger;
|
use simple_logger::SimpleLogger;
|
||||||
|
|
||||||
@@ -184,15 +183,15 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommandLineUserLogic for TestCommandLineLogic {
|
impl CommandLineUserLogic for TestCommandLineLogic {
|
||||||
fn create_user(&mut self, conn: &Connection, name: &String, public_key: &String) {
|
fn create_user(&mut self, _conn: &Connection, _name: &String, _public_key: &String) {
|
||||||
self.create_user_count += 1;
|
self.create_user_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_user(&mut self, conn: &Connection) {
|
fn list_user(&mut self, _conn: &Connection) {
|
||||||
self.list_user_count += 1;
|
self.list_user_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_securities(&mut self, conn: &Connection) {
|
fn list_securities(&mut self, _conn: &Connection) {
|
||||||
self.list_securities_count += 1;
|
self.list_securities_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,7 +292,7 @@ impl CommandLineUserLogic for ProCommandLineLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_securities(&mut self, conn: &Connection) {
|
fn list_securities(&mut self, _conn: &Connection) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,8 +313,9 @@ fn main() {
|
|||||||
let m = command.get_matches();
|
let m = command.get_matches();
|
||||||
|
|
||||||
set_logger(&m);
|
set_logger(&m);
|
||||||
let conn = get_connection(&m);
|
let mut conn = get_connection(&m);
|
||||||
// migrate(&conn);
|
let migrations: Vec<String> = Vec::new();
|
||||||
|
migrate(&mut conn, & migrations);
|
||||||
let mut logic = ProCommandLineLogic::new();
|
let mut logic = ProCommandLineLogic::new();
|
||||||
process_command_line(&conn, &m, &mut logic);
|
process_command_line(&conn, &m, &mut logic);
|
||||||
}
|
}
|
||||||
+3
-38
@@ -1,6 +1,6 @@
|
|||||||
use rusqlite::{Connection, Transaction};
|
use rusqlite::{Connection, Transaction};
|
||||||
|
|
||||||
use sha2::{Digest, Sha256, Sha512};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
const INITIAL_MIGRATION: &str = "
|
const INITIAL_MIGRATION: &str = "
|
||||||
CREATE TABLE IF NOT EXISTS shitty_migrations (
|
CREATE TABLE IF NOT EXISTS shitty_migrations (
|
||||||
@@ -9,42 +9,6 @@ CREATE TABLE IF NOT EXISTS shitty_migrations (
|
|||||||
);
|
);
|
||||||
";
|
";
|
||||||
|
|
||||||
const MIGRATION_SCRIPT: &str = "
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
public_key TEXT NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS security_types (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
name TEXT NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS securities (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
security_type INTEGER NOT NULL,
|
|
||||||
name TEXT NOT NULL UNIQUE,
|
|
||||||
symbol TEXT NOT NULL UNIQUE,
|
|
||||||
|
|
||||||
FOREIGN KEY(security_type) REFERENCES security_types(id)
|
|
||||||
);
|
|
||||||
//
|
|
||||||
// CREATE TABLE IF NOT EXISTS account(
|
|
||||||
// id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
// security INTEGER NOT NULL,
|
|
||||||
// owner INTEGER NOT NULL,
|
|
||||||
//
|
|
||||||
// FOREIGN KEY(security) REFERENCES securities(id)
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// CREATE TABLE IF NOT EXISTS account_values(
|
|
||||||
// id INTEGER PRIMARY KEY AUTOINCREMENT
|
|
||||||
// );
|
|
||||||
|
|
||||||
";
|
|
||||||
|
|
||||||
fn get_id_of_new_migration(tx: &Transaction) -> usize {
|
fn get_id_of_new_migration(tx: &Transaction) -> usize {
|
||||||
let q = "SELECT COALESCE(MAX(id) + 1, 0) FROM shitty_migrations";
|
let q = "SELECT COALESCE(MAX(id) + 1, 0) FROM shitty_migrations";
|
||||||
return tx.query_row(q, (), |row| row.get::<usize, usize>(0)).unwrap();
|
return tx.query_row(q, (), |row| row.get::<usize, usize>(0)).unwrap();
|
||||||
@@ -80,7 +44,7 @@ fn compute_migration_sha256(migration: &String) -> String {
|
|||||||
return format!("{:x}", ret);
|
return format!("{:x}", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_migration(tx: &Transaction, id: usize, migration: &String) -> Result<String, io::Error> {
|
fn check_migration(tx: &Transaction, id: usize, migration: &String) {
|
||||||
let q = "SELECT sha256 FROM shitty_migrations WHERE id = ?1";
|
let q = "SELECT sha256 FROM shitty_migrations WHERE id = ?1";
|
||||||
let res = tx.query_row(q, (&id, ), |row| row.get::<usize, String>(0)).unwrap();
|
let res = tx.query_row(q, (&id, ), |row| row.get::<usize, String>(0)).unwrap();
|
||||||
let expected = compute_migration_sha256(migration);
|
let expected = compute_migration_sha256(migration);
|
||||||
@@ -130,6 +94,7 @@ mod test {
|
|||||||
assert_eq!(c, c);
|
assert_eq!(c, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn broken_migration() {
|
fn broken_migration() {
|
||||||
let mut conn = Connection::open_in_memory().unwrap();
|
let mut conn = Connection::open_in_memory().unwrap();
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS users
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
public_key TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS security_types
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS securities
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
security_type INTEGER NOT NULL,
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
symbol TEXT NOT NULL UNIQUE,
|
||||||
|
|
||||||
|
FOREIGN KEY (security_type) REFERENCES security_types (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS account
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
security INTEGER NOT NULL,
|
||||||
|
owner INTEGER NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (security) REFERENCES securities (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS account_values
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
);
|
||||||
Reference in new issue
Block a user