@@ -1877,6 +1877,56 @@ class wallet_api_impl
1877
1877
return tx;
1878
1878
}
1879
1879
1880
+ memo_data sign_memo (string from, string to, string memo)
1881
+ {
1882
+ FC_ASSERT ( !self.is_locked () );
1883
+
1884
+ memo_data md = memo_data ();
1885
+
1886
+ // get account memo key, if that fails, try a pubkey
1887
+ try {
1888
+ account_object from_account = get_account (from);
1889
+ md.from = from_account.options .memo_key ;
1890
+ } catch (const fc::exception & e) {
1891
+ md.from = self.get_public_key ( from );
1892
+ }
1893
+ // same as above, for destination key
1894
+ try {
1895
+ account_object to_account = get_account (to);
1896
+ md.to = to_account.options .memo_key ;
1897
+ } catch (const fc::exception & e) {
1898
+ md.to = self.get_public_key ( to );
1899
+ }
1900
+
1901
+ md.set_message (get_private_key (md.from ), md.to , memo);
1902
+ return md;
1903
+ }
1904
+
1905
+ string read_memo (const memo_data& md)
1906
+ {
1907
+ FC_ASSERT (!is_locked ());
1908
+ std::string clear_text;
1909
+
1910
+ const memo_data *memo = &md;
1911
+
1912
+ try {
1913
+ FC_ASSERT (_keys.count (memo->to ) || _keys.count (memo->from ), " Memo is encrypted to a key ${to} or ${from} not in this wallet." , (" to" , memo->to )(" from" ,memo->from ));
1914
+ if ( _keys.count (memo->to ) ) {
1915
+ auto my_key = wif_to_key (_keys.at (memo->to ));
1916
+ FC_ASSERT (my_key, " Unable to recover private key to decrypt memo. Wallet may be corrupted." );
1917
+ clear_text = memo->get_message (*my_key, memo->from );
1918
+ } else {
1919
+ auto my_key = wif_to_key (_keys.at (memo->from ));
1920
+ FC_ASSERT (my_key, " Unable to recover private key to decrypt memo. Wallet may be corrupted." );
1921
+ clear_text = memo->get_message (*my_key, memo->to );
1922
+ }
1923
+ } catch (const fc::exception & e) {
1924
+ elog (" Error when decrypting memo: ${e}" , (" e" , e.to_detail_string ()));
1925
+ }
1926
+
1927
+ return clear_text;
1928
+ }
1929
+
1880
1930
signed_transaction sell_asset (string seller_account,
1881
1931
string amount_to_sell,
1882
1932
string symbol_to_sell,
@@ -3783,6 +3833,18 @@ signed_transaction wallet_api::cancel_order(object_id_type order_id, bool broadc
3783
3833
return my->cancel_order (order_id, broadcast);
3784
3834
}
3785
3835
3836
+ memo_data wallet_api::sign_memo (string from, string to, string memo)
3837
+ {
3838
+ FC_ASSERT (!is_locked ());
3839
+ return my->sign_memo (from, to, memo);
3840
+ }
3841
+
3842
+ string wallet_api::read_memo (const memo_data& memo)
3843
+ {
3844
+ FC_ASSERT (!is_locked ());
3845
+ return my->read_memo (memo);
3846
+ }
3847
+
3786
3848
string wallet_api::get_key_label ( public_key_type key )const
3787
3849
{
3788
3850
auto key_itr = my->_wallet .labeled_keys .get <by_key>().find (key);
0 commit comments