Skip to content

Commit

Permalink
Ignore address field in GetAddressUtxos response (#1607)
Browse files Browse the repository at this point in the history
The only thing we were doing with it was passing it through to Rust and
parsing it (panicking if parsing failed). The actual address is fetched
from the UTXO itself, and the Rust code was not doing anything to ensure
the two matched. Given that there seem to be bugs upstream in the address
data, we now just ignore it.
  • Loading branch information
str4d authored Oct 16, 2024
1 parent e37a35a commit d133140
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ interface Backend {
@Suppress("LongParameterList")
@Throws(RuntimeException::class)
suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ class RustBackend private constructor(
}

override suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
Expand All @@ -398,7 +397,6 @@ class RustBackend private constructor(
) = withContext(SdkDispatchers.DATABASE_IO) {
putUtxo(
dataDbFile.absolutePath,
tAddress,
txId,
index,
script,
Expand Down Expand Up @@ -722,7 +720,6 @@ class RustBackend private constructor(
@Suppress("LongParameterList")
private external fun putUtxo(
dbDataPath: String,
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
Expand Down
3 changes: 0 additions & 3 deletions backend-lib/src/main/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,6 @@ pub extern "C" fn Java_cash_z_ecc_android_sdk_internal_jni_RustBackend_putUtxo<'
mut env: JNIEnv<'local>,
_: JClass<'local>,
db_data: JString<'local>,
address: JString<'local>,
txid_bytes: JByteArray<'local>,
index: jint,
script: JByteArray<'local>,
Expand All @@ -1609,8 +1608,6 @@ pub extern "C" fn Java_cash_z_ecc_android_sdk_internal_jni_RustBackend_putUtxo<'

let script_pubkey = Script(env.convert_byte_array(script).unwrap());
let mut db_data = wallet_db(env, network, db_data)?;
let addr = utils::java_string_to_rust(env, &address);
let _address = TransparentAddress::decode(&network, &addr).unwrap();

let output = WalletTransparentOutput::from_parts(
OutPoint::new(txid, index as u32),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cash.z.wallet.sdk.internal.rpc.Service
* It is marked as "unsafe" because it is not guaranteed to be valid.
*/
class GetAddressUtxosReplyUnsafe(
val address: String,
val txid: ByteArray,
val index: Int,
val script: ByteArray,
Expand All @@ -16,7 +15,6 @@ class GetAddressUtxosReplyUnsafe(
companion object {
fun new(getAddressUtxosReply: Service.GetAddressUtxosReply): GetAddressUtxosReplyUnsafe {
return GetAddressUtxosReplyUnsafe(
address = getAddressUtxosReply.address,
txid = getAddressUtxosReply.txid.toByteArray(),
index = getAddressUtxosReply.index,
script = getAddressUtxosReply.script.toByteArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ internal class FakeRustBackend(
}

override suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,6 @@ class CompactBlockProcessor internal constructor(
// from what is _not_ returned as a UTXO, or alternatively fetch TXOs from lightwalletd instead of just UTXOs.
Twig.debug { "Found UTXO at height ${utxo.height.toInt()} with ${utxo.valueZat} zatoshi" }
backend.putUtxo(
utxo.address,
utxo.txid,
utxo.index,
utxo.script,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ internal interface TypesafeBackend {

@Suppress("LongParameterList")
suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,13 @@ internal class TypesafeBackendImpl(private val backend: Backend) : TypesafeBacke

@Suppress("LongParameterList")
override suspend fun putUtxo(
tAddress: String,
txId: ByteArray,
index: Int,
script: ByteArray,
value: Long,
height: BlockHeight
) {
return backend.putUtxo(
tAddress,
txId,
index,
script,
Expand Down

0 comments on commit d133140

Please sign in to comment.