Skip to content

Commit 2342e41

Browse files
committed
Merge remote-tracking branch 'origin/master' into transfer-history-total-count
2 parents 1392418 + 238d76a commit 2342e41

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

schema/query_answer.json

+16
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@
219219
"sender"
220220
],
221221
"properties": {
222+
"block_height": {
223+
"type": [
224+
"integer",
225+
"null"
226+
],
227+
"format": "uint64",
228+
"minimum": 0.0
229+
},
222230
"coins": {
223231
"$ref": "#/definitions/Coin"
224232
},
@@ -235,6 +243,14 @@
235243
},
236244
"sender": {
237245
"$ref": "#/definitions/HumanAddr"
246+
},
247+
"timestamp": {
248+
"type": [
249+
"integer",
250+
"null"
251+
],
252+
"format": "uint64",
253+
"minimum": 0.0
238254
}
239255
}
240256
},

src/contract.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
6161
return Err(StdError::generic_err("Decimals must not exceed 18"));
6262
}
6363

64-
let admin = msg.admin.unwrap_or_else(|| env.message.sender);
64+
let admin = msg.admin.unwrap_or(env.message.sender);
6565

6666
let prng_seed_hashed = sha_256(&msg.prng_seed.0);
6767

@@ -559,7 +559,7 @@ fn try_transfer_impl<S: Storage, A: Api, Q: Querier>(
559559
&recipient_address,
560560
amount,
561561
symbol,
562-
env.block.time,
562+
env.block
563563
)?;
564564

565565
Ok(())
@@ -707,7 +707,7 @@ fn try_transfer_from_impl<S: Storage, A: Api, Q: Querier>(
707707
&recipient_address,
708708
amount,
709709
symbol,
710-
env.block.time,
710+
env.block,
711711
)?;
712712

713713
Ok(())
@@ -1052,14 +1052,14 @@ fn check_if_admin<S: Storage>(config: &Config<S>, account: &HumanAddr) -> StdRes
10521052

10531053
fn is_valid_name(name: &str) -> bool {
10541054
let len = name.len();
1055-
3 <= len && len <= 30
1055+
(3..=30).contains(&len)
10561056
}
10571057

10581058
fn is_valid_symbol(symbol: &str) -> bool {
10591059
let len = symbol.len();
1060-
let len_is_valid = 3 <= len && len <= 6;
1060+
let len_is_valid = (3..=6).contains(&len);
10611061

1062-
len_is_valid && symbol.bytes().all(|byte| b'A' <= byte && byte <= b'Z')
1062+
len_is_valid && symbol.bytes().all(|byte| (b'A'..=b'Z').contains(&byte))
10631063
}
10641064

10651065
// pub fn migrate<S: Storage, A: Api, Q: Querier>(

src/msg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::field_reassign_with_default)] // This is triggered in `#[derive(JsonSchema)]`
2+
13
use schemars::JsonSchema;
24
use serde::{Deserialize, Serialize};
35

src/receiver.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::field_reassign_with_default)] // This is triggered in `#[derive(JsonSchema)]`
2+
13
use schemars::JsonSchema;
24
use serde::{Deserialize, Serialize};
35

src/state.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ pub struct Tx {
4141
pub sender: HumanAddr,
4242
pub receiver: HumanAddr,
4343
pub coins: Coin,
44-
pub timestamp: u64,
44+
// The timestamp and block height are optional so that the JSON schema
45+
// reflects that some SNIP-20 contracts may not include this info.
46+
pub timestamp: Option<u64>,
47+
pub block_height: Option<u64>,
4548
}
4649

4750
impl Tx {
@@ -52,7 +55,8 @@ impl Tx {
5255
sender: api.canonical_address(&self.sender)?,
5356
receiver: api.canonical_address(&self.receiver)?,
5457
coins: self.coins,
55-
timestamp: self.timestamp,
58+
timestamp: self.timestamp.unwrap_or(0),
59+
block_height: self.block_height.unwrap_or(0),
5660
};
5761
Ok(tx)
5862
}
@@ -66,6 +70,7 @@ pub struct StoredTx {
6670
pub receiver: CanonicalAddr,
6771
pub coins: Coin,
6872
pub timestamp: u64,
73+
pub block_height: u64,
6974
}
7075

7176
impl StoredTx {
@@ -76,7 +81,8 @@ impl StoredTx {
7681
sender: api.human_address(&self.sender)?,
7782
receiver: api.human_address(&self.receiver)?,
7883
coins: self.coins,
79-
timestamp: self.timestamp,
84+
timestamp: Some(self.timestamp),
85+
block_height: Some(self.block_height),
8086
};
8187
Ok(tx)
8288
}
@@ -89,7 +95,7 @@ pub fn store_transfer<S: Storage>(
8995
receiver: &CanonicalAddr,
9096
amount: Uint128,
9197
denom: String,
92-
timestamp: u64,
98+
block: cosmwasm_std::BlockInfo,
9399
) -> StdResult<()> {
94100
let mut config = Config::from_storage(store);
95101
let id = config.tx_count() + 1;
@@ -102,7 +108,8 @@ pub fn store_transfer<S: Storage>(
102108
sender: sender.clone(),
103109
receiver: receiver.clone(),
104110
coins,
105-
timestamp,
111+
timestamp: block.time,
112+
block_height: block.height,
106113
};
107114

108115
if owner != sender {

0 commit comments

Comments
 (0)