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

generate custome proxy #1678

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions contracts/examples/multisig/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ add-labels = ["multisig-external-view"]

[[proxy]]
path = "src/multisig_proxy.rs"

[[proxy]]
path = "src/multisig_view_proxy.rs"
add-unlabelled = false
add-labels = ["multisig-external-view"]
1 change: 1 addition & 0 deletions contracts/examples/multisig/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod multisig_perform;
pub mod multisig_propose;
pub mod multisig_proxy;
pub mod multisig_state;
pub mod multisig_view_proxy;
pub mod user_role;

use action::ActionFullInfo;
Expand Down
114 changes: 0 additions & 114 deletions contracts/examples/multisig/src/multisig_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,6 @@ where
.original_result()
}

/// Iterates through all actions and retrieves those that are still pending.
/// Serialized full action data:
/// - the action id
/// - the serialized action data
/// - (number of signers followed by) list of signer addresses.
pub fn get_pending_action_full_info(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ActionFullInfo<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getPendingActionFullInfo")
.original_result()
}

/// Returns `true` (`1`) if the user has signed the action.
/// Does not check whether or not the user is still a board member and the signature valid.
pub fn signed<
Expand All @@ -136,43 +122,6 @@ where
.original_result()
}

/// Indicates user rights.
/// `0` = no rights,
/// `1` = can propose, but not sign,
/// `2` = can propose and sign.
pub fn user_role<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
user: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, UserRole> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("userRole")
.argument(&user)
.original_result()
}

/// Lists all users that can sign actions.
pub fn get_all_board_members(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAllBoardMembers")
.original_result()
}

/// Lists all proposers that are not board members.
pub fn get_all_proposers(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAllProposers")
.original_result()
}

/// Used by board members to sign actions.
pub fn sign<
Arg0: ProxyArg<usize>,
Expand Down Expand Up @@ -261,69 +210,6 @@ where
.original_result()
}

/// Serialized action data of an action with index.
pub fn get_action_data<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, Action<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionData")
.argument(&action_id)
.original_result()
}

/// Gets addresses of all users who signed an action.
/// Does not check if those users are still board members or not,
/// so the result may contain invalid signers.
pub fn get_action_signers<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedVec<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionSigners")
.argument(&action_id)
.original_result()
}

/// Gets addresses of all users who signed an action and are still board members.
/// All these signatures are currently valid.
pub fn get_action_signer_count<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, usize> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionSignerCount")
.argument(&action_id)
.original_result()
}

/// It is possible for board members to lose their role.
/// They are not automatically removed from all actions when doing so,
/// therefore the contract needs to re-check every time when actions are performed.
/// This function is used to validate the signers before performing an action.
/// It also makes it easy to check before performing an action.
pub fn get_action_valid_signer_count<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, usize> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionValidSignerCount")
.argument(&action_id)
.original_result()
}

/// Initiates board member addition process.
/// Can also be used to promote a proposer to board member.
pub fn propose_add_board_member<
Expand Down
220 changes: 220 additions & 0 deletions contracts/examples/multisig/src/multisig_view_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

#![allow(dead_code)]
#![allow(clippy::all)]

use multiversx_sc::proxy_imports::*;

pub struct MultisigProxy;

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

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

pub struct MultisigProxyMethods<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> MultisigProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
/// Iterates through all actions and retrieves those that are still pending.
/// Serialized full action data:
/// - the action id
/// - the serialized action data
/// - (number of signers followed by) list of signer addresses.
pub fn get_pending_action_full_info(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ActionFullInfo<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getPendingActionFullInfo")
.original_result()
}

/// Indicates user rights.
/// `0` = no rights,
/// `1` = can propose, but not sign,
/// `2` = can propose and sign.
pub fn user_role<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
user: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, UserRole> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("userRole")
.argument(&user)
.original_result()
}

/// Lists all users that can sign actions.
pub fn get_all_board_members(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAllBoardMembers")
.original_result()
}

/// Lists all proposers that are not board members.
pub fn get_all_proposers(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAllProposers")
.original_result()
}

/// Serialized action data of an action with index.
pub fn get_action_data<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, Action<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionData")
.argument(&action_id)
.original_result()
}

/// Gets addresses of all users who signed an action.
/// Does not check if those users are still board members or not,
/// so the result may contain invalid signers.
pub fn get_action_signers<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedVec<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionSigners")
.argument(&action_id)
.original_result()
}

/// Gets addresses of all users who signed an action and are still board members.
/// All these signatures are currently valid.
pub fn get_action_signer_count<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, usize> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionSignerCount")
.argument(&action_id)
.original_result()
}

/// It is possible for board members to lose their role.
/// They are not automatically removed from all actions when doing so,
/// therefore the contract needs to re-check every time when actions are performed.
/// This function is used to validate the signers before performing an action.
/// It also makes it easy to check before performing an action.
pub fn get_action_valid_signer_count<
Arg0: ProxyArg<usize>,
>(
self,
action_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, usize> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getActionValidSignerCount")
.argument(&action_id)
.original_result()
}
}

#[type_abi]
#[derive(TopEncode)]
pub struct ActionFullInfo<Api>
where
Api: ManagedTypeApi,
{
pub action_id: usize,
pub action_data: Action<Api>,
pub signers: ManagedVec<Api, ManagedAddress<Api>>,
}

#[rustfmt::skip]
#[type_abi]
#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, Clone)]
pub enum Action<Api>
where
Api: ManagedTypeApi,
{
Nothing,
AddBoardMember(ManagedAddress<Api>),
AddProposer(ManagedAddress<Api>),
RemoveUser(ManagedAddress<Api>),
ChangeQuorum(usize),
SendTransferExecute(CallActionData<Api>),
SendAsyncCall(CallActionData<Api>),
SCDeployFromSource {
amount: BigUint<Api>,
source: ManagedAddress<Api>,
code_metadata: CodeMetadata,
arguments: ManagedVec<Api, ManagedBuffer<Api>>,
},
SCUpgradeFromSource {
sc_address: ManagedAddress<Api>,
amount: BigUint<Api>,
source: ManagedAddress<Api>,
code_metadata: CodeMetadata,
arguments: ManagedVec<Api, ManagedBuffer<Api>>,
},
}

#[type_abi]
#[derive(NestedEncode, NestedDecode, Clone)]
pub struct CallActionData<Api>
where
Api: ManagedTypeApi,
{
pub to: ManagedAddress<Api>,
pub egld_amount: BigUint<Api>,
pub endpoint_name: ManagedBuffer<Api>,
pub arguments: ManagedVec<Api, ManagedBuffer<Api>>,
}

#[type_abi]
#[derive(TopEncode, TopDecode)]
pub enum UserRole {
None,
Proposer,
BoardMember,
}
Loading
Loading