Skip to content

Commit

Permalink
[cherry-pick][cli] Cherry pick cli ptb fix (#17480)
Browse files Browse the repository at this point in the history
## Description 

The sender should be the gas object owner when gas is passed.

## Test plan 

Existing tests.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
stefan-mysten authored May 2, 2024
1 parent 4101638 commit 2aadf14
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions crates/sui/src/client_ptb/ptb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,19 @@ impl PTB {
};

// get all the metadata needed for executing the PTB: sender, gas, signing tx
// get sender's address -- active address
let Some(sender) = context.config.active_address else {
anyhow::bail!("No active address, cannot execute PTB");

let gas = program_metadata.gas_object_id.map(|x| x.value);

// the sender is the gas object if gas is provided, otherwise the active address
let sender = match gas {
Some(gas) => context
.get_object_owner(&gas)
.await
.map_err(|_| anyhow!("Could not find owner for gas object ID"))?,
None => context
.config
.active_address
.ok_or_else(|| anyhow!("No active address, cannot execute PTB"))?,
};

// get the gas price
Expand All @@ -162,8 +172,8 @@ impl PTB {
};

// find the gas coins if we have no gas coin given
let coins = if let Some(gas) = program_metadata.gas_object_id {
context.get_object_ref(gas.value).await?
let coins = if let Some(gas) = gas {
context.get_object_ref(gas).await?
} else {
context
.gas_for_owner_budget(sender, gas_budget, BTreeSet::new())
Expand Down

0 comments on commit 2aadf14

Please sign in to comment.