Skip to content

Commit

Permalink
fix: compiler issues
Browse files Browse the repository at this point in the history
Move some stuff to alloc feature
  • Loading branch information
willemneal committed Nov 14, 2024
1 parent 639e03b commit dcebd53
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 78 deletions.
37 changes: 18 additions & 19 deletions src/curr/account_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{
AccountId, Error, Hash, MuxedAccount, MuxedAccountMed25519, PublicKey, ScAddress, ScVal,
Uint256,
AccountId, Hash, MuxedAccount, MuxedAccountMed25519, PublicKey, ScAddress, ScVal, Uint256,
};

#[cfg(feature = "alloc")]
mod strkey {
use super::super::Error;
use super::*;
impl From<stellar_strkey::ed25519::PublicKey> for PublicKey {
fn from(k: stellar_strkey::ed25519::PublicKey) -> Self {
Expand Down Expand Up @@ -97,13 +97,13 @@ mod strkey {
}

impl TryFrom<&stellar_strkey::Strkey> for ScAddress {
type Error = super::Error;
type Error = Error;
fn try_from(strkey: &stellar_strkey::Strkey) -> Result<Self, Self::Error> {
match strkey {
stellar_strkey::Strkey::PublicKeyEd25519(k) => Ok(ScAddress::Account(k.into())),
stellar_strkey::Strkey::MuxedAccountEd25519(m) => Ok(ScAddress::Account(m.into())),
stellar_strkey::Strkey::Contract(k) => Ok(ScAddress::Contract(k.into())),
_ => Err(super::Error::Invalid),
_ => Err(Error::Invalid),
}
}
}
Expand Down Expand Up @@ -142,6 +142,20 @@ mod strkey {
}
}
}
impl From<AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
impl From<&AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: &AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
}

impl From<PublicKey> for MuxedAccount {
Expand Down Expand Up @@ -217,21 +231,6 @@ impl From<&AccountId> for MuxedAccount {
}
}

impl From<AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
impl From<&AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: &AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}

impl From<&AccountId> for AccountId {
fn from(AccountId(public_key): &AccountId) -> Self {
AccountId(public_key.into())
Expand Down
17 changes: 2 additions & 15 deletions src/curr/contract_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{
Hash, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, Operation, OperationBody,
ScAddress, ScVal, VecM,
ScAddress, VecM,
};

#[cfg(feature = "alloc")]
mod stellar_strkey_contract {
use super::super::Error;
use super::super::{Error, ScVal};
use super::*;
impl From<Hash> for stellar_strkey::Contract {
fn from(v: Hash) -> Self {
Expand Down Expand Up @@ -61,12 +61,6 @@ mod stellar_strkey_contract {
ScVal::Address(contract.into())
}
}
impl TryFrom<Vec<u8>> for HostFunction {
type Error = Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
bytes.as_slice().try_into()
}
}
}

impl From<&Hash> for [u8; 32] {
Expand Down Expand Up @@ -122,10 +116,3 @@ impl From<HostFunction> for Operation {
}
}
}

impl TryFrom<&[u8]> for HostFunction {
type Error = super::Error;
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
Ok(HostFunction::UploadContractWasm(bytes.try_into()?))
}
}
12 changes: 7 additions & 5 deletions src/curr/transaction_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use super::{
FeeBumpTransaction, FeeBumpTransactionEnvelope, Memo, MuxedAccount, Operation, Preconditions,
SequenceNumber, Transaction, TransactionEnvelope, TransactionExt, TransactionV1Envelope, VecM,
FeeBumpTransaction, FeeBumpTransactionEnvelope, Transaction, TransactionEnvelope,
TransactionV1Envelope, VecM,
};

#[cfg(feature = "alloc")]
use super::{Error, Memo, MuxedAccount, Operation, Preconditions, SequenceNumber, TransactionExt};
#[cfg(feature = "sha2")]
use super::{
Hash, Limits, TransactionSignaturePayload, TransactionSignaturePayloadTaggedTransaction,
WriteXdr,
};

use super::Error;

impl Transaction {
#[cfg(feature = "alloc")]
pub fn new_tx(
source_account: impl Into<MuxedAccount>,
fee: u32,
Expand All @@ -27,7 +29,7 @@ impl Transaction {
ext: TransactionExt::V0,
}
}

#[cfg(feature = "alloc")]
pub fn add_operation(mut self, operation: Operation) -> Result<Self, Error> {
let mut ops = self.operations.to_vec();
ops.push(operation);
Expand Down
37 changes: 18 additions & 19 deletions src/next/account_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{
AccountId, Error, Hash, MuxedAccount, MuxedAccountMed25519, PublicKey, ScAddress, ScVal,
Uint256,
AccountId, Hash, MuxedAccount, MuxedAccountMed25519, PublicKey, ScAddress, ScVal, Uint256,
};

#[cfg(feature = "alloc")]
mod strkey {
use super::super::Error;
use super::*;
impl From<stellar_strkey::ed25519::PublicKey> for PublicKey {
fn from(k: stellar_strkey::ed25519::PublicKey) -> Self {
Expand Down Expand Up @@ -97,13 +97,13 @@ mod strkey {
}

impl TryFrom<&stellar_strkey::Strkey> for ScAddress {
type Error = super::Error;
type Error = Error;
fn try_from(strkey: &stellar_strkey::Strkey) -> Result<Self, Self::Error> {
match strkey {
stellar_strkey::Strkey::PublicKeyEd25519(k) => Ok(ScAddress::Account(k.into())),
stellar_strkey::Strkey::MuxedAccountEd25519(m) => Ok(ScAddress::Account(m.into())),
stellar_strkey::Strkey::Contract(k) => Ok(ScAddress::Contract(k.into())),
_ => Err(super::Error::Invalid),
_ => Err(Error::Invalid),
}
}
}
Expand Down Expand Up @@ -142,6 +142,20 @@ mod strkey {
}
}
}
impl From<AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
impl From<&AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: &AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
}

impl From<PublicKey> for MuxedAccount {
Expand Down Expand Up @@ -217,21 +231,6 @@ impl From<&AccountId> for MuxedAccount {
}
}

impl From<AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}
impl From<&AccountId> for stellar_strkey::ed25519::PublicKey {
fn from(value: &AccountId) -> Self {
match value {
AccountId(key) => key.into(),
}
}
}

impl From<&AccountId> for AccountId {
fn from(AccountId(public_key): &AccountId) -> Self {
AccountId(public_key.into())
Expand Down
17 changes: 2 additions & 15 deletions src/next/contract_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{
Hash, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, Operation, OperationBody,
ScAddress, ScVal, VecM,
ScAddress, VecM,
};

#[cfg(feature = "alloc")]
mod stellar_strkey_contract {
use super::super::Error;
use super::super::{Error, ScVal};
use super::*;
impl From<Hash> for stellar_strkey::Contract {
fn from(v: Hash) -> Self {
Expand Down Expand Up @@ -61,12 +61,6 @@ mod stellar_strkey_contract {
ScVal::Address(contract.into())
}
}
impl TryFrom<Vec<u8>> for HostFunction {
type Error = Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
bytes.as_slice().try_into()
}
}
}

impl From<&Hash> for [u8; 32] {
Expand Down Expand Up @@ -122,10 +116,3 @@ impl From<HostFunction> for Operation {
}
}
}

impl TryFrom<&[u8]> for HostFunction {
type Error = super::Error;
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
Ok(HostFunction::UploadContractWasm(bytes.try_into()?))
}
}
12 changes: 7 additions & 5 deletions src/next/transaction_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use super::{
FeeBumpTransaction, FeeBumpTransactionEnvelope, Memo, MuxedAccount, Operation, Preconditions,
SequenceNumber, Transaction, TransactionEnvelope, TransactionExt, TransactionV1Envelope, VecM,
FeeBumpTransaction, FeeBumpTransactionEnvelope, Transaction, TransactionEnvelope,
TransactionV1Envelope, VecM,
};

#[cfg(feature = "alloc")]
use super::{Error, Memo, MuxedAccount, Operation, Preconditions, SequenceNumber, TransactionExt};
#[cfg(feature = "sha2")]
use super::{
Hash, Limits, TransactionSignaturePayload, TransactionSignaturePayloadTaggedTransaction,
WriteXdr,
};

use super::Error;

impl Transaction {
#[cfg(feature = "alloc")]
pub fn new_tx(
source_account: impl Into<MuxedAccount>,
fee: u32,
Expand All @@ -27,7 +29,7 @@ impl Transaction {
ext: TransactionExt::V0,
}
}

#[cfg(feature = "alloc")]
pub fn add_operation(mut self, operation: Operation) -> Result<Self, Error> {
let mut ops = self.operations.to_vec();
ops.push(operation);
Expand Down

0 comments on commit dcebd53

Please sign in to comment.