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

ReturnsNewManagedAddress result handler impl #1536

Merged
merged 2 commits into from
Apr 4, 2024
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
4 changes: 2 additions & 2 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl AdderInteract {
.run()
.await;

let new_address_bech32 = bech32::encode(&new_address.to_address());
let new_address_bech32 = bech32::encode(&new_address);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
Expand Down Expand Up @@ -149,7 +149,7 @@ impl AdderInteract {

let results = buffer.run().await;
for result in results {
let new_address_bech32 = bech32::encode(&result.to_address());
let new_address_bech32 = bech32::encode(&result);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl MultisigInteract {
.run()
.await;

let new_address_bech32 = bech32::encode(&new_address.to_address());
let new_address_bech32 = bech32::encode(&new_address);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
Expand Down Expand Up @@ -205,7 +205,7 @@ impl MultisigInteract {

let results = buffer.run().await;
for result in results {
let new_address_bech32 = bech32::encode(&result.to_address());
let new_address_bech32 = bech32::encode(&result);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
Expand Down
64 changes: 20 additions & 44 deletions contracts/feature-tests/abi-tester/src/abi_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ pub struct AbiTestType {
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested01 {
}
pub struct OnlyShowsUpAsNested01 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested02 {
Expand All @@ -415,19 +414,14 @@ pub enum AbiEnum {
Nothing,
Something(i32),
SomethingMore(u8, OnlyShowsUpAsNested08),
SomeStruct {
a: u16,
b: OnlyShowsUpAsNested09,
},
SomeStruct { a: u16, b: OnlyShowsUpAsNested09 },
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested08 {
}
pub struct OnlyShowsUpAsNested08 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested09 {
}
pub struct OnlyShowsUpAsNested09 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct AbiManagedType<Api>
Expand All @@ -440,36 +434,28 @@ where
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested03 {
}
pub struct OnlyShowsUpAsNested03 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested04 {
}
pub struct OnlyShowsUpAsNested04 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested05 {
}
pub struct OnlyShowsUpAsNested05 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested06 {
}
pub struct OnlyShowsUpAsNested06 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested07 {
}
pub struct OnlyShowsUpAsNested07 {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInSingleValueMapper {
}
pub struct OnlyShowsUpAsNestedInSingleValueMapper {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInVec {
}
pub struct OnlyShowsUpAsNestedInVec {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInArrayVec {
}
pub struct OnlyShowsUpAsNestedInArrayVec {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, ManagedVecItem)]
pub struct AbiManagedVecItem {
Expand All @@ -478,37 +464,30 @@ pub struct AbiManagedVecItem {
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInArray {
}
pub struct OnlyShowsUpAsNestedInArray {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInBox {
}
pub struct OnlyShowsUpAsNestedInBox {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInBoxedSlice {
}
pub struct OnlyShowsUpAsNestedInBoxedSlice {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInRef {
}
pub struct OnlyShowsUpAsNestedInRef {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInSlice {
}
pub struct OnlyShowsUpAsNestedInSlice {}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNestedInOption {
}
pub struct OnlyShowsUpAsNestedInOption {}

#[derive(TopEncode, TopDecode)]
pub struct OnlyShowsUpInEsdtAttr {
pub field: OnlyShowsUpAsNested10,
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode)]
pub struct OnlyShowsUpAsNested10 {
}
pub struct OnlyShowsUpAsNested10 {}

#[derive(TopEncode, TopDecode)]
pub enum ExplicitDiscriminant {
Expand All @@ -525,8 +504,5 @@ pub enum ExplicitDiscriminantMixed {
Unit,
Tuple(u16),
Five,
Struct {
a: u8,
b: u16,
},
Struct { a: u8, b: u16 },
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait Parent {
.raw_deploy()
.code(code)
.with_gas_limit(gas_left)
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.sync_call();

self.child_contract_address().set(&child_contract_address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait ForwarderRawDeployUpgrade {
.code_metadata(code_metadata)
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.returns(ReturnsRawResult)
.sync_call()
.into()
Expand All @@ -34,7 +34,7 @@ pub trait ForwarderRawDeployUpgrade {
.code_metadata(code_metadata)
.arguments_raw(args.to_arg_buffer())
.with_gas_limit(self.blockchain().get_gas_left())
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.sync_call()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait DeployContractModule {
.typed(vault_proxy::VaultProxy)
.init(opt_arg)
.code(code.clone())
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.returns(ReturnsResult)
.sync_call()
}
Expand All @@ -55,7 +55,7 @@ pub trait DeployContractModule {
.init(opt_arg)
.code_metadata(CodeMetadata::DEFAULT)
.from_source(source_address)
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.returns(ReturnsResult)
.sync_call()
.into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait ProxyTestFirst {
.init(123)
.code(code)
.code_metadata(CodeMetadata::UPGRADEABLE)
.returns(ReturnsNewAddress)
.returns(ReturnsNewManagedAddress)
.returns(ReturnsResult)
.egld(payment)
.sync_call();
Expand Down
2 changes: 2 additions & 0 deletions framework/base/src/types/interaction/tx_result_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod returns_bt;
mod returns_new_address;
mod returns_new_managed_address;
mod returns_raw_result;
mod returns_result;
mod returns_result_conv;
Expand All @@ -10,6 +11,7 @@ mod with_result_conv;

pub use returns_bt::*;
pub use returns_new_address::*;
pub use returns_new_managed_address::*;
pub use returns_raw_result::*;
pub use returns_result::*;
pub use returns_result_conv::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::types::{
DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec, TxEnv,
heap::Address, DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem,
RHListItemExec, TxEnv,
};

/// Indicates that the newly deployed address will be returned after a deploy.
Expand All @@ -9,14 +10,14 @@ impl<Env, Original> RHListItem<Env, Original> for ReturnsNewAddress
where
Env: TxEnv,
{
type Returns = ManagedAddress<Env::Api>;
type Returns = Address;
}

impl<Env, Original> RHListItemExec<DeployRawResult<Env::Api>, Env, Original> for ReturnsNewAddress
where
Env: TxEnv,
{
fn item_process_result(self, raw_result: &DeployRawResult<Env::Api>) -> Self::Returns {
raw_result.new_address.clone()
raw_result.new_address.to_address()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::types::{
DeployRawResult, ManagedAddress, ManagedBuffer, ManagedVec, RHListItem, RHListItemExec, TxEnv,
};

/// Indicates that the newly deployed address will be returned after a deploy as a ManagedAddress.
pub struct ReturnsNewManagedAddress;

impl<Env, Original> RHListItem<Env, Original> for ReturnsNewManagedAddress
where
Env: TxEnv,
{
type Returns = ManagedAddress<Env::Api>;
}

impl<Env, Original> RHListItemExec<DeployRawResult<Env::Api>, Env, Original>
for ReturnsNewManagedAddress
where
Env: TxEnv,
{
fn item_process_result(self, raw_result: &DeployRawResult<Env::Api>) -> Self::Returns {
raw_result.new_address.clone()
}
}
17 changes: 15 additions & 2 deletions framework/scenario/src/facade/world_tx/scenario_rh_impl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use multiversx_sc::{
codec::{CodecFrom, TopDecodeMulti, TopEncodeMulti},
types::{
ManagedAddress, RHList, RHListItem, RHListItemExec, ReturnsNewAddress, ReturnsResult,
ReturnsResultConv, TxEnv, WithNewAddress, WithResultConv,
ManagedAddress, RHList, RHListItem, RHListItemExec, ReturnsNewAddress,
ReturnsNewManagedAddress, ReturnsResult, ReturnsResultConv, TxEnv, WithNewAddress,
WithResultConv,
},
};

Expand Down Expand Up @@ -57,6 +58,18 @@ where
}

impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ReturnsNewAddress
where
Env: TxEnv,
{
fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns {
tx_response
.new_deployed_address
.clone()
.expect("missing returned address")
}
}

impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ReturnsNewManagedAddress
where
Env: TxEnv,
{
Expand Down
Loading