Add CashAddr Address Format
Ported from Bitcoin Unlimited, Bitcoin ABC
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "base58.h"
|
||||
#include "chainparams.h"
|
||||
#include "clientversion.h"
|
||||
#include "coins.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "core_io.h"
|
||||
#include "dstencode.h"
|
||||
#include "keystore.h"
|
||||
#include "policy/policy.h"
|
||||
#include "primitives/transaction.h"
|
||||
@@ -158,6 +160,15 @@ static void RegisterLoad(const string& strInput)
|
||||
RegisterSetJson(key, valStr);
|
||||
}
|
||||
|
||||
static CAmount ExtractAndValidateValue(const string& strValue)
|
||||
{
|
||||
CAmount value;
|
||||
if (!ParseMoney(strValue, value))
|
||||
throw runtime_error("Invalid TX output value");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static void MutateTxVersion(CMutableTransaction& tx, const string& cmdVal)
|
||||
{
|
||||
int64_t newVersion = atoi64(cmdVal);
|
||||
@@ -222,26 +233,23 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
|
||||
static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
|
||||
{
|
||||
// separate VALUE:ADDRESS in string
|
||||
size_t pos = strInput.find(':');
|
||||
if ((pos == string::npos) ||
|
||||
(pos == 0) ||
|
||||
(pos == (strInput.size() - 1)))
|
||||
throw runtime_error("TX output missing separator");
|
||||
std::vector<std::string> vStrInputParts;
|
||||
boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
|
||||
|
||||
// extract and validate VALUE
|
||||
string strValue = strInput.substr(0, pos);
|
||||
CAmount value;
|
||||
if (!ParseMoney(strValue, value))
|
||||
throw runtime_error("invalid TX output value");
|
||||
if (vStrInputParts.size() != 2)
|
||||
throw runtime_error("TX output missing or too many separators");
|
||||
|
||||
// Extract and validate VALUE
|
||||
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
|
||||
|
||||
// extract and validate ADDRESS
|
||||
string strAddr = strInput.substr(pos + 1, string::npos);
|
||||
CBitcoinAddress addr(strAddr);
|
||||
if (!addr.IsValid())
|
||||
throw runtime_error("invalid TX output address");
|
||||
|
||||
// build standard output script via GetScriptForDestination()
|
||||
CScript scriptPubKey = GetScriptForDestination(addr.Get());
|
||||
std::string strAddr = vStrInputParts[1];
|
||||
CTxDestination destination = DecodeDestination(strAddr);
|
||||
if (!IsValidDestination(destination))
|
||||
{
|
||||
throw std::runtime_error("invalid TX output address");
|
||||
}
|
||||
CScript scriptPubKey = GetScriptForDestination(destination);
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
CTxOut txout(value, scriptPubKey);
|
||||
@@ -280,20 +288,30 @@ static void MutateTxAddOutData(CMutableTransaction& tx, const string& strInput)
|
||||
static void MutateTxAddOutScript(CMutableTransaction& tx, const string& strInput)
|
||||
{
|
||||
// separate VALUE:SCRIPT in string
|
||||
size_t pos = strInput.find(':');
|
||||
if ((pos == string::npos) ||
|
||||
(pos == 0))
|
||||
std::vector<std::string> vStrInputParts;
|
||||
boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
|
||||
if (vStrInputParts.size() < 2)
|
||||
throw runtime_error("TX output missing separator");
|
||||
|
||||
// extract and validate VALUE
|
||||
string strValue = strInput.substr(0, pos);
|
||||
CAmount value;
|
||||
if (!ParseMoney(strValue, value))
|
||||
throw runtime_error("invalid TX output value");
|
||||
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
|
||||
|
||||
// extract and validate script
|
||||
string strScript = strInput.substr(pos + 1, string::npos);
|
||||
CScript scriptPubKey = ParseScript(strScript); // throws on err
|
||||
std::string strScript = vStrInputParts[1];
|
||||
CScript scriptPubKey = ParseScript(strScript);
|
||||
|
||||
// Extract FLAGS
|
||||
bool bScriptHash = false;
|
||||
if (vStrInputParts.size() > 2)
|
||||
{
|
||||
std::string flags = vStrInputParts.back();
|
||||
bScriptHash = (flags.find("S") != std::string::npos);
|
||||
}
|
||||
|
||||
if (bScriptHash)
|
||||
{
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
|
||||
}
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
CTxOut txout(value, scriptPubKey);
|
||||
|
||||
Reference in New Issue
Block a user