Update memo to accept bytes instead of a string.

This commit is contained in:
Kevin Gorham 2019-11-12 11:58:15 -05:00
parent 9cb178d6fb
commit 7e9127538f
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
8 changed files with 23 additions and 32 deletions

View File

@ -37,8 +37,7 @@ class RustBackendTest {
0,
"dummykey",
"ztestsapling1fg82ar8y8whjfd52l0xcq0w3n7nn7cask2scp9rp27njeurr72ychvud57s9tu90fdqgwdt07lg",
210_000,
""
210_000
)
}

View File

@ -75,7 +75,7 @@ data class PendingTransactionEntity(
override val id: Long = 0,
override val toAddress: String = "",
override val value: Long = -1,
override val memo: String? = null,
override val memo: ByteArray? = byteArrayOf(),
override val accountIndex: Int,
override val minedHeight: Int = -1,
override val expiryHeight: Int = -1,
@ -88,11 +88,10 @@ data class PendingTransactionEntity(
override val createTime: Long = System.currentTimeMillis(),
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
override val raw: ByteArray = ByteArray(0),
override val raw: ByteArray = byteArrayOf(),
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
override val rawTransactionId: ByteArray? = null
override val rawTransactionId: ByteArray? = byteArrayOf()
) : PendingTransaction {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is PendingTransactionEntity) return false
@ -100,7 +99,10 @@ data class PendingTransactionEntity(
if (id != other.id) return false
if (toAddress != other.toAddress) return false
if (value != other.value) return false
if (memo != other.memo) return false
if (memo != null) {
if (other.memo == null) return false
if (!memo.contentEquals(other.memo)) return false
} else if (other.memo != null) return false
if (accountIndex != other.accountIndex) return false
if (minedHeight != other.minedHeight) return false
if (expiryHeight != other.expiryHeight) return false
@ -123,7 +125,7 @@ data class PendingTransactionEntity(
var result = id.hashCode()
result = 31 * result + toAddress.hashCode()
result = 31 * result + value.hashCode()
result = 31 * result + (memo?.hashCode() ?: 0)
result = 31 * result + (memo?.contentHashCode() ?: 0)
result = 31 * result + accountIndex
result = 31 * result + minedHeight
result = 31 * result + expiryHeight
@ -137,6 +139,7 @@ data class PendingTransactionEntity(
result = 31 * result + (rawTransactionId?.contentHashCode() ?: 0)
return result
}
}
@ -152,7 +155,7 @@ data class PendingTransactionEntity(
data class ConfirmedTransaction(
override val id: Long = 0L,
override val value: Long = 0L,
override val memo: ByteArray? = null,
override val memo: ByteArray? = ByteArray(0),
override val noteId: Long = 0L,
override val blockTimeInSeconds: Long = 0L,
override val minedHeight: Int = -1,

View File

@ -101,14 +101,14 @@ class RustBackend : RustBackendWelding {
extsk: String,
to: String,
value: Long,
memo: String
memo: ByteArray?
): Long = createToAddress(
dbDataPath,
account,
extsk,
to,
value,
memo,
memo ?: ByteArray(0),
"${paramDestinationDir}/$SPEND_PARAM_FILE_NAME",
"${paramDestinationDir}/$OUTPUT_PARAM_FILE_NAME"
)
@ -216,17 +216,6 @@ class RustBackend : RustBackendWelding {
@JvmStatic private external fun initLogs()
private external fun createToAddress(
dbDataPath: String,
account: Int,
extsk: String,
to: String,
value: Long,
memo: String,
spendParamsPath: String,
outputParamsPath: String
): Long
@JvmStatic private external fun deriveExtendedSpendingKeys(seed: ByteArray, numberOfAccounts: Int): Array<String>
@JvmStatic private external fun deriveExtendedFullViewingKeys(seed: ByteArray, numberOfAccounts: Int): Array<String>

View File

@ -39,7 +39,7 @@ interface RustBackendWelding {
extsk: String,
to: String,
value: Long,
memo: String
memo: ByteArray? = byteArrayOf()
): Long
fun deriveSpendingKeys(seed: ByteArray, numberOfAccounts: Int = 1): Array<String>

View File

@ -64,7 +64,7 @@ class PersistentTransactionManager(
var tx = PendingTransactionEntity(
value = zatoshiValue,
toAddress = toAddress,
memo = memo,
memo = memo.toByteArray(),
accountIndex = fromAccountIndex
)
try {
@ -110,7 +110,7 @@ class PersistentTransactionManager(
spendingKey,
tx.value,
tx.toAddress,
tx.memo ?: "",
tx.memo,
tx.accountIndex
)
twig("successfully encoded transaction for ${tx.memo}!!")

View File

@ -10,7 +10,7 @@ interface TransactionEncoder {
spendingKey: String,
zatoshi: Long,
toAddress: String,
memo: String,
fromAccountIndex: Int
memo: ByteArray? = byteArrayOf(),
fromAccountIndex: Int = 0
): EncodedTransaction
}

View File

@ -27,7 +27,7 @@ class WalletTransactionEncoder(
spendingKey: String,
zatoshi: Long,
toAddress: String,
memo: String,
memo: ByteArray?,
fromAccountIndex: Int
): EncodedTransaction = withContext(IO) {
val transactionId = createSpend(spendingKey, zatoshi, toAddress, memo)
@ -53,7 +53,7 @@ class WalletTransactionEncoder(
spendingKey: String,
value: Long,
toAddress: String,
memo: String = "",
memo: ByteArray? = byteArrayOf(),
fromAccountIndex: Int = 0
): Long = withContext(IO) {
twigTask("creating transaction to spend $value zatoshi to" +

View File

@ -381,7 +381,7 @@ pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_RustBackend_createToAddress(
extsk: JString<'_>,
to: JString<'_>,
value: jlong,
memo: JString<'_>,
memo: jbyteArray,
spend_params: JString<'_>,
output_params: JString<'_>,
) -> jlong {
@ -398,7 +398,7 @@ pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_RustBackend_createToAddress(
if value.is_negative() {
return Err(format_err!("Amount is negative"));
}
let memo = utils::java_string_to_rust(&env, memo);
let memo_bytes = env.convert_byte_array(memo).unwrap();
let spend_params = utils::java_string_to_rust(&env, spend_params);
let output_params = utils::java_string_to_rust(&env, output_params);
@ -419,7 +419,7 @@ pub unsafe extern "C" fn Java_cash_z_wallet_sdk_jni_RustBackend_createToAddress(
}
};
let memo = Memo::from_str(&memo);
let memo = Memo::from_bytes(&memo_bytes);
let prover = LocalTxProver::new(Path::new(&spend_params), Path::new(&output_params));