Skip to content

Commit

Permalink
draft: included a new createAssetId fn in receipt; added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bolajahmad committed Jun 30, 2024
1 parent 78927e4 commit c817109
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/docs/src/guide/types/native-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ To pass an `AssetId` as an input parameter to a Sway program, you can define the
For a Sway program that returns an `AssetId` type, you can convert the returned value to a `string` as shown below:

<<< @/../../docs-snippets/src/guide/types/contract-types.test.ts#asset-id-output

### `CreateAssetId`

To create an `AssetId` from a `contractId` and `subId`. You can create the `assetId` as shown below:

```
const assetId = createAssetId(contractId, subId);
```
12 changes: 12 additions & 0 deletions packages/transactions/src/coders/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@ export const getMintedAssetId = (contractId: string, subId: string): string => {
return sha256(concat([contractIdBytes, subIdBytes]));
};

type AssetIdInput = {
bits: string;
};

export const createAssetId = (contractId: string, subId: string): AssetIdInput => {
const bits = getMintedAssetId(contractId, subId);
const assetId: AssetIdInput = {
bits,
};
return assetId;
};

export class ReceiptMintCoder extends Coder<ReceiptMint, ReceiptMint> {
constructor() {
super('ReceiptMint', 'struct ReceiptMint', 0);
Expand Down

0 comments on commit c817109

Please sign in to comment.