-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from confio/tg4-group
Add `tg4-group` contract
- Loading branch information
Showing
14 changed files
with
925 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" | ||
schema = "run --example schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[package] | ||
name = "tg4-group" | ||
version = "0.6.0" | ||
authors = ["Mauro Lacy <[email protected]>"] | ||
edition = "2018" | ||
description = "Simple tg4 implementation of group membership controlled by admin" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/confio/poe-contracts" | ||
homepage = "https://cosmwasm.com" | ||
documentation = "https://docs.cosmwasm.com" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"artifacts/*", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all instantiate/execute/query exports | ||
library = [] | ||
|
||
[dependencies] | ||
cw-utils = "0.11.1" | ||
cw2 = "0.11.1" | ||
tg-bindings = { version = "0.6.0", path = "../../packages/bindings" } | ||
tg-utils = { version = "0.6.0", path = "../../packages/utils" } | ||
tg4 = { version = "0.6.0", path = "../../packages/tg4" } | ||
cw-controllers = "0.11.1" | ||
cw-storage-plus = "0.11.1" | ||
cosmwasm-std = { version = "1.0.0-beta5" } | ||
schemars = "0.8.1" | ||
serde = { version = "1.0.103", default-features = false, features = ["derive"] } | ||
thiserror = { version = "1.0.23" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "1.0.0-beta5" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Tg4_group | ||
Copyright (C) 2022 Confio Gmbh | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# TG4 Group | ||
|
||
This is a basic implementation of the [tg4 spec](../../packages/tg4/README.md). | ||
It fulfills all elements of the spec, including the raw query lookups, | ||
and it designed to be used as a backing storage for | ||
[cw3 compliant contracts](../../packages/cw3/README.md). | ||
|
||
It stores a set of members along with an admin, and allows the admin to | ||
update the state. Raw queries (intended for cross-contract queries) | ||
can check a given member address and the total points. Smart queries (designed | ||
for client API) can do the same, and also query the admin address as well as | ||
paginate over all members. | ||
|
||
## Init | ||
|
||
To create it, you must pass in a list of members, as well as an optional | ||
`admin`, if you wish it to be mutable. | ||
|
||
```rust | ||
pub struct InitMsg { | ||
pub admin: Option<HumanAddr>, | ||
pub members: Vec<Member>, | ||
} | ||
|
||
pub struct Member { | ||
pub addr: HumanAddr, | ||
pub points: u64, | ||
} | ||
``` | ||
|
||
Members are defined by an address and a number of points. This is transformed | ||
and stored under their `CanonicalAddr`, in a format defined in | ||
[tg4 raw queries](../../packages/tg4/README.md#raw). | ||
|
||
Note that 0 *is an allowed number of points*. This doesn't give any voting rights, but | ||
it does define this address is part of the group. This could be used in | ||
e.g. a KYC whitelist to say they are allowed, but cannot participate in | ||
decision-making. | ||
|
||
## Messages | ||
|
||
Basic update messages, queries, and hooks are defined by the | ||
[tg4 spec](../../packages/tg4/README.md). Please refer to it for more info. | ||
|
||
`tg4-group` adds one message to control the group membership: | ||
|
||
`UpdateMembers{add, remove}` - takes a membership diff and adds/updates the | ||
members, as well as removing any provided addresses. If an address is on both | ||
lists, it will be removed. If it appears multiple times in `add`, only the | ||
last occurrence will be used. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for}; | ||
|
||
pub use tg4::{AdminResponse, MemberListResponse, MemberResponse, TotalPointsResponse}; | ||
pub use tg4_group::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; | ||
|
||
fn main() { | ||
let mut out_dir = current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
create_dir_all(&out_dir).unwrap(); | ||
remove_schemas(&out_dir).unwrap(); | ||
|
||
export_schema_with_title(&schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg"); | ||
export_schema_with_title(&schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg"); | ||
export_schema_with_title(&schema_for!(QueryMsg), &out_dir, "QueryMsg"); | ||
export_schema(&schema_for!(AdminResponse), &out_dir); | ||
export_schema(&schema_for!(MemberListResponse), &out_dir); | ||
export_schema(&schema_for!(MemberResponse), &out_dir); | ||
export_schema(&schema_for!(TotalPointsResponse), &out_dir); | ||
} |
Oops, something went wrong.