Sapling transaction testing
This commit is contained in:
@@ -342,8 +342,10 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
|
||||
// update the transaction with these inputs
|
||||
if (isUsingBuilder_) {
|
||||
CScript scriptPubKey = GetScriptForDestination(fromtaddr_);
|
||||
CScript scriptPubKey;
|
||||
for (auto t : t_inputs_) {
|
||||
scriptPubKey = GetScriptForDestination(std::get<4>(t));
|
||||
//printf("Checking new script: %s\n", scriptPubKey.ToString().c_str());
|
||||
uint256 txid = std::get<0>(t);
|
||||
int vout = std::get<1>(t);
|
||||
CAmount amount = std::get<2>(t);
|
||||
@@ -993,17 +995,20 @@ void AsyncRPCOperation_sendmany::sign_send_raw_transaction(UniValue obj)
|
||||
tx_ = tx;
|
||||
}
|
||||
|
||||
|
||||
bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
|
||||
std::set<CTxDestination> destinations;
|
||||
destinations.insert(fromtaddr_);
|
||||
|
||||
//printf("Looking for %s\n", boost::apply_visitor(AddressVisitorString(), fromtaddr_).c_str());
|
||||
|
||||
vector<COutput> vecOutputs;
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true, fAcceptCoinbase);
|
||||
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs) {
|
||||
CTxDestination dest;
|
||||
|
||||
if (!out.fSpendable) {
|
||||
continue;
|
||||
}
|
||||
@@ -1012,13 +1017,15 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const CScript &scriptPubKey = out.tx->vout[out.i].scriptPubKey;
|
||||
|
||||
if (destinations.size()) {
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
||||
if (!ExtractDestination(scriptPubKey, dest)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!destinations.count(address)) {
|
||||
//printf("%s\n", boost::apply_visitor(AddressVisitorString(), dest).c_str());
|
||||
if (!destinations.count(dest)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1029,8 +1036,12 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ExtractDestination(scriptPubKey, dest, true))
|
||||
continue;
|
||||
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
SendManyInputUTXO utxo(out.tx->GetHash(), out.i, nValue, isCoinbase);
|
||||
|
||||
SendManyInputUTXO utxo(out.tx->GetHash(), out.i, nValue, isCoinbase, dest);
|
||||
t_inputs_.push_back(utxo);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ using namespace libzcash;
|
||||
typedef std::tuple<std::string, CAmount, std::string> SendManyRecipient;
|
||||
|
||||
// Input UTXO is a tuple (quadruple) of txid, vout, amount, coinbase)
|
||||
typedef std::tuple<uint256, int, CAmount, bool> SendManyInputUTXO;
|
||||
typedef std::tuple<uint256, int, CAmount, bool, CTxDestination> SendManyInputUTXO;
|
||||
|
||||
// Input JSOP is a tuple of JSOutpoint, note and amount
|
||||
typedef std::tuple<JSOutPoint, SproutNote, CAmount> SendManyInputJSOP;
|
||||
|
||||
@@ -77,7 +77,7 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
||||
auto address = DecodePaymentAddress(toAddress);
|
||||
if (IsValidPaymentAddress(address)) {
|
||||
// TODO: Add Sapling support. For now, ensure we can freely convert.
|
||||
assert(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
|
||||
// assert(boost::get<libzcash::SproutPaymentAddress>(&address) != nullptr);
|
||||
tozaddr_ = address;
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid to address");
|
||||
|
||||
@@ -3451,7 +3451,9 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp)
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
std::string defaultType = ADDR_TYPE_SPROUT;
|
||||
bool allowSapling = (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= chainActive.LastTip()->nHeight);
|
||||
|
||||
std::string defaultType = allowSapling ? ADDR_TYPE_SAPLING : ADDR_TYPE_SPROUT;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -3478,10 +3480,6 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp)
|
||||
addrType = params[0].get_str();
|
||||
}
|
||||
|
||||
bool allowSapling = Params().NetworkIDString() == "regtest" || (
|
||||
Params().NetworkIDString() == "test" &&
|
||||
GetBoolArg("-experimentalfeatures", false) &&
|
||||
GetBoolArg("-developersapling", false));
|
||||
if (addrType == ADDR_TYPE_SPROUT) {
|
||||
return EncodePaymentAddress(pwalletMain->GenerateNewZKey());
|
||||
} else if (addrType == ADDR_TYPE_SAPLING && allowSapling) {
|
||||
|
||||
@@ -4406,6 +4406,12 @@ public:
|
||||
vKeys.push_back(keyId);
|
||||
}
|
||||
|
||||
void operator()(const CPubKey &key) {
|
||||
CKeyID keyId = key.GetID();
|
||||
if (keystore.HaveKey(keyId))
|
||||
vKeys.push_back(keyId);
|
||||
}
|
||||
|
||||
void operator()(const CScriptID &scriptId) {
|
||||
CScript script;
|
||||
if (keystore.GetCScript(scriptId, script))
|
||||
|
||||
@@ -1387,4 +1387,46 @@ public:
|
||||
boost::optional<libzcash::SpendingKey> operator()(const libzcash::InvalidEncoding& no) const;
|
||||
};
|
||||
|
||||
class GetPubKeyForPubKey : public boost::static_visitor<CPubKey> {
|
||||
private:
|
||||
const CKeyStore &keystore;
|
||||
|
||||
public:
|
||||
GetPubKeyForPubKey(const CKeyStore &keystoreIn) : keystore(keystoreIn) {}
|
||||
|
||||
CPubKey operator()(const CKeyID &id) const {
|
||||
return CPubKey();
|
||||
}
|
||||
|
||||
CPubKey operator()(const CPubKey &key) const {
|
||||
return key;
|
||||
}
|
||||
|
||||
CPubKey operator()(const CScriptID &sid) const {
|
||||
return CPubKey();
|
||||
}
|
||||
|
||||
CPubKey operator()(const CNoDestination &no) const {
|
||||
return CPubKey();
|
||||
}
|
||||
};
|
||||
|
||||
class AddressVisitorString : public boost::static_visitor<std::string>
|
||||
{
|
||||
public:
|
||||
std::string operator()(const CNoDestination &dest) const { return ""; }
|
||||
|
||||
std::string operator()(const CKeyID &keyID) const {
|
||||
return "key hash: " + keyID.ToString();
|
||||
}
|
||||
|
||||
std::string operator()(const CPubKey &key) const {
|
||||
return "public key: " + HexStr(key);
|
||||
}
|
||||
|
||||
std::string operator()(const CScriptID &scriptID) const {
|
||||
return "script hash: " + scriptID.ToString();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BITCOIN_WALLET_WALLET_H
|
||||
|
||||
Reference in New Issue
Block a user