Skip to content

Commit

Permalink
fix: begin_sponsoring_future_reserves
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Aug 28, 2024
1 parent c7c3b41 commit 456e5b2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
NetworkRunnable,
},
config::{self, data, network, secret},
rpc::{self},
tx::builder,
rpc,
tx::builder::{self, ops},
};

#[derive(Parser, Debug, Clone)]
Expand All @@ -20,7 +20,7 @@ pub struct Cmd {
pub tx: tx::args::Args,
/// Sequence number to bump to
#[arg(long)]
pub bump_to: i64,
pub sponsorship_id: builder::AccountId,
}

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -72,7 +72,7 @@ impl NetworkRunnable for Cmd {
_: Option<&config::Args>,
) -> Result<TxnResult<()>, Error> {
let tx_build = self.tx.tx_builder().await?;
let op = builder::ops::BumpSequence::new(self.bump_to);
let op = ops::BeginSponsoringFutureReserves::new(self.sponsorship_id.clone());

self.tx
.handle_tx(
Expand Down
32 changes: 24 additions & 8 deletions cmd/soroban-cli/src/commands/tx/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,41 @@ mod set_trustline_flags;

#[derive(Debug, Parser)]
pub enum Cmd {
/// Merge an account into another account
/// Transfers the XLM balance of an account to another account and removes the source account from the ledger
/// Threshold: High
AccountMerge(account_merge::Cmd),
/// Allows an account to pay the base reserves for another account; sponsoring account establishes the is-sponsoring-future-reserves relationship
/// There must also be an end sponsoring future reserves operation in the same transaction
/// Learn more about sponsored reserves: [Sponsored Reserves Encyclopedia Entry](https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/sponsored-reserves/)
BeginSponsoringFutureReserves(begin_sponsoring_future_reserves::Cmd),
/// Bump the sequence number of an account
/// Bumps forward the sequence number of the source account to the given sequence number, invalidating any transaction with a smaller sequence number
/// Threshold: Low
BumpSequence(bump_sequence::Cmd),
/// Change trust for an asset
/// Creates, updates, or deletes a trustline
/// Learn more about trustlines: [Trustlines Encyclopedia Entry](https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/trustlines/)
/// Threshold: Medium
ChangeTrust(change_trust::Cmd),
/// Create a new account using another account
/// Creates and funds a new account with the specified starting balance
/// Threshold: Medium
CreateAccount(create_account::Cmd),
/// Manage data on an account
/// Sets, modifies, or deletes a data entry (name/value pair) that is attached to an account
/// Learn more about entries and subentries: [Accounts section](../stellar-data-structures/accounts.mdx#subentries)
/// Threshold: Medium
ManageData(manage_data::Cmd),
/// Send a payment to an account
/// Sends an amount in a specific asset to a destination account
/// Threshold: Medium
Payment(payment::Cmd),
/// Set options on an account
/// Set option for an account such as flags, inflation destination, signers, home domain, and master key weight
/// Learn more about flags: [Flags Encyclopedia Entry](../../glossary.mdx#flags)
/// Learn more about the home domain: [Stellar Ecosystem Proposals SEP-0001](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md)
/// Learn more about signers operations and key weight: [Signature and Multisignature Encyclopedia Entry](../../encyclopedia/security/signatures-multisig.mdx)
/// Threshold: High
SetOptions(set_options::Cmd),
/// Set trustline flags on an account
/// Allows issuing account to configure authorization and trustline flags to an asset
/// The Asset parameter is of the `TrustLineAsset` type. If you are modifying a trustline to a regular asset (i.e. one in a Code:Issuer format), this is equivalent to the Asset type.
/// If you are modifying a trustline to a pool share, however, this is composed of the liquidity pool's unique ID.
/// Learn more about flags: [Flags Glossary Entry](../../glossary.mdx#flags)
/// Threshold: Low
SetTrustlineFlags(set_trustline_flags::Cmd),
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/tx/new/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub struct Cmd {
/// Account to send to
#[arg(long)]
pub destination: String,
/// Asset to send, default XLM
/// Asset to send, default native, e.i. XLM
#[arg(long, default_value = "native")]
pub asset: builder::Asset,
/// Initial balance of the account, default 1 XLM
/// Amount of the aforementioned asset to send.
#[arg(long)]
pub amount: i64,
}
Expand Down
37 changes: 29 additions & 8 deletions cmd/soroban-cli/src/commands/tx/new/set_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,45 @@ pub struct Cmd {
#[command(flatten)]
pub tx: tx::args::Args,
#[arg(long)]
/// Account of the inflation destination.
pub inflation_dest: Option<builder::AccountId>,
#[arg(long)]
/// A number from 0-255 (inclusive) representing the weight of the master key. If the weight of the master key is updated to 0, it is effectively disabled.
pub master_weight: Option<u8>,
#[arg(long)]
/// A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have [a low threshold](../../encyclopedia/security/signatures-multisig.mdx).
pub low_threshold: Option<u8>,
#[arg(long)]
/// A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have [a medium threshold](../../encyclopedia/security/signatures-multisig.mdx).
pub med_threshold: Option<u8>,
#[arg(long)]
/// A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have [a high threshold](../../encyclopedia/security/signatures-multisig.mdx).
pub high_threshold: Option<u8>,
#[arg(long)]
/// Sets the home domain of an account. See [Federation](../../encyclopedia/network-configuration/federation.mdx).
pub home_domain: Option<String>,
#[arg(long)]
/// Add, update, or remove a signer from an account.
pub signer: Option<String>,

#[arg(long, requires = "signer")]
/// Signer weight is a number from 0-255 (inclusive). The signer is deleted if the weight is 0.
pub signer_weight: Option<u8>,
#[arg(long, conflicts_with = "clear_required")]
/// When enabled, an issuer must approve an account before that account can hold its asset.
/// [More info](https://developers.stellar.org/docs/tokens/control-asset-access#authorization-required-0x1)
pub set_required: bool,
#[arg(long, conflicts_with = "clear_revocable")]
/// When enabled, an issuer can revoke an existing trustline’s authorization, thereby freezing the asset held by an account.
/// [More info](https://developers.stellar.org/docs/tokens/control-asset-access#authorization-revocable-0x2)
pub set_revocable: bool,
#[arg(long, conflicts_with = "clear_immutable")]
pub set_immutable: bool,
#[arg(long, conflicts_with = "clear_clawback_enabled")]
/// Enables the issuing account to take back (burning) all of the asset.
/// [More info](https://developers.stellar.org/docs/tokens/control-asset-access#clawback-enabled-0x8)
pub set_clawback_enabled: bool,
#[arg(long, conflicts_with = "clear_immutable")]
/// With this setting, none of the other authorization flags (`AUTH_REQUIRED_FLAG`, `AUTH_REVOCABLE_FLAG`) can be set, and the issuing account can’t be merged.
/// [More info](https://developers.stellar.org/docs/tokens/control-asset-access#authorization-immutable-0x4)
pub set_immutable: bool,
#[arg(long)]
pub clear_required: bool,
#[arg(long)]
Expand Down Expand Up @@ -127,11 +144,15 @@ impl NetworkRunnable for Cmd {
op = op.set_home_domain(&home_domain.parse()?)?;
};

// TODO: Signer implementation
// if let Some(signer) = self.signer.as_ref() {
// let signer = signer.parse()?;
// op = op.set_signer(signer);
// }
if let (Some(signer), Some(signer_weight)) =
(self.signer.as_ref(), self.signer_weight.as_ref())
{
let signer = xdr::Signer {
key: signer.parse()?,
weight: u32::from(*signer_weight),
};
op = op.set_signer(signer);
}

if self.set_required {
op = op.set_required_flag();
Expand Down
3 changes: 3 additions & 0 deletions cmd/soroban-cli/src/commands/tx/new/set_trustline_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ pub struct Cmd {
#[arg(long)]
pub asset: builder::Asset,
#[arg(long, conflicts_with = "clear_authorize")]
/// Signifies complete authorization allowing an account to transact freely with the asset to make and receive payments and place orders.
pub set_authorize: bool,
#[arg(long, conflicts_with = "clear_authorize_to_maintain_liabilities")]
/// Denotes limited authorization that allows an account to maintain current orders but not to otherwise transact with the asset.
pub set_authorize_to_maintain_liabilities: bool,
#[arg(long, conflicts_with = "clear_trustline_clawback_enabled")]
/// Enables the issuing account to take back (burning) all of the asset. See our [section on Clawbacks](https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/clawbacks)
pub set_trustline_clawback_enabled: bool,
#[arg(long)]
pub clear_authorize: bool,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use stellar_xdr::curr as xdr;

use crate::tx::builder;

pub struct BeginSponsoringFutureReserves(xdr::BeginSponsoringFutureReservesOp);

impl BeginSponsoringFutureReserves {
pub fn new(sponsored_id: impl Into<xdr::AccountId>) -> Self {
pub fn new(sponsored_id: impl Into<builder::AccountId>) -> Self {
Self(xdr::BeginSponsoringFutureReservesOp {
sponsored_id: sponsored_id.into(),
sponsored_id: sponsored_id.into().into(),
})
}
}
Expand Down

0 comments on commit 456e5b2

Please sign in to comment.