-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathcontract.rs
63 lines (59 loc) · 2.05 KB
/
contract.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response};
use ics008_wasm_client::{
define_cosmwasm_light_client_contract,
storage_utils::{save_proto_client_state, save_proto_consensus_state},
InstantiateMsg,
};
use protos::ibc::lightclients::wasm::v1::{
ClientState as ProtoClientState, ConsensusState as ProtoConsensusState,
};
use unionlabs::{
ibc::{core::client::height::Height, lightclients::ethereum::client_state::ClientState},
TryFromProto,
};
use crate::{client::EthereumLightClient, errors::Error};
// NOTE(aeryz): the fact that the host module forces the light clients to store and use the wasm wrapping
// in the client state makes this code kinda messy. But this is going to be resolved in the future versions
// of IBC (probably v9). When that feature is implemented, we can move this to the ics008 macro.
#[entry_point]
pub fn instantiate(
mut deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, Error> {
let client_state = ClientState::try_from_proto_bytes(&msg.client_state).map_err(|e| {
Error::DecodeFromProto {
reason: format!("{:?}", e),
}
})?;
save_proto_consensus_state(
deps.branch(),
ProtoConsensusState {
data: msg.consensus_state.into(),
},
&Height {
revision_number: 0,
revision_height: client_state.latest_slot,
},
);
save_proto_client_state(
deps,
ProtoClientState {
data: msg.client_state.into(),
checksum: msg.checksum.into(),
latest_height: Some(
Height {
revision_number: 0,
revision_height: client_state.latest_slot,
}
.into(),
),
},
);
Ok(Response::default())
}
#[cfg(feature = "mainnet")]
define_cosmwasm_light_client_contract!(EthereumLightClient, EthereumMainnet);
#[cfg(feature = "minimal")]
define_cosmwasm_light_client_contract!(EthereumLightClient, EthereumMinimal);