Skip to content

Commit

Permalink
limit minimum deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ro0r committed Oct 22, 2023
1 parent 1788d1b commit cbdb45e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
8 changes: 6 additions & 2 deletions eth/contracts/IRandao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ interface IRandao {
event LogCampaignAdded(
uint256 indexed campaignID,
address indexed from,
uint256 currbNum,
uint256 indexed bnum,
uint256 deposit,
uint16 commitBalkline,
uint16 commitDeadline,
uint256 bountypot
uint256 bountypot,
uint256 maxParticipant
);

event LogFollow(
Expand Down Expand Up @@ -65,6 +67,7 @@ interface IRandao {
uint256 bountypot;
uint32 commitNum;
uint32 revealsNum;
uint256 maxParticipant;
mapping(address => Consumer) consumers;
mapping(address => Participant) participants;
mapping(bytes32 => bool) commitments;
Expand All @@ -74,7 +77,8 @@ interface IRandao {
uint256 _bnum,
uint256 _deposit,
uint16 _commitBalkline,
uint16 _commitDeadline
uint16 _commitDeadline,
uint256 _maxTxFee
) external payable returns (uint256 _campaignID);

function getCampaign(
Expand Down
17 changes: 14 additions & 3 deletions eth/contracts/Randao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ contract Randao is IRandao {
uint256 _bnum,
uint256 _deposit,
uint16 _commitBalkline,
uint16 _commitDeadline
uint16 _commitDeadline,
uint256 _maxTxFee
)
external
payable
timeLineCheck(_bnum, _commitBalkline, _commitDeadline)
moreThanZero(_deposit)
returns (uint256 _campaignID)
{
uint256 maxParticipant = _deposit / _maxTxFee / 4;
require(maxParticipant > 0, "_deposit is too less!!!");

_campaignID = numCampaigns++;
Campaign storage c = campaigns[_campaignID];
c.bnum = _bnum;
Expand All @@ -76,14 +80,18 @@ contract Randao is IRandao {
c.commitDeadline = _commitDeadline;
c.bountypot = msg.value;
c.consumers[msg.sender] = Consumer(msg.sender, msg.value);
c.maxParticipant = maxParticipant;

emit LogCampaignAdded(
_campaignID,
msg.sender,
block.number,
_bnum,
_deposit,
_commitBalkline,
_commitDeadline,
msg.value
msg.value,
maxParticipant
);
}

Expand Down Expand Up @@ -175,11 +183,14 @@ contract Randao is IRandao {
beBlank(c.participants[msg.sender].commitment)
{
if (c.commitments[_hs]) {
revert("Already committed to compaign");
revert("Already committed to compaign!!!");
} else if (c.maxParticipant == 0) {
revert("More than maxParticipant!!!");
} else {
c.participants[msg.sender] = Participant(0, _hs, 0, false, false);
c.commitNum++;
c.commitments[_hs] = true;
c.maxParticipant--;
emit LogCommit(_campaignID, msg.sender, _hs);
}
}
Expand Down
14 changes: 10 additions & 4 deletions randao/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,22 @@ impl Detokenize for CampaignInfo {
#[derive(clap::Parser, Debug)]
pub struct Opts {
/// Config file
#[clap(short = 'c', long = "config", default_value = "/tmp/.randao/config/config.json")]
#[clap(
short = 'c',
long = "config",
default_value = "/tmp/.randao/config/config.json"
)]
pub config: String,
#[clap(short = 'p', long = "campaigns", default_value = "/tmp/.randao/campaigns")]
#[clap(
short = 'p',
long = "campaigns",
default_value = "/tmp/.randao/campaigns"
)]
pub campaigns: String,
#[clap(short = 'k', long = "keys", default_value = "/tmp/.randao/keys")]
pub keys: String,
#[clap(short = 'a', long = "is_campagin")]
pub is_campagin: bool,


}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
Expand Down
9 changes: 6 additions & 3 deletions randao/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const _FRC20_ADDRESS: u64 = 0x1000;
pub const BLOCK_TIME: u64 = 16;

lazy_static! {
pub static ref RANDAO_CAMPAIGNS: std::sync::Mutex<String> = std::sync::Mutex::new("campaigns/".to_string());
pub static ref RANDAO_CONF: std::sync::Mutex<String> = std::sync::Mutex::new("/tmp/.randao/config/config.json".to_string());
pub static ref RANDAO_KEYS: std::sync::Mutex<String> = std::sync::Mutex::new("keys/".to_string());
pub static ref RANDAO_CAMPAIGNS: std::sync::Mutex<String> =
std::sync::Mutex::new("campaigns/".to_string());
pub static ref RANDAO_CONF: std::sync::Mutex<String> =
std::sync::Mutex::new("/tmp/.randao/config/config.json".to_string());
pub static ref RANDAO_KEYS: std::sync::Mutex<String> =
std::sync::Mutex::new("keys/".to_string());
}

lazy_static! {
Expand Down
3 changes: 1 addition & 2 deletions randao/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ pub fn check_campaign_info(

println!("{:?}, block_number :{:?}", campaign_info, block_number);

if campaign_info.deposit.as_u128() == 0
{
if campaign_info.deposit.as_u128() == 0 {
println!("check_campaign_info err 2");
return false;
}
Expand Down

0 comments on commit cbdb45e

Please sign in to comment.