| 793 | } |
| 794 | |
| 795 | static int CommandLineRawTx(int argc, char* argv[]) |
| 796 | { |
| 797 | std::string strPrint; |
| 798 | int nRet = 0; |
| 799 | try { |
| 800 | // Skip switches; Permit common stdin convention "-" |
| 801 | while (argc > 1 && IsSwitchChar(argv[1][0]) && |
| 802 | (argv[1][1] != 0)) { |
| 803 | argc--; |
| 804 | argv++; |
| 805 | } |
| 806 | |
| 807 | CMutableTransaction tx; |
| 808 | int startArg; |
| 809 | |
| 810 | if (!fCreateBlank) { |
| 811 | // require at least one param |
| 812 | if (argc < 2) |
| 813 | throw std::runtime_error("too few parameters"); |
| 814 | |
| 815 | // param: hex-encoded bitcoin transaction |
| 816 | std::string strHexTx(argv[1]); |
| 817 | if (strHexTx == "-") // "-" implies standard input |
| 818 | strHexTx = readStdin(); |
| 819 | |
| 820 | if (!DecodeHexTx(tx, strHexTx, true)) |
| 821 | throw std::runtime_error("invalid transaction encoding"); |
| 822 | |
| 823 | startArg = 2; |
| 824 | } else |
| 825 | startArg = 1; |
| 826 | |
| 827 | for (int i = startArg; i < argc; i++) { |
| 828 | std::string arg = argv[i]; |
| 829 | std::string key, value; |
| 830 | size_t eqpos = arg.find('='); |
| 831 | if (eqpos == std::string::npos) |
| 832 | key = arg; |
| 833 | else { |
| 834 | key = arg.substr(0, eqpos); |
| 835 | value = arg.substr(eqpos + 1); |
| 836 | } |
| 837 | |
| 838 | MutateTx(tx, key, value); |
| 839 | } |
| 840 | |
| 841 | OutputTx(CTransaction(tx)); |
| 842 | } |
| 843 | catch (const std::exception& e) { |
| 844 | strPrint = std::string("error: ") + e.what(); |
| 845 | nRet = EXIT_FAILURE; |
| 846 | } |
| 847 | catch (...) { |
| 848 | PrintExceptionContinue(nullptr, "CommandLineRawTx()"); |
| 849 | throw; |
| 850 | } |
| 851 | |
| 852 | if (strPrint != "") { |
no test coverage detected