Skip to content

Commit 3527998

Browse files
authored
fix: fix the issue where sending assets using Transaction.append_payment_to_contract_op fails when the sender's account is the same as the asset issuer's account. (#1029)
1 parent c8045a4 commit 3527998

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Release History
33

44
### Pending
55

6+
#### Update
7+
- fix: fix the issue where sending assets using `Transaction.append_payment_to_contract_op` fails when the sender's account is the same as the asset issuer's account. ([#1029](https://github.com/StellarCN/py-stellar-base/pull/1029))
8+
69
### Version 12.2.0
710

811
#### Update

stellar_sdk/transaction_builder.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,17 +1602,20 @@ def append_payment_to_contract_op(
16021602
contract_instance_ledger_key,
16031603
]
16041604
read_write = [
1605-
stellar_xdr.LedgerKey(
1606-
type=stellar_xdr.LedgerEntryType.TRUSTLINE,
1607-
trust_line=stellar_xdr.LedgerKeyTrustLine(
1608-
account_id=Keypair.from_public_key(
1609-
from_address
1610-
).xdr_account_id(),
1611-
asset=asset.to_trust_line_asset_xdr_object(),
1612-
),
1613-
),
16141605
balance_ledger_key,
16151606
]
1607+
if asset.issuer != from_address:
1608+
read_write.append(
1609+
stellar_xdr.LedgerKey(
1610+
type=stellar_xdr.LedgerEntryType.TRUSTLINE,
1611+
trust_line=stellar_xdr.LedgerKeyTrustLine(
1612+
account_id=Keypair.from_public_key(
1613+
from_address
1614+
).xdr_account_id(),
1615+
asset=asset.to_trust_line_asset_xdr_object(),
1616+
),
1617+
),
1618+
)
16161619

16171620
soroban_data = (
16181621
SorobanDataBuilder()

tests/test_transaction_builder.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,73 @@ def test_append_payment_to_contract_op_with_different_op_source(self):
12911291

12921292
server.close()
12931293

1294+
@pytest.mark.integration
1295+
def test_append_payment_to_contract_op_with_asset_issuer_as_sender(self):
1296+
kp = Keypair.random()
1297+
1298+
asset = Asset("CAT", kp.public_key)
1299+
amount1 = "100.125"
1300+
amount2 = "120.7891"
1301+
1302+
integration_utils.fund_account(kp.public_key)
1303+
integration_utils.create_asset_contract(asset, kp)
1304+
destination = integration_utils.get_random_contract_id(kp)
1305+
1306+
server = Server(horizon_url=integration_utils.HORIZON_URL)
1307+
source = server.load_account(kp.public_key)
1308+
tx1 = (
1309+
TransactionBuilder(
1310+
source_account=source,
1311+
network_passphrase=integration_utils.NETWORK_PASSPHRASE,
1312+
base_fee=100,
1313+
)
1314+
.append_payment_to_contract_op(destination, asset, amount1)
1315+
.set_timeout(30)
1316+
.build()
1317+
)
1318+
tx1.sign(kp)
1319+
server.submit_transaction(tx1)
1320+
assert (
1321+
integration_utils.get_balance_for_contract(
1322+
destination, asset, kp.public_key
1323+
)
1324+
== 1001250000
1325+
)
1326+
1327+
tx2 = (
1328+
TransactionBuilder(
1329+
source_account=source,
1330+
network_passphrase=integration_utils.NETWORK_PASSPHRASE,
1331+
base_fee=100,
1332+
)
1333+
.append_payment_to_contract_op(destination, asset, amount2)
1334+
.set_timeout(30)
1335+
.build()
1336+
)
1337+
tx2.sign(kp)
1338+
server.submit_transaction(tx2)
1339+
assert (
1340+
integration_utils.get_balance_for_contract(
1341+
destination, asset, kp.public_key
1342+
)
1343+
== 2209141000
1344+
)
1345+
1346+
tx3 = (
1347+
TransactionBuilder(
1348+
source_account=source,
1349+
network_passphrase=integration_utils.NETWORK_PASSPHRASE,
1350+
base_fee=100,
1351+
)
1352+
.append_restore_asset_balance_entry_op(destination, asset)
1353+
.set_timeout(30)
1354+
.build()
1355+
)
1356+
tx3.sign(kp)
1357+
server.submit_transaction(tx3)
1358+
1359+
server.close()
1360+
12941361
def test_append_payment_to_stellar_address_raise(self):
12951362
kp = Keypair.random()
12961363
asset = Asset.native()

0 commit comments

Comments
 (0)