decred: Add new addr and addrs.

This commit is contained in:
JoeGruff 2024-03-12 13:54:43 +09:00
parent 5ff6ff110a
commit 5d19f4f601
2 changed files with 31 additions and 4 deletions

View file

@ -239,3 +239,28 @@ String signMessage(Map<String, String> args) {
);
return res.payload;
}
String? newExternalAddress(String walletName) {
final cName = walletName.toCString();
final res = executePayloadFn(
fn: () => dcrwalletApi.newExternalAddress(cName),
ptrsToFree: [cName],
skipErrorCheck: true, // errCode is checked below, before checking err
);
if (res.errCode == ErrCodeNotSynced) {
// Wallet is not synced. We do not want to give out a used address so give
// nothing.
return null;
}
checkErr(res.err);
return res.payload;
}
String addresses(String walletName) {
final cName = walletName.toCString();
final res = executePayloadFn(
fn: () => dcrwalletApi.addresses(cName),
ptrsToFree: [cName],
);
return res.payload;
}

View file

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_decred/api/libdcrwallet.dart' as libdcrwallet;
@ -11,13 +13,13 @@ class DecredWalletAddresses extends WalletAddresses {
}
String generateNewAddress() {
// TODO: generate new external address with libdcrwallet.
return "DsT4qJPPaYEuQRimfgvSKxKH3paysn1x3Nt";
return libdcrwallet.newExternalAddress(walletInfo.name) ?? '';
}
List<String> addresses() {
final currentAddress = libdcrwallet.currentReceiveAddress(walletInfo.name);
return currentAddress == null ? [] : [currentAddress];
final res = libdcrwallet.addresses(walletInfo.name);
final addrs = (json.decode(res) as List<dynamic>).cast<String>();
return addrs;
}
@override