Skip to content
Open
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
44 changes: 22 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["admin_sep", "admin", "admin_v2"]

[workspace.dependencies]
soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "5a99659f1483c926ff87ea45f8823b8c00dc4cbd" }
soroban-sdk = { git = "https://github.com/theahaco/rs-soroban-sdk", rev = "367e4efc2462c841b046aeac0dda8fcee05b790f" }

[profile.contracts]
inherits = "release"
Expand Down
3 changes: 3 additions & 0 deletions admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ admin-sep = { path = "../admin_sep" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }

[package.metadata.stellar]
cargo_inherit = true
2 changes: 1 addition & 1 deletion admin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test: build
cargo test

build:
stellar contract build --out-dir ../target/stellar
stellar scaffold build
stellar contract optimize --wasm ../target/stellar/example_admin_contract.wasm --wasm-out ../target/stellar/example_admin_contract.wasm

fmt:
Expand Down
3 changes: 3 additions & 0 deletions admin_v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ admin-sep = { path = "../admin_sep" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }

[package.metadata.stellar]
cargo_inherit = true
93 changes: 93 additions & 0 deletions admin_v2/src/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use soroban_sdk::{
Address, BytesN, Env, Symbol, Vec,
auth::{Context, ContractContext, CustomAccountInterface},
contracterror, contractimpl, contracttype,
crypto::Hash,
panic_with_error,
};

use crate::{Contract, ContractArgs, ContractClient};

#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum SACAdminGenericError {
Unauthorized = 1,
InvalidContext = 2,
MintingLimitExceeded = 3,
}

#[contracttype]
#[derive(Clone)]
pub struct Signature {
pub public_key: BytesN<32>,
pub signature: BytesN<64>,
}

#[contracttype]
pub enum SacDataKey {
Chief,
Operator(BytesN<32>), // -> true/false
MintingLimit(BytesN<32>), // -> (max_limit, curr)
}

#[contractimpl]
impl CustomAccountInterface for Contract {
type Error = SACAdminGenericError;
type Signature = Signature;

fn __check_auth(
e: Env,
payload: Hash<32>,

Check warning on line 41 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, latest, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `payload`

Check warning on line 41 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, latest, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `payload`

Check failure on line 41 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, msrv, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `payload`
signature: Self::Signature,

Check warning on line 42 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, latest, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `signature`

Check warning on line 42 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, latest, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `signature`

Check failure on line 42 in admin_v2/src/auth.rs

View workflow job for this annotation

GitHub Actions / build-and-test (admin_v2, msrv, ubuntu-latest, x86_64-unknown-linux-gnu)

unused variable: `signature`
auth_context: Vec<Context>,
) -> Result<(), SACAdminGenericError> {
// // authenticate
// e.crypto().ed25519_verify(
// &signature.public_key,
// &payload.clone().into(),
// &signature.signature,
// );
// let caller = signature.public_key.clone();

// extract from context and check required permissionss for every function
for ctx in auth_context.iter() {
let context = match ctx {
Context::Contract(c) => c,
_ => return Err(SACAdminGenericError::InvalidContext),
};

match contract_context(&e, &context) {
Funcs::NewMethod => e
.storage()
.instance()
.get::<_, Address>(&Funcs::NewMethod)
.unwrap()
.require_auth(),
Funcs::Upgrade => todo!(),
}
}

Ok(())
}
}

#[contracttype]
pub enum Funcs {
NewMethod,
Upgrade,
}

pub fn contract_context(e: &Env, contract_context: &ContractContext) -> Funcs {
if contract_context.contract != e.current_contract_address() {
panic_with_error!(e, SACAdminGenericError::InvalidContext);
}

if contract_context.fn_name == Symbol::new(e, "new_method") {
Funcs::NewMethod
} else if contract_context.fn_name == Symbol::new(e, "upgrade") {
Funcs::Upgrade
} else {
panic_with_error!(e, SACAdminGenericError::InvalidContext)
}
}
15 changes: 12 additions & 3 deletions admin_v2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![no_std]

use soroban_sdk::{Address, Env, contract, contractimpl};
use soroban_sdk::{Address, Env, String, contract, contractimpl};

use admin_sep::{Administratable, Upgradable};

use crate::auth::Funcs;
mod auth;

#[contract]
pub struct Contract;

Expand All @@ -13,8 +15,15 @@ impl Contract {
Self::set_admin(env, admin);
}

pub fn new_method(env: &Env) {
pub fn new_method(env: &Env) -> String {
let address: Address = env.storage().instance().get(&Funcs::NewMethod).unwrap();
address.require_auth();
String::from_str(env, "hello world")
}

pub fn add_role(env: &Env, role: &Address) {
Self::require_admin(env);
env.storage().instance().set(&Funcs::NewMethod, role);
}
}

Expand Down
Loading