Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 26, 2024
1 parent ed1d78f commit 223ca63
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
6 changes: 3 additions & 3 deletions crates/cvm-runtime/src/outpost/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ pub struct GetConfigResponse {
pub network_assets: Vec<NetworkAssetItem>,
}

// impl GetConfigResponse {
// pub fn
// }
impl GetConfigResponse {
pub fn get_network_for_asset()
}
10 changes: 10 additions & 0 deletions crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ pub type CvmProgram = crate::Program<Vec<CvmInstruction>>;

pub type CvmSpawnRef<'a> = (&'a CvmProgram, &'a CvmFundsFilter);


impl Default for CvmProgram {
fn default() -> Self {
Self {
tag: vec![0],
instructions: vec![],
}
}
}

impl CvmProgram {
pub fn new(instructions: Vec<CvmInstruction>) -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions crates/cvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cosmwasm-schema = { workspace = true, optional = true }
cosmwasm-std = { workspace = true, no-default-features = true, optional = true}
cw-storage-plus = { workspace = true, optional = true}

# num = { workspace = true, optional = false}
parity-scale-codec = { workspace = true, optional = true }
prost = { workspace = true, features = ["prost-derive"] }
scale-info = { workspace = true, features = ["derive"], optional = true }
Expand Down
43 changes: 43 additions & 0 deletions crates/cvm/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ pub struct AssetId(
pub Displayed<u128>,
);

impl FromStr for AssetId {
type Err = <u128 as FromStr>::Err;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(AssetId(Displayed(u128::from_str(s)?)))
}
}

impl core::fmt::Display for AssetId {
fn fmt(&self, fmtr: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0 .0.fmt(fmtr)
Expand Down Expand Up @@ -94,6 +102,25 @@ pub struct Amount {
pub slope: Displayed<u64>,
}

impl TryFrom<i64> for Amount {
type Error = ArithmeticError;

fn try_from(value: i64) -> Result<Self, Self::Error> {
if value < 0 {
return Err(ArithmeticError::Underflow);
}
Ok(Amount::absolute(value as u64 as u128))
}
}

impl FromStr for Amount {
type Err = <u128 as FromStr>::Err;

fn from_str(s: &str) -> Result<Self, Self::Err> {
u128::from_str(s).map(Amount::absolute)
}
}

/// analog of `Coin`s in IBC/CW, but with CVM numeric id and amount
/// requires registry to map id back and forth as needed
#[cfg_attr(
Expand Down Expand Up @@ -132,8 +159,24 @@ impl From<(u64, u64)> for Amount {
}

impl Amount {


pub const MAX_PARTS: u64 = 1_000_000_000_000_000_000;

pub fn one() -> Self{
Self::absolute(1)
}

pub fn try_floor_f64(value: f64) -> Result<Self, ArithmeticError> {
if value < 0.0 || value.is_nan() {
Err(ArithmeticError::Underflow)
} else if value > u128::MAX as f64 {
Err(ArithmeticError::Underflow)
} else {
Ok((value as u128).into())
}
}

pub const fn new(intercept: u128, slope: u64) -> Self {
Self {
intercept: Displayed(intercept),
Expand Down
18 changes: 0 additions & 18 deletions flake.lock

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

3 changes: 1 addition & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@
cosmwasm-json-schema-ts
mantis-blackbox
pyscipopt-latest
maturin-latest

maturin-latest
;
all =
pkgs.linkFarmFromDrvs "all"
Expand Down

0 comments on commit 223ca63

Please sign in to comment.