stellar-base 0.7.0

Low level Stellar types
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
use crate::asset::TrustLineAsset;
use crate::claim::ClaimableBalanceId;
use crate::crypto::{MuxedAccount, PublicKey, SignerKey};
use crate::error::{Error, Result};
use crate::ledger::LedgerKey;
use crate::liquidity_pool::LiquidityPoolId;
use crate::operations::Operation;
use crate::xdr;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RevokeSponsorshipOperation {
    LedgerEntry(RevokeSponsorshipLedgerEntry),
    Signer(RevokeSponsorshipSigner),
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RevokeSponsorshipLedgerEntry {
    source_account: Option<MuxedAccount>,
    ledger_key: LedgerKey,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RevokeSponsorshipSigner {
    source_account: Option<MuxedAccount>,
    account_id: PublicKey,
    signer_key: SignerKey,
}

#[derive(Debug, Default)]
pub struct RevokeSponsorshipOperationBuilder {
    source_account: Option<MuxedAccount>,
    value: Option<RevokeSponsorshipValue>,
}

#[derive(Debug)]
pub enum RevokeSponsorshipValue {
    LedgerEntry(LedgerKey),
    Signer(PublicKey, SignerKey),
}

impl RevokeSponsorshipOperation {
    /// Retrieves the operation source account.
    pub fn source_account(&self) -> &Option<MuxedAccount> {
        match *self {
            RevokeSponsorshipOperation::LedgerEntry(ref le) => le.source_account(),
            RevokeSponsorshipOperation::Signer(ref s) => s.source_account(),
        }
    }

    /// Retrieves a reference to the operation source account.
    pub fn source_account_mut(&mut self) -> &mut Option<MuxedAccount> {
        match *self {
            RevokeSponsorshipOperation::LedgerEntry(ref mut le) => le.source_account_mut(),
            RevokeSponsorshipOperation::Signer(ref mut s) => s.source_account_mut(),
        }
    }

    /// If the operation is a LedgerEntry, returns its value. Returns None otherwise.
    pub fn as_ledger_entry(&self) -> Option<&RevokeSponsorshipLedgerEntry> {
        match *self {
            RevokeSponsorshipOperation::LedgerEntry(ref inner) => Some(inner),
            _ => None,
        }
    }

    /// If the operation is a LedgerEntry, returns its value. Returns None otherwise.
    pub fn as_ledger_entry_mut(&mut self) -> Option<&mut RevokeSponsorshipLedgerEntry> {
        match *self {
            RevokeSponsorshipOperation::LedgerEntry(ref mut inner) => Some(inner),
            _ => None,
        }
    }

    /// Returns true if the operation is a LedgerEntry.
    pub fn is_ledger_entry(&self) -> bool {
        self.as_ledger_entry().is_some()
    }

    /// If the operation is a Signer, returns its value. Returns None otherwise.
    pub fn as_signer(&self) -> Option<&RevokeSponsorshipSigner> {
        match *self {
            RevokeSponsorshipOperation::Signer(ref inner) => Some(inner),
            _ => None,
        }
    }

    /// If the operation is a Signer, returns its value. Returns None otherwise.
    pub fn as_signer_mut(&mut self) -> Option<&mut RevokeSponsorshipSigner> {
        match *self {
            RevokeSponsorshipOperation::Signer(ref mut inner) => Some(inner),
            _ => None,
        }
    }

    /// Returns true if the operation is a Signer.
    pub fn is_signer(&self) -> bool {
        self.as_signer().is_some()
    }

    /// Returns tho xdr operation body.
    pub fn to_xdr_operation_body(&self) -> Result<xdr::OperationBody> {
        let inner = match *self {
            RevokeSponsorshipOperation::LedgerEntry(ref le) => {
                let ledger_key = le.ledger_key.to_xdr()?;
                xdr::RevokeSponsorshipOp::LedgerEntry(ledger_key)
            }
            RevokeSponsorshipOperation::Signer(ref s) => {
                let account_id = s.account_id.to_xdr_account_id()?;
                let signer_key = s.signer_key.to_xdr()?;
                let inner = xdr::RevokeSponsorshipOpSigner {
                    account_id,
                    signer_key,
                };
                xdr::RevokeSponsorshipOp::Signer(inner)
            }
        };
        Ok(xdr::OperationBody::RevokeSponsorship(inner))
    }

    /// Creates from the xdr operation body.
    pub fn from_xdr_operation_body(
        source_account: Option<MuxedAccount>,
        x: &xdr::RevokeSponsorshipOp,
    ) -> Result<RevokeSponsorshipOperation> {
        match x {
            xdr::RevokeSponsorshipOp::LedgerEntry(ref le) => {
                let ledger_key = LedgerKey::from_xdr(le)?;
                let inner = RevokeSponsorshipLedgerEntry {
                    source_account,
                    ledger_key,
                };
                Ok(RevokeSponsorshipOperation::LedgerEntry(inner))
            }
            xdr::RevokeSponsorshipOp::Signer(ref s) => {
                let account_id = PublicKey::from_xdr_account_id(&s.account_id)?;
                let signer_key = SignerKey::from_xdr(&s.signer_key)?;
                let inner = RevokeSponsorshipSigner {
                    source_account,
                    account_id,
                    signer_key,
                };
                Ok(RevokeSponsorshipOperation::Signer(inner))
            }
        }
    }
}

impl RevokeSponsorshipLedgerEntry {
    /// Retrieves the operation source account.
    pub fn source_account(&self) -> &Option<MuxedAccount> {
        &self.source_account
    }

    /// Retrieves a reference to the operation source account.
    pub fn source_account_mut(&mut self) -> &mut Option<MuxedAccount> {
        &mut self.source_account
    }
}

impl RevokeSponsorshipSigner {
    /// Retrieves the operation source account.
    pub fn source_account(&self) -> &Option<MuxedAccount> {
        &self.source_account
    }

    /// Retrieves a reference to the operation source account.
    pub fn source_account_mut(&mut self) -> &mut Option<MuxedAccount> {
        &mut self.source_account
    }
}

impl LedgerKey {
    /// Returns the xdr object.
    pub fn to_xdr(&self) -> Result<xdr::LedgerKey> {
        match *self {
            LedgerKey::Account(ref account_id) => {
                let account_id = account_id.to_xdr_account_id()?;
                let inner = xdr::LedgerKeyAccount { account_id };
                Ok(xdr::LedgerKey::Account(inner))
            }
            LedgerKey::Trustline(ref account_id, ref asset) => {
                let account_id = account_id.to_xdr_account_id()?;
                let asset = asset.to_xdr()?;
                let inner = xdr::LedgerKeyTrustLine { account_id, asset };
                Ok(xdr::LedgerKey::Trustline(inner))
            }
            LedgerKey::Offer(ref seller_id, ref offer_id) => {
                let seller_id = seller_id.to_xdr_account_id()?;
                let inner = xdr::LedgerKeyOffer {
                    seller_id,
                    offer_id: *offer_id,
                };
                Ok(xdr::LedgerKey::Offer(inner))
            }
            LedgerKey::Data(ref account_id, ref data_name) => {
                let account_id = account_id.to_xdr_account_id()?;
                let data_name = data_name
                    .as_bytes()
                    .to_vec()
                    .try_into()
                    .map_err(|_| Error::XdrError)?;
                let inner = xdr::LedgerKeyData {
                    account_id,
                    data_name,
                };
                Ok(xdr::LedgerKey::Data(inner))
            }
            LedgerKey::ClaimableBalance(ref balance_id) => {
                let balance_id = balance_id.to_xdr();
                let inner = xdr::LedgerKeyClaimableBalance { balance_id };
                Ok(xdr::LedgerKey::ClaimableBalance(inner))
            }
            LedgerKey::LiquidityPool(ref liquidity_pool_id) => {
                let liquidity_pool_id = liquidity_pool_id.to_xdr();
                let inner = xdr::LedgerKeyLiquidityPool { liquidity_pool_id };
                Ok(xdr::LedgerKey::LiquidityPool(inner))
            }
            LedgerKey::ContractData(ref contract_data) => {
                Ok(xdr::LedgerKey::ContractData(contract_data.clone()))
            }
            LedgerKey::ContractCode(ref contract_code) => {
                Ok(xdr::LedgerKey::ContractCode(contract_code.clone()))
            }
            LedgerKey::ConfigSetting(ref config_setting) => {
                Ok(xdr::LedgerKey::ConfigSetting(config_setting.clone()))
            }
            LedgerKey::Ttl(ref ttl) => Ok(xdr::LedgerKey::Ttl(ttl.clone())),
        }
    }

    /// Creates from the xdr object.
    pub fn from_xdr(x: &xdr::LedgerKey) -> Result<LedgerKey> {
        match x {
            xdr::LedgerKey::Account(ref account) => {
                let account_id = PublicKey::from_xdr_account_id(&account.account_id)?;
                Ok(LedgerKey::Account(account_id))
            }
            xdr::LedgerKey::Trustline(ref trustline) => {
                let account_id = PublicKey::from_xdr_account_id(&trustline.account_id)?;
                let asset = TrustLineAsset::from_xdr(&trustline.asset)?;
                Ok(LedgerKey::Trustline(account_id, asset))
            }
            xdr::LedgerKey::Offer(ref offer) => {
                let seller_id = PublicKey::from_xdr_account_id(&offer.seller_id)?;
                let offer_id = offer.offer_id;
                Ok(LedgerKey::Offer(seller_id, offer_id))
            }
            xdr::LedgerKey::Data(ref data) => {
                let account_id = PublicKey::from_xdr_account_id(&data.account_id)?;
                let data_name = data.data_name.to_string();
                Ok(LedgerKey::Data(account_id, data_name))
            }
            xdr::LedgerKey::ClaimableBalance(ref claimable_balance) => {
                let balance_id = ClaimableBalanceId::from_xdr(&claimable_balance.balance_id)?;
                Ok(LedgerKey::ClaimableBalance(balance_id))
            }
            xdr::LedgerKey::LiquidityPool(ref liquidity_pool) => {
                let liquidity_pool_id =
                    LiquidityPoolId::from_xdr(&liquidity_pool.liquidity_pool_id)?;
                Ok(LedgerKey::LiquidityPool(liquidity_pool_id))
            }
            xdr::LedgerKey::ContractData(ref contract_data) => {
                Ok(LedgerKey::ContractData(contract_data.to_owned()))
            }
            xdr::LedgerKey::ContractCode(ref contract_code) => {
                Ok(LedgerKey::ContractCode(contract_code.to_owned()))
            }
            xdr::LedgerKey::ConfigSetting(ref config_setting) => {
                Ok(LedgerKey::ConfigSetting(config_setting.to_owned()))
            }
            xdr::LedgerKey::Ttl(ref ttl) => Ok(LedgerKey::Ttl(ttl.to_owned())),
        }
    }
}

impl RevokeSponsorshipOperationBuilder {
    pub fn new() -> RevokeSponsorshipOperationBuilder {
        Default::default()
    }

    pub fn with_source_account<S>(mut self, source: S) -> RevokeSponsorshipOperationBuilder
    where
        S: Into<MuxedAccount>,
    {
        self.source_account = Some(source.into());
        self
    }

    pub fn with_ledger_key(mut self, ledger_key: LedgerKey) -> RevokeSponsorshipOperationBuilder {
        self.value = Some(RevokeSponsorshipValue::LedgerEntry(ledger_key));
        self
    }

    pub fn with_signer(
        mut self,
        account_id: PublicKey,
        signer_key: SignerKey,
    ) -> RevokeSponsorshipOperationBuilder {
        self.value = Some(RevokeSponsorshipValue::Signer(account_id, signer_key));
        self
    }

    pub fn build(self) -> Result<Operation> {
        match self.value {
            None => Err(Error::InvalidOperation(
                "missing revoke sponsorship operation ledger key or signer".to_string(),
            )),
            Some(RevokeSponsorshipValue::LedgerEntry(ledger_key)) => {
                let ledger_entry = RevokeSponsorshipLedgerEntry {
                    source_account: self.source_account,
                    ledger_key,
                };
                let inner = RevokeSponsorshipOperation::LedgerEntry(ledger_entry);
                Ok(Operation::RevokeSponsorship(inner))
            }
            Some(RevokeSponsorshipValue::Signer(account_id, signer_key)) => {
                let signer = RevokeSponsorshipSigner {
                    source_account: self.source_account,
                    account_id,
                    signer_key,
                };
                let inner = RevokeSponsorshipOperation::Signer(signer);
                Ok(Operation::RevokeSponsorship(inner))
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::asset::TrustLineAsset;
    use crate::claim::ClaimableBalanceId;
    use crate::crypto::SignerKey;
    use crate::ledger::LedgerKey;
    use crate::network::Network;
    use crate::operations::tests::*;
    use crate::operations::Operation;
    use crate::transaction::{Transaction, TransactionEnvelope, MIN_BASE_FEE};
    use crate::xdr::{XDRDeserialize, XDRSerialize};

    #[test]
    fn test_revoke_sponsorship_ledger_key_account() {
        let kp = keypair0();
        let kp1 = keypair1();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::Account(kp1.public_key()))
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAAAAAAAAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAAAAAAAAeoucsUAAABAlhwbGG2OC+ym0bD7G0GsGnbLInIVKzfLdhCl6AsyioseAydDXCVOB2A8Ywv4XfT0nC4BY26UdPBuLWG3cALmAg==";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_trustline() {
        let kp = keypair0();
        let kp1 = keypair1();
        let kp2 = keypair2();

        let abcd = TrustLineAsset::new_credit("ABCD", kp2.public_key()).unwrap();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::Trustline(kp1.public_key(), abcd))
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAAAAAAEAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAABQUJDRAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAAB6i5yxQAAAEA+1KnFKV7vhXjLxRJ+/aWfusVTrV3Az+Iscd13uKG0g6Pi41uTC5nsU07GeC2Os2bwz7r8XlNtxlkwHF89DCcG";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_offer() {
        let kp = keypair0();
        let kp1 = keypair1();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::Offer(kp1.public_key(), 123))
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAAAAAAIAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAAAAAAAewAAAAAAAAAB6i5yxQAAAECBX+hYvz4LN3DoBmTTabB7aZGCjUqps1DZaMm9jLBsHgIUrfmoVNx2e0a6t1o0nvAKpatd3SCZFWIY0W6TnAYJ";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_data() {
        let kp = keypair0();
        let kp1 = keypair1();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::Data(kp1.public_key(), "Test_Data".to_string()))
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAAAAAAMAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAAJVGVzdF9EYXRhAAAAAAAAAAAAAAHqLnLFAAAAQIEt621z4bNoQ9RXuT+bUktPySCRYocLfde5SKO2/94r4K8GBZhVzKBez80hNxfljncOuG4ZkzQ+mWaCGBjnpgE=";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_balance_id() {
        let kp = keypair0();

        let balance_id = ClaimableBalanceId::new(vec![7; 32]).unwrap();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::ClaimableBalance(balance_id))
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAAAAAAQAAAAABwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcAAAAAAAAAAeoucsUAAABAAofz60qpHGLrsNmcT9fgAnUOywCE5xDW8OMYpusgis1zODTg3fmsbFmUGB32DrGn+aeVtrLkVVjIY8vey3cVDQ==";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_account_with_source_account() {
        let kp = keypair0();
        let kp1 = keypair1();

        let op = Operation::new_revoke_sponsorship()
            .with_ledger_key(LedgerKey::Account(kp1.public_key()))
            .with_source_account(kp1.public_key())
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAEAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAASAAAAAAAAAAAAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAAAAAAAAeoucsUAAABA0Fd2Pp3NfMLTFGXbb6oks4IiwWQLqzQ71DFgVjv98Cle113hcH2toNlNEF7iT1D+262C4ajIhdAReZBubwTHCg==";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_signer_key() {
        let kp = keypair0();
        let kp1 = keypair1();

        let signer_key = SignerKey::new_from_public_key(kp1.public_key());

        let op = Operation::new_revoke_sponsorship()
            .with_signer(kp1.public_key(), signer_key)
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAAAAAASAAAAAQAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAAAAAB6i5yxQAAAECkJuiFk6qWll/g4XtiknA2GktvVLIsQuxSs2SC2NvzrzxF0WSxZjOaKdDqeZ/AfkzgajS6mCo7s9e7sg9DcF8P";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }

    #[test]
    fn test_revoke_sponsorship_ledger_key_signer_key_with_source_account() {
        let kp = keypair0();
        let kp1 = keypair1();

        let signer_key = SignerKey::new_from_public_key(kp1.public_key());

        let op = Operation::new_revoke_sponsorship()
            .with_signer(kp1.public_key(), signer_key)
            .with_source_account(kp1.public_key())
            .build()
            .unwrap();
        let mut tx = Transaction::builder(kp.public_key(), 3556091187167235, MIN_BASE_FEE)
            .add_operation(op)
            .into_transaction()
            .unwrap();
        tx.sign(kp.as_ref(), &Network::new_test()).unwrap();
        let envelope = tx.to_envelope();
        let xdr = envelope.xdr_base64().unwrap();
        let expected = "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAAAwAAAAAAAAAAAAAAAQAAAAEAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4AAAASAAAAAQAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAAAAAB6i5yxQAAAECe7rfndyOX8KE0jYOH5hH8oTYFF06UOEeQWvtLdxP9s0a/V8kTDclsyPpfCiC4dcNV5CPVifcolty05Qap2TUN";
        assert_eq!(expected, xdr);
        let back = TransactionEnvelope::from_xdr_base64(&xdr).unwrap();
        assert_eq!(envelope, back);
    }
}