Skip to content

Commit

Permalink
add missing walletId getter
Browse files Browse the repository at this point in the history
and also add a test for it, because that's the reason it almost slipped
through
  • Loading branch information
ecioppettini committed Dec 20, 2021
1 parent e9ad8d1 commit b51edb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
16 changes: 15 additions & 1 deletion bindings/wallet-cordova/src/android/WalletPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.text.Normalizer
import java.text.Normalizer.Form
import java.util.concurrent.atomic.AtomicInteger


class WalletPlugin
/**
* Constructor.
Expand Down Expand Up @@ -74,6 +73,7 @@ class WalletPlugin
"WALLET_VOTE" -> walletVote(args, callbackContext)
"WALLET_TOTAL_FUNDS" -> walletTotalFunds(args, callbackContext)
"WALLET_SPENDING_COUNTER" -> walletSpendingCounter(args, callbackContext)
"WALLET_ID" -> walletId(args, callbackContext)
"WALLET_SET_STATE" -> walletSetState(args, callbackContext)
"WALLET_PENDING_TRANSACTIONS" -> walletPendingTransactions(args, callbackContext)
"WALLET_CONFIRM_TRANSACTION" -> walletConfirmTransaction(args, callbackContext)
Expand Down Expand Up @@ -330,6 +330,20 @@ class WalletPlugin
}
}

@ExperimentalUnsignedTypes
@Throws(JSONException::class)
private fun walletId(args: CordovaArgs, callbackContext: CallbackContext) {
val walletId = args.getInt(0)
val wallet = wallets[walletId]

try {
val id = wallet?.accountId()?.toUByteArray()?.toByteArray()
callbackContext.success(id)
} catch (e: Exception) {
callbackContext.error(e.message)
}
}

@ExperimentalUnsignedTypes
@Throws(JSONException::class)
private fun walletSetState(args: CordovaArgs, callbackContext: CallbackContext) {
Expand Down
5 changes: 5 additions & 0 deletions bindings/wallet-cordova/tests/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const restoreWallet = promisifyP(primitives.walletRestore);
const importKeys = promisifyP(primitives.walletImportKeys);
const retrieveFunds = promisifyP(primitives.walletRetrieveFunds);
const spendingCounter = promisifyP(primitives.walletSpendingCounter);
const walletId = promisifyP(primitives.walletId);
const totalFunds = promisifyP(primitives.walletTotalFunds);
const convertWallet = promisifyP(primitives.walletConvert);
const setState = promisifyP(primitives.walletSetState);
Expand Down Expand Up @@ -64,6 +65,10 @@ const tests = [
const funds = await totalFunds(walletPtr);
expect(parseInt(funds)).toBe(21000);

const accountId = await walletId(walletPtr);

uint8ArrayEquals(accountId, hexStringToBytes(keys.account.account_id));

await deleteSettings(settingsPtr);
await deleteWallet(walletPtr);
}],
Expand Down
3 changes: 2 additions & 1 deletion test-vectors/free_keys/keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"account": {
"address": "ca1qkn28szy0t4ee32v7epzhget9989u8p77mtc9u4vla98q62vf5txx4am2rc",
"private_key": "c86596c2d1208885db1fe3658406aa0f7cc7b8e13c362fe46a6db277fc5064583e487588c98a6c36e2e7445c0add36f83f171cb5ccfd815509d19cd38ecb0af3",
"public_key": "ed25519_pk1563uq3r6awwv2n8kgg46x2effe0pc0hk67p09t8lffcxjnzdze3s9pc5aa"
"public_key": "ed25519_pk1563uq3r6awwv2n8kgg46x2effe0pc0hk67p09t8lffcxjnzdze3s9pc5aa",
"account_id": "a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663"
},
"utxo_keys": [
{
Expand Down

0 comments on commit b51edb2

Please sign in to comment.