Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lamafab committed Sep 8, 2023
1 parent 74ddf83 commit 3542f08
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
3 changes: 3 additions & 0 deletions rust/tw_bitcoin/src/modules/legacy/build_and_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto as CommonProto;
use tw_proto::Utxo::Proto as UtxoProto;

// Builds a Taproot transaction for the legacy protobuf structure, as used by
// `tw_bitcoin_legacy_taproot_build_and_sign_transaction` in the
// `wallet-core-rs` crate.
pub fn taproot_build_and_sign_transaction(
legacy: LegacyProto::SigningInput,
) -> Result<LegacyProto::SigningOutput> {
Expand Down
58 changes: 42 additions & 16 deletions rust/tw_bitcoin/tests/legacy_build_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ fn ffi_proto_sign_input_p2pkh_output_p2pkh() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand Down Expand Up @@ -129,8 +132,11 @@ fn ffi_proto_sign_input_p2pkh_output_p2wpkh() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand Down Expand Up @@ -195,8 +201,11 @@ fn ffi_proto_sign_input_p2pkh_output_p2tr_key_path() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand Down Expand Up @@ -255,8 +264,11 @@ fn ffi_proto_sign_input_p2pkh_output_p2tr_key_path() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand Down Expand Up @@ -298,8 +310,12 @@ fn ffi_proto_sign_input_p2wpkh_output_brc20() {

// Change output.
let change_output = unsafe {
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(16_400, alice_pubkey.as_c_ptr(), alice_pubkey.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(
16_400,
alice_pubkey.as_c_ptr(),
alice_pubkey.len(),
)
.into_vec()
};
let change_output: LegacyProto::TransactionOutput =
tw_proto::deserialize(&change_output).unwrap();
Expand Down Expand Up @@ -346,8 +362,11 @@ fn ffi_proto_sign_input_p2wpkh_output_brc20() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand All @@ -365,8 +384,12 @@ fn ffi_proto_sign_input_p2wpkh_output_brc20() {

// Tagged output.
let output = unsafe {
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(546, alice_pubkey.as_c_ptr(), alice_pubkey.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(
546,
alice_pubkey.as_c_ptr(),
alice_pubkey.len(),
)
.into_vec()
};
let output: LegacyProto::TransactionOutput = tw_proto::deserialize(&output).unwrap();

Expand Down Expand Up @@ -402,8 +425,11 @@ fn ffi_proto_sign_input_p2wpkh_output_brc20() {

// Sign and build the transaction.
let signed = unsafe {
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(serialized.as_c_ptr(), serialized.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_taproot_build_and_sign_transaction(
serialized.as_c_ptr(),
serialized.len(),
)
.into_vec()
};
let signed: LegacyProto::SigningOutput = tw_proto::deserialize(&signed).unwrap();

Expand Down
16 changes: 12 additions & 4 deletions rust/tw_bitcoin/tests/legacy_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ fn ffi_tw_bitcoin_legacy_build_p2pkh_script() {
let pubkey = PublicKey::from_slice(&pubkey_slice).unwrap();

let raw = unsafe {
legacy_ffi::tw_bitcoin_legacy_build_p2pkh_script(SATOSHIS, pubkey_slice.as_ptr(), pubkey_slice.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_build_p2pkh_script(
SATOSHIS,
pubkey_slice.as_ptr(),
pubkey_slice.len(),
)
.into_vec()
};

// The expected script.
Expand All @@ -42,8 +46,12 @@ fn ffi_tw_bitcoin_legacy_build_p2wpkh_script() {
let pubkey = PublicKey::from_slice(&pubkey_slice).unwrap();

let raw = unsafe {
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(SATOSHIS, pubkey_slice.as_ptr(), pubkey_slice.len())
.into_vec()
legacy_ffi::tw_bitcoin_legacy_build_p2wpkh_script(
SATOSHIS,
pubkey_slice.as_ptr(),
pubkey_slice.len(),
)
.into_vec()
};

// The expected script.
Expand Down
8 changes: 4 additions & 4 deletions rust/wallet_core_rs/src/ffi/bitcoin/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

#![allow(clippy::missing_safety_doc)]

use std::ffi::{c_char, CStr};
use tw_bitcoin::aliases::*;
use tw_bitcoin::native::consensus::Decodable;
use tw_bitcoin::native::{PublicKey, Transaction};
use tw_memory::ffi::c_byte_array::CByteArray;
use tw_memory::ffi::c_byte_array_ref::CByteArrayRef;
use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto as CommonProto;
use tw_proto::Bitcoin::Proto as LegacyProto;
use tw_memory::ffi::c_result::CUInt64Result;
use tw_misc::try_or_else;
use std::ffi::{c_char, CStr};
use tw_proto::Bitcoin::Proto as LegacyProto;
use tw_proto::BitcoinV2::Proto;
use tw_proto::Common::Proto as CommonProto;

// NOTE: The tests for those APIs can be found in `tw_bitcoin`.

Expand Down

0 comments on commit 3542f08

Please sign in to comment.