Skip to content

Commit

Permalink
Check for deposit address validity
Browse files Browse the repository at this point in the history
* Check in deposit RPC
* Check before adding deposits to coinbase transaction
  • Loading branch information
nchashch committed May 2, 2024
1 parent 16e8e63 commit b438d5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/drivechain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ std::vector<CTxOut> CDrivechain::GetCoinbaseOutputs()
std::string address(output.address);
LogPrintf("deposit output: address = %s, amount = %d\n", address, output.amount);
CTxDestination dest = keyIO.DecodeDestination(address);
if(std::holds_alternative<CNoDestination>(dest)) {
continue;
}
CScript scriptPubKey = GetScriptForDestination(dest);
CTxOut txout(output.amount, scriptPubKey);
txouts.push_back(txout);
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ UniValue deposit(const UniValue& params, bool fHelp) {
address = keyIO.EncodeDestination(keyID);
} else {
address = params[2].get_str();
KeyIO keyIO(Params());
CTxDestination dest = keyIO.DecodeDestination(address);
if(std::holds_alternative<CNoDestination>(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid deposit address: ") + address);
}
}

return drivechain->CreateDeposit(address, nAmount, nFee);
Expand Down

0 comments on commit b438d5f

Please sign in to comment.