js-stellar-sdk icon indicating copy to clipboard operation
js-stellar-sdk copied to clipboard

Add a `SorobanRpc.Server.getWasm(contractId)` method

Open Shaptic opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. Building ledger entries by hand sucks and you need to understand too much about Soroban internals.

Describe the solution you'd like See title, add a method to the server:

class Server {
  // ...
  getWasm(contractId: string): Promise<Buffer>;
}

which will make the correct underlying getLedgerEntries call for you.

Describe alternatives you've considered Doing it manually:

const contractLedgerKey = new Contract(contractId).getFootprint();
const response = await server.getLedgerEntries(contractLedgerKey);
const wasmHash = response.entries[0].val.contractData().val().contractInstance().executable().wasmHash();
const ledgerKeyWasmHash = xdr.LedgerKey.contractCode(new xdr.LedgerKeyContractCode({ hash: wasmHash }));
const responseWasm = await server.getLedgerEntries(ledgerKeyWasmHash);
return responseWasm.entries[0].val.contractCode().code();

This is gross.

Additional context See stellar-sdk#960, a review comment from @willemneal.

This is documented in the API reference for getLedgerEntries, but it'd still be better to make it built in.

Shaptic avatar May 08 '24 19:05 Shaptic