Skip to content

Commit

Permalink
Add UniFFI
Browse files Browse the repository at this point in the history
  • Loading branch information
ssantos21 committed May 2, 2024
1 parent 9660b00 commit 2bd67ed
Show file tree
Hide file tree
Showing 41 changed files with 5,906 additions and 135 deletions.
405 changes: 374 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clients/rust/src/broadcast_backup_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn execute(client_config: &ClientConfig, wallet_name: &str, statechain
},
};

let cpfp_tx = cpfp_tx::create(&backup_tx, &coin, to_address, fee_rate, &wallet.network)?;
let cpfp_tx = cpfp_tx::create_cpfp_tx(&backup_tx, &coin, to_address, fee_rate, &wallet.network)?;

let tx_bytes = hex::decode(&backup_tx.tx)?;
let txid = client_config.electrum_client.transaction_broadcast_raw(&tx_bytes)?;
Expand Down
16 changes: 14 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ name = "mercurylib"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "staticlib", "lib"]
name = "mercurylib"

[[bin]]
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"
required-features = ["bindings"]

[dependencies]
bitcoin = { version = "0.30.1", features = ["serde", "base64", "rand-std", "std"], default-features = false }
Expand All @@ -16,4 +23,9 @@ hex = "0.4.3"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", branch = "blinded-musig-scheme", features = [ "rand-std", "bitcoin_hashes", "std" ] }
anyhow = "1.0"
uniffi = { version = "0.27.1", features = [ "cli" ], optional = true }
thiserror = "1.0.59"

[features]
default = []
bindings = ["uniffi", "uniffi/cli"]
17 changes: 17 additions & 0 deletions lib/modify_sh/modify_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
./modify_sh/modify_kt_file.sh
./modify_sh/modify_token.sh
./modify_sh/modify_deposit_msg1.sh
./modify_sh/modify_deposit_msg_response.sh
./modify_sh/modify_sign_first_request_payload.sh
./modify_sh/modify_sign_first_response_payload.sh
./modify_sh/modify_partial_signature_request_payload.sh
./modify_sh/modify_partial_signature_response_payload.sh
./modify_sh/modify_transfer_sender_request_payload.sh
./modify_sh/modify_transfer_update_msg_request_payload.sh
./modify_sh/modify_get_msg_addr_response_payload.sh
./modify_sh/modify_key_update_response_payload.sh
./modify_sh/modify_statechain_info.sh
./modify_sh/modify_statechainInfo_response_payload.sh
./modify_sh/modify_transfer_receiver_request_payload.sh
./modify_sh/modify_transfer_receiver_response_payload.sh
./modify_sh/modify_transfer_receiver_get_response_payload.sh
39 changes: 39 additions & 0 deletions lib/modify_sh/modify_deposit_msg1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class DepositMsg1\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `authKey`:/ {
print "\t@SerialName(\"auth_key\")"
}
in_data_class && /var `tokenId`:/ {
print "\t@SerialName(\"token_id\")"
}
in_data_class && /var `signedTokenId`:/ {
print "\t@SerialName(\"signed_token_id\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to DepositMsg1 successfully."
36 changes: 36 additions & 0 deletions lib/modify_sh/modify_deposit_msg_response.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class DepositMsg1Response\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `serverPubkey`:/ {
print "\t@SerialName(\"server_pubkey\")"
}
in_data_class && /var `statechainId`:/ {
print "\t@SerialName(\"statechain_id\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to DepositMsg1Response successfully."
33 changes: 33 additions & 0 deletions lib/modify_sh/modify_get_msg_addr_response_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class GetMsgAddrResponsePayload\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `listEncTransferMsg`:/ {
print "\t@SerialName(\"list_enc_transfer_msg\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to GetMsgAddrResponsePayload successfully."
33 changes: 33 additions & 0 deletions lib/modify_sh/modify_key_update_response_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class KeyUpdateResponsePayload\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `statechainId`:/ {
print "\t@SerialName(\"statechain_id\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to KeyUpdateResponsePayload successfully."
83 changes: 83 additions & 0 deletions lib/modify_sh/modify_kt_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Directory where the files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (e.g., all Kotlin files)
FILE_PATTERN="*.kt"

# The text to find for adding @Serializable
FIND_TEXT_SERVER_CONFIG="data class ServerConfig("
FIND_TEXT_WALLET="data class Wallet("
FIND_TEXT_TOKEN="data class Token("
FIND_TEXT_ACTIVITY="data class Activity("
FIND_TEXT_COIN="data class Coin("
FIND_TEXT_SETTINGS="data class Settings("
FIND_TEXT_DEPOSIT_MSG1="data class DepositMsg1("
FIND_TEXT_DEPOSIT_MSG1_RESPONSE="data class DepositMsg1Response("
FIND_TEXT_DEPOSIT_INIT_RESULT="data class DepositInitResult("
FIND_TEXT_AGGREGATED_PUBLIC_KEY="data class AggregatedPublicKey("
FIND_TEXT_SIGN_FIRST_REQUEST_PAYLOAD="data class SignFirstRequestPayload("
FIND_TEXT_SIGN_FIRST_RESPONSE_PAYLOAD="data class SignFirstResponsePayload("
FIND_TEXT_PARTIAL_SIGNATURE_REQUEST_PAYLOAD="data class PartialSignatureRequestPayload("
FIND_TEXT_PARTIAL_SIGNATURE_RESPONSE_PAYLOAD="data class PartialSignatureResponsePayload("
FIND_TEXT_BACKUP_TX="data class BackupTx("
FIND_TEXT_TRANSFER_SENDER_REQUEST_PAYLOAD="data class TransferSenderRequestPayload("
FIND_TEXT_TRANSFER_SENDER_RESPONSE_PAYLOAD="data class TransferSenderResponsePayload("
FIND_TEXT_TRANSFER_UPDATE_MSG_REQUEST_PAYLOAD="data class TransferUpdateMsgRequestPayload("
FIND_TEXT_TRANSFER_GET_MSG_ADDR_RESPONSE_PAYLOAD="data class GetMsgAddrResponsePayload("
FIND_TEXT_TRANSFER_KEY_UPDATE_RESPONSE_PAYLOAD="data class KeyUpdateResponsePayload("
FIND_TEXT_TRANSFER_STATECHAIN_INFO="data class StatechainInfo("
FIND_TEXT_TRANSFER_STATECHAIN_INFO_RESPONSE_PAYLOAD="data class StatechainInfoResponsePayload("
FIND_TEXT_TRANSFER_RECEIVER_REQUEST_PAYLOAD="data class TransferReceiverRequestPayload("
FIND_TEXT_TRANSFER_RECEIVER_RESPONSE_PAYLOAD="data class TransferReceiverResponsePayload("
FIND_TEXT_TRANSFER_GET_RECEIVER_RESPONSE_PAYLOAD="data class TransferReceiverGetResponsePayload("

# The text to add @Serializable
ADD_TEXT="@Serializable"

# Text to find for modifying imports
IMPORT_FIND_TEXT="import com.sun.jna.ptr.*"

# New import text to add
IMPORT_ADD_SERIALIZABLE="import kotlinx.serialization.Serializable"
IMPORT_ADD_SERIALNAME="import kotlinx.serialization.SerialName"

# Import text to remove. This should be disabled when the folder struct is fixed
PACKAGE_REMOVE_TEXT="package com.mercurylayer"

# Using find to locate Kotlin files and sed to modify them
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec sed -i \
-e "/$FIND_TEXT_SERVER_CONFIG/i $ADD_TEXT" \
-e "/$FIND_TEXT_WALLET/i $ADD_TEXT" \
-e "/$FIND_TEXT_TOKEN/i $ADD_TEXT" \
-e "/$FIND_TEXT_ACTIVITY/i $ADD_TEXT" \
-e "/$FIND_TEXT_COIN/i $ADD_TEXT" \
-e "/$FIND_TEXT_SETTINGS/i $ADD_TEXT" \
-e "/$FIND_TEXT_DEPOSIT_MSG1/i $ADD_TEXT" \
-e "/$FIND_TEXT_DEPOSIT_MSG1_RESPONSE/i $ADD_TEXT" \
-e "/$FIND_TEXT_DEPOSIT_INIT_RESULT/i $ADD_TEXT" \
-e "/$FIND_TEXT_AGGREGATED_PUBLIC_KEY/i $ADD_TEXT" \
-e "/$FIND_TEXT_SIGN_FIRST_REQUEST_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_SIGN_FIRST_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_PARTIAL_SIGNATURE_REQUEST_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_PARTIAL_SIGNATURE_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_BACKUP_TX/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_SENDER_REQUEST_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_SENDER_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_UPDATE_MSG_REQUEST_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_GET_MSG_ADDR_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_KEY_UPDATE_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_STATECHAIN_INFO/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_STATECHAIN_INFO_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_RECEIVER_REQUEST_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_RECEIVER_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$FIND_TEXT_TRANSFER_GET_RECEIVER_RESPONSE_PAYLOAD/i $ADD_TEXT" \
-e "/$IMPORT_FIND_TEXT$/ {
n;
/$IMPORT_ADD_SERIALIZABLE/!i $IMPORT_ADD_SERIALIZABLE
/$IMPORT_ADD_SERIALNAME/!i $IMPORT_ADD_SERIALNAME
}" \
-e "/$PACKAGE_REMOVE_TEXT/d" {} +

echo "@Serializable annotations added successfully."
42 changes: 42 additions & 0 deletions lib/modify_sh/modify_partial_signature_request_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class PartialSignatureRequestPayload\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `statechainId`:/ {
print "\t@SerialName(\"statechain_id\")"
}
in_data_class && /var `negateSeckey`:/ {
print "\t@SerialName(\"negate_seckey\")"
}
in_data_class && /var `signedStatechainId`:/ {
print "\t@SerialName(\"signed_statechain_id\")"
}
in_data_class && /var `serverPubNonce`:/ {
print "\t@SerialName(\"server_pub_nonce\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to PartialSignatureRequestPayload successfully."
33 changes: 33 additions & 0 deletions lib/modify_sh/modify_partial_signature_response_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class PartialSignatureResponsePayload\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `partialSig`:/ {
print "\t@SerialName(\"partial_sig\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to PartialSignatureResponsePayload successfully."
36 changes: 36 additions & 0 deletions lib/modify_sh/modify_sign_first_request_payload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Directory where Kotlin files are located
SEARCH_DIR="out-kotlin/com/mercurylayer"

# File pattern to search for (assuming all Kotlin files end with .kt)
FILE_PATTERN="*.kt"

# awk script to add @SerialName within data class Token
add_serial_name() {
local file_path="$1" # Path to the file being processed

awk '
BEGIN { in_data_class = 0 }
/data class SignFirstRequestPayload\(/ { in_data_class = 1 }
/^}/ { if (in_data_class) in_data_class = 0 }
in_data_class && /var `statechainId`:/ {
print "\t@SerialName(\"statechain_id\")"
}
in_data_class && /var `signedStatechainId`:/ {
print "\t@SerialName(\"signed_statechain_id\")"
}
{ print }
' "$file_path" > tmp && mv tmp "$file_path"
}

# Export the function so it's available to the subshell spawned by find
export -f add_serial_name

# Use find to locate Kotlin files and process them with the add_serial_name function
find "$SEARCH_DIR" -type f -name "$FILE_PATTERN" -exec bash -c 'add_serial_name "$0"' {} \;

echo "@SerialName annotations added to SignFirstRequestPayload successfully."
Loading

0 comments on commit 2bd67ed

Please sign in to comment.