Skip to content

Commit

Permalink
Move the OK, UNKNOWN_ERROR consts into Symbol (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Sep 10, 2022
1 parent 16402ef commit 34b8108
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion soroban-env-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub use vmcaller_checked_env::{VmCaller, VmCallerCheckedEnv};
pub use bitset::{BitSet, BitSetError};
pub use object::Object;
pub use r#static::Static;
pub use status::{Status, OK, UNKNOWN_ERROR};
pub use status::Status;
pub use symbol::{Symbol, SymbolError, SymbolIter, SymbolStr};

#[inline(always)]
Expand Down
8 changes: 5 additions & 3 deletions soroban-env-common/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ pub struct Status(RawVal);

decl_tagged_val_wrapper_methods!(Status);

pub const UNKNOWN_ERROR: Status =
unsafe { Status::from_major_minor(0, ScStatusType::UnknownError as u32) };
pub const OK: Status = unsafe { Status::from_major_minor(0, ScStatusType::Ok as u32) };
impl Status {
pub const UNKNOWN_ERROR: Status =
unsafe { Status::from_major_minor(0, ScStatusType::UnknownError as u32) };
pub const OK: Status = unsafe { Status::from_major_minor(0, ScStatusType::Ok as u32) };
}

impl Hash for Status {
#[inline(always)]
Expand Down
18 changes: 9 additions & 9 deletions soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::fmt::Debug;
use im_rc::{OrdMap, Vector};
use num_bigint::Sign;
use soroban_env_common::{
EnvVal, TryConvert, TryFromVal, TryIntoVal, VmCaller, VmCallerCheckedEnv, OK, UNKNOWN_ERROR,
EnvVal, Status, TryConvert, TryFromVal, TryIntoVal, VmCaller, VmCallerCheckedEnv,
};

use soroban_env_common::xdr::{
Expand Down Expand Up @@ -807,7 +807,7 @@ impl Host {
let topics = self.event_topics_from_host_obj(topics)?;
let data = self.from_host_val(data)?;
self.record_contract_event(ContractEventType::System, topics, data)?;
Ok(OK.into())
Ok(Status::OK.into())
}
}

Expand Down Expand Up @@ -993,7 +993,7 @@ impl VmCallerCheckedEnv for Host {
let topics = self.event_topics_from_host_obj(topics)?;
let data = self.from_host_val(data)?;
self.record_contract_event(ContractEventType::Contract, topics, data)?;
Ok(OK.into())
Ok(Status::OK.into())
}

// Notes on metering: covered by the components.
Expand Down Expand Up @@ -1115,11 +1115,11 @@ impl VmCallerCheckedEnv for Host {
{
Ok(pk2.to_raw())
} else {
Ok(UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
Ok(Status::UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
}
}
} else {
Ok(UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
Ok(Status::UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
}
})
}
Expand All @@ -1145,11 +1145,11 @@ impl VmCallerCheckedEnv for Host {
{
Ok(pk2.to_raw())
} else {
Ok(UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
Ok(Status::UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
}
}
} else {
Ok(UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
Ok(Status::UNKNOWN_ERROR.to_raw()) //FIXME: replace with the actual status code
}
})
}
Expand All @@ -1158,7 +1158,7 @@ impl VmCallerCheckedEnv for Host {
self.visit_obj(m, |hm: &HostMap| {
match hm.get_min()? {
Some((pk, pv)) => Ok(pk.to_raw()),
None => Ok(UNKNOWN_ERROR.to_raw()), //FIXME: replace with the actual status code
None => Ok(Status::UNKNOWN_ERROR.to_raw()), //FIXME: replace with the actual status code
}
})
}
Expand All @@ -1167,7 +1167,7 @@ impl VmCallerCheckedEnv for Host {
self.visit_obj(m, |hm: &HostMap| {
match hm.get_max()? {
Some((pk, pv)) => Ok(pk.to_raw()),
None => Ok(UNKNOWN_ERROR.to_raw()), //FIXME: replace with the actual status code
None => Ok(Status::UNKNOWN_ERROR.to_raw()), //FIXME: replace with the actual status code
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-host/src/test/contract_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ContractEvent, ContractEventBody, ContractEventType, ContractEventV0, ExtensionPoint, Hash,
ScMap, ScMapEntry, ScObject::Map, ScVal,
},
ContractFunctionSet, Env, EnvBase, Host, HostError, RawVal, Symbol, OK,
ContractFunctionSet, Env, EnvBase, Host, HostError, RawVal, Status, Symbol,
};
use std::rc::Rc;

Expand Down Expand Up @@ -34,7 +34,7 @@ fn contract_event() -> Result<(), HostError> {
host.register_test_contract(id, test_contract)?;
assert_eq!(
host.call(id, sym.into(), args.into()).get_payload(),
OK.to_raw().get_payload()
Status::OK.to_raw().get_payload()
);

let event_ref = ContractEvent {
Expand Down
14 changes: 7 additions & 7 deletions soroban-env-host/src/test/map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
xdr::{ScMap, ScMapEntry, ScObject, ScVal, ScVec},
CheckedEnv, Host, HostError, RawVal, RawValConvertible, Symbol, UNKNOWN_ERROR,
CheckedEnv, Host, HostError, RawVal, RawValConvertible, Status, Symbol,
};

#[test]
Expand Down Expand Up @@ -55,12 +55,12 @@ fn map_prev_and_next() -> Result<(), HostError> {
assert_eq!(
host.map_prev_key(obj.to_object(), 0_u32.into())?
.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
assert_eq!(
host.map_prev_key(obj.to_object(), 1_u32.into())?
.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
assert_eq!(
host.map_prev_key(obj.to_object(), 2_u32.into())?
Expand All @@ -83,12 +83,12 @@ fn map_prev_and_next() -> Result<(), HostError> {
assert_eq!(
host.map_next_key(obj.to_object(), 5_u32.into())?
.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
assert_eq!(
host.map_next_key(obj.to_object(), 4_u32.into())?
.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
assert_eq!(
host.map_next_key(obj.to_object(), 3_u32.into())?
Expand Down Expand Up @@ -138,7 +138,7 @@ fn map_prev_and_next_heterogeneous() -> Result<(), HostError> {
{
assert_eq!(
host.map_prev_key(test_map, 0_u32.into())?.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
assert_eq!(
host.map_prev_key(test_map, 4_u32.into())?.get_payload(),
Expand Down Expand Up @@ -183,7 +183,7 @@ fn map_prev_and_next_heterogeneous() -> Result<(), HostError> {
assert_eq!(
host.map_next_key(test_map, sym.clone().into())?
.get_payload(),
UNKNOWN_ERROR.to_raw().get_payload()
Status::UNKNOWN_ERROR.to_raw().get_payload()
);
}

Expand Down

0 comments on commit 34b8108

Please sign in to comment.