wallet: Implement `z_listunifiedreceivers`

Closes zcash/zcash#5181.
This commit is contained in:
Jack Grigg 2022-01-14 00:56:33 +00:00
parent 8617622e0d
commit baaa3c4ac0
2 changed files with 33 additions and 4 deletions

View File

@ -19,6 +19,10 @@ class WalletAccountsTest(BitcoinTestFramework):
'-orchardwallet',
]] * self.num_nodes)
def check_receiver_types(self, ua, expected):
actual = self.nodes[0].z_listunifiedreceivers(ua)
assert_equal(set(expected), set(actual))
def run_test(self):
# With a new wallet, the first account will be 0.
account0 = self.nodes[0].z_getnewaccount()
@ -53,6 +57,10 @@ class WalletAccountsTest(BitcoinTestFramework):
ua1 = addr1['unifiedaddress']
assert(ua0 != ua1)
# The UA contains the expected receiver kinds.
self.check_receiver_types(ua0, ['transparent', 'sapling'])
self.check_receiver_types(ua1, ['transparent', 'sapling'])
if __name__ == '__main__':
WalletAccountsTest().main()

View File

@ -3285,11 +3285,32 @@ UniValue z_listunifiedreceivers(const UniValue& params, bool fHelp)
if (!fExperimentalOrchardWallet) {
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: the Orchard wallet experimental extensions are disabled.");
}
std::string ua = params[0].get_str();
KeyIO keyIO(Params());
auto decoded = keyIO.DecodePaymentAddress(params[0].get_str());
if (!decoded.has_value()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
if (!std::holds_alternative<libzcash::UnifiedAddress>(decoded.value())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Address is not a unified address");
}
auto ua = std::get<libzcash::UnifiedAddress>(decoded.value());
UniValue result(UniValue::VOBJ);
result.pushKV("transparent", "TODO");
result.pushKV("sapling", "TODO");
result.pushKV("orchard", "TODO " + ua);
for (const auto& receiver : ua) {
std::visit(match {
[&](const libzcash::SaplingPaymentAddress& addr) {
result.pushKV("sapling", keyIO.EncodePaymentAddress(addr));
},
[&](const CScriptID& addr) {
result.pushKV("transparent", keyIO.EncodePaymentAddress(addr));
},
[&](const CKeyID& addr) {
result.pushKV("transparent", keyIO.EncodePaymentAddress(addr));
},
[](auto rest) {},
}, receiver);
}
return result;
}