Denio
5 years ago
committed by
GitHub
9 changed files with 522 additions and 43 deletions
@ -0,0 +1,104 @@ |
|||
name: Rust |
|||
|
|||
on: [push, pull_request] |
|||
|
|||
jobs: |
|||
build: |
|||
name: Build on ${{ matrix.os }} |
|||
runs-on: ${{ matrix.os }} |
|||
strategy: |
|||
matrix: |
|||
os: [ubuntu-latest, windows-latest, macOS-latest] |
|||
|
|||
steps: |
|||
- uses: actions/checkout@v1 |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: 1.38.0 |
|||
override: true |
|||
- name: cargo fetch |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: fetch |
|||
- name: Build |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: build |
|||
args: --verbose --release --all |
|||
- name: Run tests |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: test |
|||
args: --verbose --release --all |
|||
- name: Upload ubuntu/macos |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') |
|||
with: |
|||
<<<<<<< HEAD |
|||
<<<<<<< HEAD |
|||
name: ${{ matrix.os }}-silentdragonlite-cli |
|||
path: target/release/silentdragonlite-cli |
|||
======= |
|||
name: ${{ matrix.os }}-silentdragonlite-cli |
|||
path: target/release/silentdragonlite-cli |
|||
======= |
|||
name: ${{ matrix.os }}-zecwallet-cli |
|||
path: target/release/zecwallet-cli |
|||
>>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 |
|||
- name: Upload windows |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'windows') |
|||
with: |
|||
<<<<<<< HEAD |
|||
name: ${{ matrix.os }}-silentdragonlite-cli.exe |
|||
path: target/release/silentdragonlite-cli.exe |
|||
|
|||
>>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 |
|||
======= |
|||
name: ${{ matrix.os }}-zecwallet-cli.exe |
|||
path: target/release/zecwallet-cli.exe |
|||
|
|||
>>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 |
|||
|
|||
linux_arm7: |
|||
name: Linux ARMv7 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: armv7-unknown-linux-gnueabihf |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target armv7-unknown-linux-gnueabihf |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_armv7-silentdragonlite-cli |
|||
path: target/armv7-unknown-linux-gnueabihf/release/silentdragonlite-cli |
|||
|
|||
linux_aarch64: |
|||
name: Linux ARM64 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: aarch64-unknown-linux-gnu |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target aarch64-unknown-linux-gnu |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_aarch64-silentdragonlite-cli |
|||
path: target/aarch64-unknown-linux-gnu/release/silentdragonlite-cli |
|||
|
@ -0,0 +1,80 @@ |
|||
name: Rust |
|||
|
|||
on: [push, pull_request] |
|||
|
|||
jobs: |
|||
build: |
|||
name: Build on ${{ matrix.os }} |
|||
runs-on: ${{ matrix.os }} |
|||
strategy: |
|||
matrix: |
|||
os: [ubuntu-latest, windows-latest, macOS-latest] |
|||
|
|||
steps: |
|||
- uses: actions/checkout@v1 |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: 1.38.0 |
|||
override: true |
|||
- name: cargo fetch |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: fetch |
|||
- name: Build |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: build |
|||
args: --verbose --release --all |
|||
- name: Run tests |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: test |
|||
args: --verbose --release --all |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: ${{ matrix.os }}-zecwallet-cli |
|||
path: target/release/zecwallet-cli |
|||
|
|||
linux_arm7: |
|||
name: Linux ARMv7 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: armv7-unknown-linux-gnueabihf |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target armv7-unknown-linux-gnueabihf |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_armv7-zecwallet-cli |
|||
path: target/armv7-unknown-linux-gnueabihf/release/zecwallet-cli |
|||
|
|||
linux_aarch64: |
|||
name: Linux ARM64 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: aarch64-unknown-linux-gnu |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target aarch64-unknown-linux-gnu |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_aarch64-zecwallet-cli |
|||
path: target/aarch64-unknown-linux-gnu/release/zecwallet-cli |
|||
|
@ -0,0 +1,93 @@ |
|||
name: Rust |
|||
|
|||
on: [push, pull_request] |
|||
|
|||
jobs: |
|||
build: |
|||
name: Build on ${{ matrix.os }} |
|||
runs-on: ${{ matrix.os }} |
|||
strategy: |
|||
matrix: |
|||
os: [ubuntu-latest, windows-latest, macOS-latest] |
|||
|
|||
steps: |
|||
- uses: actions/checkout@v1 |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: 1.38.0 |
|||
override: true |
|||
- name: cargo fetch |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: fetch |
|||
- name: Build |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: build |
|||
args: --verbose --release --all |
|||
- name: Run tests |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: test |
|||
args: --verbose --release --all |
|||
- name: Upload ubuntu/macos |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') |
|||
with: |
|||
<<<<<<< HEAD |
|||
name: ${{ matrix.os }}-silentdragonlite-cli |
|||
path: target/release/silentdragonlite-cli |
|||
======= |
|||
name: ${{ matrix.os }}-silentdragonlite-cli |
|||
path: target/release/silentdragonlite-cli |
|||
- name: Upload windows |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'windows') |
|||
with: |
|||
name: ${{ matrix.os }}-silentdragonlite-cli.exe |
|||
path: target/release/silentdragonlite-cli.exe |
|||
|
|||
>>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 |
|||
|
|||
linux_arm7: |
|||
name: Linux ARMv7 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: armv7-unknown-linux-gnueabihf |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target armv7-unknown-linux-gnueabihf |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_armv7-silentdragonlite-cli |
|||
path: target/armv7-unknown-linux-gnueabihf/release/silentdragonlite-cli |
|||
|
|||
linux_aarch64: |
|||
name: Linux ARM64 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: aarch64-unknown-linux-gnu |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target aarch64-unknown-linux-gnu |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_aarch64-silentdragonlite-cli |
|||
path: target/aarch64-unknown-linux-gnu/release/silentdragonlite-cli |
|||
|
@ -0,0 +1,88 @@ |
|||
name: Rust |
|||
|
|||
on: [push, pull_request] |
|||
|
|||
jobs: |
|||
build: |
|||
name: Build on ${{ matrix.os }} |
|||
runs-on: ${{ matrix.os }} |
|||
strategy: |
|||
matrix: |
|||
os: [ubuntu-latest, windows-latest, macOS-latest] |
|||
|
|||
steps: |
|||
- uses: actions/checkout@v1 |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: 1.38.0 |
|||
override: true |
|||
- name: cargo fetch |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: fetch |
|||
- name: Build |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: build |
|||
args: --verbose --release --all |
|||
- name: Run tests |
|||
uses: actions-rs/cargo@v1 |
|||
with: |
|||
command: test |
|||
args: --verbose --release --all |
|||
- name: Upload ubuntu/macos |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') |
|||
with: |
|||
name: ${{ matrix.os }}-zecwallet-cli |
|||
path: target/release/zecwallet-cli |
|||
- name: Upload windows |
|||
uses: actions/upload-artifact@v1 |
|||
if: contains(matrix.os, 'windows') |
|||
with: |
|||
name: ${{ matrix.os }}-zecwallet-cli.exe |
|||
path: target/release/zecwallet-cli.exe |
|||
|
|||
|
|||
linux_arm7: |
|||
name: Linux ARMv7 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: armv7-unknown-linux-gnueabihf |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target armv7-unknown-linux-gnueabihf |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_armv7-zecwallet-cli |
|||
path: target/armv7-unknown-linux-gnueabihf/release/zecwallet-cli |
|||
|
|||
linux_aarch64: |
|||
name: Linux ARM64 |
|||
runs-on: ubuntu-latest |
|||
steps: |
|||
- uses: actions/checkout@master |
|||
- uses: actions-rs/toolchain@v1 |
|||
with: |
|||
toolchain: stable |
|||
target: aarch64-unknown-linux-gnu |
|||
override: true |
|||
- uses: actions-rs/cargo@v1 |
|||
with: |
|||
use-cross: true |
|||
command: build |
|||
args: --release --target aarch64-unknown-linux-gnu |
|||
- name: Upload |
|||
uses: actions/upload-artifact@v1 |
|||
with: |
|||
name: linux_aarch64-zecwallet-cli |
|||
path: target/aarch64-unknown-linux-gnu/release/zecwallet-cli |
|||
|
@ -0,0 +1,90 @@ |
|||
pub fn get_closest_checkpoint(chain_name: &str, height: u64) -> Option<(u64, &'static str, &'static str)> { |
|||
match chain_name { |
|||
"test" => get_test_checkpoint(height), |
|||
"main" => get_main_checkpoint(height), |
|||
_ => None |
|||
} |
|||
} |
|||
|
|||
fn get_test_checkpoint(height: u64) -> Option<(u64, &'static str, &'static str)> { |
|||
let checkpoints: Vec<(u64, &str, &str)> = vec![ |
|||
(105942, "", |
|||
"" |
|||
), |
|||
(105943, "", |
|||
"" |
|||
) |
|||
]; |
|||
|
|||
find_checkpoint(height, checkpoints) |
|||
} |
|||
|
|||
|
|||
fn get_main_checkpoint(height: u64) -> Option<(u64, &'static str, &'static str)> { |
|||
let checkpoints: Vec<(u64, &str, &str)> = vec![ |
|||
(105942, "00000001c0199f329ee03379bf1387856dbab23765da508bf9b9d8d544f212c0", |
|||
"" |
|||
) |
|||
]; |
|||
|
|||
find_checkpoint(height, checkpoints) |
|||
} |
|||
|
|||
fn find_checkpoint(height: u64, chkpts: Vec<(u64, &'static str, &'static str)>) -> Option<(u64, &'static str, &'static str)> { |
|||
// Find the closest checkpoint
|
|||
let mut heights = chkpts.iter().map(|(h, _, _)| *h as u64).collect::<Vec<_>>(); |
|||
heights.sort(); |
|||
|
|||
match get_first_lower_than(height, heights) { |
|||
Some(closest_height) => { |
|||
chkpts.iter().find(|(h, _, _)| *h == closest_height).map(|t| *t) |
|||
}, |
|||
None => None |
|||
} |
|||
} |
|||
|
|||
fn get_first_lower_than(height: u64, heights: Vec<u64>) -> Option<u64> { |
|||
// If it's before the first checkpoint, return None.
|
|||
if heights.len() == 0 || height < heights[0] { |
|||
return None; |
|||
} |
|||
|
|||
for (i, h) in heights.iter().enumerate() { |
|||
if height < *h { |
|||
return Some(heights[i-1]); |
|||
} |
|||
} |
|||
|
|||
return Some(*heights.last().unwrap()); |
|||
} |
|||
|
|||
#[cfg(test)] |
|||
pub mod tests { |
|||
use super::*; |
|||
|
|||
#[test] |
|||
fn test_lower_than() { |
|||
assert_eq!(get_first_lower_than( 9, vec![10, 30, 40]), None); |
|||
assert_eq!(get_first_lower_than(10, vec![10, 30, 40]).unwrap(), 10); |
|||
assert_eq!(get_first_lower_than(11, vec![10, 30, 40]).unwrap(), 10); |
|||
assert_eq!(get_first_lower_than(29, vec![10, 30, 40]).unwrap(), 10); |
|||
assert_eq!(get_first_lower_than(30, vec![10, 30, 40]).unwrap(), 30); |
|||
assert_eq!(get_first_lower_than(40, vec![10, 30, 40]).unwrap(), 40); |
|||
assert_eq!(get_first_lower_than(41, vec![10, 30, 40]).unwrap(), 40); |
|||
assert_eq!(get_first_lower_than(99, vec![10, 30, 40]).unwrap(), 40); |
|||
} |
|||
|
|||
#[test] |
|||
fn test_checkpoints() { |
|||
assert_eq!(get_test_checkpoint(990000), None); |
|||
assert_eq!(get_test_checkpoint(100000).unwrap().0, 100000); |
|||
assert_eq!(get_test_checkpoint(110000).unwrap().0, 100000); |
|||
assert_eq!(get_test_checkpoint(111000).unwrap().0, 1100000); |
|||
assert_eq!(get_test_checkpoint(112000).unwrap().0, 1100000); |
|||
|
|||
assert_eq!(get_main_checkpoint(990000), None); |
|||
assert_eq!(get_main_checkpoint(110000).unwrap().0, 110000); |
|||
assert_eq!(get_main_checkpoint(111000).unwrap().0, 110000); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue