Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
feat: add any instruction support
Browse files Browse the repository at this point in the history
  • Loading branch information
iamyulong authored and xstelea committed Mar 31, 2023
1 parent 5a855ac commit 3fb536b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
10 changes: 9 additions & 1 deletion lib/__tests__/manifest-values.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ describe('manifest builder', () => {
'resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k',
['#123#']
)
.instruction('SET_METADATA', [
Address(
'component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x'
),
'key',
Enum(0, Enum(0, 'value')),
])
.build()
.toString()
)
Expand All @@ -233,7 +240,8 @@ CALL_FUNCTION Address("package_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq5
CALL_METHOD Address("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "withdraw" Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Decimal("5");
MINT_FUNGIBLE Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Decimal("5");
CALL_METHOD Address("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "withdraw" Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Decimal("5");
CALL_METHOD Address("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "withdraw_non_fungibles" Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Array<NonFungibleLocalId>(NonFungibleLocalId("#123#"));`)
CALL_METHOD Address("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "withdraw_non_fungibles" Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Array<NonFungibleLocalId>(NonFungibleLocalId("#123#"));
SET_METADATA Address("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "key" Enum(0u8, Enum(0u8, "value"));`)
})

// Compile the above output with `rtmc` to ensure the SDK is up to date
Expand Down
22 changes: 17 additions & 5 deletions lib/manifest-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ManifestBuilder {
* @returns
*/
takeFromWorktopByIds(
nonFungibleLocalIds: [NonFungibleLocalIdString],
nonFungibleLocalIds: NonFungibleLocalIdString[],
resourceAddress: AddressString,
bucketName: string
): ManifestBuilder {
Expand Down Expand Up @@ -150,7 +150,7 @@ export class ManifestBuilder {
* @returns
*/
assertWorktopContainsByIds(
nonFungibleLocalIds: [NonFungibleLocalIdString],
nonFungibleLocalIds: NonFungibleLocalIdString[],
resourceAddress: AddressString
): ManifestBuilder {
var temp = nonFungibleLocalIds
Expand Down Expand Up @@ -250,7 +250,7 @@ export class ManifestBuilder {
* @returns
*/
createProofFromAuthZoneByIds(
nonFungibleLocalIds: [NonFungibleLocalIdString],
nonFungibleLocalIds: NonFungibleLocalIdString[],
resourceAddress: AddressString,
proofName: string
): ManifestBuilder {
Expand Down Expand Up @@ -404,7 +404,7 @@ export class ManifestBuilder {
withdrawNonFungiblesFromAccount(
accountAddress: AddressString,
resourceAddress: AddressString,
nonFungibleLocalIds: [NonFungibleLocalIdString]
nonFungibleLocalIds: NonFungibleLocalIdString[]
): ManifestBuilder {
var temp = nonFungibleLocalIds
.map(function (id) {
Expand Down Expand Up @@ -474,7 +474,7 @@ export class ManifestBuilder {
createProofFromAccountByIds(
accountAddress: AddressString,
resourceAddress: AddressString,
nonFungibleLocalIds: [NonFungibleLocalIdString]
nonFungibleLocalIds: NonFungibleLocalIdString[]
): ManifestBuilder {
var temp = nonFungibleLocalIds
.map(function (id) {
Expand All @@ -489,6 +489,18 @@ export class ManifestBuilder {
return this
}

/**
* Add any instruction.
*
* @param name The instruction name
* @param args The instruction arguments
* @returns
*/
instruction(name: string, args: string[]): ManifestBuilder {
this.instructions.push(`${name} ${args.join(' ')};`)
return this
}

/**
* Builds a transaction manifest.
*
Expand Down
14 changes: 10 additions & 4 deletions lib/manifest-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ export const String = <T extends string>(str: T): `"${T}"` => {
return `"${str}"`
}

export const Enum = (field: string, ...args: string[]): string => {
return args.length > 0
? `Enum("${field}",${args.join(',')})`
: `Enum("${field}")`
export const Enum = (field: string | number, ...args: string[]): string => {
if (typeof field === 'number') {
return args.length > 0
? `Enum(${field}u8,${args.join(',')})`
: `Enum(${field}u8)`
} else {
return args.length > 0
? `Enum("${field}",${args.join(',')})`
: `Enum("${field}")`
}
}

export const Tuple = <T extends string[]>(...args: T): `Tuple(${string})` => {
Expand Down

0 comments on commit 3fb536b

Please sign in to comment.