@@ -109,6 +109,7 @@ decl_event!(
109
109
<T as Trait >:: ContractId ,
110
110
<T as Trait >:: PlanId ,
111
111
<T as Trait >:: ChallengeId ,
112
+ <T as Trait >:: AttestationId
112
113
{
113
114
/// New data feed registered
114
115
NewFeed ( FeedId ) ,
@@ -126,11 +127,11 @@ decl_event!(
126
127
/// Proof-of-storage not confirmed
127
128
ProofOfStorageFailed ( ChallengeId ) ,
128
129
/// Attestation of retrievability requested
129
- NewAttestation ( ChallengeId ) ,
130
+ NewAttestation ( AttestationId ) ,
130
131
/// Proof of retrievability confirmed
131
- AttestationReportConfirmed ( ChallengeId ) ,
132
+ AttestationReportConfirmed ( AttestationId ) ,
132
133
/// Data serving not verified
133
- AttestationReportFailed ( ChallengeId ) ,
134
+ AttestationReportFailed ( AttestationId ) ,
134
135
}
135
136
) ;
136
137
@@ -144,7 +145,7 @@ enum Role {
144
145
Attestor
145
146
}
146
147
147
- type NoiseKey = H512 ;
148
+ type NoiseKey = Public ;
148
149
149
150
#[ derive( Decode , PartialEq , Eq , Encode , Clone , Default , RuntimeDebug ) ]
150
151
struct User < T : Trait > {
@@ -208,8 +209,6 @@ struct Challenge<T: Trait> {
208
209
chunks : Vec < ChunkIndex >
209
210
}
210
211
211
-
212
-
213
212
#[ derive( Decode , PartialEq , Eq , Encode , Clone , RuntimeDebug ) ]
214
213
pub struct Node {
215
214
index : u64 ,
@@ -315,12 +314,14 @@ impl Node {
315
314
}
316
315
}
317
316
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 ;
324
325
325
326
#[ derive( Decode , PartialEq , Eq , Encode , Clone , Default , RuntimeDebug ) ]
326
327
struct Attestation < T : Trait > {
@@ -493,9 +494,9 @@ decl_module!{
493
494
contract: contract_id,
494
495
chunks: random_chunks
495
496
} ;
496
- <GetChallengeByID <T >>:: insert( challenge_id, challenge) ;
497
+ <GetChallengeByID <T >>:: insert( challenge_id, challenge. clone ( ) ) ;
497
498
<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 ( ) ) ) ;
499
500
/*
500
501
const ranges = DB.contracts[contractID - 1].ranges // [ [0, 3], [5, 7] ]
501
502
const chunks = ranges.map(range => getRandomInt(range[0], range[1] + 1))
@@ -512,10 +513,18 @@ decl_module!{
512
513
}
513
514
514
515
#[ 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 > ) {
516
517
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 {
519
528
Self :: deposit_event( RawEvent :: ProofOfStorageConfirmed ( challenge_id. clone( ) ) ) ;
520
529
} else {
521
530
Self :: deposit_event( RawEvent :: ProofOfStorageFailed ( challenge_id. clone( ) ) ) ;
@@ -546,7 +555,8 @@ decl_module!{
546
555
attestor: rand_attestor,
547
556
contract: contract_id
548
557
} ;
549
-
558
+ <GetAttestationByID <T >>:: insert( attestation_id, attestation. clone( ) ) ;
559
+ Self :: deposit_event( RawEvent :: NewAttestation ( attestation_id. clone( ) ) ) ;
550
560
}
551
561
/*
552
562
const [ attestorID ] = getRandom(DB.attestors)
@@ -559,10 +569,27 @@ decl_module!{
559
569
}
560
570
561
571
#[ 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 > ) {
563
573
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
+ }
566
593
}
567
594
/*
568
595
console.log('Submitting Proof Of Retrievability Attestation with ID:', attestationID)
@@ -597,7 +624,7 @@ impl<T: Trait> Module<T> {
597
624
address : user_address. clone ( ) ,
598
625
noise_key : noise_key
599
626
} ;
600
- <GetUserByID < T > >:: insert ( x, new_user) ;
627
+ <GetUserByID < T > >:: insert ( x, new_user. clone ( ) ) ;
601
628
<GetIDByUser < T > >:: insert ( & user_address, x. clone ( ) ) ;
602
629
<GetNextUserID < T > >:: put ( x+One :: one ( ) ) ;
603
630
}
0 commit comments