Skip to content
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 helpful abstractions for common invocation types. #703

Merged
merged 8 commits into from
Nov 2, 2023

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Oct 10, 2023

What

This adds four new aliases for Operation to make common versions of Operation.invokeHostFunction easier to create.

/** Returns an operation that invokes a contract function. */
function invokeContractFunction({
  contract: string,
  function: string,
  args: xdr.ScVal[],
  auth?: xdr.SorobanAuthorizationEntry[],
  source?: string
}): xdr.Operation;

/** Returns an operation that creates a custom WASM contract. */
function createCustomContract({
  address: Address,
  wasmHash: Uint8Array | Buffer
  salt?: Uint8Array | Buffer,
  auth?: xdr.SorobanAuthorizationEntry[],
  source?: string
}): xdr.Operation;

/** Returns an operation that wraps a Stellar asset into a token contract. */
function createStellarAssetContract({
  asset: Asset | string,
  auth?: xdr.SorobanAuthorizationEntry[],
  source?: string
}): xdr.Operation;

/** Returns an operation that uploads WASM for a contract. */
function uploadContractWasm({
  wasm: Uint8Array | Buffer,
  auth?: xdr.SorobanAuthorizationEntry,
  source?: string
}): xdr.Operation;

Why

Closes #700 and #697.

@Shaptic Shaptic added this to the Soroban Pubnet Release milestone Oct 10, 2023
@Shaptic Shaptic self-assigned this Oct 10, 2023
@github-actions
Copy link

github-actions bot commented Oct 12, 2023

Size Change: +30 kB (+1%)

Total Size: 3.19 MB

Filename Size Change
dist/stellar-base.js 2.34 MB +22.4 kB (+1%)
dist/stellar-base.min.js 850 kB +7.59 kB (+1%)

compressed-size-action

@Shaptic Shaptic marked this pull request as ready for review October 12, 2023 18:47
@Shaptic Shaptic linked an issue Oct 24, 2023 that may be closed by this pull request
@Shaptic Shaptic changed the base branch from master to stable October 31, 2023 21:56
@@ -35,3 +46,184 @@ export function invokeHostFunction(opts) {

return new xdr.Operation(opAttributes);
}

/**
* Returns an operation that invokes a contract function.
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than imbuing base with this app knowhow, is it worthwhile for separation to implement these function wrappers in js-stellar-sdk/src/contract_spec.ts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's still better in base because it's just a variation of the XDR rather than something related to the RPC server or Horizon. To be honest, the only reason why ContractSpec is in stellar-sdk is because it was written in TypeScript. So yeah, I do think it belongs more here.

Copy link
Contributor

@kalepail kalepail left a comment

Choose a reason for hiding this comment

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

Have not reviewed the code but assuming these all work these are very helpful functions and will be a tremendous value add for a lot of folks. 👏

@Shaptic Shaptic merged commit f024014 into stable Nov 2, 2023
4 checks passed
@Shaptic Shaptic deleted the better-invocation branch November 2, 2023 15:52
Shaptic added a commit that referenced this pull request Dec 5, 2023
…#710)

* Upgrade XDR to the final, stable testnet version. (#704, #715)

XDR has been upgraded to the latest stable version. This is mostly renames, but
it includes the following relevant breaking changes:
  - `Operation.bumpFootprintExpiration` is now `extendFootprintTtl` and its
  `ledgersToExpire` field is now named `extendTo`, but it serves the same
  purpose. - `xdr.ContractExecutable.contractExecutableToken` is now
  `contractExecutableStellarAsset` - `xdr.SorobanTransactionData.refundableFee`
  is now `resourceFee` - In turn, `SorobanDataBuilder.setRefundableFee` is now
  `setResourceFee` - This new fee encompasses the entirety of the
  Soroban-related resource fees. Note that this is distinct from the
  "network-inclusion" fee that you would set on your transaction (i.e.
  `TransactionBuilder(..., { fee: ... })`). - In TypeScript, the
  `Operation.BumpFootprintExpiration` is now `Operation.ExtendFootprintTtl`

Commit: stellar/stellar-xdr @ bb54e50

* Add helpful abstractions for common invocation types. (#703)
* Drop incorrect key entry for contract footprint (#709)
* Republish package under @stellar/ scope (#714)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Easily create different types of host function invocations add: deploy(wasm) method
3 participants