Skip to content

Commit

Permalink
exclude fns starting with __
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed Jun 5, 2024
1 parent a42bfd0 commit 2b47216
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/crates/soroban-spec-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ pub fn generate(spec: &[ScSpecEntry]) -> String {
cases: vec![],
});
}
let (fns, other): (Vec<_>, Vec<_>) = collected
// Filter out function entries with names that start with "__"
let filtered_collected: Vec<_> = collected
.into_iter()
.filter(|entry| !matches!(entry, Entry::Function { name, .. } if name.starts_with("__")))
.collect();
let (fns, other): (Vec<_>, Vec<_>) = filtered_collected
.into_iter()
.partition(|entry| matches!(entry, Entry::Function { .. }));
let top = other.iter().map(entry_to_method_type).join("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use soroban_sdk::{
auth::{Context, CustomAccountInterface},
contract, contracterror, contractimpl, contracttype,
crypto::Hash,
symbol_short, Bytes, BytesN, Env, Symbol, Vec,
symbol_short, vec, Address, Bytes, BytesN, Env, Symbol, Vec,
};

#[contract]
Expand All @@ -15,12 +15,53 @@ pub enum Error {
NotFound = 1,
NotPermitted = 2,
ClientDataJsonChallengeIncorrect = 3,
Secp256r1PublicKeyParse = 4,
Secp256r1SignatureParse = 5,
Secp256r1VerifyFailed = 6,
JsonParseError = 7,
InvalidContext = 8,
AlreadyInited = 9,
NotInited = 10,
}

const SIGNERS: Symbol = symbol_short!("sigs");
const FACTORY: Symbol = symbol_short!("factory");
const SUDO_SIGNER: Symbol = symbol_short!("sudo_sig");

#[contractimpl]
impl Contract {
pub fn extend_ttl(env: &Env) {
let max_ttl = env.storage().max_ttl();
let contract_address = env.current_contract_address();

env.storage().instance().extend_ttl(max_ttl, max_ttl);
env.deployer()
.extend_ttl(contract_address.clone(), max_ttl, max_ttl);
env.deployer()
.extend_ttl_for_code(contract_address.clone(), max_ttl, max_ttl);
env.deployer()
.extend_ttl_for_contract_instance(contract_address.clone(), max_ttl, max_ttl);
}
pub fn init(env: Env, id: Bytes, pk: BytesN<65>, factory: Address) -> Result<(), Error> {
if env.storage().instance().has(&SUDO_SIGNER) {
return Err(Error::AlreadyInited);
}

let max_ttl = env.storage().max_ttl();

env.storage().persistent().set(&id, &pk);
env.storage().persistent().extend_ttl(&id, max_ttl, max_ttl);

env.storage().instance().set(&SUDO_SIGNER, &id);
env.storage().instance().set(&FACTORY, &factory);
env.storage().instance().set(&SIGNERS, &vec![&env, id]);

Self::extend_ttl(&env);

Ok(())
}
}

#[contracttype]
pub struct Signature {
pub id: BytesN<32>,
Expand All @@ -29,7 +70,6 @@ pub struct Signature {
pub signature: BytesN<64>,
}

// Dummy implementation for the demo
#[derive(Debug)]
struct ClientDataJson<'a> {
challenge: &'a str,
Expand Down

0 comments on commit 2b47216

Please sign in to comment.