Skip to content

Commit

Permalink
Rename Binary=>Bytes, FixedBinary=>BytesN (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Aug 2, 2022
1 parent d18267b commit e351553
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 201 deletions.
4 changes: 2 additions & 2 deletions macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub fn derive_fn(

pub fn invoke(
e: &soroban_sdk::Env,
contract_id: &soroban_sdk::FixedBinary<32>,
contract_id: &soroban_sdk::BytesN<32>,
#(#invoke_args),*
) #output {
use soroban_sdk::{EnvVal, IntoVal, Symbol, Vec};
Expand All @@ -218,7 +218,7 @@ pub fn derive_fn(
#[cfg_attr(feature = "docs", doc(cfg(feature = "testutils")))]
pub fn invoke_xdr(
e: &soroban_sdk::Env,
contract_id: &soroban_sdk::FixedBinary<32>,
contract_id: &soroban_sdk::BytesN<32>,
#(#invoke_args),*
) #output {
use soroban_sdk::TryIntoVal;
Expand Down
6 changes: 3 additions & 3 deletions macros/src/map_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn map_type(t: &Type) -> Result<ScSpecTypeDef, Error> {
"Symbol" => Ok(ScSpecTypeDef::Symbol),
"Bitset" => Ok(ScSpecTypeDef::Bitset),
"Status" => Ok(ScSpecTypeDef::Status),
"Binary" => Ok(ScSpecTypeDef::Binary),
"Bytes" => Ok(ScSpecTypeDef::Binary),
"BigInt" => Ok(ScSpecTypeDef::BigInt),
s => Ok(ScSpecTypeDef::Udt(ScSpecTypeUdt {
name: s.try_into().map_err(|e| {
Expand Down Expand Up @@ -92,8 +92,8 @@ pub fn map_type(t: &Type) -> Result<ScSpecTypeDef, Error> {
value_type: Box::new(map_type(v)?),
})))
}
// TODO: Add proper support for FixedBinary as a first class spec type.
"FixedBinary" => Ok(ScSpecTypeDef::Binary),
// TODO: Add proper support for BytesN as a first class spec type.
"BytesN" => Ok(ScSpecTypeDef::Binary),
_ => Err(Error::new(
angle_bracketed.span(),
"generics unsupported on user-defined types in contract functions",
Expand Down
40 changes: 20 additions & 20 deletions sdk/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use core::{borrow::Borrow, cmp::Ordering, fmt::Debug};
use crate::{
env::internal::{Env as _, RawVal, RawValConvertible},
env::EnvObj,
Binary, ConversionError, Env, EnvType, EnvVal, FixedBinary, IntoVal, Object,
Bytes, BytesN, ConversionError, Env, EnvType, EnvVal, IntoVal, Object,
};

/// Account references a Stellar account and provides access to information
/// about the account, such as its thresholds and signers.
#[derive(Clone)]
pub struct Account(FixedBinary<32>);
pub struct Account(BytesN<32>);

impl Debug for Account {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Expand Down Expand Up @@ -43,50 +43,50 @@ impl Ord for Account {
}
}

impl Borrow<Binary> for Account {
fn borrow(&self) -> &Binary {
impl Borrow<Bytes> for Account {
fn borrow(&self) -> &Bytes {
self.0.borrow()
}
}

impl Borrow<Binary> for &Account {
fn borrow(&self) -> &Binary {
impl Borrow<Bytes> for &Account {
fn borrow(&self) -> &Bytes {
self.0.borrow()
}
}

impl Borrow<Binary> for &mut Account {
fn borrow(&self) -> &Binary {
impl Borrow<Bytes> for &mut Account {
fn borrow(&self) -> &Bytes {
self.0.borrow()
}
}

impl Borrow<FixedBinary<32>> for Account {
fn borrow(&self) -> &FixedBinary<32> {
impl Borrow<BytesN<32>> for Account {
fn borrow(&self) -> &BytesN<32> {
self.0.borrow()
}
}

impl Borrow<FixedBinary<32>> for &Account {
fn borrow(&self) -> &FixedBinary<32> {
impl Borrow<BytesN<32>> for &Account {
fn borrow(&self) -> &BytesN<32> {
self.0.borrow()
}
}

impl Borrow<FixedBinary<32>> for &mut Account {
fn borrow(&self) -> &FixedBinary<32> {
impl Borrow<BytesN<32>> for &mut Account {
fn borrow(&self) -> &BytesN<32> {
self.0.borrow()
}
}

impl AsRef<Binary> for Account {
fn as_ref(&self) -> &Binary {
impl AsRef<Bytes> for Account {
fn as_ref(&self) -> &Bytes {
self.0.as_ref()
}
}

impl AsRef<FixedBinary<32>> for Account {
fn as_ref(&self) -> &FixedBinary<32> {
impl AsRef<BytesN<32>> for Account {
fn as_ref(&self) -> &BytesN<32> {
&self.0
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Account {
/// Creates an account from a public key.
///
/// TODO: Return a `Result` `Err` if the account does not exist. Currently panics if account does not exist.
pub fn from_public_key(public_key: &FixedBinary<32>) -> Result<Account, ()> {
pub fn from_public_key(public_key: &BytesN<32>) -> Result<Account, ()> {
let acc = Account(public_key.clone());
// TODO: Fail when account doesn't exist. In the meantime cause a trap
// at this point by trying to get some information about the account
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Account {

/// Returns the signer weight for the signer for this Stellar account. If
/// the signer does not exist for the account, returns zero (`0`).
pub fn signer_weight(&self, signer: &FixedBinary<32>) -> u32 {
pub fn signer_weight(&self, signer: &BytesN<32>) -> u32 {
let env = self.env();
let val = env.account_get_signer_weight(self.to_object(), signer.to_object());
unsafe { <u32 as RawValConvertible>::unchecked_from_val(val) }
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
env::internal::{Env as _, EnvBase, RawValConvertible},
env::{EnvObj, EnvType},
xdr::ScObjectType,
Binary, ConversionError, Env, EnvVal, IntoVal, RawVal, TryFromVal, TryIntoVal,
Bytes, ConversionError, Env, EnvVal, IntoVal, RawVal, TryFromVal, TryIntoVal,
};

/// BigInt is an arbitrary sized signed integer.
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Display for BigInt {
let env = self.env();
let bi = self.0.to_object();
let obj: EnvObj = env.bigint_to_radix_be(bi, 10u32.into()).in_env(env);
if let Ok(bin) = TryInto::<Binary>::try_into(obj) {
if let Ok(bin) = TryInto::<Bytes>::try_into(obj) {
let sign = env.bigint_cmp(bi, env.bigint_from_u64(0));
if let -1 = unsafe { <i32 as RawValConvertible>::unchecked_from_val(sign) } {
write!(f, "-")?;
Expand Down
Loading

0 comments on commit e351553

Please sign in to comment.