From a13be48ae08f30023f39de278eb5378c3100bba7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 15 Aug 2015 16:13:40 +0200 Subject: [PATCH] ethkey can be used to make transactions as well as sign them. --- ethkey/KeyAux.h | 100 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/ethkey/KeyAux.h b/ethkey/KeyAux.h index 0dac480dc..891a07063 100644 --- a/ethkey/KeyAux.h +++ b/ethkey/KeyAux.h @@ -144,6 +144,67 @@ public: m_mode = OperationMode::SignTx; m_signKey = argv[++i]; } + else if (arg == "--tx-data" && i + 1 < argc) + try + { + m_toSign.data = fromHex(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } + else if (arg == "--tx-nonce" && i + 1 < argc) + try + { + m_toSign.nonce = u256(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } + else if ((arg == "--tx-dest" || arg == "--tx-to" || arg == "--tx-destination") && i + 1 < argc) + try + { + m_toSign.creation = false; + m_toSign.to = toAddress(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } + else if (arg == "--tx-gas" && i + 1 < argc) + try + { + m_toSign.gas = u256(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } + else if (arg == "--tx-gasprice" && i + 1 < argc) + try + { + m_toSign.gasPrice = u256(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } + else if (arg == "--tx-value" && i + 1 < argc) + try + { + m_toSign.value = u256(argv[++i]); + } + catch (...) + { + cerr << "Invalid argument to " << arg << endl; + exit(-1); + } else if (arg == "--decode-tx") m_mode = OperationMode::DecodeTx; else if (arg == "--import-bare") @@ -315,30 +376,28 @@ public: case OperationMode::SignTx: { Secret s = getSecret(m_signKey); + if (m_inputs.empty()) + m_inputs.push_back(string()); for (string const& i: m_inputs) { - bool isFile; - bytes b = inputData(i, &isFile); - if (b.empty()) - cerr << "Unknown file or bad hex: '" << i << "'" << endl; - else - try - { - TransactionBase t(b, CheckTransaction::None); - t.sign(s); - cout << t.sha3() << ": "; - if (isFile) - { - writeFile(i + ".signed", toHex(t.rlp())); - cout << i + ".signed" << endl; - } - else - cout << toHex(t.rlp()) << endl; - } - catch (Exception& ex) + bool isFile = false; + try + { + TransactionBase t = i.empty() ? TransactionBase(m_toSign) : TransactionBase(inputData(i, &isFile), CheckTransaction::None); + t.sign(s); + cout << t.sha3() << ": "; + if (isFile) { - cerr << "Invalid transaction: " << ex.what() << endl; + writeFile(i + ".signed", toHex(t.rlp())); + cout << i + ".signed" << endl; } + else + cout << toHex(t.rlp()) << endl; + } + catch (Exception& ex) + { + cerr << "Invalid transaction: " << ex.what() << endl; + } } break; } @@ -699,6 +758,7 @@ private: /// Signing string m_signKey; + TransactionSkeleton m_toSign; string m_kdf = "scrypt"; map m_kdfParams;