jk_cosmwasm_std/types.rs
1use serde::{Deserialize, Serialize};
2
3use crate::addresses::Addr;
4use crate::coins::Coin;
5use crate::timestamp::Timestamp;
6
7#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
8pub struct Env {
9 pub block: BlockInfo,
10 pub contract: ContractInfo,
11}
12
13#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
14pub struct BlockInfo {
15 /// The height of a block is the number of blocks preceding it in the blockchain.
16 pub height: u64,
17 /// Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).
18 ///
19 /// The source of this is the [BFT Time in Tendermint](https://docs.tendermint.com/master/spec/consensus/bft-time.html),
20 /// which has the same nanosecond precision as the `Timestamp` type.
21 ///
22 /// # Examples
23 ///
24 /// Using chrono:
25 ///
26 /// ```
27 /// # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp};
28 /// # let env = Env {
29 /// # block: BlockInfo {
30 /// # height: 12_345,
31 /// # time: Timestamp::from_nanos(1_571_797_419_879_305_533),
32 /// # chain_id: "cosmos-testnet-14002".to_string(),
33 /// # },
34 /// # contract: ContractInfo {
35 /// # address: Addr::unchecked("contract"),
36 /// # },
37 /// # };
38 /// # extern crate chrono;
39 /// use chrono::NaiveDateTime;
40 /// let seconds = env.block.time.seconds();
41 /// let nsecs = env.block.time.subsec_nanos();
42 /// let dt = NaiveDateTime::from_timestamp(seconds as i64, nsecs as u32);
43 /// ```
44 ///
45 /// Creating a simple millisecond-precision timestamp (as used in JavaScript):
46 ///
47 /// ```
48 /// # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp};
49 /// # let env = Env {
50 /// # block: BlockInfo {
51 /// # height: 12_345,
52 /// # time: Timestamp::from_nanos(1_571_797_419_879_305_533),
53 /// # chain_id: "cosmos-testnet-14002".to_string(),
54 /// # },
55 /// # contract: ContractInfo {
56 /// # address: Addr::unchecked("contract"),
57 /// # },
58 /// # };
59 /// let millis = env.block.time.nanos() / 1_000_000;
60 /// ```
61 pub time: Timestamp,
62 pub chain_id: String,
63}
64
65/// Additional information from [MsgInstantiateContract] and [MsgExecuteContract], which is passed
66/// along with the contract execution message into the `instantiate` and `execute` entry points.
67///
68/// It contains the essential info for authorization - identity of the call, and payment.
69///
70/// [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.15.0/x/wasm/internal/types/tx.proto#L47-L61
71/// [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.15.0/x/wasm/internal/types/tx.proto#L68-L78
72#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
73pub struct MessageInfo {
74 /// The `sender` field from `MsgInstantiateContract` and `MsgExecuteContract`.
75 /// You can think of this as the address that initiated the action (i.e. the message). What that
76 /// means exactly heavily depends on the application.
77 ///
78 /// The x/wasm module ensures that the sender address signed the transaction or
79 /// is otherwise authorized to send the message.
80 ///
81 /// Additional signers of the transaction that are either needed for other messages or contain unnecessary
82 /// signatures are not propagated into the contract.
83 pub sender: Addr,
84 /// The funds that are sent to the contract as part of `MsgInstantiateContract`
85 /// or `MsgExecuteContract`. The transfer is processed in bank before the contract
86 /// is executed such that the new balance is visible during contract execution.
87 pub funds: Vec<Coin>,
88}
89
90#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
91pub struct ContractInfo {
92 pub address: Addr,
93}