Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master to version 0.9.42 #30

Merged
merged 11 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
898 changes: 558 additions & 340 deletions Cargo.lock

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "substrate-stellar-sdk"
version = "0.2.4"
authors = ["Torsten Stüber <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
license = "Apache-2.0"
description = "A Substrate compatible SDK for Stellar"
repository = "https://github.com/pendulum-chain/substrate-stellar-sdk"
readme = "README.md"
Expand All @@ -12,28 +12,29 @@ exclude = ["autogenerator/*"]

[dependencies]
serde_json = { version = '1.0.64', default-features = false, features = ["alloc"], optional = true }
serde = { version = "1.0.100", default-features = false, features = ["derive", "alloc"], optional = true }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
sp-std = { version = "5.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37", optional = true }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37", optional = true }
serde = { version = "1.0.136", default-features = false, features = ["derive", "alloc"], optional = true }
hex = { version = "0.4", default-features = false , features = ["alloc"]}
sp-std = { version = "5.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42", optional = true }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42", optional = true }
sodalite = { version = "0.4.0" }
sha2 = { default-features = false, version = "0.9.9" }
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
base64 = { default-features = false, version = "0.13.0" }
num-rational = { version = "0.4", default-features = false }

num-rational = {version = "0.4", default-features = false}
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}

[features]
default = ["offchain", "std"]
default = [ "offchain", "std" ]
all-types = []
offchain = ["sp-runtime", "sp-io", "serde_json", "serde"]
offchain = [ "sp-runtime", "sp-io", "serde_json", "serde" ]
std = [
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"serde_json/std",
"serde/std",
"hex/std",
"num-rational/std"
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"serde_json/std",
"serde/std",
"scale-info/std",
"hex/std",
"num-rational/std"
]
2 changes: 1 addition & 1 deletion autogenerator/x2JavaScript/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace :xdr do
"Stellar-contract-env-meta.x",
"Stellar-contract-meta.x",
"Stellar-contract-spec.x"

]

task :update => [:download, :generate]
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use hex::FromHexError;
#[cfg(feature = "offchain")]
use crate::horizon::FetchError;

use sp_std::vec::Vec;

#[derive(Debug, Clone, PartialEq)]
pub enum StellarSdkError {
InvalidBase32Character {
Expand Down Expand Up @@ -86,4 +88,6 @@ pub enum StellarSdkError {

#[cfg(feature = "offchain")]
FetchError(FetchError),

DecodeError(Vec<u8>), // String converted as Bytes of u8
}
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ extern crate alloc;

mod lib {
#[cfg(not(feature = "std"))]
pub use alloc::string::{String, ToString, FromUtf8Error};
pub use alloc::string::{FromUtf8Error, String, ToString};
#[cfg(feature = "std")]
pub use std::string::{String, ToString, FromUtf8Error};
pub use std::string::{FromUtf8Error, String, ToString};
}

mod amount;
Expand Down Expand Up @@ -47,6 +47,9 @@ pub use xdr::{
#[cfg(feature = "all-types")]
pub use xdr::impls::transaction_set_type::*;

#[cfg(feature = "all-types")]
pub use xdr::impls::error::*;

pub use utils::std::StellarTypeToString;

pub use amount::*;
Expand Down
6 changes: 4 additions & 2 deletions src/xdr/impls/claimable_balance_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{AsBinary, ClaimableBalanceId, StellarSdkError, XdrCodec};
use crate::lib::{String, ToString};
use crate::{
lib::{String, ToString},
AsBinary, ClaimableBalanceId, StellarSdkError, XdrCodec,
};

pub trait IntoClaimbleBalanceId {
fn into_claimable_balance_id(self) -> Result<ClaimableBalanceId, StellarSdkError>;
Expand Down
10 changes: 10 additions & 0 deletions src/xdr/impls/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::{lib::String, types::Error};
use scale_info::prelude::format;

impl<E: From<sp_std::str::Utf8Error>> crate::StellarTypeToString<Self, E> for Error {
fn as_encoded_string(&self) -> Result<String, E> {
let msg = self.msg.get_vec();
let msg = sp_std::str::from_utf8(msg).map_err(E::from)?;
Ok(format!("Error{{ code:{:?} message:{msg} }}", self.code))
}
}
2 changes: 1 addition & 1 deletion src/xdr/impls/generalized_transaction_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
lib::{String, FromUtf8Error},
compound_types::UnlimitedVarArray,
lib::{FromUtf8Error, String},
types::{GeneralizedTransactionSet, TransactionPhase, TxSetComponent},
Hash, IntoHash, StellarSdkError, TransactionEnvelope, XdrCodec,
};
Expand Down
3 changes: 3 additions & 0 deletions src/xdr/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ pub mod operations;
pub mod transaction;
pub mod transaction_envelope;

#[cfg(feature = "all-types")]
pub mod error;

#[cfg(feature = "all-types")]
pub mod generalized_transaction_set;

Expand Down
43 changes: 27 additions & 16 deletions src/xdr/impls/transaction_set_type.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![allow(dead_code)]
use crate::{Hash, IntoHash, ReadStream, TransactionEnvelope, WriteStream, XdrCodec};
use crate::compound_types::UnlimitedVarArray;
use crate::types::{GeneralizedTransactionSet, TransactionSet};
use crate::xdr::streams::DecodeError;

use crate::{
compound_types::UnlimitedVarArray,
types::{GeneralizedTransactionSet, TransactionSet},
xdr::streams::DecodeError,
Hash, IntoHash, ReadStream, TransactionEnvelope, WriteStream, XdrCodec,
};

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum TransactionSetType {
Expand All @@ -12,7 +13,7 @@ pub enum TransactionSetType {
}

pub trait InitExt<T> {
fn new(tx_set:T) -> Self;
fn new(tx_set: T) -> Self;
}

impl InitExt<TransactionSet> for TransactionSetType {
Expand All @@ -28,13 +29,10 @@ impl InitExt<GeneralizedTransactionSet> for TransactionSetType {
}

impl TransactionSetType {

pub fn get_tx_set_hash(&self) -> Result<Hash, ()> {
match self {
TransactionSetType::TransactionSet(tx_set) =>
tx_set.clone().into_hash().map_err(|_| ()),
TransactionSetType::GeneralizedTransactionSet(tx_set) =>
tx_set.clone().into_hash().map_err(|_| ()),
TransactionSetType::TransactionSet(tx_set) => tx_set.clone().into_hash().map_err(|_| ()),
TransactionSetType::GeneralizedTransactionSet(tx_set) => tx_set.clone().into_hash().map_err(|_| ()),
}
}

Expand All @@ -48,26 +46,39 @@ impl TransactionSetType {
}
}

impl From<TransactionSet> for TransactionSetType {
fn from(value: TransactionSet) -> Self {
TransactionSetType::TransactionSet(value)
}
}

impl From<GeneralizedTransactionSet> for TransactionSetType {
fn from(value: GeneralizedTransactionSet) -> Self {
TransactionSetType::GeneralizedTransactionSet(value)
}
}

impl XdrCodec for TransactionSetType {
fn to_xdr_buffered(&self, write_stream: &mut WriteStream) {
match self {
TransactionSetType::TransactionSet(set) => {
(0 as i32).to_xdr_buffered(write_stream);
set.to_xdr_buffered(write_stream)
}
},
TransactionSetType::GeneralizedTransactionSet(set) => {
(1 as i32).to_xdr_buffered(write_stream);
set.to_xdr_buffered(write_stream)
}
},
}
}

fn from_xdr_buffered<T: AsRef<[u8]>>(read_stream: &mut ReadStream<T>) -> Result<Self, DecodeError> {
match i32::from_xdr_buffered(read_stream)? {
0 => Ok(TransactionSetType::TransactionSet(TransactionSet::from_xdr_buffered(read_stream)?)),
1 => Ok(TransactionSetType::GeneralizedTransactionSet(GeneralizedTransactionSet::from_xdr_buffered(read_stream)?)),
_ => Err(DecodeError::InvalidEnumDiscriminator { at_position: 0 })
1 => Ok(TransactionSetType::GeneralizedTransactionSet(GeneralizedTransactionSet::from_xdr_buffered(
read_stream,
)?)),
_ => Err(DecodeError::InvalidEnumDiscriminator { at_position: 0 }),
}
}
}

2 changes: 2 additions & 0 deletions src/xdr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ pub mod compound_types;
pub mod impls;
pub mod streams;
pub mod types;

#[macro_use]
pub mod xdr_codec;
Loading
Loading