Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! [adapter][mov…
Browse files Browse the repository at this point in the history
…e] Relax object/pure arg ordering. remove return values
  • Loading branch information
tnowacki committed Apr 21, 2022
1 parent b29f233 commit 89e97ba
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
46 changes: 22 additions & 24 deletions sui/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,21 +743,28 @@ async fn call_move(

// These steps can potentially be condensed and moved into the client/manager level
// Extract the input args
let (object_ids, pure_args) =
let json_args =
resolve_move_function_args(package_obj, module.clone(), function.clone(), args.to_vec())?;

// Fetch all the objects needed for this call
let mut input_objs = vec![];
for obj_id in object_ids.clone() {
input_objs.push(
context
.gateway
.get_object_info(obj_id)
.await?
.into_object()?,
);
let mut objects = BTreeMap::new();
let mut args = Vec::with_capacity(json_args.len());
for json_arg in json_args {
args.push(match json_arg {
SuiJsonCallArg::Object(id) => {
let obj = context.gateway.get_object_info(id).await?.into_object()?;
let arg = if obj.is_shared() {
CallArg::SharedObject(id)
} else {
CallArg::ImmOrOwnedObject(obj.compute_object_reference())
};
objects.insert(id, obj);
arg
}
SuiJsonCallArg::Pure(bytes) => CallArg::Pure(bytes),
})
}
let forbidden_gas_objects = BTreeSet::from_iter(object_ids.clone().into_iter());
let forbidden_gas_objects = objects.keys().copied().collect();
let gas_object = context
.choose_gas_for_wallet(*gas, *gas_budget, forbidden_gas_objects)
.await?;
Expand All @@ -770,35 +777,26 @@ async fn call_move(
.ok_or_else(|| anyhow!("Cannot get package from object"))?
.deserialize_module(module)?;
resolve_and_type_check(
&objects,
&compiled_module,
function,
type_args,
input_objs,
pure_args.clone(),
args.clone(),
)?;

// Fetch the object info for the gas obj
let gas_obj_ref = gas_object.compute_object_reference();

// Fetch the objects for the object args
let mut object_args_refs = Vec::new();
for obj_id in object_ids {
let obj_info = context.gateway.get_object_info(obj_id).await?;
object_args_refs.push(obj_info.object()?.compute_object_reference());
}

let data = context
.gateway
.move_call(
sender,
package_obj_ref,
module.to_owned(),
function.to_owned(),
type_args.to_vec(),
type_args.to_owned(),
gas_obj_ref,
object_args_refs,
vec![],
pure_args,
args,
*gas_budget,
)
.await?;
Expand Down
32 changes: 15 additions & 17 deletions sui_core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ fn transfer_object_move_transaction(
framework_obj_ref: ObjectRef,
gas_object_ref: ObjectRef,
) -> Transaction {
let pure_args = vec![bcs::to_bytes(&AccountAddress::from(dest)).unwrap()];
let args = vec![
CallArg::ImmOrOwnedObject(object_ref),
CallArg::Pure(bcs::to_bytes(&AccountAddress::from(dest)).unwrap()),
];

to_transaction(
TransactionData::new_move_call(
Expand All @@ -71,9 +74,7 @@ fn transfer_object_move_transaction(
ident_str!("transfer").to_owned(),
Vec::new(),
gas_object_ref,
vec![object_ref],
vec![],
pure_args,
args,
GAS_VALUE_FOR_TESTING / 2,
),
secret,
Expand All @@ -89,9 +90,9 @@ pub fn crate_object_move_transaction(
gas_object_ref: ObjectRef,
) -> Transaction {
// When creating an ObjectBasics object, we provide the value (u64) and address which will own the object
let pure_arguments = vec![
value.to_le_bytes().to_vec(),
bcs::to_bytes(&AccountAddress::from(dest)).unwrap(),
let arguments = vec![
CallArg::Pure(value.to_le_bytes().to_vec()),
CallArg::Pure(bcs::to_bytes(&AccountAddress::from(dest)).unwrap()),
];

to_transaction(
Expand All @@ -102,9 +103,7 @@ pub fn crate_object_move_transaction(
ident_str!("create").to_owned(),
Vec::new(),
gas_object_ref,
Vec::new(),
vec![],
pure_arguments,
arguments,
GAS_VALUE_FOR_TESTING / 2,
),
&*secret,
Expand All @@ -126,9 +125,7 @@ fn delete_object_move_transaction(
ident_str!("delete").to_owned(),
Vec::new(),
gas_object_ref,
vec![object_ref],
Vec::new(),
vec![],
vec![CallArg::ImmOrOwnedObject(object_ref)],
GAS_VALUE_FOR_TESTING / 2,
),
secret,
Expand All @@ -143,7 +140,10 @@ fn set_object_move_transaction(
framework_obj_ref: ObjectRef,
gas_object_ref: ObjectRef,
) -> Transaction {
let pure_args = vec![bcs::to_bytes(&value).unwrap()];
let args = vec![
CallArg::ImmOrOwnedObject(object_ref),
CallArg::Pure(bcs::to_bytes(&value).unwrap()),
];

to_transaction(
TransactionData::new_move_call(
Expand All @@ -153,9 +153,7 @@ fn set_object_move_transaction(
ident_str!("set_value").to_owned(),
Vec::new(),
gas_object_ref,
vec![object_ref],
vec![],
pure_args,
args,
GAS_VALUE_FOR_TESTING / 2,
),
secret,
Expand Down

0 comments on commit 89e97ba

Please sign in to comment.