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

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

Merged
merged 32 commits into from
Feb 7, 2025
Merged

Conversation

satoshiotomakan
Copy link
Collaborator

@satoshiotomakan satoshiotomakan commented Feb 3, 2025

Description

Migrate Ripple blockchain implementation to Rust.
Mainly adds tw_ripple crate that provides a comprehensive implementation of the Ripple/XRP blockchain in Rust.

Source Code

The code of this crate is mainly inspired by xrpl-rust and xrpl-py, and tested well against unit tests from xrpl-py.

Rust Usage

use std::str::FromStr;
use tw_keypair::ecdsa::secp256k1;
use tw_keypair::traits::KeyPairTrait;
use tw_ripple::address::classic_address::ClassicAddress;
use tw_ripple::address::RippleAddress;
use tw_ripple::encode::encode_tx;
use tw_ripple::modules::transaction_signer::TransactionSigner;
use tw_ripple::transaction::transaction_builder::TransactionBuilder;
use tw_ripple::transaction::transaction_type::TransactionType;
use tw_ripple::types::amount::Amount;
use tw_ripple::types::amount::native_amount::NativeAmount;

let key: secp256k1::KeyPair = todo!();

let mut builder = TransactionBuilder::default();
builder
    .fee(NativeAmount::new(10).unwrap())
    .sequence(32_268_248_u32)
    .last_ledger_sequence(32_268_269_u32)
    .account_str("rfxdLwsZnoespnTDDb1Xhvbc8EFNdztaoq")
    .unwrap()
    .signing_pub_key(&key.public());

let xrp_amount = Amount::NativeAmount(NativeAmount::new(10).unwrap());
let destination = ClassicAddress::from_str("rU893viamSnsfP3zjzM2KPxjqZjXSXK6VF").unwrap();
let destination_tag = None;

let payment = builder.payment(xrp_amount, destination, destination_tag).unwrap();
let unsigned_tx = TransactionType::Payment(payment);

let signed_tx = TransactionSigner::sign(unsigned_tx, key.private()).unwrap();
let signing_only = false;
let _encoded_tx = encode_tx(&signed_tx, signing_only).unwrap();

How to test

Run Rust, C++, Android, iOS, KMP, WASM tests

Breaking Changes

1.TWRippleXAddress module has been deprecated and deleted.
2. OperationPayment.destinationTag, SigningInput.sequence, SigningInput.lastLedgerSequence are uint32 now (were int64 previously)
3. TransactionCompiler.compile() now takes a raw secp256k1 signature (64 bytes), while it took the signature as ASN DER.1 (up to 72 bytes).

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

* Add `AccountId`, `Amount`, `Blob`, `IssuedCurrency` XRPL types
* Add definitions
* Add `STObject` structure helper
* Add `CommonFields` and `EscrowCancel` structures
* Finish `XRPLTypes` deserialization
* Encode field and value
* Encode value with variable length
* Fix `Vector256` encoding
* Take `nftoken_id` as a hex-encoded string, not a byte vector
* Add `tw_ripple` documentation
* Fix C++ tests
* Add WASM test
@satoshiotomakan satoshiotomakan marked this pull request as ready for review February 6, 2025 14:25
* Fix compilation issues after merging master
Copy link

github-actions bot commented Feb 6, 2025

Binary size comparison

➡️ aarch64-apple-ios:

- 13.10 MB
+ 13.50 MB 	 +411 KB

➡️ aarch64-apple-ios-sim:

- 13.10 MB
+ 13.50 MB 	 +411 KB

➡️ aarch64-linux-android:

- 17.06 MB
+ 17.72 MB 	 +681 KB

➡️ armv7-linux-androideabi:

- 14.37 MB
+ 14.89 MB 	 +530 KB

➡️ wasm32-unknown-emscripten:

- 12.12 MB
+ 12.58 MB 	 +470 KB

* Minimize `definitions.json`
* Add `SpecialField` enum when parsing `STObject`
Copy link
Collaborator

@gupnik gupnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@satoshiotomakan satoshiotomakan merged commit 1af489d into master Feb 7, 2025
14 checks passed
@satoshiotomakan satoshiotomakan deleted the s/rust-xrp branch February 7, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants