sui
sui copied to clipboard
[bcs] generics + bcs schema
So far it is a draft and the PR is lacking documentation. Quick summary of changes:
// bcs is now an instance
// address type is built-in based on the configuration
// generics are now supported out of the box for vector and all of the types
import { BCS } from "@mysten/bcs";
const bcs = new BCS({
vectorType: 'vector', // name of the vector type
addressLength: 20, // address of the address type (eg 20 Sui, 32 Aptos)
addressEncoding: 'hex',
genericSeparators: ['<', '>'] // open and close symbols
});
// we can now fork istances
const bcs_v2 = new BCS(bcs);
bcs.registerStructType('Container<T>', {
owner: 'address',
content: 'T'
});
let bytes = bcs.ser('Container<u64>', { owner: '0x.......', content: '1337' }).toString('hex');
// same for de
bcs.de('Container<u64>', bytes, 'hex');
// also vectors
bcs.ser('vector<Container<u64>>', [ { owner: '...', content: '1337 } ] /* .... */).toString('hex');
⚠️ 🦋 Changesets Warning: This PR has changes to public npm packages, but does not contain a changeset. You can create a changeset easily by running pnpm changeset, and following the prompts. If your change does not need a changeset (e.g. a documentation-only change), you can ignore this message. This warning will be removed when a changeset is added to this pull request.
💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3363012943#artifacts
@Jordan-Mysten @666lcz merging this buddy in if tests pass. Addressed your comments, we now use expect everywhere, and merged recent u16, u32, u256.
README and npm update will go in a separate PR to speed up current TS SDK development and reduce amount of conflicts.