Skip to content

Commit

Permalink
Merge pull request #1497 from multiversx/tx-payment-refactor
Browse files Browse the repository at this point in the history
Unified syntax - payment refactor (part 1)
  • Loading branch information
andrei-marinica authored Mar 22, 2024
2 parents 52b4653 + 2497d68 commit e32bd89
Show file tree
Hide file tree
Showing 27 changed files with 417 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use core::marker::PhantomData;
use codec::Empty;

use crate::{
api::StorageMapperApi,
imports::{ErrorApiImpl, ManagedType},
api::{ErrorApiImpl, StorageMapperApi},
storage::StorageKey,
storage_set,
types::ManagedType,
};

use super::{
Expand Down
7 changes: 2 additions & 5 deletions framework/base/src/types/interaction/deploy_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use multiversx_sc_codec::TopEncodeMulti;

use crate::types::{CodeMetadata, ManagedBuffer, ManagedBufferCachedBuilder};

use super::{
Code, FunctionCall, ManagedArgBuffer, Tx, TxCodeSource, TxData, TxEnv, TxFrom, TxGas,
TxPayment, TxTo,
};
use super::{ManagedArgBuffer, TxCodeSource, TxData, TxEnv};

/// Holds deploy data: code, code metadata, and arguments.
pub struct DeployCall<Env, CodeSource>
Expand Down Expand Up @@ -42,7 +39,7 @@ where

fn to_call_data_string(&self) -> ManagedBuffer<Env::Api> {
// Implement as needed for deployment-specific data
let mut result = ManagedBufferCachedBuilder::default();
let result = ManagedBufferCachedBuilder::default();
// result.append_managed_buffer(&self.code);
// Add other fields as needed
result.into_managed_buffer()
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/types/interaction/expr/address_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<Env> TxToSpecified<Env> for AddressExpr
where
Env: TxEnv,
{
fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
fn with_address_ref<F, R>(&self, _env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/types/interaction/expr/sc_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a, Env> TxToSpecified<Env> for ScExpr<'a>
where
Env: TxEnv,
{
fn with_address_ref<F, R>(&self, env: &Env, f: F) -> R
fn with_address_ref<F, R>(&self, _env: &Env, f: F) -> R
where
F: FnOnce(&ManagedAddress<Env::Api>) -> R,
{
Expand Down
6 changes: 0 additions & 6 deletions framework/base/src/types/interaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ mod tx_env_sc;
mod tx_from;
mod tx_gas;
mod tx_payment;
mod tx_payment_egld;
mod tx_payment_egld_value;
mod tx_payment_normalize;
mod tx_proxy;
mod tx_result_handler;
mod tx_rh_list;
Expand Down Expand Up @@ -73,9 +70,6 @@ pub use tx_env_sc::*;
pub use tx_from::*;
pub use tx_gas::*;
pub use tx_payment::*;
pub use tx_payment_egld::*;
pub use tx_payment_egld_value::TxEgldValue;
pub use tx_payment_normalize::TxPaymentNormalize;
pub use tx_proxy::*;
pub use tx_result_handler::*;
pub use tx_rh_list::*;
Expand Down
23 changes: 11 additions & 12 deletions framework/base/src/types/interaction/tx.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use crate::{
api::{self, CallTypeApi, ManagedTypeApi},
contract_base::{BlockchainWrapper, SendRawWrapper},
api::CallTypeApi,
contract_base::BlockchainWrapper,
types::{
BigUint, CodeMetadata, EgldOrEsdtTokenPayment, EsdtTokenPayment, ManagedAddress,
ManagedBuffer, ManagedOption, ManagedVec, MultiEsdtPayment,
},
};
use alloc::boxed::Box;

use multiversx_sc_codec::TopEncodeMulti;

use super::{
contract_call_exec::UNSPECIFIED_GAS_LIMIT, contract_call_trait::ContractCallBase,
AnnotatedValue, AsyncCall, Code, ContractCallNoPayment, ContractCallWithEgld, ContractDeploy,
DeployCall, Egld, EgldPayment, ExplicitGas, FromSource, FunctionCall, ManagedArgBuffer,
OriginalResultMarker, RHList, RHListAppendNoRet, RHListAppendRet, RHListItem, TxCodeSource,
TxCodeValue, TxData, TxDataFunctionCall, TxEgldValue, TxEnv, TxFrom, TxFromSourceValue,
TxFromSpecified, TxGas, TxPayment, TxPaymentEgldOnly, TxPaymentNormalize, TxProxyTrait,
TxResultHandler, TxScEnv, TxTo, TxToSpecified,
contract_call_exec::UNSPECIFIED_GAS_LIMIT, contract_call_trait::ContractCallBase, Code,
ContractCallNoPayment, ContractCallWithEgld, ContractDeploy, DeployCall, Egld, EgldPayment,
ExplicitGas, FromSource, FunctionCall, ManagedArgBuffer, OriginalResultMarker, RHList,
RHListAppendNoRet, RHListAppendRet, RHListItem, TxCodeSource, TxCodeValue, TxData, TxEgldValue,
TxEnv, TxFrom, TxFromSourceValue, TxGas, TxPayment, TxPaymentEgldOnly, TxPaymentNormalize,
TxProxyTrait, TxResultHandler, TxScEnv, TxTo, TxToSpecified,
};

#[must_use]
Expand Down Expand Up @@ -623,7 +622,7 @@ where
RH: TxResultHandler<Env>,
{
pub fn code<CodeValue>(
mut self,
self,
code: CodeValue,
) -> Tx<Env, From, To, Payment, Gas, DeployCall<Env, Code<CodeValue>>, RH>
where
Expand All @@ -641,7 +640,7 @@ where
}

pub fn from_source<FromSourceValue>(
mut self,
self,
source_address: FromSourceValue,
) -> Tx<Env, From, To, Payment, Gas, DeployCall<Env, FromSource<FromSourceValue>>, RH>
where
Expand Down
5 changes: 2 additions & 3 deletions framework/base/src/types/interaction/tx_call_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use crate::{

use super::{
contract_call_exec::decode_result, Code, ConsNoRet, ConsRet, DeployCall, FromSource,
OriginalResultMarker, RHList, RHListItem, Tx, TxCodeValue, TxDataFunctionCall,
TxEmptyResultHandler, TxEnv, TxFromSourceValue, TxGas, TxPayment, TxPaymentEgldOnly,
TxResultHandler, TxScEnv, TxToSpecified,
OriginalResultMarker, RHList, RHListItem, Tx, TxCodeValue, TxEmptyResultHandler, TxEnv,
TxFromSourceValue, TxGas, TxPaymentEgldOnly, TxResultHandler, TxScEnv,
};

pub trait RHListItemDeploy<Env, Original>: RHListItem<Env, Original>
Expand Down
4 changes: 2 additions & 2 deletions framework/base/src/types/interaction/tx_call_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{

use super::{
contract_call_exec::decode_result, BackTransfers, ConsNoRet, ConsRet, OriginalResultMarker,
RHList, RHListItem, Tx, TxDataFunctionCall, TxEnv, TxGas, TxPayment, TxPaymentNormalize,
TxScEnv, TxToSpecified,
RHList, RHListItem, Tx, TxDataFunctionCall, TxEnv, TxGas, TxPaymentNormalize, TxScEnv,
TxToSpecified,
};

pub trait RHListItemSync<Env, Original>: RHListItem<Env, Original>
Expand Down
5 changes: 1 addition & 4 deletions framework/base/src/types/interaction/tx_code_source.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
api::ManagedTypeApi,
types::{ManagedAddress, ManagedBuffer},
};
use crate::types::{ManagedAddress, ManagedBuffer};

use super::{AnnotatedValue, TxEnv};

Expand Down
6 changes: 2 additions & 4 deletions framework/base/src/types/interaction/tx_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::{
api::ManagedTypeApi,
contract_base::SendRawWrapper,
formatter::SCLowerHex,
types::{CodeMetadata, ManagedAddress, ManagedBuffer, ManagedBufferCachedBuilder, ManagedVec},
types::{ManagedBuffer, ManagedBufferCachedBuilder},
};

use super::{FunctionCall, ManagedArgBuffer, Tx, TxEnv, TxFrom, TxGas, TxPayment, TxTo};
use super::{FunctionCall, TxEnv};

pub trait TxData<Env>
where
Expand Down
7 changes: 1 addition & 6 deletions framework/base/src/types/interaction/tx_env.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use crate::{
api::CallTypeApi,
types::{ManagedAddress, ManagedBuffer},
};

use super::AnnotatedValue;
use crate::{api::CallTypeApi, types::ManagedAddress};

pub trait TxEnv: Sized {
type Api: CallTypeApi;
Expand Down
4 changes: 1 addition & 3 deletions framework/base/src/types/interaction/tx_env_sc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::{
types::ManagedAddress,
};

use super::{
contract_call_exec::TRANSFER_EXECUTE_DEFAULT_LEFTOVER, AnnotatedValue, Tx, TxBaseWithEnv, TxEnv,
};
use super::{contract_call_exec::TRANSFER_EXECUTE_DEFAULT_LEFTOVER, Tx, TxBaseWithEnv, TxEnv};

pub struct TxScEnv<Api>
where
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/types/interaction/tx_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
env.default_gas()
}

fn explicit_or_gas_left(&self, env: &Env) -> u64 {
fn explicit_or_gas_left(&self, _env: &Env) -> u64 {
Env::Api::blockchain_api_impl().get_gas_left()
}
}
Expand Down
Loading

0 comments on commit e32bd89

Please sign in to comment.