Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tg4 spec and uses #34

Merged
merged 43 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e6ad560
Copy cw4 spec files
maurolacy Apr 20, 2021
c9dab7a
Rename package to tg4
maurolacy Apr 20, 2021
57f77ae
Update README
maurolacy Apr 20, 2021
b4d718c
Rename Cw4 to Tg4
maurolacy Apr 20, 2021
3985685
Update cargo lock file
maurolacy Apr 20, 2021
5e2b9af
Update schema
maurolacy Apr 20, 2021
38b4966
Copy cw4-group contract files
maurolacy Apr 20, 2021
d05cf8d
Rename contract to tg4-group
maurolacy Apr 20, 2021
73f561e
Update README
maurolacy Apr 20, 2021
9a49e9f
Add cargo config
maurolacy Apr 20, 2021
3705e53
Rename Cw4 to Tg4
maurolacy Apr 20, 2021
a41fe0b
Update cargo lock file
maurolacy Apr 20, 2021
3ef2af7
Add schema
maurolacy Apr 20, 2021
6012b06
Copy cw4-stake contract files
maurolacy Apr 20, 2021
eaae119
Rename contract to tg4-stake
maurolacy Apr 20, 2021
21db125
Update README
maurolacy Apr 20, 2021
1e18844
Add cargo config
maurolacy Apr 20, 2021
ef9dad2
Fix Cargo.toml
maurolacy Apr 20, 2021
b30261d
Rename Cw4 to Tg4
maurolacy Apr 20, 2021
1cf611d
Update cargo lock file
maurolacy Apr 20, 2021
c05d19f
Update schema
maurolacy Apr 20, 2021
ed25acf
Add ListMembersByWeight to tg4 spec
maurolacy Apr 20, 2021
dc96183
Add members() IndexedSnapshotMap
maurolacy Apr 20, 2021
40f47fd
Add list_members_by_weight method / msg
maurolacy Apr 20, 2021
df046cc
Add list_members() pagination / limits tests
maurolacy Apr 20, 2021
b0fb05a
Add list_members_by_weight() pagination / limits tests
maurolacy Apr 20, 2021
fdf432a
Fix: Descending order requires swapped bounds
maurolacy Apr 20, 2021
86dfbd4
Update schema
maurolacy Apr 20, 2021
cc0da95
Add members() IndexedSnapshotMap to cw4-group
maurolacy Apr 20, 2021
1d965a2
Add list_members_by_weight method / msg
maurolacy Apr 20, 2021
2f2d911
Add list_members_by_weight to Tg4Contract
maurolacy Apr 20, 2021
355f9ff
Migrate tgrade-valset to Tg4
maurolacy Apr 20, 2021
c242ef6
Update schema
maurolacy Apr 20, 2021
0fcbdb4
Break if enough validators already
maurolacy Apr 20, 2021
6f7840e
Update tg4 package README
maurolacy Apr 20, 2021
44f2a22
Take only required validators or less
maurolacy Apr 21, 2021
325fd4d
Use Member instead of tuple
maurolacy Apr 21, 2021
2a5d9b6
Update tg4 schema
maurolacy Apr 21, 2021
85f1a1b
Change to Option<Member> for start_after
maurolacy Apr 21, 2021
9008400
Update schema
maurolacy Apr 21, 2021
0935220
Use Option<Member> start_after
maurolacy Apr 21, 2021
135238a
Add members indexed snapshot map comments
maurolacy Apr 21, 2021
afab281
cargo fmt
maurolacy Apr 21, 2021
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
140 changes: 69 additions & 71 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions contracts/tg4-group/.cargo/config
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"
33 changes: 33 additions & 0 deletions contracts/tg4-group/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "tg4-group"
version = "0.1.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Simple TG4 implementation of group membership controlled by an admin"
repository = "https://github.com/confio/tgrade-contracts"
homepage = "https://tgrade.finance"

# 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]
cw0 = { version = "0.6.0-beta2" }
cw2 = { version = "0.6.0-beta2" }
cw-controllers = { version = "0.6.0-beta2" }
cw-storage-plus = { version = "0.6.0-beta2", features = ["iterator"] }
tg4 = { path = "../../packages/tg4", version = "0.1.0" }
cosmwasm-std = { version = "=0.14.0-beta3" }
schemars = "0.8"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.21" }

[dev-dependencies]
cosmwasm-schema = { version = "=0.14.0-beta3" }
51 changes: 51 additions & 0 deletions contracts/tg4-group/README.md
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](https://github.com/CosmWasm/cosmwasm-plus/blob/master/packages/cw3/README.mdl).

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 weight. 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 weight: u64,
}
```

Members are defined by an address and a weight. 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 weight*. 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.

22 changes: 22 additions & 0 deletions contracts/tg4-group/examples/schema.rs
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, TotalWeightResponse};
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(&mut schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(&mut schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg");
export_schema_with_title(&mut 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!(TotalWeightResponse), &out_dir);
}
13 changes: 13 additions & 0 deletions contracts/tg4-group/schema/admin_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "AdminResponse",
"type": "object",
"properties": {
"admin": {
"type": [
"string",
"null"
]
}
}
}
Loading