-
Notifications
You must be signed in to change notification settings - Fork 189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would really be more like |
||||||
|
||||||
## Operations that affect multiple accounts | ||||||
|
||||||
If a transaction has operations with multiple source accounts, it will require the source account signature for each operation. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to be numbered as |
||||||
// | ||||||
let aAccount = await server.loadAccount(A.publicKey()); | ||||||
let tx = new TransactionBuilder(aAccount, { fee: BASE_FEE }) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({})) | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd probably get rid of this blank line here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, neat! i didn't know there was a |
||||||
.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). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## 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); | ||||||
``` |
There was a problem hiding this comment.
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?