Skip to content

Commit 84ecdd3

Browse files
authored
Merge pull request CosmWasm#1234 from CosmWasm/fix-deadlink-bft-time
Fix deadlink to BFT time
2 parents d8e79f9 + 88294ec commit 84ecdd3

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

devtools/deadlinks.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _filter(elem):
2525
# Create a list containing all links
2626
links = [link.get("href") for link in filter(_filter, soup.find_all("a", href=True))]
2727
if links:
28-
print(links)
28+
print("Checking", links)
2929

3030
# Initialize list for broken links.
3131
broken_links = []
@@ -50,17 +50,19 @@ def _validate_url(url):
5050
def check_project(project):
5151
project_path = doc_folder + project
5252
broken_links = {}
53+
html_file_found = False
5354

5455
for dirName, subdirList, fileList in os.walk(project_path):
5556
for fname in fileList:
5657
if fname.endswith(".html"):
58+
html_file_found = True
5759
fpath = dirName + '/' + fname
5860

5961
file_broken_links = get_broken_links(fpath)
6062
if file_broken_links:
6163
broken_links[fpath] = file_broken_links
6264

63-
return broken_links
65+
return html_file_found, broken_links
6466

6567
# main
6668

@@ -76,7 +78,10 @@ def check_project(project):
7678
]
7779

7880
for project in projects:
79-
broken_links.update(check_project(project))
81+
html_file_found, broken = check_project(project)
82+
if not html_file_found:
83+
print("No .html file found in project " + project + ". Did you generate the docs?")
84+
broken_links.update(broken)
8085

8186
if len(broken_links) > 0:
8287
print("Dead links found!")

packages/std/examples/schema.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use std::env::current_dir;
22
use std::fs::create_dir_all;
33

44
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};
5-
use cosmwasm_std::{CosmosMsg, Empty, QueryRequest, Timestamp};
5+
use cosmwasm_std::{BlockInfo, CosmosMsg, Empty, QueryRequest, Timestamp};
66

77
fn main() {
88
let mut out_dir = current_dir().unwrap();
99
out_dir.push("schema");
1010
create_dir_all(&out_dir).unwrap();
1111
remove_schemas(&out_dir).unwrap();
1212

13+
export_schema(&schema_for!(BlockInfo), &out_dir);
1314
export_schema(&schema_for!(Timestamp), &out_dir);
1415
export_schema_with_title(&schema_for!(CosmosMsg), &out_dir, "CosmosMsg");
1516
export_schema_with_title(&schema_for!(QueryRequest<Empty>), &out_dir, "QueryRequest");

packages/std/schema/block_info.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "BlockInfo",
4+
"type": "object",
5+
"required": [
6+
"chain_id",
7+
"height",
8+
"time"
9+
],
10+
"properties": {
11+
"chain_id": {
12+
"type": "string"
13+
},
14+
"height": {
15+
"description": "The height of a block is the number of blocks preceding it in the blockchain.",
16+
"type": "integer",
17+
"format": "uint64",
18+
"minimum": 0.0
19+
},
20+
"time": {
21+
"description": "Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).\n\nThe source of this is the [BFT Time in Tendermint](https://github.com/tendermint/tendermint/blob/58dc1726/spec/consensus/bft-time.md), which has the same nanosecond precision as the `Timestamp` type.\n\n# Examples\n\nUsing chrono:\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; # extern crate chrono; use chrono::NaiveDateTime; let seconds = env.block.time.seconds(); let nsecs = env.block.time.subsec_nanos(); let dt = NaiveDateTime::from_timestamp(seconds as i64, nsecs as u32); ```\n\nCreating a simple millisecond-precision timestamp (as used in JavaScript):\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; let millis = env.block.time.nanos() / 1_000_000; ```",
22+
"allOf": [
23+
{
24+
"$ref": "#/definitions/Timestamp"
25+
}
26+
]
27+
}
28+
},
29+
"definitions": {
30+
"Timestamp": {
31+
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
32+
"allOf": [
33+
{
34+
"$ref": "#/definitions/Uint64"
35+
}
36+
]
37+
},
38+
"Uint64": {
39+
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
40+
"type": "string"
41+
}
42+
}
43+
}

packages/std/src/types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use schemars::JsonSchema;
12
use serde::{Deserialize, Serialize};
23

34
use crate::addresses::Addr;
@@ -25,13 +26,13 @@ pub struct TransactionInfo {
2526
pub index: u32,
2627
}
2728

28-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
29+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2930
pub struct BlockInfo {
3031
/// The height of a block is the number of blocks preceding it in the blockchain.
3132
pub height: u64,
3233
/// Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).
3334
///
34-
/// The source of this is the [BFT Time in Tendermint](https://docs.tendermint.com/master/spec/consensus/bft-time.html),
35+
/// The source of this is the [BFT Time in Tendermint](https://github.com/tendermint/tendermint/blob/58dc1726/spec/consensus/bft-time.md),
3536
/// which has the same nanosecond precision as the `Timestamp` type.
3637
///
3738
/// # Examples

0 commit comments

Comments
 (0)