-
Notifications
You must be signed in to change notification settings - Fork 148
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
add guide for extending a persistent entry and contract using the javascript sdk #1163
base: main
Are you sure you want to change the base?
add guide for extending a persistent entry and contract using the javascript sdk #1163
Conversation
Heya @Mackenzie-OO7! Thank you for another great submission. Apologies for the delay in review, we'll get to this ASAP! |
Hi @Mackenzie-OO7 - thanks again so much for your contributions! Have you been able to look at the feedback yet? |
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.
Please review:
https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop
Operation.extendFootprintTtl The Read-only set needs to contain the ledger key and the read/write section needs to be empty
ExtendFootprintTTLOp is a Soroban operation that will extend the live until ledger of the entries specified in the read-only set of the footprint. The read-write set must be empty.
// Create footprint for the entry | ||
const footprint = new StellarSdk.xdr.LedgerFootprint({ | ||
readOnly: [], | ||
readWrite: [persistentEntry], |
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.
The Read/Write set must be empty. The LedgerKey needs to be added to the readOnly footprint:
https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop
}), | ||
) | ||
.setTimeout(30) | ||
.build(); |
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.
We probably want to prepareTransaction
first before it gets sent so that simulateTransaction
and assembleTransaction
gets run
// Create footprint with both identifiers | ||
const footprint = new StellarSdk.xdr.LedgerFootprint({ | ||
readOnly: [], | ||
readWrite: [contractHash, persistentEntry], |
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.
- The extend footprint operations needs to be in the readOnly footprint
https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop
ExtendFootprintTTLOp is a Soroban operation that will extend the live until ledger of the entries specified in the read-only set of the footprint. The read-write set must be empty.
- This needs to be executed as 2 operations because the 2 ledger keys have different TTL entries.
Persistence storage entries are extended individually by passing in their key
Instance storage and the contract instance are extended together, but their thresholds are evaluated separately
ExtendFootprintTTLOp is a Soroban operation, and therefore must be the only operation in a transaction.
You can only have 1 soroban operation per transaction
.addOperation( | ||
StellarSdk.Operation.extendFootprintTtl({ | ||
extendTo: 500_000, | ||
footprint: footprint, |
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.
You should use the SorobanDataBuilder
to build out the SorobanTransactionData
not just the footprint
https://stellar.github.io/js-stellar-sdk/SorobanDataBuilder.html
// Create footprint for contract code | ||
const footprint = new StellarSdk.xdr.LedgerFootprint({ | ||
readOnly: [], | ||
readWrite: [contractHash], |
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.
Again this needs to be in ReadOnly
https://developers.stellar.org/docs/learn/encyclopedia/storage/state-archival#extendfootprintttlop
- Add the `extendFootprintTtl` operation with your intended TTL | ||
- Sign and submit the transaction | ||
|
||
:::note TTL can only be extended by the deployer or an authorized account. ::: |
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 is actually not accurate:
https://developers.stellar.org/docs/learn/encyclopedia/storage/persisting-data#access-control
There is no access control for TTL extension operations. Any user may invoke ExtendFootprintTTLOp on any LedgerEntry.
description: How to extend a persistent entry and contract using the JavaScript SDK | ||
--- | ||
|
||
Persistent storage is used for storing data and contracts that need to remain on the network for a long period. |
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.
Contract instances and contract code(wasm hash) are actually instance storage with persistent durability
.build(); | ||
|
||
transaction.sign(sourceKeypair); | ||
return await server.sendTransaction(transaction); |
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.
You need to
Simulate
https://stellar.github.io/js-stellar-sdk/module-rpc.Server.html#simulateTransaction
And Assemble transactions
https://stellar.github.io/js-stellar-sdk/module-rpc.html#.assembleTransaction
Or do prepare to perform both operations using prepareTransaction
using https://stellar.github.io/js-stellar-sdk/module-rpc.Server.html#prepareTransaction
const fee = "200100"; | ||
|
||
// Create the contract code identifier | ||
const contractHash = new StellarSdk.xdr.LedgerKey.contractCode({ |
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.
const contract = new Contract(getDeployedContractId());
const instance = contract.getFootprint();
It's easier to use the contract getFootprint()
function
hi! somehow I missed this, but I see there's new feedback now and I'll get to it. thanks for the reminder. |
closes #610