1
1
use crate :: credential:: rdf_marker:: IRI_VC_TYPE ;
2
2
use crate :: credential:: vc:: { Claim , VerifiableCredential } ;
3
3
use crate :: ContractError ;
4
- use cosmwasm_std:: Addr ;
4
+ use cosmwasm_std:: { Addr , Env , MessageInfo } ;
5
5
use itertools:: Itertools ;
6
6
7
7
#[ derive( Debug , PartialEq ) ]
8
8
pub struct DataverseCredential < ' a > {
9
- pub submitter_addr : Addr ,
9
+ pub height : String ,
10
+ pub timestamp : String ,
11
+ pub tx_index : Option < String > ,
12
+ pub sender : Addr ,
10
13
pub id : & ' a str ,
11
14
pub issuer : & ' a str ,
12
15
pub r#type : & ' a str ,
@@ -38,14 +41,17 @@ impl<'a> DataverseCredential<'a> {
38
41
}
39
42
}
40
43
41
- impl < ' a > TryFrom < ( Addr , & ' a VerifiableCredential < ' a > ) > for DataverseCredential < ' a > {
44
+ impl < ' a > TryFrom < ( Env , MessageInfo , & ' a VerifiableCredential < ' a > ) > for DataverseCredential < ' a > {
42
45
type Error = ContractError ;
43
46
44
47
fn try_from (
45
- ( submitter_addr , vc) : ( Addr , & ' a VerifiableCredential < ' a > ) ,
48
+ ( env , info , vc) : ( Env , MessageInfo , & ' a VerifiableCredential < ' a > ) ,
46
49
) -> Result < Self , Self :: Error > {
47
50
Ok ( DataverseCredential {
48
- submitter_addr,
51
+ height : env. block . height . to_string ( ) ,
52
+ timestamp : env. block . time . seconds ( ) . to_string ( ) ,
53
+ tx_index : env. transaction . map ( |tx| tx. index . to_string ( ) ) ,
54
+ sender : info. sender ,
49
55
id : vc. id ,
50
56
issuer : vc. issuer ,
51
57
r#type : DataverseCredential :: extract_vc_type ( vc) ?,
@@ -61,21 +67,25 @@ mod test {
61
67
use super :: * ;
62
68
use crate :: testutil:: testutil;
63
69
use axone_rdf:: dataset:: Dataset ;
70
+ use cosmwasm_std:: testing:: message_info;
64
71
use rio_api:: model:: { Literal , NamedNode , Quad } ;
72
+ use testing:: addr:: { addr, SENDER } ;
73
+ use testing:: mock:: mock_env_addr;
65
74
66
75
#[ test]
67
76
fn proper_from_verifiable ( ) {
68
77
let owned_quads = testutil:: read_test_quads ( "vc-valid.nq" ) ;
69
78
let dataset = Dataset :: from ( owned_quads. as_slice ( ) ) ;
70
79
let vc = VerifiableCredential :: try_from ( & dataset) . unwrap ( ) ;
71
- let dc_res = DataverseCredential :: try_from ( (
72
- Addr :: unchecked ( "axone1072nc6egexqr2v6vpp7yxwm68plvqnkf5uemr0" ) ,
73
- & vc,
74
- ) ) ;
80
+ let dc_res =
81
+ DataverseCredential :: try_from ( ( mock_env_addr ( ) , message_info ( & addr ( SENDER ) , & [ ] ) , & vc) ) ;
75
82
76
83
assert ! ( dc_res. is_ok( ) ) ;
77
84
assert_eq ! ( dc_res. unwrap( ) , DataverseCredential {
78
- submitter_addr: Addr :: unchecked( "axone1072nc6egexqr2v6vpp7yxwm68plvqnkf5uemr0" ) ,
85
+ height: "12345" . to_string( ) ,
86
+ timestamp: "1571797419" . to_string( ) ,
87
+ tx_index: Some ( "3" . to_string( ) ) ,
88
+ sender: addr( SENDER ) ,
79
89
id: "https://w3id.org/axone/ontology/vnext/schema/credential/digital-service/description/72cab400-5bd6-4eb4-8605-a5ee8c1a45c9" ,
80
90
issuer: "did:key:zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3" ,
81
91
r#type: "https://w3id.org/axone/ontology/vnext/schema/credential/digital-service/description/DigitalServiceDescriptionCredential" ,
@@ -120,7 +130,8 @@ mod test {
120
130
let dataset = Dataset :: from ( owned_quads. as_slice ( ) ) ;
121
131
let vc = VerifiableCredential :: try_from ( & dataset) . unwrap ( ) ;
122
132
let dc_res = DataverseCredential :: try_from ( (
123
- Addr :: unchecked ( "axone1072nc6egexqr2v6vpp7yxwm68plvqnkf5uemr0" ) ,
133
+ mock_env_addr ( ) ,
134
+ message_info ( & addr ( SENDER ) , & [ ] ) ,
124
135
& vc,
125
136
) ) ;
126
137
0 commit comments