1
1
#[ cfg( not( feature = "library" ) ) ]
2
2
use cosmwasm_std:: entry_point;
3
- use cosmwasm_std:: { Binary , Deps , DepsMut , Env , MessageInfo , Response , StdError , StdResult } ;
3
+ use cosmwasm_std:: {
4
+ instantiate2_address, to_binary, Binary , CodeInfoResponse , Deps , DepsMut , Env , MessageInfo ,
5
+ Response , StdError , StdResult , WasmMsg ,
6
+ } ;
4
7
use cw2:: set_contract_version;
5
8
6
9
use crate :: error:: ContractError ;
7
10
use crate :: msg:: { ExecuteMsg , InstantiateMsg , QueryMsg } ;
11
+ use crate :: state:: { Dataverse , DATAVERSE } ;
8
12
9
13
// version info for migration info
10
14
const CONTRACT_NAME : & str = concat ! ( "crates.io:" , env!( "CARGO_PKG_NAME" ) ) ;
@@ -13,13 +17,42 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
13
17
#[ cfg_attr( not( feature = "library" ) , entry_point) ]
14
18
pub fn instantiate (
15
19
deps : DepsMut < ' _ > ,
16
- _env : Env ,
20
+ env : Env ,
17
21
_info : MessageInfo ,
18
- _msg : InstantiateMsg ,
22
+ msg : InstantiateMsg ,
19
23
) -> Result < Response , ContractError > {
20
24
set_contract_version ( deps. storage , CONTRACT_NAME , CONTRACT_VERSION ) ?;
21
25
22
- Err ( StdError :: generic_err ( "Not implemented" ) . into ( ) )
26
+ let creator = deps. api . addr_canonicalize ( env. contract . address . as_str ( ) ) ?;
27
+ let CodeInfoResponse { checksum, .. } = deps
28
+ . querier
29
+ . query_wasm_code_info ( msg. triplestore_config . code_id . u64 ( ) ) ?;
30
+ let salt = Binary :: from ( msg. name . as_bytes ( ) ) ;
31
+
32
+ let triplestore_address = deps
33
+ . api
34
+ . addr_humanize ( & instantiate2_address ( & checksum, & creator, & salt) ?) ?;
35
+
36
+ DATAVERSE . save (
37
+ deps. storage ,
38
+ & Dataverse {
39
+ name : msg. name . clone ( ) ,
40
+ triplestore_address : triplestore_address. to_string ( ) ,
41
+ } ,
42
+ ) ?;
43
+
44
+ Ok ( Response :: new ( )
45
+ . add_attribute ( "triplestore_address" , triplestore_address)
46
+ . add_message ( WasmMsg :: Instantiate2 {
47
+ admin : Some ( env. contract . address . to_string ( ) ) ,
48
+ code_id : msg. triplestore_config . code_id . u64 ( ) ,
49
+ label : format ! ( "{}_triplestore" , msg. name) ,
50
+ msg : to_binary ( & okp4_cognitarium:: msg:: InstantiateMsg {
51
+ limits : msg. triplestore_config . limits ,
52
+ } ) ?,
53
+ funds : vec ! [ ] ,
54
+ salt,
55
+ } ) )
23
56
}
24
57
25
58
#[ cfg_attr( not( feature = "library" ) , entry_point) ]
0 commit comments