Skip to content

Commit

Permalink
Merge pull request #11 from burnt-labs/features/events
Browse files Browse the repository at this point in the history
Features/events
  • Loading branch information
ash-burnt authored Nov 6, 2023
2 parents c6f5e9a + 20819c6 commit b97d774
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ target = "wasm32-unknown-unknown"

[workspace.dependencies]
cosmos-sdk-proto = { version = "0.19", default-features = false }
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.2", features = ["stargate"] }
cw2 = "1.0"
cw-storage-plus = "1"
cw-utils = "1"
cosmwasm-schema = "=1.4.1"
cosmwasm-std = { version = "=1.4.1", features = ["stargate"] }
cw2 = "1.1.1"
cw-storage-plus = "1.1.0"
cw-utils = "1.0.2"
hex = "0.4"
prost = "0.11"
sha2 = { version = "0.10.8", features = ["oid"]}
Expand Down
2 changes: 1 addition & 1 deletion account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ bech32 = { workspace = true }
base64 = { workspace = true }
phf = { workspace = true }
rsa = { workspace = true }
getrandom = { workspace = true}
getrandom = { workspace = true }
57 changes: 35 additions & 22 deletions account/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Binary, Deps, DepsMut, Env, MessageInfo, Order, Response};
use cosmwasm_std::{Addr, Binary, Deps, DepsMut, Env, Event, MessageInfo, Order, Response};

use crate::auth::{AddAuthenticator, Authenticator};
use crate::{
Expand All @@ -25,9 +25,16 @@ pub fn init(
AUTHENTICATORS.save(deps.storage, id, &authenticator)?;
}

Ok(Response::new()
.add_attribute("method", "init")
.add_attribute("authenticator_id", id.to_string()))
Ok(
Response::new().add_event(Event::new("create_abstract_account").add_attributes(vec![
("contract_address", env.contract.address.to_string()),
(
"authenticator",
serde_json::to_string(&authenticator).unwrap(),
),
("authenticator_id", id.to_string()),
])),
)
}

pub fn before_tx(
Expand Down Expand Up @@ -93,13 +100,15 @@ pub fn add_auth_method(
add_authenticator: AddAuthenticator,
) -> ContractResult<Response> {
assert_self(&info.sender, &env.contract.address)?;
match add_authenticator {
match add_authenticator.clone() {
AddAuthenticator::Secp256K1 {
id,
pubkey,
signature,
} => {
let auth = Authenticator::Secp256K1 { pubkey };
let auth = Authenticator::Secp256K1 {
pubkey: pubkey.clone(),
};

if !auth.verify(
deps.api,
Expand All @@ -110,9 +119,7 @@ pub fn add_auth_method(
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, id, &auth)?;
Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("authenticator_id", id.to_string()))
Ok(())
}
}
AddAuthenticator::Ed25519 {
Expand All @@ -131,9 +138,7 @@ pub fn add_auth_method(
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, id, &auth)?;
Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("authenticator_id", id.to_string()))
Ok(())
}
}
AddAuthenticator::EthWallet {
Expand All @@ -152,9 +157,7 @@ pub fn add_auth_method(
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, id, &auth)?;
Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("authenticator_id", id.to_string()))
Ok(())
}
}
AddAuthenticator::Jwt {
Expand All @@ -174,12 +177,19 @@ pub fn add_auth_method(
Err(ContractError::InvalidSignature)
} else {
AUTHENTICATORS.save(deps.storage, id, &auth)?;
Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("authenticator_id", id.to_string()))
Ok(())
}
}
}
}?;
Ok(
Response::new().add_event(Event::new("add_auth_method").add_attributes(vec![
("contract_address", env.contract.address.to_string()),
(
"authenticator",
serde_json::to_string(&add_authenticator).unwrap(),
),
])),
)
}

pub fn remove_auth_method(
Expand All @@ -199,9 +209,12 @@ pub fn remove_auth_method(
}

AUTHENTICATORS.remove(deps.storage, id);
Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("authenticator_id", id.to_string()))
Ok(
Response::new().add_event(Event::new("remove_auth_method").add_attributes(vec![
("contract_address", env.contract.address.to_string()),
("authenticator_id", id.to_string()),
])),
)
}

pub fn assert_self(sender: &Addr, contract: &Addr) -> ContractResult<()> {
Expand Down

0 comments on commit b97d774

Please sign in to comment.