Skip to content

refactor(XRP): Move Ripple blockchain to Rust #4250

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

Merged
merged 32 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
db78bef
refactor(ripple): Add Ripple blockchain skeleton
satoshiotomakan Jan 28, 2025
c1b997c
refactor(ripple): Add Classic and X addresses
satoshiotomakan Jan 28, 2025
81bd052
refactor(ripple): Add more XAddress tests
satoshiotomakan Jan 29, 2025
d1cf952
refactor(ripple): Start working on transaction binary encoding
satoshiotomakan Jan 31, 2025
24fc460
refactor(ripple): Remove `serde_with` dependency
satoshiotomakan Jan 31, 2025
1d60c8f
refactor(ripple): Simplify `Result::tw_err` method
satoshiotomakan Jan 31, 2025
d4be95f
refactor(ripple): Implement `Encodable` for `XRPLTypes`
satoshiotomakan Jan 31, 2025
f62f210
refactor(ripple): Finish `Encoder`
satoshiotomakan Feb 1, 2025
7ca99a3
refactor(ripple): Add Transaction encoding from JSON test
satoshiotomakan Feb 2, 2025
5c5d882
refactor(ripple): Add `TransactionSigner`, `TransactionBuilder` from …
satoshiotomakan Feb 3, 2025
603cc94
refactor(ripple): Add `TrustSet`
satoshiotomakan Feb 4, 2025
6ac06f6
refactor(ripple): Add more Payment and TokenPayment tests
satoshiotomakan Feb 4, 2025
10674b9
refactor(ripple): Add `EscrowCreate`
satoshiotomakan Feb 4, 2025
c98707e
refactor(ripple): Add more `EscrowCreate` tests
satoshiotomakan Feb 4, 2025
a2268e1
refactor(ripple): Add `EscrowCancel`
satoshiotomakan Feb 4, 2025
7e4e7e6
refactor(ripple): Add `EscrowFinish`
satoshiotomakan Feb 4, 2025
c9aa577
refactor(ripple): Add `NFTokenBurn`
satoshiotomakan Feb 4, 2025
670e050
refactor(ripple): Add `NFTokenCreateOffer`
satoshiotomakan Feb 4, 2025
8f5c8cd
refactor(ripple): Add `NFTokenAcceptOffer`
satoshiotomakan Feb 4, 2025
c1f1b20
refactor(ripple): Add `NFTokenCancelOffer`
satoshiotomakan Feb 4, 2025
0717be8
refactor(ripple): Add `SourceTag`
satoshiotomakan Feb 5, 2025
2b981e5
refactor(ripple): Add transaction pre-image hashing and compiling
satoshiotomakan Feb 5, 2025
111643c
refactor(ripple): Add additional checks for XRP and IssuedCurrency am…
satoshiotomakan Feb 6, 2025
55b9b0f
refactor(ripple): Replace C++ implementation
satoshiotomakan Feb 6, 2025
1dc34a2
refactor(ripple): Minor change
satoshiotomakan Feb 6, 2025
c533885
refactor(ripple): Do not set `destinationTag` if `destination` is XAd…
satoshiotomakan Feb 6, 2025
0944d36
Merge branch 'master' into s/rust-xrp
satoshiotomakan Feb 6, 2025
d7970d2
refactor(ripple): Add fuzz tests
satoshiotomakan Feb 6, 2025
e553eac
refactor(ripple): Improve code coverage
satoshiotomakan Feb 6, 2025
8a2c059
refactor(ripple): Avoid bigdecimal duplication
satoshiotomakan Feb 6, 2025
66dbe62
refactor(ripple): Code improvements
satoshiotomakan Feb 6, 2025
dcf0e15
refactor(ripple): PR review comments
satoshiotomakan Feb 7, 2025
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
72 changes: 0 additions & 72 deletions include/TrustWalletCore/TWRippleXAddress.h

This file was deleted.

27 changes: 24 additions & 3 deletions rust/Cargo.lock

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

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"chains/tw_native_injective",
"chains/tw_pactus",
"chains/tw_polkadot",
"chains/tw_ripple",
"chains/tw_ronin",
"chains/tw_solana",
"chains/tw_sui",
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_aptos/src/aptos_move_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub fn fungible_asset_transfer(
),
ident_str!("transfer").to_owned(),
vec![TypeTag::from_str("0x1::fungible_asset::Metadata")
.tw_err(|_| SigningErrorType::Error_internal)?],
.tw_err(SigningErrorType::Error_internal)?],
vec![
bcs::encode(&metadata_address)?,
bcs::encode(&to)?,
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_aptos/src/transaction_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub fn convert_proto_struct_tag_to_type_tag(
"{}::{}::{}",
struct_tag.account_address, struct_tag.module, struct_tag.name
))
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
}

pub fn convert_type_tag_to_struct_tag(type_tag: TypeTag) -> Aptos::Proto::StructTag<'static> {
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl BinanceCompiler {
let encoded_tx = BinanceAminoSerializer::serialize_signed_tx(&signed_tx)?;

let signature_json =
serde_json::to_string(&signature_json).tw_err(|_| SigningErrorType::Error_internal)?;
serde_json::to_string(&signature_json).tw_err(SigningErrorType::Error_internal)?;
Ok(Proto::SigningOutput {
encoded: encoded_tx.into(),
signature: signature_bytes.into(),
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/modules/preimager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct JsonPreimager;
impl JsonPreimager {
pub fn preimage_hash(unsigned: &UnsignedTransaction) -> SigningResult<JsonTxPreimage> {
let encoded_tx =
serde_json::to_string(unsigned).tw_err(|_| SigningErrorType::Error_internal)?;
serde_json::to_string(unsigned).tw_err(SigningErrorType::Error_internal)?;
let tx_hash = sha2::sha256(encoded_tx.as_bytes());
let tx_hash = H256::try_from(tx_hash.as_slice()).expect("sha256 must return 32 bytes");
Ok(JsonTxPreimage {
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/modules/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ impl BinanceAminoSerializer {
sequence: signed.unsigned.sequence,
};
// There is no need to use Amino encoding here as the prefix is empty.
serialize(&sign_msg).tw_err(|_| SigningErrorType::Error_internal)
serialize(&sign_msg).tw_err(SigningErrorType::Error_internal)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl BinanceWalletConnector {
request: WCProto::ParseRequestInput<'_>,
) -> SigningResult<WCProto::ParseRequestOutput<'static>> {
let amino_req: SignAminoRequest = serde_json::from_str(&request.payload)
.tw_err(|_| SigningErrorType::Error_input_parse)
.tw_err(SigningErrorType::Error_input_parse)
.context("Error deserializing WalletConnect signAmino request as JSON")?;

// Parse a `SigningInput` from the given `signDoc`.
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_binance/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl BinanceSigner {
let encoded_tx = BinanceAminoSerializer::serialize_signed_tx(&signed_tx)?;

let signature_json =
serde_json::to_string(&signature_json).tw_err(|_| SigningErrorType::Error_internal)?;
serde_json::to_string(&signature_json).tw_err(SigningErrorType::Error_internal)?;
Ok(Proto::SigningOutput {
encoded: encoded_tx.into(),
signature: signature_bytes.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl TWBinanceProto for TransferOutOrder {
let from = BinanceAddress::from_key_hash_with_coin(coin, msg.from.to_vec())?;

let to_bytes =
H160::try_from(msg.to.as_ref()).tw_err(|_| SigningErrorType::Error_invalid_address)?;
H160::try_from(msg.to.as_ref()).tw_err(SigningErrorType::Error_invalid_address)?;
let to = EthereumAddress::from_bytes(to_bytes);

let amount_proto = msg
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_bitcoin/src/babylon/proto_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn staking_params_from_proto(
let staking_locktime: u16 = params
.staking_time
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("stakingTime cannot be greater than 65535")?;

let covenants_pks = parse_schnorr_pks(&params.covenant_committee_public_keys)
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn parse_schnorr_pubkey_sig(
) -> SigningResult<(schnorr::XOnlyPublicKey, BitcoinSchnorrSignature)> {
let pk = parse_schnorr_pk(pubkey_sig.public_key.as_ref())?;
let sig = schnorr::Signature::try_from(pubkey_sig.signature.as_ref())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid signature")?;
let btc_sign = BitcoinSchnorrSignature::new(sig, sighash_ty)?;
Ok((pk, btc_sign))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl<Context: UtxoContext> BabylonOutputProtobuf for OutputProtobuf<'_, Context>
op_return: &Proto::mod_OutputBuilder::OpReturn,
) -> SigningResult<TransactionOutput> {
let tag = H32::try_from(op_return.tag.as_ref())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Expected exactly 4 bytes tag")?;
let staker =
parse_schnorr_pk(&op_return.staker_public_key).context("Invalid stakerPublicKey")?;
let staking_locktime: u16 = op_return
.staking_time
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("stakingTime cannot be greater than 65535")?;
let finality_provider = &parse_schnorr_pk(&op_return.finality_provider_public_key)
.context("Invalid finalityProviderPublicKeys")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> OutputPsbt<'a> {
.output
.value
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_utxo_amount)
.tw_err(SigningErrorType::Error_invalid_utxo_amount)
.context("PSBT Output amount is too large")?;
let script_pubkey = Script::from(self.output.script_pubkey.to_bytes());
Ok(TransactionOutput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ where
psbt_input: &Proto::Psbt,
) -> SigningResult<PsbtRequest<Context>> {
let psbt = Psbt::deserialize(&psbt_input.psbt)
.tw_err(|_| SigningErrorType::Error_input_parse)
.tw_err(SigningErrorType::Error_input_parse)
.context("Error deserializing PSBT")?;

let version = psbt
.unsigned_tx
.version
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid PSBT transaction version")?;
let lock_time = psbt.unsigned_tx.lock_time.to_consensus_u32();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> UtxoPsbt<'a> {

let amount = amount
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_utxo_amount)
.tw_err(SigningErrorType::Error_invalid_utxo_amount)
.context("PSBT UTXO amount is too large")?;

Ok(UtxoBuilder::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn chain_info(
fn prefix_to_u8(prefix: u32, prefix_name: &str) -> SigningResult<u8> {
prefix
.try_into()
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.with_context(|| format!("Invalid {prefix_name} prefix. It must fit uint8"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a, Context: UtxoContext> OutputProtobuf<'a, Context> {
tweaked_pubkey: &[u8],
) -> SigningResult<TransactionOutput> {
let tweaked_x_only = H256::try_from(tweaked_pubkey)
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid P2TR tweaked public key. Expected 32 bytes x-only public key")?;
Ok(self
.prepare_builder()?
Expand All @@ -136,7 +136,7 @@ impl<'a, Context: UtxoContext> OutputProtobuf<'a, Context> {
)?;

let merkle_root = H256::try_from(taproot_script_path.merkle_root.as_ref())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid OutputTaprootScriptPath.merkle_root. Must be a 32 byte array")?;

Ok(self
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a, Context: UtxoContext> OutputProtobuf<'a, Context> {
},
};
Hash::<N>::try_from(hash_data.as_slice())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.with_context(|| format!("Expected exactly {N} bytes redeem script hash"))
}

Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'a, Context: UtxoContext> OutputProtobuf<'a, Context> {
},
};
Hash::<N>::try_from(hash_data.as_slice())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.with_context(|| format!("Expected exactly {N} bytes public key hash"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<'a, Context: UtxoContext> UtxoProtobuf<'a, Context> {
PublicKeyOrHashType::pubkey(ref pubkey) => pubkey.as_ref(),
PublicKeyOrHashType::hash(ref hash) => {
let hash = H160::try_from(hash.as_ref())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Expected 20 bytes public key hash")?;
self.public_keys.get_public_key(&hash)?
},
Expand All @@ -253,7 +253,7 @@ pub fn parse_out_point(maybe_out_point: &Option<UtxoProto::OutPoint>) -> Signing
.context("No OutPoint provided for a UTXO")?;

let hash = H256::try_from(out_point.hash.as_ref())
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid previous txid")?;

Ok(OutPoint {
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_greenfield/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl GreenfieldCompiler {
signature_bytes.clone(),
);
let signature_json = serde_json::to_string(&[signature_json])
.tw_err(|_| SigningErrorType::Error_internal)
.tw_err(SigningErrorType::Error_internal)
.context("Error serializing signatures as JSON")?;

Ok(Proto::SigningOutput {
Expand Down
6 changes: 3 additions & 3 deletions rust/chains/tw_greenfield/src/modules/eip712_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ impl Eip712Signer {
let msg_to_sign = Eip712Message {
types: types_builder.build(),
domain: serde_json::to_value(domain)
.tw_err(|_| SigningErrorType::Error_internal)
.tw_err(SigningErrorType::Error_internal)
.context("Error serializing EIP712Domain as JSON")?,
primary_type: Eip712Transaction::TYPE_NAME.to_string(),
message: serde_json::to_value(tx_to_sign)
.tw_err(|_| SigningErrorType::Error_internal)
.tw_err(SigningErrorType::Error_internal)
.context("Error serializing EIP712 message payload as JSON")?,
};

let tx_hash = msg_to_sign.hash().map_err(to_signing)?;
let eip712_tx =
serde_json::to_string(&msg_to_sign).tw_err(|_| SigningErrorType::Error_internal)?;
serde_json::to_string(&msg_to_sign).tw_err(SigningErrorType::Error_internal)?;

Ok(Eip712TxPreimage { eip712_tx, tx_hash })
}
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/tw_greenfield/src/modules/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl TxBuilder {
let fee = Self::fee_from_proto(fee, &signer)?;

let eth_chain_id = U256::from_str(&input.eth_chain_id)
.tw_err(|_| SigningErrorType::Error_invalid_params)
.tw_err(SigningErrorType::Error_invalid_params)
.context("Invalid ETH chain ID")?;

Ok(GreenfieldUnsignedTransaction {
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_internet_computer/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl<Context: InternetComputerContext> Signer<Context> {
let signed_transaction =
sign_transaction(private_key, canister_id, &transaction.transaction_oneof)?;

let cbor_encoded_signed_transaction = tw_encoding::cbor::encode(&signed_transaction)
.tw_err(|_| CommonError::Error_internal)?;
let cbor_encoded_signed_transaction =
tw_encoding::cbor::encode(&signed_transaction).tw_err(CommonError::Error_internal)?;

Ok(Proto::SigningOutput {
signed_transaction: cbor_encoded_signed_transaction.into(),
Expand Down
Loading
Loading