1
+ use crate :: platform:: block_info_from_metadata:: block_info_from_metadata;
1
2
use crate :: platform:: transition:: broadcast_identity:: BroadcastRequestForNewIdentity ;
2
3
use crate :: platform:: transition:: broadcast_request:: BroadcastRequestForStateTransition ;
3
4
use crate :: platform:: Fetch ;
4
5
use crate :: { Error , Sdk } ;
5
-
6
+ use dapi_grpc:: platform:: v0:: get_epochs_info_request:: { self , GetEpochsInfoRequestV0 } ;
7
+ use dapi_grpc:: platform:: v0:: GetEpochsInfoRequest ;
6
8
use dapi_grpc:: platform:: VersionedGrpcResponse ;
7
9
use dapi_grpc:: tonic:: Code ;
10
+ use dpp:: dashcore:: hashes:: Hash ;
8
11
use dpp:: dashcore:: PrivateKey ;
9
12
use dpp:: identity:: signer:: Signer ;
10
13
use dpp:: prelude:: { AssetLockProof , Identity } ;
11
- use drive_proof_verifier:: error:: ContextProviderError ;
12
- use drive_proof_verifier:: DataContractProvider ;
13
-
14
- use crate :: platform:: block_info_from_metadata:: block_info_from_metadata;
15
14
use dpp:: state_transition:: proof_result:: StateTransitionProofResult ;
16
15
use drive:: drive:: Drive ;
17
- use rs_dapi_client:: { DapiClientError , DapiRequest , RequestSettings } ;
16
+ use drive_proof_verifier:: error:: ContextProviderError ;
17
+ use drive_proof_verifier:: { ContextProvider , DataContractProvider } ;
18
+ use rs_dapi_client:: { DapiClientError , DapiRequest , DapiRequestExecutor , RequestSettings } ;
18
19
19
20
#[ async_trait:: async_trait]
20
21
/// A trait for putting an identity to platform
@@ -37,6 +38,71 @@ pub trait PutIdentity<S: Signer> {
37
38
) -> Result < Identity , Error > ;
38
39
}
39
40
41
+ #[ async_trait:: async_trait]
42
+ pub trait AssetLockProofVerifier {
43
+ /// Verifies the asset lock proof against the platform
44
+ async fn verify ( & self , sdk : & Sdk ) -> Result < ( ) , Error > ;
45
+ }
46
+
47
+ #[ async_trait:: async_trait]
48
+ impl AssetLockProofVerifier for AssetLockProof {
49
+ async fn verify ( & self , sdk : & Sdk ) -> Result < ( ) , Error > {
50
+ let context_provider = sdk
51
+ . context_provider ( )
52
+ . ok_or ( Error :: Config ( "Context Provider not configured" . to_string ( ) ) ) ?;
53
+
54
+ // Check status of Platform first
55
+ // TODO: implement some caching mechanism to avoid fetching the same data multiple times
56
+ let request = GetEpochsInfoRequest {
57
+ version : Some ( get_epochs_info_request:: Version :: V0 (
58
+ GetEpochsInfoRequestV0 {
59
+ ascending : false ,
60
+ count : 1 ,
61
+ prove : true ,
62
+ start_epoch : None ,
63
+ } ,
64
+ ) ) ,
65
+ } ;
66
+ let response = sdk. execute ( request, RequestSettings :: default ( ) ) . await ?;
67
+
68
+ let platform_core_chain_locked_height = response. metadata ( ) ?. core_chain_locked_height ;
69
+ let proof = response. proof_owned ( ) ?;
70
+ let platform_quorum_hash = proof. quorum_hash . try_into ( ) . map_err ( |e : Vec < u8 > | {
71
+ Error :: Protocol ( dpp:: ProtocolError :: DecodingError ( format ! (
72
+ "Invalid quorum hash size {}, expected 32 bytes" ,
73
+ e. len( )
74
+ ) ) )
75
+ } ) ?;
76
+
77
+ let platform_quorum_type = proof. quorum_type ;
78
+
79
+ let ( quorum_hash, core_chain_locked_height) = match self {
80
+ AssetLockProof :: Chain ( v) => ( platform_quorum_hash, v. core_chain_locked_height ) ,
81
+ AssetLockProof :: Instant ( v) => (
82
+ v. instant_lock ( ) . cyclehash . to_raw_hash ( ) . to_byte_array ( ) ,
83
+ platform_core_chain_locked_height,
84
+ ) ,
85
+ } ;
86
+
87
+ // Try to fetch the quorum public key; if it fails, the
88
+ let result = context_provider. get_quorum_public_key (
89
+ platform_quorum_type,
90
+ quorum_hash,
91
+ core_chain_locked_height,
92
+ ) ;
93
+
94
+ match result {
95
+ Err ( ContextProviderError :: InvalidQuorum ( s) ) => Err ( Error :: QuorumNotFound {
96
+ e : ContextProviderError :: InvalidQuorum ( s) ,
97
+ quorum_hash_hex : hex:: encode ( quorum_hash) ,
98
+ quorum_type : platform_quorum_type,
99
+ core_chain_locked_height,
100
+ } ) ,
101
+ Err ( e) => Err ( e. into ( ) ) ,
102
+ Ok ( _) => Ok ( ( ) ) ,
103
+ }
104
+ }
105
+ }
40
106
#[ async_trait:: async_trait]
41
107
impl < S : Signer > PutIdentity < S > for Identity {
42
108
async fn put_to_platform (
0 commit comments