spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Implementation of `svm_transfer` host function #419

Closed kobby-pentangeli closed 2 years ago

kobby-pentangeli commented 2 years ago

This PR addresses issue#406, i.e. introducing a new host function that sends coins from the current executing account to a destination account.

TODO:

neysofu commented 2 years ago

Reviewing :)

neysofu commented 2 years ago

The loading of the destination account fails because the helper function create_account in vmcalls_tests.rs creates a new GlobalState::in_memory at every call. The two accounts effectively exist in two separate databases. I believe we've never had a test that required creating multiple accounts!

The solution is:

  1. Add a gs: &GlobalState parameter to create_account and .clone() it inside the function body if necessary. Cloning a GlobalState is relatively cheap because it's wrapped in an Arc.
  2. Put let gs = GlobalState::in_memory(); where necessary and pass it as an argument to create_account.