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

Poc easy polls #65

Merged
merged 50 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
dea3c21
draft
sczembor Jul 20, 2023
e8f1d3f
draft
sczembor Jul 21, 2023
a7b66d6
draft
sczembor Jul 25, 2023
afe26d2
finish respond method; add simple unit test
sczembor Jul 31, 2023
d4a35d8
add custom errors
sczembor Aug 2, 2023
f74f123
add unit tests for responds
sczembor Aug 2, 2023
bffd781
improve the respond implementation
sczembor Aug 8, 2023
7929cf1
add corss contract call to registry
sczembor Aug 9, 2023
73b55b1
implement text_answers result method
sczembor Aug 10, 2023
a2265da
Merge branch 'master' into poc_easy_polls
sczembor Aug 10, 2023
ecd2a83
update the structure
sczembor Aug 11, 2023
8863cae
Merge branch 'poc_easy_polls' of https://github.com/near-ndc/i-am-hum…
sczembor Aug 11, 2023
e768996
merge
sczembor Aug 11, 2023
6e9a85a
Merge branch 'master' into poc_easy_polls
sczembor Aug 11, 2023
da4476b
Update contracts/easy-poll/Cargo.toml
sczembor Aug 11, 2023
197e3bf
Apply suggestions from code review
sczembor Aug 11, 2023
bd867f8
update the structs, apply code review suggestions; improve the unit t…
sczembor Aug 11, 2023
35af0ea
apply code review suggestions
sczembor Aug 11, 2023
791eca9
add more unit tests; remove unused structs
sczembor Aug 14, 2023
e601730
Merge branch 'master' into poc_easy_polls
sczembor Aug 30, 2023
eebbe4a
apply code review suggestions
sczembor Aug 30, 2023
70c13b3
Update contracts/easy-poll/src/ext.rs
sczembor Aug 30, 2023
274f9fe
mErge branch 'poc_easy_polls' of https://github.com/near-ndc/i-am-hum…
sczembor Aug 31, 2023
41433b5
Update contracts/easy-poll/src/storage.rs
sczembor Aug 31, 2023
f93aad5
Update contracts/easy-poll/src/storage.rs
sczembor Aug 31, 2023
4952829
Update contracts/easy-poll/src/lib.rs
sczembor Aug 31, 2023
7514834
Update contracts/easy-poll/src/lib.rs
sczembor Aug 31, 2023
e42031b
merge branch 'poc_easy_polls' of https://github.com/near-ndc/i-am-hum…
sczembor Aug 31, 2023
1ea6889
apply code review suggestions
sczembor Aug 31, 2023
f8b137a
add comment'
sczembor Aug 31, 2023
54b8ab2
Merge branch 'master' into poc_easy_polls
sczembor Sep 8, 2023
3f2ac05
Update contracts/easy-poll/src/lib.rs
sczembor Sep 8, 2023
b2d3045
Update contracts/easy-poll/src/lib.rs
sczembor Sep 8, 2023
12c5af8
add events
sczembor Sep 8, 2023
590c4f1
apply code review suggestions
sczembor Sep 11, 2023
6707620
add serialize, deserialize
sczembor Sep 11, 2023
d5dd012
Apply suggestions from code review
sczembor Sep 11, 2023
56519f9
apply code review suggestions
sczembor Sep 11, 2023
b9b4a56
test fix
sczembor Sep 11, 2023
ab96d0b
Apply suggestions from code review
sczembor Sep 12, 2023
ab8cc91
fix
sczembor Sep 12, 2023
249fedd
Update contracts/easy-poll/src/lib.rs
sczembor Sep 12, 2023
397752a
move debug to test only
sczembor Sep 12, 2023
e54afa4
Merge branch 'poc_easy_polls' of https://github.com/near-ndc/i-am-hum…
sczembor Sep 12, 2023
3a4c741
refactor on_human_verifed and initalize_results methods
sczembor Sep 12, 2023
f5a3510
do not store answers on chain
sczembor Sep 13, 2023
ef83ec9
apply code review suggestions
sczembor Sep 13, 2023
dd10a8e
Update contracts/easy-poll/src/lib.rs
robert-zaremba Sep 13, 2023
046db48
Update contracts/easy-poll/src/lib.rs
sczembor Sep 13, 2023
747d479
change choices to unique vector rather than true/false
sczembor Sep 13, 2023
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
18 changes: 18 additions & 0 deletions contracts/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
"oracle",
"registry",
"soulbound-class",

"easy-poll",
"human_checker",
"ubi",
"demo-issuer",
Expand Down
30 changes: 30 additions & 0 deletions contracts/easy-poll/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "easy-poll"
version = "0.0.1"
authors = [
"NDC GWG (https://near.social/#/mob.near/widget/ProfilePage?accountId=govworkinggroup.near)",
]
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]


[dependencies]
uint.workspace = true
near-sdk.workspace = true
serde_json.workspace = true

cost = { path = "../cost" }
sbt = { path = "../sbt" }

[dev-dependencies]
pretty_assertions.workspace = true
anyhow.workspace = true
tokio.workspace = true
workspaces.workspace = true
near-primitives.workspace = true
near-units.workspace = true
tracing.workspace = true
1 change: 1 addition & 0 deletions contracts/easy-poll/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../Makefile-common.mk
10 changes: 10 additions & 0 deletions contracts/easy-poll/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Easy Poll

Proof of concept


Based on https://www.notion.so/near-ndc/EasyPoll-v2-f991a29781ca452db154c64922717d19#35d9a363be34495bb13ad5fa4b73cafe

## Usage

## Deployed contracts
35 changes: 35 additions & 0 deletions contracts/easy-poll/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use near_sdk::env::panic_str;
use near_sdk::FunctionError;

/// Contract errors
#[cfg_attr(not(target_arch = "wasm32"), derive(PartialEq))]
#[derive(Debug)]
sczembor marked this conversation as resolved.
Show resolved Hide resolved
pub enum PollError {
RequiredAnswer(usize),
NoSBTs,
sczembor marked this conversation as resolved.
Show resolved Hide resolved
NotFound,
NotActive,
OpinionRange,
WrongAnswer,
IncorrectAnswerVector,
AlredyAnswered,
}

impl FunctionError for PollError {
fn panic(&self) -> ! {
match self {
PollError::RequiredAnswer(index) => {
panic_str(&format!("Answer to a required question index={} was not provided",index))
}
PollError::NoSBTs => panic_str("voter is not a verified human"),
sczembor marked this conversation as resolved.
Show resolved Hide resolved
PollError::NotFound => panic_str("poll not found"),
PollError::NotActive => panic_str("poll is not active"),
PollError::OpinionRange => panic_str("opinion must be between 0 and 10"),
sczembor marked this conversation as resolved.
Show resolved Hide resolved
PollError::WrongAnswer => {
panic_str("answer provied does not match the expected question")
},
PollError::IncorrectAnswerVector => panic_str("the answer vector provided is incorrect and does not match the questions in the poll"),
PollError::AlredyAnswered => panic_str("user has already answered")
}
}
}
46 changes: 46 additions & 0 deletions contracts/easy-poll/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use near_sdk::serde::Serialize;
use serde_json::json;

use sbt::{EventPayload, NearEvent};

use crate::PollId;

fn emit_event<T: Serialize>(event: EventPayload<T>) {
NearEvent {
standard: "ndc-easy-polls",
sczembor marked this conversation as resolved.
Show resolved Hide resolved
version: "0.0.1",
sczembor marked this conversation as resolved.
Show resolved Hide resolved
event,
}
.emit();
}

pub(crate) fn emit_create_poll(poll_id: PollId) {
emit_event(EventPayload {
event: "create_poll",
data: json!({ "poll_id": poll_id }),
});
}

pub(crate) fn emit_respond(poll_id: PollId) {
emit_event(EventPayload {
event: "respond",
data: json!({ "poll_id": poll_id }),
sczembor marked this conversation as resolved.
Show resolved Hide resolved
});
}

#[cfg(test)]
mod unit_tests {
use near_sdk::test_utils;

use super::*;

#[test]
fn log_vote() {
let expected1 = r#"EVENT_JSON:{"standard":"ndc-easy-polls","version":"0.0.1","event":"create_poll","data":{"poll_id":21}}"#;
let expected2 = r#"EVENT_JSON:{"standard":"ndc-easy-polls","version":"0.0.1","event":"respond","data":{"poll_id":22}}"#;
emit_create_poll(21);
assert_eq!(vec![expected1], test_utils::get_logs());
emit_respond(22);
assert_eq!(vec![expected1, expected2], test_utils::get_logs());
}
}
9 changes: 9 additions & 0 deletions contracts/easy-poll/src/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub use crate::storage::*;
use near_sdk::{ext_contract, AccountId};
use sbt::TokenId;

#[ext_contract(ext_registry)]
trait ExtRegistry {
// queries
fn is_human(&self, account: AccountId) -> Vec<(AccountId, Vec<TokenId>)>;
}
Loading
Loading