Skip to content

Commit b51edb2

Browse files
committed
add missing walletId getter
and also add a test for it, because that's the reason it almost slipped through
1 parent e9ad8d1 commit b51edb2

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

bindings/wallet-cordova/src/android/WalletPlugin.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import java.text.Normalizer
99
import java.text.Normalizer.Form
1010
import java.util.concurrent.atomic.AtomicInteger
1111

12-
1312
class WalletPlugin
1413
/**
1514
* Constructor.
@@ -74,6 +73,7 @@ class WalletPlugin
7473
"WALLET_VOTE" -> walletVote(args, callbackContext)
7574
"WALLET_TOTAL_FUNDS" -> walletTotalFunds(args, callbackContext)
7675
"WALLET_SPENDING_COUNTER" -> walletSpendingCounter(args, callbackContext)
76+
"WALLET_ID" -> walletId(args, callbackContext)
7777
"WALLET_SET_STATE" -> walletSetState(args, callbackContext)
7878
"WALLET_PENDING_TRANSACTIONS" -> walletPendingTransactions(args, callbackContext)
7979
"WALLET_CONFIRM_TRANSACTION" -> walletConfirmTransaction(args, callbackContext)
@@ -330,6 +330,20 @@ class WalletPlugin
330330
}
331331
}
332332

333+
@ExperimentalUnsignedTypes
334+
@Throws(JSONException::class)
335+
private fun walletId(args: CordovaArgs, callbackContext: CallbackContext) {
336+
val walletId = args.getInt(0)
337+
val wallet = wallets[walletId]
338+
339+
try {
340+
val id = wallet?.accountId()?.toUByteArray()?.toByteArray()
341+
callbackContext.success(id)
342+
} catch (e: Exception) {
343+
callbackContext.error(e.message)
344+
}
345+
}
346+
333347
@ExperimentalUnsignedTypes
334348
@Throws(JSONException::class)
335349
private fun walletSetState(args: CordovaArgs, callbackContext: CallbackContext) {

bindings/wallet-cordova/tests/src/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const restoreWallet = promisifyP(primitives.walletRestore);
2424
const importKeys = promisifyP(primitives.walletImportKeys);
2525
const retrieveFunds = promisifyP(primitives.walletRetrieveFunds);
2626
const spendingCounter = promisifyP(primitives.walletSpendingCounter);
27+
const walletId = promisifyP(primitives.walletId);
2728
const totalFunds = promisifyP(primitives.walletTotalFunds);
2829
const convertWallet = promisifyP(primitives.walletConvert);
2930
const setState = promisifyP(primitives.walletSetState);
@@ -64,6 +65,10 @@ const tests = [
6465
const funds = await totalFunds(walletPtr);
6566
expect(parseInt(funds)).toBe(21000);
6667

68+
const accountId = await walletId(walletPtr);
69+
70+
uint8ArrayEquals(accountId, hexStringToBytes(keys.account.account_id));
71+
6772
await deleteSettings(settingsPtr);
6873
await deleteWallet(walletPtr);
6974
}],

test-vectors/free_keys/keys.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"account": {
1010
"address": "ca1qkn28szy0t4ee32v7epzhget9989u8p77mtc9u4vla98q62vf5txx4am2rc",
1111
"private_key": "c86596c2d1208885db1fe3658406aa0f7cc7b8e13c362fe46a6db277fc5064583e487588c98a6c36e2e7445c0add36f83f171cb5ccfd815509d19cd38ecb0af3",
12-
"public_key": "ed25519_pk1563uq3r6awwv2n8kgg46x2effe0pc0hk67p09t8lffcxjnzdze3s9pc5aa"
12+
"public_key": "ed25519_pk1563uq3r6awwv2n8kgg46x2effe0pc0hk67p09t8lffcxjnzdze3s9pc5aa",
13+
"account_id": "a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663"
1314
},
1415
"utxo_keys": [
1516
{

0 commit comments

Comments
 (0)