Skip to content

Commit

Permalink
Allow transfers to SC
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Besancon committed Dec 12, 2024
1 parent 6102f0e commit 79356e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
24 changes: 6 additions & 18 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,24 +701,12 @@ impl ExecutionContext {
) -> Result<(), ExecutionError> {
if let Some(from_addr) = &from_addr {
// check access rights
if check_rights {
// ensure we can't spend from an address on which we have no write access
if !self.has_write_rights_on(from_addr) {
return Err(ExecutionError::RuntimeError(format!(
"spending from address {} is not allowed in this context",
from_addr
)));
}

// ensure we can't transfer towards SC addresses on which we have no write access
if let Some(to_addr) = &to_addr {
if matches!(to_addr, Address::SC(..)) && !self.has_write_rights_on(to_addr) {
return Err(ExecutionError::RuntimeError(format!(
"crediting SC address {} is not allowed without write access to it",
to_addr
)));
}
}
// ensure we can't spend from an address on which we have no write access
if check_rights && !self.has_write_rights_on(from_addr) {
return Err(ExecutionError::RuntimeError(format!(
"spending from address {} is not allowed in this context",
from_addr
)));
}
}

Expand Down
5 changes: 5 additions & 0 deletions massa-execution-worker/src/speculative_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ impl SpeculativeLedger {
))
})?;
changes.set_balance(to_addr, new_balance);
} else if matches!(to_addr, Address::SC(..)) {
return Err(ExecutionError::RuntimeError(format!(
"cannot transfer coins to non-existing smart contract address {}",
to_addr
)));
} else if let Some(remaining_coins) =
amount.checked_sub(self.storage_costs_constants.ledger_entry_base_cost)
{
Expand Down

0 comments on commit 79356e5

Please sign in to comment.