diff --git a/api/methods/getLedgerEntries.mdx b/api/methods/getLedgerEntries.mdx index 2d5ae1e4..9103c904 100644 --- a/api/methods/getLedgerEntries.mdx +++ b/api/methods/getLedgerEntries.mdx @@ -24,25 +24,24 @@ pip install --upgrade stellar-sdk ::: ```python -from stellar_sdk import xdr -from stellar_sdk.strkey import StrKey -from stellar_sdk.soroban import Symbol +from stellar_sdk import xdr, scval, Address def get_ledger_key_symbol(contract_id: str, symbol_text: str) -> str: - ledger_key = xdr.LedgerKey( - type=xdr.LedgerEntryType.CONTRACT_DATA, - contract_data=xdr.LedgerKeyContractData( - contract_id=xdr.hash.Hash(StrKey.decode_contract(contract_id)), - key=Symbol(symbol_text).to_xdr_sc_val(), - ), - ) - return ledger_key.to_xdr() + ledger_key = xdr.LedgerKey( + type=xdr.LedgerEntryType.CONTRACT_DATA, + contract_data=xdr.LedgerKeyContractData( + contract=Address(contract_id).to_xdr_sc_address(), + key=scval.to_symbol(symbol_text), + durability=xdr.ContractDataDurability.PERSISTENT + ), + ) + return ledger_key.to_xdr() print( - get_ledger_key_symbol( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", - "COUNTER" - ) + get_ledger_key_symbol( + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI", + "COUNTER" + ) ) ``` @@ -55,13 +54,14 @@ yarn add @stellar/stellar-sdk ``` ```js -import { xdr, StrKey } from "@stellar/stellar-sdk"; +import { xdr, Address } from "@stellar/stellar-sdk"; const getLedgerKeySymbol = (contractId, symbolText) => { const ledgerKey = xdr.LedgerKey.contractData( new xdr.LedgerKeyContractData({ - contractId: StrKey.decodeContract(contractId), + contract: new Address(contractId).toScAddress(), key: xdr.ScVal.scvSymbol(symbolText), + durability: xdr.ContractDataDurability.persistent() }), ); return ledgerKey.toXDR("base64"); @@ -69,7 +69,7 @@ const getLedgerKeySymbol = (contractId, symbolText) => { console.log( getLedgerKeySymbol( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI", "COUNTER", ), ); @@ -86,13 +86,12 @@ This functionality is included in the JavaScript [`stellar-sdk`](https://www.npm Accounts are stored as ledger entries, so we can use this method to look up an account along with it's current sequence number. ```js -import { xdr, Keypair, StrKey } from '@stellar/stellar-sdk' +import { xdr, Keypair } from '@stellar/stellar-sdk' const getLedgerKeyAccount = (address) => { - const publicKey = StrKey.decodeEd25519PublicKey(address) const ledgerKey = xdr.LedgerKey.account( new xdr.LedgerKeyAccount({ - accountId: Keypair.fromPublicKey(publicKey).xdrPublicKey(), + accountId: Keypair.fromPublicKey(address).xdrPublicKey(), }) ) return ledgerKey.toXDR('base64') @@ -128,11 +127,11 @@ And the response we get contains the `LedgerEntryData` with the current informat "entries": [ { "key": "AAAAAAAAAACp3BPIqFxM9XSnW6aHvavD3GWlJGfuylOt5tZL6CQtdQ==", - "xdr": "AAAAAAAAAACp3BPIqFxM9XSnW6aHvavD3GWlJGfuylOt5tZL6CQtdQAAABdIdugAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA", + "xdr": "AAAAAAAAAACp3BPIqFxM9XSnW6aHvavD3GWlJGfuylOt5tZL6CQtdQAAABdIdugAAAWpygAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA", "lastModifiedLedgerSeq": "164303" } ], - "latestLedger": "246819" + "latestLedger": 246819 } } ``` @@ -141,7 +140,7 @@ We can then parse this result as an `xdr.LedgerEntryData` type. ```js const parsed = xdr.LedgerEntryData.fromXDR( - "AAAAAAAAAACp3BPIqFxM9XSnW6aHvavD3GWlJGfuylOt5tZL6CQtdQAAABdIdugAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA", + "AAAAAAAAAACp3BPIqFxM9XSnW6aHvavD3GWlJGfuylOt5tZL6CQtdQAAABdIdugAAAWpygAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA", "base64", ); console.log(parsed); @@ -165,45 +164,43 @@ When you deploy a contract, first the code is "installed" (i.e. it is uploaded o ##### Python ```python -from stellar_sdk import xdr -from stellar_sdk.strkey import StrKey +from stellar_sdk import xdr, Address def get_ledger_key_contract_code(contract_id: str) -> str: - ledger_key = xdr.LedgerKey( - type=xdr.LedgerEntryType.CONTRACT_DATA, - contract_data=xdr.LedgerKeyContractData( - contract_id=xdr.Hash(StrKey.decodeContract(contract_id)), - key=xdr.SCVal( - type=xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_EXECUTABLE, - ), - ), - ) - return ledger_key.to_xdr() + ledger_key = xdr.LedgerKey( + type=xdr.LedgerEntryType.CONTRACT_DATA, + contract_data=xdr.LedgerKeyContractData( + contract=Address(contract_id).to_xdr_sc_address(), + key=xdr.SCVal(xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), + durability=xdr.ContractDataDurability.PERSISTENT + ) + ) + return ledger_key.to_xdr() print( - get_ledger_key_contract_code( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE" - ) + get_ledger_key_contract_code( + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI" + ) ) -# OUTPUT: AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA== +# OUTPUT: AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB ``` ##### JavaScript ```javascript -import { Address, xdr } from "@stellar/stellar-sdk"; +import { Contract } from "@stellar/stellar-sdk"; function getLedgerKeyContractCode(contractId) { - const instance = new ContractId(contractId).getFootprint(); + const instance = new Contract(contractId).getFootprint(); return instance.toXDR("base64"); } console.log( getLedgerKeyContractCode( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI", ), ); -// OUTPUT: AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA== +// OUTPUT: AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB ``` We then take our output from this function, and use it as the element in the `keys` array parameter in our call to the `getLedgerEntries` method. @@ -214,7 +211,7 @@ We then take our output from this function, and use it as the element in the `ke "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA=="] + "keys": ["AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB"] } } ``` @@ -228,12 +225,12 @@ And the response we get contains the `LedgerEntryData` that can be used to find "result": { "entries": [ { - "key": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA==", - "xdr": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=", + "key": "AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB", + "xdr": "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA", "lastModifiedLedgerSeq": "261603" } ], - "latestLedger": "262322" + "latestLedger": 262322 } } ``` @@ -251,28 +248,28 @@ def get_ledger_key_wasm_id(contract_code_ledger_entry_data: str) -> str: # First, we dig the wasm_id hash out of the xdr we received from RPC contract_code_wasm_hash = xdr.LedgerEntryData.from_xdr( contract_code_ledger_entry_data - ).contract_data.val.exec.wasm_id.hash + ).contract_data.val.instance.executable.wasm_hash # Now, we can create the `LedgerKey` as we've done in previous examples ledger_key = xdr.LedgerKey( type=xdr.LedgerEntryType.CONTRACT_CODE, contract_code=xdr.LedgerKeyContractCode( - hash=xdr.hash.Hash(contract_code_wasm_hash) + hash=contract_code_wasm_hash ), ) return ledger_key.to_xdr() print( get_ledger_key_wasm_id( - "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=" + "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA" ) ) -# OUTPUT: AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC +# OUTPUT: AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6 ``` ##### JavaScript ```javascript -const { xdr } = require("@stellar/stellar-sdk"); +import { xdr } from '@stellar/stellar-sdk' function getLedgerKeyWasmId(contractCodeLedgerEntryData) { const entry = xdr.LedgerEntryData.fromXDR( @@ -280,11 +277,11 @@ function getLedgerKeyWasmId(contractCodeLedgerEntryData) { "base64", ); - const instance = entry.contractData().val().instance(); + const wasmHash = entry.contractData().val().instance().executable().wasmHash(); let ledgerKey = xdr.LedgerKey.contractCode( new xdr.LedgerKeyContractCode({ - hash: instance.wasmHash(), + hash: wasmHash, }), ); @@ -293,10 +290,10 @@ function getLedgerKeyWasmId(contractCodeLedgerEntryData) { console.log( getLedgerKeyWasmId( - "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=", + "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA", ), ); -// OUTPUT: AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC +// OUTPUT: AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6 ``` Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that has been deployed under the `ContractId` we started out with so very long ago. This `LedgerKey` can be used in a final request to the Soroban-RPC endpoint. @@ -307,7 +304,7 @@ Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that ha "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC"] + "keys": ["AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6"] } } ``` @@ -321,13 +318,13 @@ And the response we get contains (even more) `LedgerEntryData` that we can decod "result": { "entries": [ { - "key": "AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC", - "xdr": "AAAABwAAAABkFigQlPcho8wyTcWhGacRAegPF7A9kv5Siv7FYji4ggAAAlQAYXNtAQAAAAEPA2ACfn4BfmABfgF+YAAAAgcBAXYBRwAAAwQDAQICBQMBABEGGQN/AUGAgMAAC38AQYWAwAALfwBBkIDAAAsHMQUGbWVtb3J5AgAFaGVsbG8AAQFfAAMKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwIK4QID1gIDAn8CfgF/I4CAgIAAQSBrIgEkgICAgAACQAJAIACnQf8BcSICQQ5GDQAgAkHKAEcNAQtCACEDQXshAgNAAkACQAJAAkAgAkUNAEIBIQQgAkGFgMCAAGotAAAiBUHfAEYNAyAFrSEEIAVBUGpBCkkNAiAFQb9/akEaSQ0BAkAgBUGff2pBGk8NACAEQkV8IQQMBAsQgoCAgAAACyABIAA3AwggASADQgiGQg6ENwMAQQAhAgNAAkAgAkEQRw0AQQAhAgJAA0AgAkEQRg0BIAFBEGogAmogASACaikDADcDACACQQhqIQIMAAsLIAFBEGqtQiCGQgSEQoSAgIAgEICAgIAAIQQgAUEgaiSAgICAACAEDwsgAUEQaiACakICNwMAIAJBCGohAgwACwsgBEJLfCEEDAELIARCUnwhBAsgAkEBaiECIAQgA0IGhoQhAwwACwsAAAsEAAAACwIACwsOAQBBgIDAAAsFSGVsbG8AHhFjb250cmFjdGVudm1ldGF2MAAAAAAAAAAUAAAAJQBDDmNvbnRyYWN0c3BlY3YwAAAAAAAAAAAAAAAFaGVsbG8AAAAAAAABAAAAAAAAAAJ0bwAAAAAAEQAAAAEAAAPqAAAAEQ==", - "lastModifiedLedgerSeq": "75206", - "liveUntilLedgerSeq": "320384" + "key": "AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6", + "xdr": "AAAABwAAAADkM21tyQ4ZVGw1Vvwvtf+UiEA7LajkboaQspe9ztbx+gAAAkgAYXNtAQAAAAEVBGACfn4BfmADfn5+AX5gAAF+YAAAAhkEAWwBMAAAAWwBMQAAAWwBXwABAWwBOAAAAwUEAgMDAwUDAQAQBhkDfwFBgIDAAAt/AEGAgMAAC38AQYCAwAALBzUFBm1lbW9yeQIACWluY3JlbWVudAAEAV8ABwpfX2RhdGFfZW5kAwELX19oZWFwX2Jhc2UDAgqnAQSSAQIBfwF+QQAhAAJAAkACQEKOutCvhtQ5QgEQgICAgABCAVINAEKOutCvhtQ5QgEQgYCAgAAiAUL/AYNCBFINASABQiCIpyEACyAAQQFqIgBFDQFCjrrQr4bUOSAArUIghkIEhCIBQgEQgoCAgAAaQoSAgICgBkKEgICAwAwQg4CAgAAaIAEPCwAACxCFgICAAAALCQAQhoCAgAAACwQAAAALAgALAHMOY29udHJhY3RzcGVjdjAAAAAAAAAAQEluY3JlbWVudCBpbmNyZW1lbnRzIGFuIGludGVybmFsIGNvdW50ZXIsIGFuZCByZXR1cm5zIHRoZSB2YWx1ZS4AAAAJaW5jcmVtZW50AAAAAAAAAAAAAAEAAAAEAB4RY29udHJhY3RlbnZtZXRhdjAAAAAAAAAAFAAAAAAAbw5jb250cmFjdG1ldGF2MAAAAAAAAAAFcnN2ZXIAAAAAAAAGMS43Ni4wAAAAAAAAAAAACHJzc2RrdmVyAAAALzIwLjMuMSNiYTA0NWE1N2FmOTcxZmM4M2U0NzU3NDZiNTlhNTAzYjdlZjQxNjQ5AA==", + "lastModifiedLedgerSeq": 368441, + "liveUntilLedgerSeq": 2442040 } ], - "latestLedger": "262384" + "latestLedger": 370940 } } ``` diff --git a/docs/guides/rpc/generate-ledger-keys-python.mdx b/docs/guides/rpc/generate-ledger-keys-python.mdx index 23e0004f..9f2bfb8a 100644 --- a/docs/guides/rpc/generate-ledger-keys-python.mdx +++ b/docs/guides/rpc/generate-ledger-keys-python.mdx @@ -6,23 +6,22 @@ hide_table_of_contents: true In the [`increment` example contract] stores an integer value in a ledger entry that is identified by a key with the symbol `COUNTER`. The value of this ledger key can be derived using the following code snippets. ```python -from stellar_sdk import xdr -from stellar_sdk.strkey import StrKey -from stellar_sdk.soroban import Symbol +from stellar_sdk import xdr, scval, Address def get_ledger_key_symbol(contract_id: str, symbol_text: str) -> str: ledger_key = xdr.LedgerKey( type=xdr.LedgerEntryType.CONTRACT_DATA, contract_data=xdr.LedgerKeyContractData( - contract_id=xdr.hash.Hash(StrKey.decode_contract(contract_id)), - key=Symbol(symbol_text).to_xdr_sc_val(), + contract=Address(contract_id).to_xdr_sc_address(), + key=scval.to_symbol(symbol_text), + durability=xdr.ContractDataDurability.PERSISTENT ), ) return ledger_key.to_xdr() print( get_ledger_key_symbol( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI", "COUNTER" ) ) diff --git a/docs/guides/rpc/retrieve-contract-code-js.mdx b/docs/guides/rpc/retrieve-contract-code-js.mdx index 19a7d911..1b15a44a 100644 --- a/docs/guides/rpc/retrieve-contract-code-js.mdx +++ b/docs/guides/rpc/retrieve-contract-code-js.mdx @@ -8,20 +8,20 @@ When you deploy a contract, first the code is "installed" (i.e., it is uploaded 1. First, we look up the contract itself, to see which code hash it is referencing. 2. Then, we can look up the raw Wasm byte-code using that hash. -```js -import { Address, xdr } from "stellar-sdk"; +```javascript +import { Contract } from "@stellar/stellar-sdk"; function getLedgerKeyContractCode(contractId) { - const [_, instance] = new ContractId(contractId).getFootprint(); + const instance = new Contract(contractId).getFootprint(); return instance.toXDR("base64"); } console.log( getLedgerKeyContractCode( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI", ), ); -// OUTPUT: AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA== +// OUTPUT: AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB ``` We then take our output from this function, and use it as the element in the `keys` array parameter in our call to the `getLedgerEntries` method. @@ -32,7 +32,7 @@ We then take our output from this function, and use it as the element in the `ke "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA=="] + "keys": ["AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB"] } } ``` @@ -46,8 +46,8 @@ And the response we get contains the `LedgerEntryData` that can be used to find "result": { "entries": [ { - "key": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA==", - "xdr": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=", + "key": "AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB", + "xdr": "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA", "lastModifiedLedgerSeq": 261603 } ], @@ -58,8 +58,8 @@ And the response we get contains the `LedgerEntryData` that can be used to find Now take the `xdr` field from the previous response's `result` object, and create a `LedgerKey` from the hash contained inside. -```js -const { xdr } = require("soroban-client"); +```javascript +import { xdr } from '@stellar/stellar-sdk' function getLedgerKeyWasmId(contractCodeLedgerEntryData) { const entry = xdr.LedgerEntryData.fromXDR( @@ -67,11 +67,11 @@ function getLedgerKeyWasmId(contractCodeLedgerEntryData) { "base64", ); - const instance = entry.contractData().val().instance(); + const wasmHash = entry.contractData().val().instance().executable().wasmHash(); let ledgerKey = xdr.LedgerKey.contractCode( new xdr.LedgerKeyContractCode({ - hash: instance.wasmHash(), + hash: wasmHash, }), ); @@ -80,10 +80,10 @@ function getLedgerKeyWasmId(contractCodeLedgerEntryData) { console.log( getLedgerKeyWasmId( - "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=", + "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA", ), ); -// OUTPUT: AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC +// OUTPUT: AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6 ``` Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that has been deployed under the `ContractId` we started out with so very long ago. This `LedgerKey` can be used in a final request to the Soroban-RPC endpoint. @@ -94,7 +94,7 @@ Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that ha "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC"] + "keys": ["AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6"] } } ``` @@ -108,13 +108,13 @@ And the response we get contains (even more) `LedgerEntryData` that we can decod "result": { "entries": [ { - "key": "AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC", - "xdr": "AAAABwAAAABkFigQlPcho8wyTcWhGacRAegPF7A9kv5Siv7FYji4ggAAAlQAYXNtAQAAAAEPA2ACfn4BfmABfgF+YAAAAgcBAXYBRwAAAwQDAQICBQMBABEGGQN/AUGAgMAAC38AQYWAwAALfwBBkIDAAAsHMQUGbWVtb3J5AgAFaGVsbG8AAQFfAAMKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwIK4QID1gIDAn8CfgF/I4CAgIAAQSBrIgEkgICAgAACQAJAIACnQf8BcSICQQ5GDQAgAkHKAEcNAQtCACEDQXshAgNAAkACQAJAAkAgAkUNAEIBIQQgAkGFgMCAAGotAAAiBUHfAEYNAyAFrSEEIAVBUGpBCkkNAiAFQb9/akEaSQ0BAkAgBUGff2pBGk8NACAEQkV8IQQMBAsQgoCAgAAACyABIAA3AwggASADQgiGQg6ENwMAQQAhAgNAAkAgAkEQRw0AQQAhAgJAA0AgAkEQRg0BIAFBEGogAmogASACaikDADcDACACQQhqIQIMAAsLIAFBEGqtQiCGQgSEQoSAgIAgEICAgIAAIQQgAUEgaiSAgICAACAEDwsgAUEQaiACakICNwMAIAJBCGohAgwACwsgBEJLfCEEDAELIARCUnwhBAsgAkEBaiECIAQgA0IG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1N2FmOTcxZmM4M2U0NzU3NDZiNTlhNTAzYjdlZjQxNjQ5AA==", + "lastModifiedLedgerSeq": 368441, + "liveUntilLedgerSeq": 2442040 } ], - "latestLedger": 262384 + "latestLedger": 370940 } } ``` diff --git a/docs/guides/rpc/retrieve-contract-code-python.mdx b/docs/guides/rpc/retrieve-contract-code-python.mdx index 9f8e172b..40eb4b7d 100644 --- a/docs/guides/rpc/retrieve-contract-code-python.mdx +++ b/docs/guides/rpc/retrieve-contract-code-python.mdx @@ -9,27 +9,25 @@ When you deploy a contract, first the code is "installed" (i.e., it is uploaded 2. Then, we can look up the raw Wasm byte-code using that hash. ```python -from stellar_sdk import xdr -from stellar_sdk.strkey import StrKey +from stellar_sdk import xdr, Address def get_ledger_key_contract_code(contract_id: str) -> str: - ledger_key = xdr.LedgerKey( - type=xdr.LedgerEntryType.CONTRACT_DATA, - contract_data=xdr.LedgerKeyContractData( - contract_id=xdr.Hash(StrKey.decodeContract(contract_id)), - key=xdr.SCVal( - type=xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_EXECUTABLE, - ), - ), - ) - return ledger_key.to_xdr() + ledger_key = xdr.LedgerKey( + type=xdr.LedgerEntryType.CONTRACT_DATA, + contract_data=xdr.LedgerKeyContractData( + contract=Address(contract_id).to_xdr_sc_address(), + key=xdr.SCVal(xdr.SCValType.SCV_LEDGER_KEY_CONTRACT_INSTANCE), + durability=xdr.ContractDataDurability.PERSISTENT + ) + ) + return ledger_key.to_xdr() print( - get_ledger_key_contract_code( - "CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE" - ) + get_ledger_key_contract_code( + "CCPYZFKEAXHHS5VVW5J45TOU7S2EODJ7TZNJIA5LKDVL3PESCES6FNCI" + ) ) -# OUTPUT: AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA== +# OUTPUT: AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB ``` We then take our output from this function, and use it as the element in the `keys` array parameter in our call to the `getLedgerEntries` method. @@ -40,7 +38,7 @@ We then take our output from this function, and use it as the element in the `ke "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA=="] + "keys": ["AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB"] } } ``` @@ -54,8 +52,8 @@ And the response we get contains the `LedgerEntryData` that can be used to find "result": { "entries": [ { - "key": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFA==", - "xdr": "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=", + "key": "AAAABgAAAAGfjJVEBc55drW3U87N1Py0Rw0/nlqUA6tQ6r28khEl4gAAABQAAAAB", + "xdr": "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA", "lastModifiedLedgerSeq": 261603 } ], @@ -73,22 +71,22 @@ def get_ledger_key_wasm_id(contract_code_ledger_entry_data: str) -> str: # First, we dig the wasm_id hash out of the xdr we received from RPC contract_code_wasm_hash = xdr.LedgerEntryData.from_xdr( contract_code_ledger_entry_data - ).contract_data.val.exec.wasm_id.hash + ).contract_data.val.instance.executable.wasm_hash # Now, we can create the `LedgerKey` as we've done in previous examples ledger_key = xdr.LedgerKey( type=xdr.LedgerEntryType.CONTRACT_CODE, contract_code=xdr.LedgerKeyContractCode( - hash=xdr.hash.Hash(contract_code_wasm_hash) + hash=contract_code_wasm_hash ), ) return ledger_key.to_xdr() print( get_ledger_key_wasm_id( - "AAAABq+aJSfjs7VXHWOwJGujK30xpTI3Zt98YN/As+O6b98jAAAAFAAAABIAAAAAZBYoEJT3IaPMMk3FoRmnEQHoDxewPZL+Uor+xWI4uII=" + "AAAABgAAAAAAAAABn4yVRAXOeXa1t1POzdT8tEcNP55alAOrUOq9vJIRJeIAAAAUAAAAAQAAABMAAAAA5DNtbckOGVRsNVb8L7X/lIhAOy2o5G6GkLKXvc7W8foAAAAA" ) ) -# OUTPUT: AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC +# OUTPUT: AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6 ``` Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that has been deployed under the `ContractId` we started out with so very long ago. This `LedgerKey` can be used in a final request to the Soroban-RPC endpoint. @@ -99,7 +97,7 @@ Now, finally we have a `LedgerKey` that correspond to the Wasm byte-code that ha "id": 8675309, "method": "getLedgerEntries", "params": { - "keys": ["AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC"] + "keys": ["AAAAB+QzbW3JDhlUbDVW/C+1/5SIQDstqORuhpCyl73O1vH6"] } } ``` @@ -113,13 +111,13 @@ And the response we get contains (even more) `LedgerEntryData` that we can decod "result": { "entries": [ { - "key": "AAAAB2QWKBCU9yGjzDJNxaEZpxEB6A8XsD2S/lKK/sViOLiC", - "xdr": "AAAABwAAAABkFigQlPcho8wyTcWhGacRAegPF7A9kv5Siv7FYji4ggAAAlQAYXNtAQAAAAEPA2ACfn4BfmABfgF+YAAAAgcBAXYBRwAAAwQDAQICBQMBABEGGQN/AUGAgMAAC38AQYWAwAALfwBBkIDAAAsHMQUGbWVtb3J5AgAFaGVsbG8AAQFfAAMKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwIK4QID1gIDAn8CfgF/I4CAgIAAQSBrIgEkgICAgAACQAJAIACnQf8BcSICQQ5GDQAgAkHKAEcNAQtCACEDQXshAgNAAkACQAJAAkAgA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xCFgICAAAALCQAQhoCAgAAACwQAAAALAgALAHMOY29udHJhY3RzcGVjdjAAAAAAAAAAQEluY3JlbWVudCBpbmNyZW1lbnRzIGFuIGludGVybmFsIGNvdW50ZXIsIGFuZCByZXR1cm5zIHRoZSB2YWx1ZS4AAAAJaW5jcmVtZW50AAAAAAAAAAAAAAEAAAAEAB4RY29udHJhY3RlbnZtZXRhdjAAAAAAAAAAFAAAAAAAbw5jb250cmFjdG1ldGF2MAAAAAAAAAAFcnN2ZXIAAAAAAAAGMS43Ni4wAAAAAAAAAAAACHJzc2RrdmVyAAAALzIwLjMuMSNiYTA0NWE1N2FmOTcxZmM4M2U0NzU3NDZiNTlhNTAzYjdlZjQxNjQ5AA==", + "lastModifiedLedgerSeq": 368441, + "liveUntilLedgerSeq": 2442040 } ], - "latestLedger": 262384 + "latestLedger": 370940 } } ```