Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Implement host function: svm_tx_amount #488

Open
YaronWittenstein opened this issue Dec 26, 2021 · 0 comments
Open

Implement host function: svm_tx_amount #488

YaronWittenstein opened this issue Dec 26, 2021 · 0 comments
Assignees
Labels
AA Related to the Accounts Abstraction simple-coin-iteration-1 svm svm-core SVM core change

Comments

@YaronWittenstein
Copy link
Contributor

YaronWittenstein commented Dec 26, 2021

Depends on #487

We need to ask the Host for the amount value supplied in the Transaction.

One classic usage is tracking how much money the current executing Account has been funded.
So each time an Account gets funding, it will execute some piece of code (see SVM SDK fundable hooks feature - similar to the payable of Solidity)

That code will ask the Host for the current transaction value to update some Storage variable of itself.

Implementation Proposal

The host function signature should look probably like this:

fn tx_amount(env: &FuncEnv) -> u64 {
  // ...
}

The amount will be taken from the Envelope.

Fundable Hooks

Fundable hooks are SVM SDK mechanisms to share common pieces of code between different #[endpoint].
When an endpoint wants to use an existing fundable hook, it should add this annotation:
#[fundable(FUNDABLE_HOOK_NAME)]

Links:

Open Question

  • @avive @lrettig - do we let an Account ask for its current balance? (in a running Contract code).
  • Is the svm_tx_amount can be called from within verify? (I don't see any problem with that since it's part of the Transaction)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AA Related to the Accounts Abstraction simple-coin-iteration-1 svm svm-core SVM core change
Projects
None yet
Development

No branches or pull requests

2 participants