diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -222,6 +222,8 @@ }, }, }, + {"payoutAddress", RPCArg::Type::STR, RPCArg::Optional::OMITTED, + "A payout address (not required for legacy proofs)"}, }, RPCResult{RPCResult::Type::STR_HEX, "proof", "A string that is a serialized, hex-encoded proof data."}, @@ -241,7 +243,23 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid master key"); } - avalanche::ProofBuilder pb(sequence, expiration, masterKey); + CTxDestination payoutAddress = CNoDestination(); + if (!avalanche::Proof::useLegacy(gArgs)) { + if (request.params[4].isNull()) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + "A payout address is required if `-legacyavaproof` is false"); + } + payoutAddress = DecodeDestination(request.params[4].get_str(), + config.GetChainParams()); + + if (!IsValidDestination(payoutAddress)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid payout address"); + } + } + + avalanche::ProofBuilder pb(sequence, expiration, masterKey, + GetScriptForDestination(payoutAddress)); const UniValue &stakes = request.params[3].get_array(); for (size_t i = 0; i < stakes.size(); i++) { @@ -661,7 +679,7 @@ // ------------------- ------------------------ ---------------------- ---------- { "avalanche", "getavalanchekey", getavalanchekey, {}}, { "avalanche", "addavalanchenode", addavalanchenode, {"nodeid"}}, - { "avalanche", "buildavalancheproof", buildavalancheproof, {"sequence", "expiration", "master", "stakes"}}, + { "avalanche", "buildavalancheproof", buildavalancheproof, {"sequence", "expiration", "master", "stakes", "payoutAddress"}}, { "avalanche", "decodeavalancheproof", decodeavalancheproof, {"proof"}}, { "avalanche", "delegateavalancheproof", delegateavalancheproof, {"proof", "privatekey", "publickey", "delegation"}}, { "avalanche", "getavalanchepeerinfo", getavalanchepeerinfo, {}}, diff --git a/test/functional/abc_rpc_buildavalancheproof.py b/test/functional/abc_rpc_buildavalancheproof.py --- a/test/functional/abc_rpc_buildavalancheproof.py +++ b/test/functional/abc_rpc_buildavalancheproof.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the buildavalancheproof RPC""" +from test_framework.address import ADDRESS_ECREG_UNSPENDABLE from test_framework.avatools import create_coinbase_stakes from test_framework.key import ECKey from test_framework.test_framework import BitcoinTestFramework @@ -102,14 +103,32 @@ extra_args=self.extra_args[0] + ['-legacyavaproof=0']) - # FIXME The buildavalancheproof does not support a payout script - # parameter yet, so it builds an invalid proof with an empty script - invalid_payout = node.buildavalancheproof( - 0, 0, wif_privkey, [good_stake]) assert_raises_rpc_error(-8, - "The proof is invalid: payout-script-non-standard", - node.verifyavalancheproof, - invalid_payout) + "A payout address is required if `-legacyavaproof` is false", + node.buildavalancheproof, + 0, + 0, + wif_privkey, + [good_stake], + ) + + assert_raises_rpc_error(-8, + "Invalid payout address", + node.buildavalancheproof, + 0, + 0, + wif_privkey, + [good_stake], + "ecregtest:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcrl5mqkq", + ) + + # Happy path + node.buildavalancheproof( + 0, + 0, + wif_privkey, + [good_stake], + ADDRESS_ECREG_UNSPENDABLE) if __name__ == '__main__':