Skip to content

Commit

Permalink
Merge pull request #25 from mintthemoon/staging
Browse files Browse the repository at this point in the history
add multi-owner `cw-ownable` with cosmwasm v2
  • Loading branch information
CyberHoward authored Aug 14, 2024
2 parents 2c6d0f5 + d2799db commit 4620865
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 216 deletions.
2 changes: 1 addition & 1 deletion packages/optional-indexes/src/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct OptionalUniqueIndex<IK, T, PK = ()> {
phantom: PhantomData<PK>,
}

impl<'a, IK, T, PK> OptionalUniqueIndex<IK, T, PK> {
impl<IK, T, PK> OptionalUniqueIndex<IK, T, PK> {
pub const fn new(idx_fn: fn(&T) -> Option<IK>, idx_namespace: &'static str) -> Self {
Self {
index: idx_fn,
Expand Down
10 changes: 10 additions & 0 deletions packages/ownable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
}
```

You can use ownership for other purposes:

```rust
use cw_ownable::OwnershipStore;

pub const CREATOR: OwnershipStore = OwnershipStore::new("creator");
```

`CREATOR` has all functions in place: `initialize_owner`, `is_owner`, `assert_owner`, and `get_ownership`.

## License

Contents of this crate at or prior to version `0.5.0` are published under [GNU Affero General Public License v3](https://github.com/steak-enjoyers/cw-plus-plus/blob/9c8fcf1c95b74dd415caf5602068c558e9d16ecc/LICENSE) or later; contents after the said version are published under [Apache-2.0](../../LICENSE) license.
8 changes: 5 additions & 3 deletions packages/ownable/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn merge_variants(metadata: TokenStream, left: TokenStream, right: TokenStream)
let Enum(DataEnum {
variants,
..
}) = &mut left.data else {
}) = &mut left.data
else {
return syn::Error::new(left.ident.span(), "only enums can accept variants")
.to_compile_error()
.into();
Expand All @@ -33,14 +34,15 @@ fn merge_variants(metadata: TokenStream, left: TokenStream, right: TokenStream)
let Enum(DataEnum {
variants: to_add,
..
}) = right.data else {
}) = right.data
else {
return syn::Error::new(left.ident.span(), "only enums can provide variants")
.to_compile_error()
.into();
};

// insert variants from the right to the left
variants.extend(to_add.into_iter());
variants.extend(to_add);

quote! { #left }.into()
}
Expand Down
Loading

0 comments on commit 4620865

Please sign in to comment.