Skip to content

Commit 379053e

Browse files
author
Joshua Mir
committed
request_proof_of_storage_challenge (pending proper random)
1 parent 91e8dfa commit 379053e

File tree

1 file changed

+17
-0
lines changed
  • datdot-node/pallets/datdot/src

1 file changed

+17
-0
lines changed

datdot-node/pallets/datdot/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,16 @@ decl_module!{
501501
let user_address = ensure_signed(origin)?;
502502
if let Some(contract) = <GetContractByID<T>>::get(&contract_id){
503503
let ranges = contract.ranges;
504+
let random_chunks = Self::random_from_ranges(ranges);
505+
let challenge_id = <GetNextChallengeID<T>>::get();
506+
let challenge = Challenge::<T> {
507+
id: challenge_id.clone(),
508+
contract: contract_id,
509+
chunks: random_chunks
510+
};
511+
<GetChallengeByID<T>>::insert(challenge_id, challenge);
512+
<GetNextChallengeID<T>>::put(challenge_id.clone()+One::one());
513+
Self::deposit_event(RawEvent::NewProofOfStorageChallenge(challenge_id));
504514
/*
505515
const ranges = DB.contracts[contractID - 1].ranges // [ [0, 3], [5, 7] ]
506516
const chunks = ranges.map(range => getRandomInt(range[0], range[1] + 1))
@@ -610,6 +620,13 @@ impl<T: Trait> Module<T> {
610620
(_, _, _) => ()
611621
}
612622
}
623+
624+
fn random_from_ranges(ranges: Ranges<T::ChunkIndex>) -> Vec<T::ChunkIndex>{
625+
//TODO, currently only returns first chunk of every available range,
626+
//should return some random selection.
627+
ranges.iter().map(|x|x.0).collect()
628+
}
629+
613630
//borrowing from society pallet ---
614631
fn pick_usize<'a, R: RngCore>(rng: &mut R, max: usize) -> usize {
615632

0 commit comments

Comments
 (0)