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

Commit

Permalink
feat: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
iamyulong authored and xstelea committed Mar 28, 2023
1 parent 98d561c commit 0f6198f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 48 deletions.
40 changes: 12 additions & 28 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(NonFungibleId("0905000000"), NonFungibleId("0907000000")) ResourceAddress("resource_sim1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqu57yag") Bucket("nfts");
# Create a new fungible resource
CREATE_RESOURCE Enum("Fungible", 0u8) Map<String, String>() Map<Enum, Tuple>() 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>(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<any, any>) => {
document.getElementById('results')!.innerHTML = `<pre>${JSON.stringify(
Expand Down
42 changes: 22 additions & 20 deletions lib/manifest-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)};`
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0f6198f

Please sign in to comment.