Skip to content

Commit

Permalink
Tidy + bumpt to v1.0 (#19)
Browse files Browse the repository at this point in the history
* Updated readme to reflect release process

* one of the benches was measuring a bit more than it should have been.

(nice catch clippy)

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
gilescope and bkchr authored Oct 8, 2021
1 parent 4b6bb1b commit e2e23d7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# An auto defined `clippy` feature was introduced,
# but it was found to clash with user defined features,
# so was renamed to `cargo-clippy`.
#
# If you want standard clippy run:
# RUSTFLAGS= cargo clippy
[target.'cfg(feature = "cargo-clippy")']
rustflags = ["-Aclippy::stable_sort_primitive"]
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[package]
name = "ss58-registry"
authors = [
"Parity Technologies <[email protected]>",
]
version = "0.0.1"
authors = ["Parity Technologies <[email protected]>"]
version = "1.0.0"
edition = "2018"
description = "Registry of known SS58 address types"
license = "Apache-2.0"
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# SS58 Registry

List of wellknown [SS58](https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)) account types as an enum.
[![GitHub license](https://img.shields.io/badge/license-Apache2-green)](#LICENSE) [![GitLab Status](https://gitlab.parity.io/parity/ss58-registry/badges/master/pipeline.svg)](https://gitlab.parity.io/parity/ss58-registry/pipelines)

This is driven from the [json data file](src/ss58-registry.json) which contains entries like this:
A list of known [SS58](https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)) account types as an enum.

This is driven from the [json data file](ss58-registry.json) which contains entries like this:

```js
{
Expand All @@ -20,7 +22,19 @@ This is driven from the [json data file](src/ss58-registry.json) which contains

## Process:

If you wish to add an additional account type then please raise a pull request adding to the json file.
1. Fork and clone this repo

2. Add an additional account type to `ss58-registry.json` (contiguous prefixes are better)

3. Bump the minor (middle) version number of the `Cargo.toml` by running:
```
cargo install cargo-bump && cargo bump minor
```
4. git stage, commit, push and then raise a pull request

5. Once the PR has landed, one of the admins can
[create a new release](https://github.com/paritytech/ss58-registry/releases/new).
This will release the new version to [crates.io](https://crates.io/crates/ss58-registry)

## Licensing:

Expand Down
16 changes: 8 additions & 8 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
extern crate test;
use std::hint::black_box;

use ss58_registry;
use test::Bencher;
static BENCH_SIZE: u16 = 100;
use ss58_registry::{from_address_format, Ss58AddressFormat, Ss58AddressFormatRegistry};
Expand All @@ -21,9 +20,9 @@ fn new(b: &mut Bencher) {
#[bench]
fn is_custom(b: &mut Bencher) {
let v: Vec<Ss58AddressFormat> =
(0..BENCH_SIZE).map(|i| ss58_registry::Ss58AddressFormat::custom(i)).collect();
(0..BENCH_SIZE).map(ss58_registry::Ss58AddressFormat::custom).collect();
b.iter(|| {
for i in v.iter() {
for i in &v {
let _ = i.is_custom();
}
})
Expand All @@ -32,9 +31,9 @@ fn is_custom(b: &mut Bencher) {
#[bench]
fn is_reserved(b: &mut Bencher) {
let v: Vec<Ss58AddressFormat> =
(0..BENCH_SIZE).map(|i| ss58_registry::Ss58AddressFormat::custom(i)).collect();
(0..BENCH_SIZE).map(ss58_registry::Ss58AddressFormat::custom).collect();
b.iter(|| {
for i in v.iter() {
for i in &v {
let _ = i.is_reserved();
}
})
Expand All @@ -43,9 +42,9 @@ fn is_reserved(b: &mut Bencher) {
#[bench]
fn to_string(b: &mut Bencher) {
let v: Vec<Ss58AddressFormat> =
(0..BENCH_SIZE).map(|i| ss58_registry::Ss58AddressFormat::custom(i)).collect();
(0..BENCH_SIZE).map(ss58_registry::Ss58AddressFormat::custom).collect();
b.iter(|| {
for i in v.iter() {
for i in &v {
let _ = i.to_string();
}
})
Expand All @@ -65,7 +64,8 @@ fn known_to_prefix(b: &mut Bencher) {
fn name_to_enum(b: &mut Bencher) {
b.iter(|| {
for name in ss58_registry::Ss58AddressFormat::all_names() {
let _: Ss58AddressFormatRegistry = (*name).try_into().expect(&format!("{}", name));
let _: Ss58AddressFormatRegistry =
(*name).try_into().unwrap_or_else(|_| panic!("{}", name));
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn main() {

let dest_path = Path::new(&out_dir).join("account_type_enum.rs");
if let Err(err) = fs::write(&dest_path, result) {
eprintln!("failed to write generated code to {:?}: {}", &dest_path, err);
eprintln!("failed to write generated code to {}: {}", &dest_path.display(), err);
std::process::exit(-1);
}
}
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
use_field_init_shorthand = true
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/account_type_enum.rs"));
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct ParseError;

/// A custom address format. See also Ss58AddressFormatRegistry
/// A custom address format. See also [`Ss58AddressFormatRegistry`]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Ss58AddressFormat {
prefix: u16,
Expand All @@ -43,6 +43,7 @@ impl Ss58AddressFormat {
pub fn all_names() -> &'static [&'static str] {
&ALL_SS58_ADDRESS_FORMAT_NAMES
}

/// All known address formats.
pub fn all() -> &'static [Ss58AddressFormatRegistry] {
&ALL_SS58_ADDRESS_FORMATS
Expand Down Expand Up @@ -89,12 +90,12 @@ impl TryFrom<Ss58AddressFormat> for Ss58AddressFormatRegistry {
}
}

/// const function to convert Ss58AddressFormat to u16
/// const function to convert [`Ss58AddressFormat`] to u16
pub const fn from_address_format(x: Ss58AddressFormat) -> u16 {
x.prefix
}

/// const function to convert Ss58AddressFormat to u16
/// const function to convert [`Ss58AddressFormat`] to u16
pub const fn from_known_address_format(x: Ss58AddressFormatRegistry) -> u16 {
x as u16
}
Expand All @@ -108,7 +109,7 @@ impl From<Ss58AddressFormatRegistry> for Ss58AddressFormat {
impl From<u8> for Ss58AddressFormat {
#[inline]
fn from(x: u8) -> Ss58AddressFormat {
Ss58AddressFormat::from(x as u16)
Ss58AddressFormat::from(u16::from(x))
}
}

Expand Down Expand Up @@ -198,7 +199,7 @@ mod tests {
#[test]
fn enum_to_name_and_back() {
for name in Ss58AddressFormat::all_names() {
let val: Ss58AddressFormatRegistry = (*name).try_into().expect(&format!("{}", name));
let val: Ss58AddressFormatRegistry = (*name).try_into().expect(name);
assert_eq!(name, &val.to_string());
}
}
Expand Down

0 comments on commit e2e23d7

Please sign in to comment.