Skip to content

Commit

Permalink
feat(rt-sync): add persistency layer (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse committed Dec 24, 2024
1 parent b0b88b8 commit 4346a47
Show file tree
Hide file tree
Showing 11 changed files with 1,050 additions and 1 deletion.
37 changes: 36 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ jobs:
cd ../cli
cargo clippy -- -D warnings
build:
name: Cargo Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
workspaces: |
lib -> target
cache-on-failure: "true"

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "27.2"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- run: cargo build
working-directory: lib

- name: Check git status
env:
GIT_PAGER: cat
run: |
status=$(git status --porcelain)
if [[ -n "$status" ]]; then
echo "Git status has changes"
echo "$status"
git diff
exit 1
else
echo "No changes in git status"
fi
tests:
name: Test sdk-core
runs-on: ubuntu-latest
Expand Down Expand Up @@ -341,4 +376,4 @@ jobs:
rm Cargo.lock
cargo update --package secp256k1-zkp
cargo clippy -- -D warnings
cargo clippy -- -D warnings
4 changes: 4 additions & 0 deletions lib/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ electrum-client = { version = "0.19.0" }
zbase32 = "0.1.2"
x509-parser = { version = "0.16.0" }
tempfile = "3"
tonic = { version = "0.12.3", features = ["tls"] }
prost = "0.13.3"
uuid = { version = "1.8.0", features = ["v4"] }

[dev-dependencies]
lazy_static = "1.5.0"
Expand All @@ -64,6 +67,7 @@ uuid = { version = "1.8.0", features = ["v4"] }
[build-dependencies]
anyhow = { version = "1.0.79", features = ["backtrace"] }
glob = "0.3.1"
tonic-build = "0.12.3"

# Pin these versions to fix iOS build issues
[target.'cfg(target_os = "ios")'.build-dependencies]
Expand Down
9 changes: 9 additions & 0 deletions lib/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ fn setup_x86_64_android_workaround() {
}
}

fn compile_protos() -> Result<()> {
tonic_build::configure()
.build_server(false)
.out_dir("./src/sync/model")
.compile_protos(&["src/sync/proto/sync.proto"], &["src/sync/proto"])?;
Ok(())
}

fn main() -> Result<()> {
setup_x86_64_android_workaround();
compile_protos()?;
Ok(())
}
1 change: 1 addition & 0 deletions lib/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub mod sdk;
pub(crate) mod send_swap;
pub(crate) mod signer;
pub(crate) mod swapper;
pub(crate) mod sync;
pub(crate) mod test_utils;
pub(crate) mod utils;
pub(crate) mod wallet;
Expand Down
23 changes: 23 additions & 0 deletions lib/core/src/persist/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,28 @@ pub(crate) fn current_migrations() -> Vec<&'static str> {
ALTER TABLE send_swaps ADD COLUMN pair_fees_json TEXT NOT NULL DEFAULT '';
ALTER TABLE chain_swaps ADD COLUMN pair_fees_json TEXT NOT NULL DEFAULT '';
",
"CREATE TABLE IF NOT EXISTS sync_state(
data_id TEXT NOT NULL PRIMARY KEY,
record_id TEXT NOT NULL,
record_revision INTEGER NOT NULL,
is_local INTEGER NOT NULL DEFAULT 1
) STRICT;",
"CREATE TABLE IF NOT EXISTS sync_settings(
key TEXT NOT NULL PRIMARY KEY,
value TEXT NOT NULL
) STRICT;",
"CREATE TABLE IF NOT EXISTS sync_outgoing(
record_id TEXT NOT NULL PRIMARY KEY,
data_id TEXT NOT NULL UNIQUE,
record_type INTEGER NOT NULL,
commit_time INTEGER NOT NULL,
updated_fields_json TEXT
) STRICT;",
"CREATE TABLE IF NOT EXISTS sync_incoming(
record_id TEXT NOT NULL PRIMARY KEY,
revision INTEGER NOT NULL UNIQUE,
schema_version TEXT NOT NULL,
data BLOB NOT NULL
) STRICT;",
]
}
1 change: 1 addition & 0 deletions lib/core/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod chain;
mod migrations;
pub(crate) mod receive;
pub(crate) mod send;
pub(crate) mod sync;

use std::collections::HashSet;
use std::{fs::create_dir_all, path::PathBuf, str::FromStr};
Expand Down
Loading

0 comments on commit 4346a47

Please sign in to comment.