Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contract/nepa_contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/test_snapshots/
10 changes: 0 additions & 10 deletions contract/nepa_contract/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions contract/nepa_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ name = "nepa_contract"
version = "0.1.0"
edition = "2021"

[workspace]

[lib]
crate-type = ["cdylib"] # This tells Rust to compile to WebAssembly

[workspace]

[dependencies]
soroban-sdk = { version = "20.0.0", features = ["alloc"] } # The Stellar Smart Contract SDK
soroban-fixed-point-math = "=1.0.0" # Fixed-point arithmetic for price calculations
soroban-sdk = { version = "=20.5.0", features = ["alloc"] } # The Stellar Smart Contract SDK
serde = { version = "1.0", default-features = false } # Serialization for oracle data
serde-json-core = "0.5" # JSON parsing for oracle responses

[features]
testutils = ["soroban-sdk/testutils"]

[dev-dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.5.0", features = ["testutils"] }

[profile.release]
opt-level = "z" # Optimizes the contract for small size
overflow-checks = true
debug = 0
strip = "symbols"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("testutils"))'] }
33 changes: 15 additions & 18 deletions contract/nepa_contract/src/data_migration.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use soroban_sdk::{contracttype, symbol_short, Address, Env, Map, Symbol, Vec};
use soroban_sdk::{contracttype, symbol_short, Address, BytesN, Env, Map, Symbol, Vec};

#[contracttype]
#[derive(Clone)]
#[contracttype]
pub struct MigrationScript {
pub from_version: u32,
pub to_version: u32,
pub script_hash: soroban_sdk::BytesN<32>,
pub script_hash: BytesN<32>,
pub description: Symbol,
}

Expand All @@ -22,17 +22,16 @@ impl DataMigration {
let migration_scripts: Map<u32, Vec<MigrationScript>> = Map::new(&env);
env.storage()
.instance()
.set(&symbol_short!("MIGR"), &migration_scripts);
.set(&symbol_short!("MIGS"), &migration_scripts);
}

/// Register a migration script
#[allow(dead_code)]
pub fn register_migration_script(
env: Env,
admin: Address,
from_version: u32,
to_version: u32,
script_hash: soroban_sdk::BytesN<32>,
script_hash: BytesN<32>,
description: Symbol,
) -> Result<(), Symbol> {
// Verify admin
Expand All @@ -58,10 +57,10 @@ impl DataMigration {
let mut migrations: Map<u32, Vec<MigrationScript>> = env
.storage()
.instance()
.get(&symbol_short!("MIGR"))
.unwrap_or_else(|| Map::new(&env));
.get(&symbol_short!("MIGS"))
.unwrap_or(Map::new(&env));

let version_migrations = migrations.get(to_version).unwrap_or_else(|| Vec::new(&env));
let version_migrations = migrations.get(to_version).unwrap_or(Vec::new(&env));

// Add new migration script
let mut updated_migrations = version_migrations;
Expand All @@ -71,7 +70,7 @@ impl DataMigration {
// Store updated migrations
env.storage()
.instance()
.set(&symbol_short!("MIGR"), &migrations);
.set(&symbol_short!("MIGS"), &migrations);

// Emit registration event
env.events().publish(
Expand All @@ -87,10 +86,10 @@ impl DataMigration {
let migrations: Map<u32, Vec<MigrationScript>> = env
.storage()
.instance()
.get(&symbol_short!("MIGR"))
.unwrap_or_else(|| Map::new(&env));
.get(&symbol_short!("MIGS"))
.unwrap_or(Map::new(&env));

migrations.get(to_version).unwrap_or_else(|| Vec::new(&env))
migrations.get(to_version).unwrap_or(Vec::new(&env))
}

/// Execute migration for a specific upgrade path
Expand Down Expand Up @@ -136,7 +135,7 @@ impl DataMigration {
}

if !migration_found {
return Err(symbol_short!("MIG_NF"));
return Err(symbol_short!("NO_MIG"));
}

Ok(())
Expand Down Expand Up @@ -166,15 +165,14 @@ impl DataMigration {

// For now, we'll emit a backup event
env.events().publish(
(symbol_short!("D_BACKUP"), backup_id.clone()),
(symbol_short!("DATA_BKUP"), backup_id.clone()),
backup_timestamp,
);

Ok(backup_id)
}

/// Restore data from backup
#[allow(dead_code)]
pub fn restore_data(env: Env, admin: Address, backup_id: Symbol) -> Result<(), Symbol> {
// Verify admin
let current_admin = env
Expand All @@ -194,15 +192,14 @@ impl DataMigration {

// For now, we'll emit a restore event
env.events().publish(
(symbol_short!("D_RESTORE"), backup_id),
(symbol_short!("DATA_RST"), backup_id),
env.ledger().timestamp(),
);

Ok(())
}

/// Get admin
#[allow(dead_code)]
pub fn get_admin(env: Env) -> Address {
env.storage()
.instance()
Expand Down
Loading
Loading