Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 553 Lines • ▼ Show 20 Lines | for (unsigned int i = 0; i < N_SIGHASH_OPTS; i++) { | ||||
sigHashType = SigHashType(sigHashOptions[i].flags); | sigHashType = SigHashType(sigHashOptions[i].flags); | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
static Amount AmountFromValue(const UniValue &value) { | |||||
if (!value.isNum() && !value.isStr()) { | |||||
throw std::runtime_error("Amount is not a number or string"); | |||||
} | |||||
int64_t n; | |||||
if (!ParseFixedPoint(value.getValStr(), 8, &n)) { | |||||
throw std::runtime_error("Invalid amount"); | |||||
} | |||||
Amount amount = n * SATOSHI; | |||||
if (!MoneyRange(amount)) { | |||||
throw std::runtime_error("Amount out of range"); | |||||
} | |||||
return amount; | |||||
} | |||||
static void MutateTxSign(CMutableTransaction &tx, const std::string &flagStr) { | static void MutateTxSign(CMutableTransaction &tx, const std::string &flagStr) { | ||||
SigHashType sigHashType = SigHashType().withForkId(); | SigHashType sigHashType = SigHashType().withForkId(); | ||||
if ((flagStr.size() > 0) && !findSigHashFlags(sigHashType, flagStr)) { | if ((flagStr.size() > 0) && !findSigHashFlags(sigHashType, flagStr)) { | ||||
throw std::runtime_error("unknown sighash flag/sign option"); | throw std::runtime_error("unknown sighash flag/sign option"); | ||||
} | } | ||||
// mergedTx will end up with all the signatures; it | // mergedTx will end up with all the signatures; it | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) { | ||||
"\nvs:\n" + ScriptToAsmStr(scriptPubKey); | "\nvs:\n" + ScriptToAsmStr(scriptPubKey); | ||||
throw std::runtime_error(err); | throw std::runtime_error(err); | ||||
} | } | ||||
CTxOut txout; | CTxOut txout; | ||||
txout.scriptPubKey = scriptPubKey; | txout.scriptPubKey = scriptPubKey; | ||||
txout.nValue = Amount::zero(); | txout.nValue = Amount::zero(); | ||||
if (prevOut.exists("amount")) { | if (prevOut.exists("amount")) { | ||||
txout.nValue = AmountFromValue(prevOut["amount"]); | txout.nValue = prevOut["amount"]; | ||||
} | } | ||||
view.AddCoin(out, Coin(txout, 1, false), true); | view.AddCoin(out, Coin(txout, 1, false), true); | ||||
} | } | ||||
// If redeemScript given and private keys given, add redeemScript to the | // If redeemScript given and private keys given, add redeemScript to the | ||||
// tempKeystore so it can be signed: | // tempKeystore so it can be signed: | ||||
if (scriptPubKey.IsPayToScriptHash() && | if (scriptPubKey.IsPayToScriptHash() && | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | try { | ||||
MutateTx(tx, key, value, chainParams); | MutateTx(tx, key, value, chainParams); | ||||
} | } | ||||
OutputTx(CTransaction(tx)); | OutputTx(CTransaction(tx)); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
strPrint = std::string("error: ") + e.what(); | strPrint = std::string("error: ") + e.what(); | ||||
nRet = EXIT_FAILURE; | nRet = EXIT_FAILURE; | ||||
} catch (const UniValue &e) { | |||||
strPrint = std::string("error code: ") + e["code"].getValStr() + | |||||
" message: " + e["message"].getValStr(); | |||||
nRet = EXIT_FAILURE; | |||||
} catch (...) { | } catch (...) { | ||||
PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | ||||
throw; | throw; | ||||
} | } | ||||
if (strPrint != "") { | if (strPrint != "") { | ||||
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint); | tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint); | ||||
} | } | ||||
Show All 31 Lines |