Skip to content

Commit

Permalink
Add whitelist upgrade hasher
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <[email protected]>
  • Loading branch information
AurevoirXavier committed Mar 11, 2024
1 parent 3b90dfd commit 76d60eb
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Fetch latest code
uses: actions/checkout@v4
- name: Build
run: cd whitelist-upgrade-hasher && cargo b -r --locked
- name: Compress
run: |
mv whitelist-upgrade-hasher/target/release/wuh .
zstd --ultra -22 -o wuh.zst wuh
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: wuh
path: wuh.zst
retention-days: 1

release:
name: Release
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Hash
run: |
mkdir -p artifacts
mv wuh* artifacts/
cd artifacts
sha256sum * | tee ../SHA256
md5sum * | tee ../MD5
mv ../SHA256 .
mv ../MD5 .
- name: Publish
uses: softprops/action-gh-release@v1
with:
discussion_category_name: Announcements
generate_release_notes: true
files: artifacts/*
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
.idea
.vscode

# Cache
build
# Package manager
## Cargo
target
48 changes: 48 additions & 0 deletions whitelist-upgrade-hasher/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions whitelist-upgrade-hasher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
edition = "2021"
name = "wuh"
version = "0.1.0"

[dependencies]
# crates.io
array-bytes = { version = "6.2" }
blake2-rfc = { version = "0.2" }
35 changes: 35 additions & 0 deletions whitelist-upgrade-hasher/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// std
use std::{env, error::Error, fs};
// crates.io
use blake2_rfc::blake2b;

fn main() -> Result<(), Box<dyn Error>> {
let args = env::args().collect::<Vec<_>>();
let p = args.get(1).expect("missing WASM file path");
let whitelist_pi = args
.get(2)
.expect("missing whitelist pallet index")
.trim_start_matches("0x");
let parachain_system_pi = args
.get(3)
.expect("missing parachain system pallet index")
.trim_start_matches("0x");
let w = fs::read(p)?;
let h1 = blake2b::blake2b(32, &[], &w);
let h1 = h1.as_bytes();
let mut c = vec![
u8::from_str_radix(whitelist_pi, 16)?,
0x03,
u8::from_str_radix(parachain_system_pi, 16)?,
0x02,
];

c.extend_from_slice(&h1);
c.push(0x01);

let h2 = blake2b::blake2b(32, &[], &c);

println!("{}", array_bytes::bytes2hex("0x", h2));

Ok(())
}

0 comments on commit 76d60eb

Please sign in to comment.