Skip to content

Commit

Permalink
add missing conversion transaction functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Dec 7, 2021
1 parent c145aa3 commit e9ad8d1
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions bindings/wallet-cordova/src/android/WalletPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class WalletPlugin
"WALLET_CONFIRM_TRANSACTION" -> walletConfirmTransaction(args, callbackContext)
"WALLET_CONVERT" -> walletConvert(args, callbackContext)
"CONVERSION_TRANSACTIONS_SIZE" -> conversionTransactionsSize(args, callbackContext)
"CONVERSION_TRANSACTIONS_GET" -> conversionTransactionsGet(args, callbackContext)
"CONVERSION_IGNORED" -> conversionIgnored(args, callbackContext)
"PENDING_TRANSACTIONS_SIZE" -> pendingTransactionsSize(args, callbackContext)
"PENDING_TRANSACTIONS_GET" -> pendingTransactionsGet(args, callbackContext)
"BLOCK_DATE_FROM_SYSTEM_TIME" -> blockDateFromSystemTime(args, callbackContext)
Expand All @@ -90,7 +92,11 @@ class WalletPlugin
"SETTINGS_DELETE" -> settingsDelete(args, callbackContext)
"PROPOSAL_DELETE" -> proposalDelete(args, callbackContext)
"PENDING_TRANSACTIONS_DELETE" -> pendingTransactionsDelete(args, callbackContext)
else -> return false
"CONVERSION_DELETE" -> conversionDelete(args, callbackContext)
else -> {
Log.w(TAG, "not found: $action")
return false
}
}
return true
}
Expand Down Expand Up @@ -393,7 +399,7 @@ class WalletPlugin
)
val conversionId = nextConversionId.incrementAndGet()
conversionPool[conversionId] = conversion!!
callbackContext.success(conversionId)
callbackContext.success(conversionId.toString())
} catch (e: Exception) {
callbackContext.error(e.message)
}
Expand Down Expand Up @@ -530,37 +536,37 @@ class WalletPlugin
}
}

// @ExperimentalUnsignedTypes
// @Throws(JSONException::class)
// private fun conversionTransactionsGet(args: CordovaArgs, callbackContext: CallbackContext) {
// val conversionId = args.getInt(0)
// val index = args.getInt(1)
// val conversion = conversionPool[conversionId]
// try {
// val transaction: ByteArray = conversion?.fragments?.get(index).serialize().toUbyteArray().toByteArray()
// callbackContext.success(transaction)
// } catch (e: Exception) {
// callbackContext.error(e.message)
// }
// }

// @ExperimentalUnsignedTypes
// @Throws(JSONException::class)
// private fun conversionIgnored(args: CordovaArgs, callbackContext: CallbackContext) {
// val conversionId = args.getInt(0)
// val conversion = conversionPool[conversionId]

// try {
// val value = conversion?.ignoredValue
// val count = conversion?.ignoredCount

// val json = JSONObject().put("value", value).put("ignored", count)
// callbackContext.success(json)

// } catch (e: Exception) {
// callbackContext.error(e.message)
// }
// }
@ExperimentalUnsignedTypes
@Throws(JSONException::class)
private fun conversionTransactionsGet(args: CordovaArgs, callbackContext: CallbackContext) {
val conversionId = args.getInt(0)
val index = args.getInt(1)
val conversion = conversionPool[conversionId]
try {
val transaction: ByteArray? = conversion?.fragments?.get(index)?.serialize()?.toUByteArray()?.toByteArray()
callbackContext.success(transaction)
} catch (e: Exception) {
callbackContext.error(e.message)
}
}

@ExperimentalUnsignedTypes
@Throws(JSONException::class)
private fun conversionIgnored(args: CordovaArgs, callbackContext: CallbackContext) {
val conversionId = args.getInt(0)
val conversion = conversionPool[conversionId]

try {
val value = conversion?.ignoredValue
val count = conversion?.ignoredCount

val json = JSONObject().put("value", value).put("ignored", count)
callbackContext.success(json)

} catch (e: Exception) {
callbackContext.error(e.message)
}
}

@ExperimentalUnsignedTypes
@Throws(JSONException::class)
Expand Down Expand Up @@ -610,6 +616,18 @@ class WalletPlugin
}
}

@ExperimentalUnsignedTypes
@Throws(JSONException::class)
private fun conversionDelete(args: CordovaArgs, callbackContext: CallbackContext) {
val cid: Int = args.getInt(0)
try {
conversionPool.remove(cid)
callbackContext.success()
} catch (e: Exception) {
callbackContext.error(e.message)
}
}

companion object {
const val TAG = "WALLET"
}
Expand Down

0 comments on commit e9ad8d1

Please sign in to comment.