diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index a642cb5..93ba8e0 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1341,6 +1341,18 @@ namespace monero { return epee::string_tools::buff_to_hex_nodelimer(wallet2->export_outputs_to_str(true)); } + int MoneroWallet::importOutputsHex(const string& outputsHex) { + + // validate and parse hex data + cryptonote::blobdata blob; + if (!epee::string_tools::parse_hexstr_to_binbuff(outputsHex, blob)) { + throw runtime_error("Failed to parse hex."); + } + + // import hex and return result + return wallet2->import_outputs_from_str(blob); + } + void MoneroWallet::save() { cout << "save()" << endl; wallet2->store(); diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 7fad8f6..7671466 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -1006,14 +1006,14 @@ namespace monero { */ string getOutputsHex() const; -// /** -// * Import outputs in hex format. -// * -// * @param outputsHex are outputs in hex format -// * @return the number of outputs imported -// */ -// public int importOutputsHex(string outputsHex); -// + /** + * Import outputs in hex format. + * + * @param outputsHex are outputs in hex format + * @return the number of outputs imported + */ + int importOutputsHex(const string& outputsHex); + // /** // * Set an arbitrary attribute. // * diff --git a/todo.txt b/todo.txt index 7c440ef..a08a83e 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,4 @@ +handle e.g. restricted or hw wallet limitations in wallet_rpc_server, e.g. on_import_outputs? wallet2 does not automatically save unlike rpc; where to invoke save and how to separate for tests? throw MoneroErrors instead of runtime_errors toPropertyTree() should take node as parameter; optimize memory elsewhere