turing-wallet-provider 1.4.17 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -921,13 +921,24 @@ const results = await wallet.sendBatchRequest(mixedOperations);
|
|
|
921
921
|
|
|
922
922
|
### 关联请求
|
|
923
923
|
|
|
924
|
-
在某些场景下,`signMessage`
|
|
924
|
+
在某些场景下,`signMessage` 的消息体中需要包含前一个请求生成的交易 txid。由于 txid 在请求前无法确定,因此可以在 `signMessage` 请求上添加 `dependsOn` 字段,让钱包自动完成 txid 的提取和注入。
|
|
925
925
|
|
|
926
|
-
不添加 `dependsOn`
|
|
926
|
+
不添加 `dependsOn` 时,两个请求仍然作为独立请求各自执行,互不影响。
|
|
927
|
+
|
|
928
|
+
#### 支持的第一个方法
|
|
929
|
+
|
|
930
|
+
| 方法 | txid 提取方式 |
|
|
931
|
+
| --- | --- |
|
|
932
|
+
| `signAssociatedTransaction` | 从返回的 `txraws: string[]` 中计算每个 txraw 的 txid |
|
|
933
|
+
| `sendTransaction` | `broadcastEnabled: true` 时从返回的 `txid` 按逗号拆分;`broadcastEnabled: false` 时从返回的 `txraw` 按逗号拆分后计算 txid |
|
|
934
|
+
|
|
935
|
+
无论哪种方法,最终注入到 `signMessage` 的 `message` JSON 中的都是一个 **txid 字符串数组**。
|
|
927
936
|
|
|
928
937
|
#### 用法
|
|
929
938
|
|
|
930
|
-
批量请求固定为两个请求:第一个是 `signAssociatedTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
|
|
939
|
+
批量请求固定为两个请求:第一个是 `signAssociatedTransaction` 或 `sendTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
|
|
940
|
+
|
|
941
|
+
#### 示例一:signAssociatedTransaction + signMessage
|
|
931
942
|
|
|
932
943
|
```ts
|
|
933
944
|
const requests = [
|
|
@@ -987,18 +998,61 @@ const results = await wallet.sendBatchRequest(requests);
|
|
|
987
998
|
// { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }
|
|
988
999
|
```
|
|
989
1000
|
|
|
1001
|
+
#### 示例二:sendTransaction + signMessage
|
|
1002
|
+
|
|
1003
|
+
```ts
|
|
1004
|
+
const requests = [
|
|
1005
|
+
{
|
|
1006
|
+
method: "sendTransaction",
|
|
1007
|
+
params: {
|
|
1008
|
+
flag: "STABLECOIN_CREATE",
|
|
1009
|
+
ft_data: JSON.stringify({
|
|
1010
|
+
name: "USD Test",
|
|
1011
|
+
symbol: "USDT",
|
|
1012
|
+
decimal: 6,
|
|
1013
|
+
amount: 100000000,
|
|
1014
|
+
}),
|
|
1015
|
+
address: "",
|
|
1016
|
+
mint_message: "SourceChain: BSC, TXID: 34434...",
|
|
1017
|
+
broadcastEnabled: true,
|
|
1018
|
+
domain: "",
|
|
1019
|
+
},
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
method: "signMessage",
|
|
1023
|
+
params: {
|
|
1024
|
+
message: JSON.stringify({
|
|
1025
|
+
action: "create_stablecoin",
|
|
1026
|
+
}),
|
|
1027
|
+
encoding: "utf8",
|
|
1028
|
+
},
|
|
1029
|
+
dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
|
|
1030
|
+
},
|
|
1031
|
+
];
|
|
1032
|
+
|
|
1033
|
+
const results = await wallet.sendBatchRequest(requests);
|
|
1034
|
+
|
|
1035
|
+
// results[0] => sendTransaction 的结果: { txid: "txid1,txid2" }
|
|
1036
|
+
// results[1] => signMessage 的结果: { address, pubkey, sig, message }
|
|
1037
|
+
// 其中 message 为包含 txids 的完整 JSON,例如:
|
|
1038
|
+
// { "action": "create_stablecoin", "txids": ["txid1", "txid2"] }
|
|
1039
|
+
```
|
|
1040
|
+
|
|
990
1041
|
#### 执行流程
|
|
991
1042
|
|
|
992
|
-
1.
|
|
993
|
-
2.
|
|
1043
|
+
1. 执行第一个请求(`signAssociatedTransaction` 或 `sendTransaction`)
|
|
1044
|
+
2. 从结果中提取 txid 数组:
|
|
1045
|
+
- `signAssociatedTransaction`:从 `txraws` 计算每个 txraw 的 txid
|
|
1046
|
+
- `sendTransaction`(`broadcastEnabled: true`):将 `txid` 按逗号拆分
|
|
1047
|
+
- `sendTransaction`(`broadcastEnabled: false`):将 `txraw` 按逗号拆分后计算 txid
|
|
994
1048
|
3. 解析 `signMessage` 的 `message` JSON,将 txid 数组注入到 `dependsOn` 指定的字段
|
|
995
1049
|
4. 使用注入后的完整消息执行 `signMessage`
|
|
996
1050
|
|
|
997
1051
|
#### 约束
|
|
998
1052
|
|
|
999
|
-
- 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction`,第二个为 `signMessage`
|
|
1053
|
+
- 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction` 或 `sendTransaction`,第二个为 `signMessage`
|
|
1000
1054
|
- `dependsOn` 的值为字符串,表示注入到 message JSON 中的字段名
|
|
1001
|
-
-
|
|
1055
|
+
- 如果第一个请求执行失败,`signMessage` 也会失败
|
|
1002
1056
|
- `signMessage` 的 `message` 参数必须是合法的 JSON 字符串
|
|
1003
1057
|
|
|
1004
1058
|
## evm.sendTransaction
|