Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract call argument method #1240

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions framework/base/src/contract_base/wrappers/send_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
pub fn contract_call<R>(
&self,
to: ManagedAddress<A>,
endpoint_name: ManagedBuffer<A>,
endpoint_name: impl Into<ManagedBuffer<A>>,
) -> ContractCallNoPayment<A, R> {
ContractCallNoPayment::new(to, endpoint_name)
}
Expand Down Expand Up @@ -375,10 +375,8 @@ where
child_sc_address: ManagedAddress<A>,
new_owner: &ManagedAddress<A>,
) -> ContractCallNoPayment<A, ()> {
let mut contract_call =
ContractCallNoPayment::new(child_sc_address, CHANGE_OWNER_BUILTIN_FUNC_NAME);
contract_call.proxy_arg(&new_owner);
contract_call
self.contract_call(child_sc_address, CHANGE_OWNER_BUILTIN_FUNC_NAME)
.argument(&new_owner)
}

/// Allows synchronously calling a local function by name. Execution is resumed afterwards.
Expand Down
130 changes: 49 additions & 81 deletions framework/base/src/esdt/system_sc_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,23 @@ where
) -> ContractCallWithEgld<SA, ()> {
let esdt_system_sc_address = self.esdt_system_sc_address();

let mut contract_call = ContractCallWithEgld::new(
esdt_system_sc_address,
ISSUE_AND_SET_ALL_ROLES_ENDPOINT_NAME,
issue_cost,
);

contract_call.proxy_arg(&token_display_name);
contract_call.proxy_arg(&token_ticker);

let token_type_name = match token_type {
EsdtTokenType::Fungible => "FNG",
EsdtTokenType::NonFungible => "NFT",
EsdtTokenType::SemiFungible => "SFT",
EsdtTokenType::Meta => "META",
EsdtTokenType::Invalid => "",
};
contract_call.proxy_arg(&token_type_name);
contract_call.proxy_arg(&num_decimals);

contract_call
ContractCallWithEgld::new(
esdt_system_sc_address,
ISSUE_AND_SET_ALL_ROLES_ENDPOINT_NAME,
issue_cost,
)
.argument(&token_display_name)
.argument(&token_ticker)
.argument(&token_type_name)
.argument(&num_decimals)
}

/// Deduplicates code from all the possible issue functions
Expand Down Expand Up @@ -268,12 +265,9 @@ where
token_identifier: &TokenIdentifier<SA>,
amount: &BigUint<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("mint");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(amount);

contract_call
self.esdt_system_sc_call_no_args("mint")
.argument(token_identifier)
.argument(amount)
}

/// Produces a contract call to the ESDT system SC,
Expand All @@ -283,31 +277,22 @@ where
token_identifier: &TokenIdentifier<SA>,
amount: &BigUint<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("ESDTBurn");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(amount);

contract_call
self.esdt_system_sc_call_no_args("ESDTBurn")
.argument(token_identifier)
.argument(amount)
}

/// The manager of an ESDT token may choose to suspend all transactions of the token,
/// except minting, freezing/unfreezing and wiping.
pub fn pause(self, token_identifier: &TokenIdentifier<SA>) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("pause");

contract_call.proxy_arg(token_identifier);

contract_call
self.esdt_system_sc_call_no_args("pause")
.argument(token_identifier)
}

/// The reverse operation of `pause`.
pub fn unpause(self, token_identifier: &TokenIdentifier<SA>) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("unPause");

contract_call.proxy_arg(token_identifier);

contract_call
self.esdt_system_sc_call_no_args("unPause")
.argument(token_identifier)
}

/// The manager of an ESDT token may freeze the tokens held by a specific account.
Expand All @@ -318,12 +303,9 @@ where
token_identifier: &TokenIdentifier<SA>,
address: &ManagedAddress<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("freeze");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(address);

contract_call
self.esdt_system_sc_call_no_args("freeze")
.argument(token_identifier)
.argument(address)
}

/// The reverse operation of `freeze`, unfreezing, will allow further transfers to and from the account.
Expand All @@ -332,12 +314,9 @@ where
token_identifier: &TokenIdentifier<SA>,
address: &ManagedAddress<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("unFreeze");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(address);

contract_call
self.esdt_system_sc_call_no_args("unFreeze")
.argument(token_identifier)
.argument(address)
}

/// The manager of an ESDT token may wipe out all the tokens held by a frozen account.
Expand All @@ -349,12 +328,9 @@ where
token_identifier: &TokenIdentifier<SA>,
address: &ManagedAddress<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("wipe");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(address);

contract_call
self.esdt_system_sc_call_no_args("wipe")
.argument(token_identifier)
.argument(address)
}

/// This function converts an SFT to a metaESDT by adding decimals to its structure in the metachain ESDT System SC.
Expand All @@ -364,12 +340,9 @@ where
token_identifier: &TokenIdentifier<SA>,
num_decimals: usize,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("changeSFTToMetaESDT");

contract_call.proxy_arg(&token_identifier);
contract_call.proxy_arg(&num_decimals);

contract_call
self.esdt_system_sc_call_no_args("changeSFTToMetaESDT")
.argument(&token_identifier)
.argument(&num_decimals)
}

/// This function can be called only if canSetSpecialRoles was set to true.
Expand All @@ -382,10 +355,10 @@ where
token_identifier: &TokenIdentifier<SA>,
roles_iter: RoleIter,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("setSpecialRole");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(address);
let mut contract_call = self
.esdt_system_sc_call_no_args("setSpecialRole")
.argument(token_identifier)
.argument(address);
for role in roles_iter {
if role != EsdtLocalRole::None {
contract_call.push_raw_argument(role.as_role_name());
Expand All @@ -405,10 +378,10 @@ where
token_identifier: &TokenIdentifier<SA>,
roles_iter: RoleIter,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("unSetSpecialRole");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(address);
let mut contract_call = self
.esdt_system_sc_call_no_args("unSetSpecialRole")
.argument(token_identifier)
.argument(address);
for role in roles_iter {
if role != EsdtLocalRole::None {
contract_call.push_raw_argument(role.as_role_name());
Expand All @@ -423,12 +396,9 @@ where
token_identifier: &TokenIdentifier<SA>,
new_owner: &ManagedAddress<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("transferOwnership");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(new_owner);

contract_call
self.esdt_system_sc_call_no_args("transferOwnership")
.argument(token_identifier)
.argument(new_owner)
}

pub fn transfer_nft_create_role(
Expand All @@ -437,22 +407,20 @@ where
old_creator: &ManagedAddress<SA>,
new_creator: &ManagedAddress<SA>,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("transferNFTCreateRole");

contract_call.proxy_arg(token_identifier);
contract_call.proxy_arg(old_creator);
contract_call.proxy_arg(new_creator);

contract_call
self.esdt_system_sc_call_no_args("transferNFTCreateRole")
.argument(token_identifier)
.argument(old_creator)
.argument(new_creator)
}

pub fn control_changes(
self,
token_identifier: &TokenIdentifier<SA>,
property_arguments: &TokenPropertyArguments,
) -> ContractCallNoPayment<SA, ()> {
let mut contract_call = self.esdt_system_sc_call_no_args("controlChanges");
contract_call.proxy_arg(token_identifier);
let mut contract_call = self
.esdt_system_sc_call_no_args("controlChanges")
.argument(token_identifier);
append_token_property_arguments(&mut contract_call, property_arguments);
contract_call
}
Expand Down
12 changes: 12 additions & 0 deletions framework/base/src/types/interaction/contract_call_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ where
endpoint_arg.multi_encode_or_handle_err(&mut self.get_mut_basic().arg_buffer, h);
}

/// Serializes and pushes a value to the arguments buffer.
///
/// Accepts multi-values, so it might effectively be adding more than one raw argument.
///
/// Warning: this method serializes any serializable type,
/// but does no type checking against the destination endpoint ABI.
/// Only use for raw calls, built without a proxy.
fn argument<T: TopEncodeMulti>(mut self, arg: &T) -> Self {
self.proxy_arg(arg);
self
}

/// For cases where we build the contract call by hand.
///
/// No serialization occurs, just direct conversion to ManagedBuffer.
Expand Down
Loading