Skip to content

Commit

Permalink
Merge pull request #1896 from multiversx/call-value-spica
Browse files Browse the repository at this point in the history
Call value updates
  • Loading branch information
andrei-marinica authored Jan 8, 2025
2 parents 82e19de + 374ef63 commit d65164f
Show file tree
Hide file tree
Showing 112 changed files with 2,827 additions and 358 deletions.
64 changes: 50 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ members = [
"contracts/feature-tests/panic-message-features",
"contracts/feature-tests/panic-message-features/meta",
"contracts/feature-tests/payable-features",
"contracts/feature-tests/payable-features/interactor",
"contracts/feature-tests/payable-features/meta",
"contracts/feature-tests/rust-snippets-generator-test",
"contracts/feature-tests/rust-snippets-generator-test/meta",
Expand Down
3 changes: 3 additions & 0 deletions chain/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ pub mod types;

/// Re-exported for convenience.
pub use multiversx_sc_codec as codec;

/// The equivalent ESDT token identifier for transferring EGLD, the native MultiversX token.
pub const EGLD_000000_TOKEN_IDENTIFIER: &str = "EGLD-000000";
5 changes: 5 additions & 0 deletions chain/vm/src/tx_mock/tx_cache_balance_util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use multiversx_chain_core::EGLD_000000_TOKEN_IDENTIFIER;
use num_bigint::BigUint;

use crate::{
Expand Down Expand Up @@ -109,6 +110,10 @@ impl TxCache {
nonce: u64,
value: &BigUint,
) -> Result<(), TxPanic> {
if esdt_token_identifier == EGLD_000000_TOKEN_IDENTIFIER.as_bytes() {
return self.transfer_egld_balance(from, to, value);
}

if !is_system_sc_address(from) && !is_system_sc_address(to) {
let metadata = self.subtract_esdt_balance(from, esdt_token_identifier, nonce, value)?;
self.increase_esdt_balance(to, esdt_token_identifier, nonce, value, metadata);
Expand Down
6 changes: 4 additions & 2 deletions chain/vm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ pub type RawHandle = i32;
use num_bigint::BigUint;
use num_traits::Zero;

pub(crate) fn top_encode_u64(value: u64) -> Vec<u8> {
/// Helper function to quickly encode a u64 value, according to the MultiversX codec format.
pub fn top_encode_u64(value: u64) -> Vec<u8> {
top_encode_big_uint(&BigUint::from(value))
}

pub(crate) fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
/// Helper function to quickly encode a BigUint value, according to the MultiversX codec format.
pub fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
if value.is_zero() {
Vec::new()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"arguments": [
[
"nested:str:TOKENA-1234",
"nested:str:EGLD",
"nested:str:TOKENB-1234"
]
],
Expand All @@ -108,7 +107,6 @@
"out": [
[
"nested:str:TOKENA-1234",
"nested:str:EGLD",
"nested:str:TOKENB-1234"
]
],
Expand All @@ -117,6 +115,54 @@
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "echo_managed_vec_of_token_identifier-EGLD",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "echo_managed_vec_of_token_identifier",
"arguments": [
[
"nested:str:EGLD"
]
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "4",
"message": "str:argument decode error (mv): ESDT expected",
"logs": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "echo_managed_vec_of_token_identifier-EGLD-000000",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "echo_managed_vec_of_token_identifier",
"arguments": [
[
"nested:str:EGLD-000000"
]
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "4",
"message": "str:argument decode error (mv): ESDT expected",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ where

pub fn send_async_accept_multi_transfer<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, MultiValue3<TokenIdentifier<Env::Api>, u64, BigUint<Env::Api>>>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, MultiValue3<EgldOrEsdtTokenIdentifier<Env::Api>, u64, BigUint<Env::Api>>>>,
>(
self,
to: Arg0,
Expand Down Expand Up @@ -445,7 +445,7 @@ where

pub fn transf_exec_multi_accept_funds<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, MultiValue3<TokenIdentifier<Env::Api>, u64, BigUint<Env::Api>>>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, MultiValue3<EgldOrEsdtTokenIdentifier<Env::Api>, u64, BigUint<Env::Api>>>>,
>(
self,
to: Arg0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ pub trait ForwarderAsyncCallModule {
fn send_async_accept_multi_transfer(
&self,
to: ManagedAddress,
token_payments: MultiValueEncoded<MultiValue3<TokenIdentifier, u64, BigUint>>,
token_payments: MultiValueEncoded<MultiValue3<EgldOrEsdtTokenIdentifier, u64, BigUint>>,
) {
let mut all_token_payments = ManagedVec::new();

for multi_arg in token_payments.into_iter() {
let (token_identifier, token_nonce, amount) = multi_arg.into_tuple();
let payment = EsdtTokenPayment::new(token_identifier, token_nonce, amount);
let payment = EgldOrEsdtTokenPayment::new(token_identifier, token_nonce, amount);

all_token_payments.push(payment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ pub trait ForwarderSyncCallModule {
.returns(ReturnsResult)
.sync_call();

let (egld_value, esdt_transfers_multi) = result.into_tuple();

self.accept_funds_sync_result_event(&egld_value, &esdt_transfers_multi);
self.accept_funds_sync_result_event(&result);
}

#[endpoint]
Expand Down Expand Up @@ -159,8 +157,7 @@ pub trait ForwarderSyncCallModule {
#[event("accept_funds_sync_result")]
fn accept_funds_sync_result_event(
&self,
#[indexed] egld_value: &BigUint,
#[indexed] multi_esdt: &MultiValueEncoded<EsdtTokenPaymentMultiValue>,
#[indexed] multi_esdt: &MultiValueEncoded<EgldOrEsdtTokenPaymentMultiValue>,
);

#[endpoint]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ pub trait ForwarderTransferExecuteModule {
fn transf_exec_multi_accept_funds(
&self,
to: ManagedAddress,
token_payments: MultiValueEncoded<MultiValue3<TokenIdentifier, u64, BigUint>>,
token_payments: MultiValueEncoded<MultiValue3<EgldOrEsdtTokenIdentifier, u64, BigUint>>,
) {
let mut all_token_payments = ManagedVec::new();

for multi_arg in token_payments.into_iter() {
let (token_identifier, token_nonce, amount) = multi_arg.into_tuple();
let payment = EsdtTokenPayment::new(token_identifier, token_nonce, amount);
let payment = EgldOrEsdtTokenPayment::new(token_identifier, token_nonce, amount);

all_token_payments.push(payment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where

pub fn accept_funds_echo_payment(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, (), Gas, MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>> {
self.wrapped_tx
.raw_call("accept_funds_echo_payment")
.original_result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where

pub fn accept_funds_echo_payment(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, (), Gas, MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>> {
self.wrapped_tx
.raw_call("accept_funds_echo_payment")
.original_result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait CallPromisesDirectModule {
) {
let mut token_payments_vec = ManagedVec::new();
for token_payment_arg in token_payment_args {
token_payments_vec.push(token_payment_arg.into_esdt_token_payment());
token_payments_vec.push(token_payment_arg.into_inner());
}

let gas_limit = (self.blockchain().get_gas_left() - extra_gas_for_callback) * 9 / 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where

pub fn accept_funds_echo_payment(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, (), Gas, MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>> {
self.wrapped_tx
.raw_call("accept_funds_echo_payment")
.original_result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where

pub fn accept_funds_echo_payment(
self,
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue2<BigUint<Env::Api>, MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, (), Gas, MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>> {
self.wrapped_tx
.raw_call("accept_funds_echo_payment")
.original_result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"endpoint": "str:accept_funds",
"topics": [
"str:accept_funds",
"str:EGLD",
"0",
"0x03e8"
],
"data": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"endpoint": "str:accept_funds",
"topics": [
"str:accept_funds",
"str:EGLD",
"0",
"1000"
],
"data": [
Expand Down
Loading

0 comments on commit d65164f

Please sign in to comment.