Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) { | ||||
return; | return; | ||||
} | } | ||||
out.push_back(Pair("reqSigs", nRequired)); | out.push_back(Pair("reqSigs", nRequired)); | ||||
out.push_back(Pair("type", GetTxnOutputType(type))); | out.push_back(Pair("type", GetTxnOutputType(type))); | ||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const CTxDestination &addr : addresses) { | for (const CTxDestination &addr : addresses) { | ||||
a.push_back(CBitcoinAddress(addr).ToString()); | a.push_back(EncodeDestination(addr)); | ||||
} | } | ||||
out.push_back(Pair("addresses", a)); | out.push_back(Pair("addresses", a)); | ||||
} | } | ||||
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | ||||
UniValue &entry) { | UniValue &entry) { | ||||
entry.push_back(Pair("txid", tx.GetId().GetHex())); | entry.push_back(Pair("txid", tx.GetId().GetHex())); | ||||
▲ Show 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | for (unsigned int idx = 0; idx < inputs.size(); idx++) { | ||||
} | } | ||||
} | } | ||||
CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence); | CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence); | ||||
rawTx.vin.push_back(in); | rawTx.vin.push_back(in); | ||||
} | } | ||||
std::set<CBitcoinAddress> setAddress; | std::set<CTxDestination> destinations; | ||||
std::vector<std::string> addrList = sendTo.getKeys(); | std::vector<std::string> addrList = sendTo.getKeys(); | ||||
for (const std::string &name_ : addrList) { | for (const std::string &name_ : addrList) { | ||||
if (name_ == "data") { | if (name_ == "data") { | ||||
std::vector<uint8_t> data = | std::vector<uint8_t> data = | ||||
ParseHexV(sendTo[name_].getValStr(), "Data"); | ParseHexV(sendTo[name_].getValStr(), "Data"); | ||||
CTxOut out(0, CScript() << OP_RETURN << data); | CTxOut out(0, CScript() << OP_RETURN << data); | ||||
rawTx.vout.push_back(out); | rawTx.vout.push_back(out); | ||||
} else { | } else { | ||||
CBitcoinAddress address(name_); | CTxDestination destination = DecodeDestination(name_); | ||||
if (!address.IsValid()) { | if (!IsValidDestination(destination)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
std::string("Invalid Bitcoin address: ") + | std::string("Invalid Bitcoin address: ") + | ||||
name_); | name_); | ||||
} | } | ||||
if (setAddress.count(address)) { | if (!destinations.insert(destination).second) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
std::string("Invalid parameter, duplicated address: ") + | std::string("Invalid parameter, duplicated address: ") + | ||||
name_); | name_); | ||||
} | } | ||||
setAddress.insert(address); | CScript scriptPubKey = GetScriptForDestination(destination); | ||||
CScript scriptPubKey = GetScriptForDestination(address.Get()); | |||||
CAmount nAmount = AmountFromValue(sendTo[name_]); | CAmount nAmount = AmountFromValue(sendTo[name_]); | ||||
CTxOut out(nAmount, scriptPubKey); | CTxOut out(nAmount, scriptPubKey); | ||||
rawTx.vout.push_back(out); | rawTx.vout.push_back(out); | ||||
} | } | ||||
} | } | ||||
return EncodeHexTx(rawTx); | return EncodeHexTx(rawTx); | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | static UniValue decodescript(const Config &config, | ||||
ScriptPubKeyToJSON(script, r, false); | ScriptPubKeyToJSON(script, r, false); | ||||
UniValue type; | UniValue type; | ||||
type = find_value(r, "type"); | type = find_value(r, "type"); | ||||
if (type.isStr() && type.get_str() != "scripthash") { | if (type.isStr() && type.get_str() != "scripthash") { | ||||
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | // P2SH cannot be wrapped in a P2SH. If this script is already a P2SH, | ||||
// don't return the address for a P2SH of the P2SH. | // don't return the address for a P2SH of the P2SH. | ||||
r.push_back( | r.push_back(Pair("p2sh", EncodeDestination(CScriptID(script)))); | ||||
Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString())); | |||||
} | } | ||||
return r; | return r; | ||||
} | } | ||||
/** | /** | ||||
* Pushes a JSON object for script verification or signing errors to vErrorsRet. | * Pushes a JSON object for script verification or signing errors to vErrorsRet. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines |