Skip to content

Commit

Permalink
Merge pull request #1514 from multiversx/builtin-func-sc
Browse files Browse the repository at this point in the history
builtin func sc migration to new proxies and unified syntax
  • Loading branch information
mihaicalinluca authored Mar 28, 2024
2 parents 5604d75 + 9fd7383 commit 81aae14
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ multiversx_sc::imports!();
/// Test contract for investigating async calls.
#[multiversx_sc::contract]
pub trait BuiltinFuncFeatures {
#[proxy]
fn builtin_func_proxy(&self, to: ManagedAddress) -> builtin_func_proxy::Proxy<Self::Api>;

#[init]
fn init(&self) {}

#[endpoint]
fn call_set_user_name(&self, address: ManagedAddress, name: ManagedBuffer) {
self.builtin_func_proxy(address)
.set_user_name(&name)
self.tx()
.to(&address)
.typed(builtin_func_proxy::UserBuiltinProxy)
.set_user_name(name)
.async_call()
.call_and_exit()
}

#[endpoint]
fn call_delete_user_name(&self, address: ManagedAddress) {
self.builtin_func_proxy(address)
self.tx()
.to(&address)
.typed(builtin_func_proxy::UserBuiltinProxy)
.delete_user_name()
.async_call()
.call_and_exit();
.call_and_exit()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
multiversx_sc::imports!();
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

#[multiversx_sc::derive::proxy]
pub trait UserBuiltin {
#[endpoint(SetUserName)]
fn set_user_name(&self, name: &ManagedBuffer);
////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#[endpoint(DeleteUserName)]
fn delete_user_name(&self);
#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct UserBuiltinProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for UserBuiltinProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = UserBuiltinProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
UserBuiltinProxyMethods { wrapped_tx: tx }
}
}

pub struct UserBuiltinProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, To, Gas> UserBuiltinProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn set_user_name<
Arg0: CodecInto<ManagedBuffer<Env::Api>>,
>(
self,
name: Arg0,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("SetUserName")
.argument(&name)
.original_result()
}

pub fn delete_user_name(
self,
) -> TxProxyCall<Env, From, To, Gas, ()> {
self.wrapped_tx
.raw_call()
.function_name("DeleteUserName")
.original_result()
}
}

0 comments on commit 81aae14

Please sign in to comment.