Radix Scrypto 交易清单多次从账户转账

Radix Scrypto transaction manifest multiple transfer from account

我们如何在一个清单中从一个帐户进行多次代币转移?例如:

账户 A -- 代币 A --> 账户 B

账户 A -- 代币 B --> 账户 B

账户 A -- 代币 A --> 账户 C

账户 A -- 代币 B --> 账户 C

我这样做了:

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge1");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") BucketRef("badge1");

CALL_METHOD_WITH_ALL_RESOURCES Address("02a2a79aa613da237bcda37fd79af36e09eadd195976092cb24696") "deposit_batch";

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge2");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") BucketRef("badge2");

CALL_METHOD_WITH_ALL_RESOURCES Address("02a2a79aa613da237bcda37fd79af36e09eadd195976092cb24696") "deposit_batch";

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge3");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") BucketRef("badge3");
CALL_METHOD_WITH_ALL_RESOURCES Address("0236ca00316c8eb5ad51b0cb5e3f232cb871803a85ec3847b36bb4") "deposit_batch";

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge4");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") BucketRef("badge4");

CALL_METHOD_WITH_ALL_RESOURCES Address("0236ca00316c8eb5ad51b0cb5e3f232cb871803a85ec3847b36bb4") "deposit_batch";

但是我得到这个错误:

Error: CompileError(GeneratorError(IdValidatorError(BucketRefNotFound(Rid(1)))))

当我们调用 CALL_METHOD_WITH_ALL_RESOURCES

时,我们似乎丢失了对帐户的所有引用

您确实是正确的,CALL_METHOD_WITH_ALL_RESOURCES 指令删除了交易中的所有 BucketRef。发生这种情况的具体行是:https://github.com/radixdlt/radixdlt-scrypto/blob/7cb4af0b35b8462f214e839590234602a11281d0/radix-engine/src/engine/process.rs#L367

解决此问题的方法之一是避免在 rtm 文件结束之前使用 CALL_METHOD_WITH_ALL_RESOURCES,而是替换 rtm 中的 CALL_METHOD_WITH_ALL_RESOURCES =] 文件 TAKE_ALL_FROM_WORKTOP 和常规 deposit 方法调用。

因此,作为一个高层次的观点,我们试图为每一次转移做的是: 1- 克隆徽章。 2- 使用克隆徽章提取代币。 3- 从撤回的令牌中创建一个桶。 4- 将我们刚刚创建的桶存入接收者的账户。

我已对您的 rtm 文件进行了上述修改:

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge1");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") BucketRef("badge1");
TAKE_ALL_FROM_WORKTOP Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") Bucket("transfer1_bucket");
CALL_METHOD Address("02a2a79aa613da237bcda37fd79af36e09eadd195976092cb24696") "deposit" Bucket("transfer1_bucket");

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge2");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") BucketRef("badge2");
TAKE_ALL_FROM_WORKTOP Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") Bucket("transfer2_bucket");
CALL_METHOD Address("02a2a79aa613da237bcda37fd79af36e09eadd195976092cb24696") "deposit" Bucket("transfer2_bucket");

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge3");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") BucketRef("badge3");
TAKE_ALL_FROM_WORKTOP Address("03bcc1960b6f99bae8614c3bf276ee3217f800f5cc7bdc48db9a5f") Bucket("transfer3_bucket");
CALL_METHOD Address("0236ca00316c8eb5ad51b0cb5e3f232cb871803a85ec3847b36bb4") "deposit" Bucket("transfer3_bucket");

CLONE_BUCKET_REF BucketRef(1u32) BucketRef("badge4");
CALL_METHOD Address("0293c502780e23621475989d707cd8128e4506362e5fed6ac0c00a") "withdraw" Decimal("2000") Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") BucketRef("badge4");
TAKE_ALL_FROM_WORKTOP Address("031773788de8e4d2947d6592605302d4820ad060ceab06eb2d4711") Bucket("transfer4_bucket");
CALL_METHOD Address("0236ca00316c8eb5ad51b0cb5e3f232cb871803a85ec3847b36bb4") "deposit" Bucket("transfer4_bucket");

编辑:我只想强调这个答案是针对 Scrypto v0.3.0 的。