Changeset View
Changeset View
Standalone View
Standalone View
src/core_write.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | const std::map<uint8_t, std::string> mapSigHashTypes = { | ||||
"NONE|FORKID|ANYONECANPAY"}, | "NONE|FORKID|ANYONECANPAY"}, | ||||
{SIGHASH_SINGLE, "SINGLE"}, | {SIGHASH_SINGLE, "SINGLE"}, | ||||
{SIGHASH_SINGLE | SIGHASH_ANYONECANPAY, "SINGLE|ANYONECANPAY"}, | {SIGHASH_SINGLE | SIGHASH_ANYONECANPAY, "SINGLE|ANYONECANPAY"}, | ||||
{SIGHASH_SINGLE | SIGHASH_FORKID, "SINGLE|FORKID"}, | {SIGHASH_SINGLE | SIGHASH_FORKID, "SINGLE|FORKID"}, | ||||
{SIGHASH_SINGLE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY, | {SIGHASH_SINGLE | SIGHASH_FORKID | SIGHASH_ANYONECANPAY, | ||||
"SINGLE|FORKID|ANYONECANPAY"}, | "SINGLE|FORKID|ANYONECANPAY"}, | ||||
}; | }; | ||||
std::string SighashToStr(uint8_t sighash_type) { | |||||
const auto &it = mapSigHashTypes.find(sighash_type); | |||||
if (it == mapSigHashTypes.end()) { | |||||
return ""; | |||||
} | |||||
return it->second; | |||||
} | |||||
/** | /** | ||||
* Create the assembly string representation of a CScript object. | * Create the assembly string representation of a CScript object. | ||||
* @param[in] script CScript object to convert into the asm string | * @param[in] script CScript object to convert into the asm string | ||||
* representation. | * representation. | ||||
* @param[in] fAttemptSighashDecode Whether to attempt to decode sighash | * @param[in] fAttemptSighashDecode Whether to attempt to decode sighash | ||||
* types on data within the script that matches the format of a signature. Only | * types on data within the script that matches the format of a signature. Only | ||||
* pass true for scripts you believe could contain signatures. For example, pass | * pass true for scripts you believe could contain signatures. For example, pass | ||||
* false, or omit the this argument (defaults to false), for scriptPubKeys. | * false, or omit the this argument (defaults to false), for scriptPubKeys. | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags) { | std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags) { | ||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serializeFlags); | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | serializeFlags); | ||||
ssTx << tx; | ssTx << tx; | ||||
return HexStr(ssTx.begin(), ssTx.end()); | return HexStr(ssTx.begin(), ssTx.end()); | ||||
} | } | ||||
void ScriptToUniv(const CScript &script, UniValue &out, bool include_address) { | |||||
out.pushKV("asm", ScriptToAsmStr(script)); | |||||
out.pushKV("hex", HexStr(script.begin(), script.end())); | |||||
std::vector<std::vector<uint8_t>> solns; | |||||
txnouttype type; | |||||
Solver(script, type, solns); | |||||
out.pushKV("type", GetTxnOutputType(type)); | |||||
CTxDestination address; | |||||
if (include_address && ExtractDestination(script, address)) { | |||||
out.pushKV("address", EncodeDestination(address, GetConfig())); | |||||
} | |||||
} | |||||
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, | void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, | ||||
bool fIncludeHex) { | bool fIncludeHex) { | ||||
txnouttype type; | txnouttype type; | ||||
std::vector<CTxDestination> addresses; | std::vector<CTxDestination> addresses; | ||||
int nRequired; | int nRequired; | ||||
out.pushKV("asm", ScriptToAsmStr(scriptPubKey)); | out.pushKV("asm", ScriptToAsmStr(scriptPubKey)); | ||||
if (fIncludeHex) { | if (fIncludeHex) { | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |