Skip to content

Commit

Permalink
Changing ending of the dispute
Browse files Browse the repository at this point in the history
- dispute ends when judge issues a verdict
- majority of votes starts from  70%
- changed indexing of dispute rounds
- deposit distribution is done when judge issues a verdict
  • Loading branch information
mgralinski-bright committed Jan 11, 2024
1 parent ef0f671 commit 203b4d6
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 244 deletions.
8 changes: 5 additions & 3 deletions cli/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use liminal_ark_relations::{

pub mod helpers;

pub const MAJORITY_OF_VOTES: f32 = 0.70; // 70%

pub struct PublicVote {
pub id: AccountId,
pub pub_key: Vec<u8>,
Expand Down Expand Up @@ -102,21 +104,21 @@ pub fn prepare_counting_inputs(
}
}

let votes_minimum: u8 = (0.75 * votes.len() as f32).ceil() as u8;
let votes_minimum: u8 = (MAJORITY_OF_VOTES * votes.len() as f32).ceil() as u8;
let votes_maximum: u8 = votes.len() as u8 - votes_minimum;
let verdict = if sum_votes >= votes_minimum {
jurors_banned = jurors_banned
.iter()
.enumerate()
.filter(|&(index, _)| decoded_votes[index] != 0)
.filter(|&(index, _)| decoded_votes[index] == 0)
.map(|(_, &ref value)| value.clone())
.collect();
VerdictRelation::Positive
} else if sum_votes <= votes_maximum {
jurors_banned = jurors_banned
.iter()
.enumerate()
.filter(|&(index, _)| decoded_votes[index] == 0)
.filter(|&(index, _)| decoded_votes[index] == 1)
.map(|(_, &ref value)| value.clone())
.collect();
VerdictRelation::Negative
Expand Down
15 changes: 0 additions & 15 deletions cli/src/bright_disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,4 @@ impl BrightDisputes {

Ok(())
}

/// Calls 'distribute_deposit' of the contract.
pub async fn distribute_deposit(
&self,
connection: &SignedConnection,
dispute_id: u32,
) -> Result<()> {
let ink_contract: Instance = (&self.contract).into();

connection
.exec(ink_contract.distribute_deposit(dispute_id))
.await?;

Ok(())
}
}
17 changes: 3 additions & 14 deletions cli/src/bright_disputes_ink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use scale::Encode as _;

#[allow(dead_code)]
pub const CODE_HASH: [u8; 32] = [
134, 34, 57, 191, 103, 29, 44, 56, 12, 231, 88, 242, 64, 144, 53, 34, 131, 56, 170, 238, 192,
142, 229, 240, 82, 204, 67, 181, 250, 239, 22, 82,
172, 163, 202, 102, 55, 35, 203, 88, 236, 195, 156, 213, 90, 245, 231, 194, 112, 179, 169, 197,
90, 183, 142, 26, 36, 52, 220, 49, 44, 93, 167, 79,
];

#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Instance {
ink_wrapper_types::ReadCall::new(self.account_id, data)
}

/// Get single dispute by id
/// Remove single dispute by id
#[allow(dead_code, clippy::too_many_arguments)]
pub fn remove_dispute(&self, dispute_id: u32) -> ink_wrapper_types::ExecCall {
let data = {
Expand Down Expand Up @@ -405,17 +405,6 @@ impl Instance {
ink_wrapper_types::ExecCall::new(self.account_id, data)
}

/// Judge can confirm his participation in dispute
#[allow(dead_code, clippy::too_many_arguments)]
pub fn distribute_deposit(&self, dispute_id: u32) -> ink_wrapper_types::ExecCall {
let data = {
let mut data = vec![117, 233, 246, 239];
dispute_id.encode_to(&mut data);
data
};
ink_wrapper_types::ExecCall::new(self.account_id, data)
}

/// Register a verification key.
#[allow(dead_code, clippy::too_many_arguments)]
pub fn register_vk(&self, relation: Relation, vk: Vec<u8>) -> ink_wrapper_types::ExecCall {
Expand Down
5 changes: 0 additions & 5 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,4 @@ pub enum ContractCmd {
caller_account: String,
dispute_id: u32,
},
/// Distribute dispute deposit
DistributeDeposit {
caller_account: String,
dispute_id: u32,
},
}
14 changes: 1 addition & 13 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
Command, Config,
ContractCmd::{
ConfirmDefendant, ConfirmJudgeParticipation, ConfirmJurorParticipation, CountTheVotes,
CreateDispute, DistributeDeposit, GetDispute, GetDisputeFull, ProcessDisputeRound,
CreateDispute, GetDispute, GetDisputeFull, ProcessDisputeRound,
RegisterAsAnActiveJuror, UnregisterAsAnActiveJuror, UpdateDefendantDescription,
UpdateOwnerDescription, Vote,
},
Expand Down Expand Up @@ -284,18 +284,6 @@ async fn handle_contract_command(
dispute_state
);
}
DistributeDeposit {
caller_account,
dispute_id,
} => {
let account = keypair_from_string(&caller_account);
let signed_connection = SignedConnection::from_connection(connection, account.clone());

bright_dispute
.distribute_deposit(&signed_connection, dispute_id)
.await?;
info!("Deposit distributed successfully!");
}
}
Ok(())
}
Expand Down
Loading

0 comments on commit 203b4d6

Please sign in to comment.