Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | static void MutateTxAddInput(CMutableTransaction &tx, | ||||
} | } | ||||
// append to transaction input list | // append to transaction input list | ||||
CTxIn txin(txid, vout, CScript(), nSequenceIn); | CTxIn txin(txid, vout, CScript(), nSequenceIn); | ||||
tx.vin.push_back(txin); | tx.vin.push_back(txin); | ||||
} | } | ||||
static void MutateTxAddOutAddr(CMutableTransaction &tx, | static void MutateTxAddOutAddr(CMutableTransaction &tx, | ||||
const std::string &strInput) { | const std::string &strInput, | ||||
const CChainParams &chainParams) { | |||||
// Separate into VALUE:ADDRESS | // Separate into VALUE:ADDRESS | ||||
std::vector<std::string> vStrInputParts; | std::vector<std::string> vStrInputParts; | ||||
boost::split(vStrInputParts, strInput, boost::is_any_of(":")); | boost::split(vStrInputParts, strInput, boost::is_any_of(":")); | ||||
if (vStrInputParts.size() != 2) { | if (vStrInputParts.size() != 2) { | ||||
throw std::runtime_error("TX output missing or too many separators"); | throw std::runtime_error("TX output missing or too many separators"); | ||||
} | } | ||||
// Extract and validate VALUE | // Extract and validate VALUE | ||||
Amount value = ExtractAndValidateValue(vStrInputParts[0]); | Amount value = ExtractAndValidateValue(vStrInputParts[0]); | ||||
// extract and validate ADDRESS | // extract and validate ADDRESS | ||||
std::string strAddr = vStrInputParts[1]; | std::string strAddr = vStrInputParts[1]; | ||||
CTxDestination destination = DecodeDestination(strAddr); | CTxDestination destination = DecodeDestination(strAddr, chainParams); | ||||
if (!IsValidDestination(destination)) { | if (!IsValidDestination(destination)) { | ||||
throw std::runtime_error("invalid TX output address"); | throw std::runtime_error("invalid TX output address"); | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForDestination(destination); | CScript scriptPubKey = GetScriptForDestination(destination); | ||||
// construct TxOut, append to transaction output list | // construct TxOut, append to transaction output list | ||||
CTxOut txout(value, scriptPubKey); | CTxOut txout(value, scriptPubKey); | ||||
tx.vout.push_back(txout); | tx.vout.push_back(txout); | ||||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | class Secp256k1Init { | ||||
ECCVerifyHandle globalVerifyHandle; | ECCVerifyHandle globalVerifyHandle; | ||||
public: | public: | ||||
Secp256k1Init() { ECC_Start(); } | Secp256k1Init() { ECC_Start(); } | ||||
~Secp256k1Init() { ECC_Stop(); } | ~Secp256k1Init() { ECC_Stop(); } | ||||
}; | }; | ||||
static void MutateTx(CMutableTransaction &tx, const std::string &command, | static void MutateTx(CMutableTransaction &tx, const std::string &command, | ||||
const std::string &commandVal) { | const std::string &commandVal, | ||||
const CChainParams &chainParams) { | |||||
std::unique_ptr<Secp256k1Init> ecc; | std::unique_ptr<Secp256k1Init> ecc; | ||||
if (command == "nversion") { | if (command == "nversion") { | ||||
MutateTxVersion(tx, commandVal); | MutateTxVersion(tx, commandVal); | ||||
} else if (command == "locktime") { | } else if (command == "locktime") { | ||||
MutateTxLocktime(tx, commandVal); | MutateTxLocktime(tx, commandVal); | ||||
} else if (command == "delin") { | } else if (command == "delin") { | ||||
MutateTxDelInput(tx, commandVal); | MutateTxDelInput(tx, commandVal); | ||||
} else if (command == "in") { | } else if (command == "in") { | ||||
MutateTxAddInput(tx, commandVal); | MutateTxAddInput(tx, commandVal); | ||||
} else if (command == "delout") { | } else if (command == "delout") { | ||||
MutateTxDelOutput(tx, commandVal); | MutateTxDelOutput(tx, commandVal); | ||||
} else if (command == "outaddr") { | } else if (command == "outaddr") { | ||||
MutateTxAddOutAddr(tx, commandVal); | MutateTxAddOutAddr(tx, commandVal, chainParams); | ||||
} else if (command == "outpubkey") { | } else if (command == "outpubkey") { | ||||
MutateTxAddOutPubKey(tx, commandVal); | MutateTxAddOutPubKey(tx, commandVal); | ||||
} else if (command == "outmultisig") { | } else if (command == "outmultisig") { | ||||
MutateTxAddOutMultiSig(tx, commandVal); | MutateTxAddOutMultiSig(tx, commandVal); | ||||
} else if (command == "outscript") { | } else if (command == "outscript") { | ||||
MutateTxAddOutScript(tx, commandVal); | MutateTxAddOutScript(tx, commandVal); | ||||
} else if (command == "outdata") { | } else if (command == "outdata") { | ||||
MutateTxAddOutData(tx, commandVal); | MutateTxAddOutData(tx, commandVal); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (ferror(stdin)) { | ||||
throw std::runtime_error("error reading stdin"); | throw std::runtime_error("error reading stdin"); | ||||
} | } | ||||
boost::algorithm::trim_right(ret); | boost::algorithm::trim_right(ret); | ||||
return ret; | return ret; | ||||
} | } | ||||
static int CommandLineRawTx(int argc, char *argv[]) { | static int CommandLineRawTx(int argc, char *argv[], | ||||
const CChainParams &chainParams) { | |||||
std::string strPrint; | std::string strPrint; | ||||
int nRet = 0; | int nRet = 0; | ||||
try { | try { | ||||
// Skip switches; Permit common stdin convention "-" | // Skip switches; Permit common stdin convention "-" | ||||
while (argc > 1 && IsSwitchChar(argv[1][0]) && (argv[1][1] != 0)) { | while (argc > 1 && IsSwitchChar(argv[1][0]) && (argv[1][1] != 0)) { | ||||
argc--; | argc--; | ||||
argv++; | argv++; | ||||
} | } | ||||
Show All 30 Lines | try { | ||||
size_t eqpos = arg.find('='); | size_t eqpos = arg.find('='); | ||||
if (eqpos == std::string::npos) { | if (eqpos == std::string::npos) { | ||||
key = arg; | key = arg; | ||||
} else { | } else { | ||||
key = arg.substr(0, eqpos); | key = arg.substr(0, eqpos); | ||||
value = arg.substr(eqpos + 1); | value = arg.substr(eqpos + 1); | ||||
} | } | ||||
MutateTx(tx, key, value); | MutateTx(tx, key, value, chainParams); | ||||
} | } | ||||
OutputTx(CTransaction(tx)); | OutputTx(CTransaction(tx)); | ||||
} | } | ||||
catch (const boost::thread_interrupted &) { | catch (const boost::thread_interrupted &) { | ||||
throw; | throw; | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
Show All 22 Lines | try { | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} catch (...) { | } catch (...) { | ||||
PrintExceptionContinue(nullptr, "AppInitRawTx()"); | PrintExceptionContinue(nullptr, "AppInitRawTx()"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
int ret = EXIT_FAILURE; | int ret = EXIT_FAILURE; | ||||
try { | try { | ||||
ret = CommandLineRawTx(argc, argv); | ret = CommandLineRawTx(argc, argv, Params()); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
PrintExceptionContinue(&e, "CommandLineRawTx()"); | PrintExceptionContinue(&e, "CommandLineRawTx()"); | ||||
} catch (...) { | } catch (...) { | ||||
PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | PrintExceptionContinue(nullptr, "CommandLineRawTx()"); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } |