Skip to content

Add doc: When Operation Source Accounts differ from that of the Parent Transaction #1022 #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions docs/learn/fundamentals/transactions/unique-source-for-operation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
title: "When operation source accounts differ from that of the parent transaction"
sidebar_label: Unique Source Accounts for Operations
description: "Learn"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little vague for a description? were you meaning for this to be "Learn" or was it a placeholder maybe?

sidebar_position: 40
---

# When operation source accounts differ from that of the parent transaction

Let's review the unique case where an operation may have a source account different from that of the parent transaction envelope.

There are two main situations where this may happen:

1. Operations that affect more than one account
2. Operations with a high threshold weight
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would really be more like Transactions that ... and Transactions with ... here


## Operations that affect multiple accounts

If a transaction has operations with multiple source accounts, it will require the source account signature for each operation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be clearer. it reads a little like a single operation could have multiple source accounts attached to it. and signature for each operation sounds like every operation has to be signed. the transaction requires a valid signature from all source accounts present in the tx and/or the operations.


One case where this happens is with specialized transactions such as [Sponsored Reserves](../../encyclopedia/transactions-specialized/sponsored-reserves) where a sponsoring account agrees to pay the base reserves for a sponsored account.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
One case where this happens is with specialized transactions such as [Sponsored Reserves](../../encyclopedia/transactions-specialized/sponsored-reserves) where a sponsoring account agrees to pay the base reserves for a sponsored account.
One case where this happens is with specialized transactions such as [Sponsored Reserves](../../encyclopedia/transactions-specialized/sponsored-reserves.mdx) where a sponsoring account agrees to pay the base reserves for a sponsored account.


In this example, there are two sponsoring accounts, `S1` and `S2`, that sponsor trustlines for Account `A`.

```ts
//
// 2. Both S1 and S2 sponsor trustlines for Account A for different assets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be numbered as 2.? seems a bit out of place

//
let aAccount = await server.loadAccount(A.publicKey());
let tx = new TransactionBuilder(aAccount, { fee: BASE_FEE })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need the network passphrase in the tx builder options, too

.addOperation(
Operation.beginSponsoringFutureReserves({
source: S1.publicKey(),
sponsoredId: A.publicKey(),
}),
)
.addOperation(
Operation.changeTrust({
asset: usdcAsset,
limit: "5000",
}),
)
.addOperation(Operation.endSponsoringFutureReserves({}))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd probably get rid of this blank line here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i see now. we're separating the two sponsorship sandwiches with the line.

i could go either way

.addOperation(
Operation.beginSponsoringFutureReserves({
source: S2.publicKey(),
sponsoredId: A.publicKey(),
}),
)
.addOperation(
Operation.changeTrust({
asset: usdtAsset,
limit: "2500",
}),
)
.addOperation(Operation.endSponsoringFutureReserves({}))
.setNetworkPassphrase(Networks.TESTNET)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, neat! i didn't know there was a .setNetworkPassphrase method... learned something new!

.setTimeout(180)
.build();

// All 3 accounts must approve/sign this transaction.
tx.sign(S1, S2, A);
let txResponse = await server.submitTransaction(tx);
```

Learn more about [Sponsored Reserves here](../../encyclopedia/transactions-specialized/sponsored-reserves).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Learn more about [Sponsored Reserves here](../../encyclopedia/transactions-specialized/sponsored-reserves).
Learn more about [Sponsored Reserves here](../../encyclopedia/transactions-specialized/sponsored-reserves.mdx).


## Operations with a high threshold weight

Operations fall into one of three threshold categories:

1. Low
2. Medium
3. High

Each threshold category has a weight between 0 and 255. This determines the signature weight required for an operation. The combined weight of all signatures for the source account of the operation meets the threshold for the operation. Combined weight of the signatures for the source account of the transaction meets the low threshold for the source account.

Here is an example.

```ts
const account = await server.loadAccount(sourceAccountKeypair.publicKey());

const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET, // or StellarSdk.Networks.PUBLIC
})
.addOperation(
StellarSdk.Operation.setOptions({
signer: {
pubKey: signer1Keypair.publicKey(),
weight: 1,
},
}),
)
.addOperation(
StellarSdk.Operation.setOptions({
signer: {
pubKey: signer2PublicKey,
weight: 1,
},
lowThreshold: 2,
medThreshold: 2,
highThreshold: 2,
}),
)
.setTimeout(30)
.build();

transaction.sign(sourceAccountKeypair);
transaction.sign(signer1Keypair);
```