Skip to content

Allow specifying mixed types for vectors in nativeToScVal - #803

Merged
Shaptic merged 3 commits into
protocol-23from
loosen-vec-reqs
Jun 25, 2025
Merged

Shaptic merged 3 commits into
protocol-23from
loosen-vec-reqs

Conversation

@Shaptic

@Shaptic Shaptic commented Jun 18, 2025 •

Copy link
Copy Markdown
Contributor

Previously, you could only specify a single type or use defaults:

nativeToScVal([1, 2, 3], { type: 'i128' }); // Vec<I128>
nativeToScVal([1, "2", 3], { type: 'i128' }); // error
nativeToScVal([1, "2", 3]); // Vec<u32, string, u32>

but now you can specify types for each element in the array

nativeToScVal([1, "2", 3], { type: ['i128', 'string', 'i128'] }); // Vec<I128, String, I128>

This is super helpful because contracts are just Vec<Val> so they can be anything and unnamed enums also require this format.

@Shaptic
Shaptic requested review from a team and jeesunikim June 18, 2025 19:06
@github-actions

github-actions Bot commented Jun 18, 2025 •

Copy link
Copy Markdown

Size Change: +5.61 kB (+0.16%)

Total Size: 3.45 MB

Filename Size Change
dist/stellar-base.js 2.55 MB +3.85 kB (+0.15%)
dist/stellar-base.min.js 902 kB +1.75 kB (+0.19%)

compressed-size-action

Comment thread src/scval.js Resolved
Comment thread test/unit/scval_test.js
});
expect(scv.switch().name).to.equal('scvVec');
expect(scv.value().length).to.equal(4);
['scvI128', 'scvSymbol', 'scvBool', 'scvString'].forEach(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wow, that is very elastic, many ways for the caller to leverage!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right?? should be helpful for downstream

@sreuland sreuland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, I'm light on experience in js base though, so, can take this approval at whatever grade you choose.

@Shaptic

Shaptic commented Jun 25, 2025

Copy link
Copy Markdown
Contributor Author

@sreuland you're my go to on all of these 🙏 so I'll take what I can get :shipit:

@Shaptic
Shaptic merged commit f3eac8a into protocol-23 Jun 25, 2025
@Shaptic
Shaptic deleted the loosen-vec-reqs branch June 25, 2025 00:02
Shaptic added a commit that referenced this pull request Jun 25, 2025
* Add strkey support for liquidity pools and claimable balances (#799)
* Regenerate XDR with latest Protocol 23 version (#800)
* Migrate cryptographic libraries to use modern @noble/curves. (#802)
* Add support for encoding `Address` to/from new `StrKey`s (#801)
* Allow specifying mixed types for vectors in `nativeToScVal` (#803)
* Prepare v14.0.0-rc.1, Protocol 23 for release (#804)
@jeesunikim jeesunikim mentioned this pull request Jul 2, 2025
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants