From 0f6198f1b11f11fb0e74db8114a0ac173c3eba65 Mon Sep 17 00:00:00 2001 From: Yulong Wu Date: Tue, 28 Mar 2023 10:09:47 +0100 Subject: [PATCH] feat: update examples --- examples/index.ts | 40 ++++++++++++--------------------------- lib/manifest-builder.ts | 42 +++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/examples/index.ts b/examples/index.ts index cb2afcf..2fa5321 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -9,42 +9,26 @@ const sdk = WalletSdk({ logLevel: 'DEBUG', }) -const transactionManifest = `# Withdraw XRD from account -CALL_METHOD ComponentAddress("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "withdraw_by_amount" Decimal("5.0") ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag"); +const transactionManifest = ` +# Withdraw XRD from account +CALL_METHOD Address("account_sim1qjy5fakwygc45fkyhyxxulsf5zfae0ycez0x05et9hqs7d0gtn") "withdraw" Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Decimal("5.0"); # Buy GUM with XRD -TAKE_FROM_WORKTOP_BY_AMOUNT Decimal("2.0") ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag") Bucket("xrd"); -CALL_METHOD ComponentAddress("component_sim1q2f9vmyrmeladvz0ejfttcztqv3genlsgpu9vue83mcs835hum") "buy_gumball" Bucket("xrd"); -ASSERT_WORKTOP_CONTAINS_BY_AMOUNT Decimal("3.0") ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag"); -ASSERT_WORKTOP_CONTAINS ResourceAddress("resource_sim1qzhdk7tq68u8msj38r6v6yqa5myc64ejx3ud20zlh9gseqtux6"); +TAKE_FROM_WORKTOP_BY_AMOUNT Decimal("2.0") Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Bucket("xrd"); +CALL_METHOD Address("component_sim1qd8djmepmq7hxqaakt9rl3hkce532px42s8eh4qmqlks9f87dn") "buy_gumball" Bucket("xrd"); +ASSERT_WORKTOP_CONTAINS_BY_AMOUNT Decimal("3.0") Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k"); +ASSERT_WORKTOP_CONTAINS Address("resource_sim1q2ym536cwvvf3cy9p777t4qjczqwf79hagp3wn93srvsgvqtwe"); # Create a proof from bucket, clone it and drop both -TAKE_FROM_WORKTOP ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag") Bucket("some_xrd"); -CREATE_PROOF_FROM_BUCKET Bucket("some_xrd") Proof("proof1"); -CLONE_PROOF Proof("proof1") Proof("proof2"); -DROP_PROOF Proof("proof1"); -DROP_PROOF Proof("proof2"); - -# Create a proof from account and drop it -CALL_METHOD ComponentAddress("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "create_proof_by_amount" Decimal("5.0") ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag"); -POP_FROM_AUTH_ZONE Proof("proof3"); -DROP_PROOF Proof("proof3"); +TAKE_FROM_WORKTOP Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Bucket("some_xrd"); # Return a bucket to worktop RETURN_TO_WORKTOP Bucket("some_xrd"); -TAKE_FROM_WORKTOP_BY_IDS Set(NonFungibleId("0905000000"), NonFungibleId("0907000000")) ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag") Bucket("nfts"); - -# Create a new fungible resource -CREATE_RESOURCE Enum("Fungible", 0u8) Map() Map() Some(Enum("Fungible", Decimal("1.0"))); - -# Cancel all buckets and move resources to account -CALL_METHOD ComponentAddress("component_sim1q0kryz5scup945usk39qjc2yjh6l5zsyuh8t7v5pk0tshjs68x") "deposit_batch" Expression("ENTIRE_WORKTOP"); - -# Drop all proofs -DROP_ALL_PROOFS; +TAKE_FROM_WORKTOP_BY_IDS Array(NonFungibleLocalId("#1#")) Address("resource_sim1qyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs6d89k") Bucket("nfts"); -# Complicated method that takes all of the number types -CALL_METHOD ComponentAddress("component_sim1q2f9vmyrmeladvz0ejfttcztqv3genlsgpu9vue83mcs835hum") "complicated_method" Decimal("1") PreciseDecimal("2");` +# Move all resources in worktop to account +CALL_METHOD Address("account_sim1qjy5fakwygc45fkyhyxxulsf5zfae0ycez0x05et9hqs7d0gtn") "deposit_batch" Expression("ENTIRE_WORKTOP"); +` const displayResults = (result: Result) => { document.getElementById('results')!.innerHTML = `
${JSON.stringify(
diff --git a/lib/manifest-builder.ts b/lib/manifest-builder.ts
index d3c92d6..6495cba 100644
--- a/lib/manifest-builder.ts
+++ b/lib/manifest-builder.ts
@@ -71,20 +71,20 @@ export class ManifestBuilder {
   /**
    * Take some non-fungibles from worktop.
    *
-   * @param nonFungibleIds The non-fungible IDs
+   * @param nonFungibleLocalIds The non-fungible IDs
    * @param address The resource address
    * @param bucketName The name of the new bucket
    * @returns
    */
   takeFromWorktopByIds(
-    nonFungibleIds: string,
+    nonFungibleLocalIds: string,
     address: AddressString,
     bucketName: string
   ): ManifestBuilder {
     this.instructions.push(
-      `TAKE_FROM_WORKTOP_BY_IDS ${nonFungibleIds} ${Address(address)} ${Bucket(
-        bucketName
-      )};`
+      `TAKE_FROM_WORKTOP_BY_IDS ${nonFungibleLocalIds} ${Address(
+        address
+      )} ${Bucket(bucketName)};`
     )
     this.buckets.set(bucketName, this.id_allocator++)
     return this
@@ -134,16 +134,18 @@ export class ManifestBuilder {
   /**
    * Asserts worktop contains some non-fungibles.
    *
-   * @param nonFungibleIds The non-fungible IDs
+   * @param nonFungibleLocalIds The non-fungible IDs
    * @param address The resource address
    * @returns
    */
   assertWorktopContainsByIds(
-    nonFungibleIds: string,
+    nonFungibleLocalIds: string,
     address: AddressString
   ): ManifestBuilder {
     this.instructions.push(
-      `ASSERT_WORKTOP_CONTAINS_BY_IDS ${nonFungibleIds} ${Address(address)};`
+      `ASSERT_WORKTOP_CONTAINS_BY_IDS ${nonFungibleLocalIds} ${Address(
+        address
+      )};`
     )
     return this
   }
@@ -224,18 +226,18 @@ export class ManifestBuilder {
   /**
    * Creates a composite proof from the auth zone for the give non-fungibles.
    *
-   * @param nonFungibleIds The non-fungible IDs
+   * @param nonFungibleLocalIds The non-fungible IDs
    * @param address The resource address
    * @param proofName The name of the new proof
    * @returns
    */
   createProofFromAuthZoneByIds(
-    nonFungibleIds: string,
+    nonFungibleLocalIds: string,
     address: AddressString,
     proofName: string
   ): ManifestBuilder {
     this.instructions.push(
-      `CREATE_PROOF_FROM_AUTH_ZONE_BY_IDS ${nonFungibleIds} ${Address(
+      `CREATE_PROOF_FROM_AUTH_ZONE_BY_IDS ${nonFungibleLocalIds} ${Address(
         address
       )} ${Proof(proofName)};`
     )
@@ -290,20 +292,20 @@ export class ManifestBuilder {
   /**
    * Calls a function on a blueprint.
    *
-   * @param packageAddress  The package address
+   * @param address  The package address
    * @param blueprintName  The blueprint name
    * @param functionName  The function name
    * @param args The arguments, which must be in manifest format, e.g. `1u8`, `"string"`, `Bucket("name")`
    */
   callFunction(
-    packageAddress: AddressString,
+    address: AddressString,
     blueprintName: string,
     functionName: string,
     args: string[]
   ): ManifestBuilder {
     this.instructions.push(
       `CALL_FUNCTION ${Address(
-        packageAddress
+        address
       )} "${blueprintName}" "${functionName}" ${args.join(' ')};`
     )
     return this
@@ -384,19 +386,19 @@ export class ManifestBuilder {
    * Withdraws some non-fungibles from account.
    *
    * @param accountAddress The account component address
-   * @param nonFungibleIds The non-fungible IDs
+   * @param nonFungibleLocalIds The non-fungible IDs
    * @param address The resource address
    * @returns
    */
   withdrawFromAccountByIds(
     accountAddress: AddressString,
-    nonFungibleIds: string,
+    nonFungibleLocalIds: string,
     address: AddressString
   ): ManifestBuilder {
     this.instructions.push(
       `CALL_METHOD ${Address(
         accountAddress
-      )} "withdraw_by_ids" ${nonFungibleIds} ${Address(address)};`
+      )} "withdraw_by_ids" ${nonFungibleLocalIds} ${Address(address)};`
     )
     return this
   }
@@ -445,19 +447,19 @@ export class ManifestBuilder {
    * Creates proof of some non-fungibles from account.
    *
    * @param accountAddress The account component address
-   * @param nonFungibleIds The non-fungible IDs
+   * @param nonFungibleLocalIds The non-fungible IDs
    * @param address The resource address
    * @returns
    */
   createProofFromAccountByIds(
     accountAddress: AddressString,
-    nonFungibleIds: string,
+    nonFungibleLocalIds: string,
     address: AddressString
   ): ManifestBuilder {
     this.instructions.push(
       `CALL_METHOD ${Address(
         accountAddress
-      )} "create_proof_by_ids" ${nonFungibleIds} ${Address(address)};`
+      )} "create_proof_by_ids" ${nonFungibleLocalIds} ${Address(address)};`
     )
     return this
   }