Skip to content

Commit

Permalink
Change transfer_object to transfer_coin (MystenLabs#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Mar 4, 2022
1 parent 0a76477 commit ae842e2
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 125 deletions.
2 changes: 1 addition & 1 deletion sui/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl WalletCommands {

let (cert, effects) = context
.address_manager
.transfer_object(*from, *object_id, *gas, *to, signature_callback)
.transfer_coin(*from, *object_id, *gas, *to, signature_callback)
.await?;
let time_total = time_start.elapsed().as_micros();

Expand Down
6 changes: 2 additions & 4 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,12 @@ impl AuthorityState {
}
temporary_store.write_object(gas_object);

if output_object.is_read_only() {
if let Err(err) = output_object.transfer(recipient) {
return Ok(ExecutionStatus::Failure {
gas_used: gas::MIN_OBJ_TRANSFER_GAS,
error: Box::new(SuiError::CannotTransferReadOnlyObject),
error: Box::new(err),
});
}

output_object.transfer(recipient);
temporary_store.write_object(output_object);
Ok(ExecutionStatus::Success { gas_used })
}
Expand Down
11 changes: 8 additions & 3 deletions sui_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub struct ClientState {
// Operations are considered successful when they successfully reach a quorum of authorities.
#[async_trait]
pub trait Client {
/// Send object to a Sui account.
async fn transfer_object(
/// Send coin object to a Sui address.
async fn transfer_coin(
&mut self,
signer: SuiAddress,
object_id: ObjectID,
Expand Down Expand Up @@ -667,7 +667,7 @@ impl<A> Client for ClientAddressManager<A>
where
A: AuthorityAPI + Send + Sync + Clone + 'static,
{
async fn transfer_object(
async fn transfer_coin(
&mut self,
signer: SuiAddress,
object_id: ObjectID,
Expand All @@ -677,6 +677,11 @@ where
) -> Result<(CertifiedTransaction, TransactionEffects), anyhow::Error> {
let account = self.get_account(&signer)?;
let object_ref = account.latest_object_ref(&object_id)?;
self.get_object_info(object_id)
.await?
.object()?
.is_transfer_elegible()?;

let gas_payment = account.latest_object_ref(&gas_payment)?;
let data = TransactionData::new_transfer(recipient, object_ref, signer, gas_payment);
let signature = tx_signer.sign(&signer, data.clone()).await?;
Expand Down
36 changes: 18 additions & 18 deletions sui_core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ async fn test_initiating_valid_transfer() {
(sender, SequenceNumber::from(0))
);
let (certificate, _) = client
.transfer_object(
.transfer_coin(
sender,
object_id_1,
gas_object,
Expand Down Expand Up @@ -548,7 +548,7 @@ async fn test_initiating_valid_transfer_despite_bad_authority() {
let (sender, sender_key) = get_key_pair();
let mut client = init_local_client_and_fund_account_bad(sender, authority_objects).await;
let (certificate, _) = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand Down Expand Up @@ -593,7 +593,7 @@ async fn test_initiating_transfer_low_funds() {
let (sender, sender_key) = get_key_pair();
let mut client = init_local_client_and_fund_account_bad(sender, authority_objects).await;
assert!(client
.transfer_object(
.transfer_coin(
sender,
object_id_2,
gas_object,
Expand Down Expand Up @@ -649,7 +649,7 @@ async fn test_bidirectional_transfer() {
);
// Transfer object to client.
let (certificate, _) = client
.transfer_object(
.transfer_coin(
addr1,
object_id,
gas_object1,
Expand Down Expand Up @@ -694,7 +694,7 @@ async fn test_bidirectional_transfer() {

// Transfer the object back to Client1
client
.transfer_object(
.transfer_coin(
addr2,
object_id,
gas_object2,
Expand Down Expand Up @@ -727,7 +727,7 @@ async fn test_bidirectional_transfer() {

// Should fail if Client 2 double spend the object
assert!(client
.transfer_object(
.transfer_coin(
addr2,
object_id,
gas_object2,
Expand Down Expand Up @@ -796,7 +796,7 @@ async fn test_client_state_sync_with_transferred_object() {

// Transfer object to client.
client
.transfer_object(
.transfer_coin(
addr1,
object_id,
gas_object_id,
Expand Down Expand Up @@ -1393,7 +1393,7 @@ async fn test_transfer_object_error() {
// Test 1: Double spend
let object_id = *objects.next().unwrap();
client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand All @@ -1403,7 +1403,7 @@ async fn test_transfer_object_error() {
.await
.unwrap();
let result = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand All @@ -1427,7 +1427,7 @@ async fn test_transfer_object_error() {
.unwrap();

let result = client
.transfer_object(
.transfer_coin(
sender,
obj.id(),
gas_object,
Expand All @@ -1451,7 +1451,7 @@ async fn test_transfer_object_error() {
.unwrap();

let result = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand Down Expand Up @@ -1481,7 +1481,7 @@ async fn test_transfer_object_error() {
.unwrap();

let result = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand Down Expand Up @@ -1685,7 +1685,7 @@ async fn test_object_store_transfer() {

// Transfer object to client.
let _certificate = client
.transfer_object(
.transfer_coin(
addr1,
object_id,
gas_object1,
Expand All @@ -1712,7 +1712,7 @@ async fn test_object_store_transfer() {

// Transfer the object back to Client1
let _certificate = client
.transfer_object(
.transfer_coin(
addr2,
object_id,
gas_object2,
Expand Down Expand Up @@ -2293,7 +2293,7 @@ async fn test_transfer_pending_transactions() {
// Test 1: Normal transfer
let object_id = *objects.next().unwrap();
client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand All @@ -2317,7 +2317,7 @@ async fn test_transfer_pending_transactions() {
.unwrap();

let result = client
.transfer_object(
.transfer_coin(
sender,
obj.id(),
gas_object,
Expand Down Expand Up @@ -2348,7 +2348,7 @@ async fn test_transfer_pending_transactions() {
.unwrap();

let result = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand Down Expand Up @@ -2382,7 +2382,7 @@ async fn test_transfer_pending_transactions() {
.unwrap();
// Try to use those objects in another transaction
let result = client
.transfer_object(
.transfer_coin(
sender,
object_id,
gas_object,
Expand Down
Loading

0 comments on commit ae842e2

Please sign in to comment.