Neptune-Crypto / neptune-core

anonymous peer-to-peer cash
Apache License 2.0
24 stars 7 forks source link

make create_transaction() read only. attempt 3. #162

Closed dan-da closed 1 month ago

dan-da commented 2 months ago

Addresses #122. Obsoletes #159.

This is my 3rd attempt to refactor create_transaction(). Perhaps 3rd try is the charm.

For original background motivation and discussion, see previous attempts: #136 and #159.

Some goals of this attempt are:

Changes since #159:

highlights / key changes:

rpc_server:

global_state:

wallet:

transaction:

other:

Explanations of things that may not be obvious:

  1. preparing for derived keys. Presently some functions call WalletSecret::nth_generation_spending_key(&self, counter: u16), passing 0. I've now added ::next_unused_generation_spending_key(&mut self), which presently always uses index 0 but in the future will increment a stateful counter. The difficulty is that it must take &mut self, so it cannot be called from within GlobalState methods that take &self, such as create_transaction(). So create_transaction() now requires the caller to provide the next unused spending key.

  2. let me know if there's something else. I put a lot of code comments, but let me know if anything is unclear.

dan-da commented 1 month ago

I went ahead and merged this. @Sword-Smith if you have any concerns, pls let me know.