@@ -109,6 +109,7 @@ decl_event!(
109109 <T as Trait >:: ContractId ,
110110 <T as Trait >:: PlanId ,
111111 <T as Trait >:: ChallengeId ,
112+ <T as Trait >:: AttestationId
112113 {
113114 /// New data feed registered
114115 NewFeed ( FeedId ) ,
@@ -126,11 +127,11 @@ decl_event!(
126127 /// Proof-of-storage not confirmed
127128 ProofOfStorageFailed ( ChallengeId ) ,
128129 /// Attestation of retrievability requested
129- NewAttestation ( ChallengeId ) ,
130+ NewAttestation ( AttestationId ) ,
130131 /// Proof of retrievability confirmed
131- AttestationReportConfirmed ( ChallengeId ) ,
132+ AttestationReportConfirmed ( AttestationId ) ,
132133 /// Data serving not verified
133- AttestationReportFailed ( ChallengeId ) ,
134+ AttestationReportFailed ( AttestationId ) ,
134135 }
135136) ;
136137
@@ -144,7 +145,7 @@ enum Role {
144145 Attestor
145146}
146147
147- type NoiseKey = H512 ;
148+ type NoiseKey = Public ;
148149
149150#[ derive( Decode , PartialEq , Eq , Encode , Clone , Default , RuntimeDebug ) ]
150151struct User < T : Trait > {
@@ -208,8 +209,6 @@ struct Challenge<T: Trait> {
208209 chunks : Vec < ChunkIndex >
209210}
210211
211-
212-
213212#[ derive( Decode , PartialEq , Eq , Encode , Clone , RuntimeDebug ) ]
214213pub struct Node {
215214 index : u64 ,
@@ -315,12 +314,14 @@ impl Node {
315314 }
316315}
317316
318- #[ derive( Decode , PartialEq , Eq , Encode , Clone , RuntimeDebug ) ]
319- pub struct Proof {
320- index : u64 ,
321- nodes : Vec < Node > ,
322- signature : Option < Signature >
323- }
317+ // #[derive(Decode, PartialEq, Eq, Encode, Clone, RuntimeDebug)]
318+ // pub struct Proof {
319+ // index: u64,
320+ // nodes: Vec<Node>,
321+ // signature: Option<Signature>
322+ // }
323+
324+ type Proof = Public ;
324325
325326#[ derive( Decode , PartialEq , Eq , Encode , Clone , Default , RuntimeDebug ) ]
326327struct Attestation < T : Trait > {
@@ -493,9 +494,9 @@ decl_module!{
493494 contract: contract_id,
494495 chunks: random_chunks
495496 } ;
496- <GetChallengeByID <T >>:: insert( challenge_id, challenge) ;
497+ <GetChallengeByID <T >>:: insert( challenge_id, challenge. clone ( ) ) ;
497498 <GetNextChallengeID <T >>:: put( challenge_id. clone( ) +One :: one( ) ) ;
498- Self :: deposit_event( RawEvent :: NewProofOfStorageChallenge ( challenge_id) ) ;
499+ Self :: deposit_event( RawEvent :: NewProofOfStorageChallenge ( challenge_id. clone ( ) ) ) ;
499500 /*
500501 const ranges = DB.contracts[contractID - 1].ranges // [ [0, 3], [5, 7] ]
501502 const chunks = ranges.map(range => getRandomInt(range[0], range[1] + 1))
@@ -512,10 +513,18 @@ decl_module!{
512513 }
513514
514515 #[ weight = ( 100000 , Operational , Pays :: No ) ] //todo weight
515- fn submit_proof_of_storage( origin, challenge_id: T :: ChallengeId , proof : Proof ) {
516+ fn submit_proof_of_storage( origin, challenge_id: T :: ChallengeId , proofs : Vec < Proof > ) {
516517 let user_address = ensure_signed( origin) ?;
517- if let Some ( challenge) = <GetChallengeByID <T >>:: get( challenge_id. clone( ) ) {
518- if Self :: validate_proof( proof, challenge) {
518+ let mut success: bool = true ;
519+ if let Some ( challenge) = <GetChallengeByID <T >>:: get( & challenge_id) {
520+ for proof in proofs {
521+ if Self :: validate_proof( proof. clone( ) , challenge. clone( ) ) {
522+ success = success && true ;
523+ } else {
524+ success = success && false ;
525+ }
526+ }
527+ if success {
519528 Self :: deposit_event( RawEvent :: ProofOfStorageConfirmed ( challenge_id. clone( ) ) ) ;
520529 } else {
521530 Self :: deposit_event( RawEvent :: ProofOfStorageFailed ( challenge_id. clone( ) ) ) ;
@@ -546,7 +555,8 @@ decl_module!{
546555 attestor: rand_attestor,
547556 contract: contract_id
548557 } ;
549-
558+ <GetAttestationByID <T >>:: insert( attestation_id, attestation. clone( ) ) ;
559+ Self :: deposit_event( RawEvent :: NewAttestation ( attestation_id. clone( ) ) ) ;
550560 }
551561 /*
552562 const [ attestorID ] = getRandom(DB.attestors)
@@ -559,10 +569,27 @@ decl_module!{
559569 }
560570
561571 #[ weight = ( 100000 , Operational , Pays :: No ) ] //todo weight
562- fn submit_attestation_report( origin, attestation_id: T :: AttestationId , report : Report ) {
572+ fn submit_attestation_report( origin, attestation_id: T :: AttestationId , reports : Vec < Report > ) {
563573 let user_address = ensure_signed( origin) ?;
564- if let Some ( attestation) = <GetAttestationByID <T >>:: get( attestation_id) {
565-
574+ let mut success: bool = true ;
575+ if let Some ( attestation) = <GetAttestationByID <T >>:: get( & attestation_id) {
576+ for report in reports {
577+ match report. latency {
578+ Some ( _) => {
579+ // report passed
580+ success = success && true ;
581+ } ,
582+ _ => {
583+ // report failed
584+ success = success && false ;
585+ }
586+ }
587+ }
588+ if success {
589+ Self :: deposit_event( RawEvent :: AttestationReportConfirmed ( attestation_id. clone( ) ) ) ;
590+ } else {
591+ Self :: deposit_event( RawEvent :: AttestationReportFailed ( attestation_id. clone( ) ) ) ;
592+ }
566593 }
567594 /*
568595 console.log('Submitting Proof Of Retrievability Attestation with ID:', attestationID)
@@ -597,7 +624,7 @@ impl<T: Trait> Module<T> {
597624 address : user_address. clone ( ) ,
598625 noise_key : noise_key
599626 } ;
600- <GetUserByID < T > >:: insert ( x, new_user) ;
627+ <GetUserByID < T > >:: insert ( x, new_user. clone ( ) ) ;
601628 <GetIDByUser < T > >:: insert ( & user_address, x. clone ( ) ) ;
602629 <GetNextUserID < T > >:: put ( x+One :: one ( ) ) ;
603630 }
0 commit comments