turing-wallet-provider 1.4.17 → 1.5.1
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 +67 -7
- package/dist/types/providerTypes.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -320,6 +320,8 @@ interface RequestParam {
|
|
|
320
320
|
lockTime?: number | string; // 锁仓至指定区块高度(POOLNFT 相关),或冻结至指定 unix 时间戳(STABLECOIN_FREEZE),大数请使用 string
|
|
321
321
|
broadcastEnabled?: boolean;
|
|
322
322
|
mint_message?: string; // 铸造/增发跨链信息(STABLECOIN_CREATE / STABLECOIN_MINT 使用)
|
|
323
|
+
utxo_txid?: string; // 目标 UTXO 的交易 ID(STABLECOIN_FREEZE / STABLECOIN_UNFREEZE 使用)
|
|
324
|
+
utxo_index?: number; // 目标 UTXO 的输出索引(STABLECOIN_FREEZE / STABLECOIN_UNFREEZE 使用)
|
|
323
325
|
}
|
|
324
326
|
|
|
325
327
|
const params = [param: RequestParam];
|
|
@@ -750,6 +752,8 @@ const params = [
|
|
|
750
752
|
flag: "STABLECOIN_FREEZE", // 必填
|
|
751
753
|
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
752
754
|
address: "", // 必填,被冻结的目标地址
|
|
755
|
+
utxo_txid: "", // 必填,目标稳定币 UTXO 的交易 ID
|
|
756
|
+
utxo_index: 0, // 必填,目标稳定币 UTXO 的输出索引
|
|
753
757
|
lockTime: 1774410989, // 必填,冻结至指定 unix 时间戳
|
|
754
758
|
broadcastEnabled: true, // 可选,默认 true
|
|
755
759
|
domain: "", // 可选
|
|
@@ -771,6 +775,8 @@ const params = [
|
|
|
771
775
|
flag: "STABLECOIN_UNFREEZE", // 必填
|
|
772
776
|
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
773
777
|
address: "", // 必填,被解冻的目标地址
|
|
778
|
+
utxo_txid: "", // 必填,目标稳定币 UTXO 的交易 ID
|
|
779
|
+
utxo_index: 0, // 必填,目标稳定币 UTXO 的输出索引
|
|
774
780
|
broadcastEnabled: true, // 可选,默认 true
|
|
775
781
|
domain: "", // 可选
|
|
776
782
|
},
|
|
@@ -921,13 +927,24 @@ const results = await wallet.sendBatchRequest(mixedOperations);
|
|
|
921
927
|
|
|
922
928
|
### 关联请求
|
|
923
929
|
|
|
924
|
-
在某些场景下,`signMessage`
|
|
930
|
+
在某些场景下,`signMessage` 的消息体中需要包含前一个请求生成的交易 txid。由于 txid 在请求前无法确定,因此可以在 `signMessage` 请求上添加 `dependsOn` 字段,让钱包自动完成 txid 的提取和注入。
|
|
925
931
|
|
|
926
|
-
不添加 `dependsOn`
|
|
932
|
+
不添加 `dependsOn` 时,两个请求仍然作为独立请求各自执行,互不影响。
|
|
933
|
+
|
|
934
|
+
#### 支持的第一个方法
|
|
935
|
+
|
|
936
|
+
| 方法 | txid 提取方式 |
|
|
937
|
+
| --- | --- |
|
|
938
|
+
| `signAssociatedTransaction` | 从返回的 `txraws: string[]` 中计算每个 txraw 的 txid |
|
|
939
|
+
| `sendTransaction` | `broadcastEnabled: true` 时从返回的 `txid` 按逗号拆分;`broadcastEnabled: false` 时从返回的 `txraw` 按逗号拆分后计算 txid |
|
|
940
|
+
|
|
941
|
+
无论哪种方法,最终注入到 `signMessage` 的 `message` JSON 中的都是一个 **txid 字符串数组**。
|
|
927
942
|
|
|
928
943
|
#### 用法
|
|
929
944
|
|
|
930
|
-
批量请求固定为两个请求:第一个是 `signAssociatedTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
|
|
945
|
+
批量请求固定为两个请求:第一个是 `signAssociatedTransaction` 或 `sendTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
|
|
946
|
+
|
|
947
|
+
#### 示例一:signAssociatedTransaction + signMessage
|
|
931
948
|
|
|
932
949
|
```ts
|
|
933
950
|
const requests = [
|
|
@@ -987,18 +1004,61 @@ const results = await wallet.sendBatchRequest(requests);
|
|
|
987
1004
|
// { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }
|
|
988
1005
|
```
|
|
989
1006
|
|
|
1007
|
+
#### 示例二:sendTransaction + signMessage
|
|
1008
|
+
|
|
1009
|
+
```ts
|
|
1010
|
+
const requests = [
|
|
1011
|
+
{
|
|
1012
|
+
method: "sendTransaction",
|
|
1013
|
+
params: {
|
|
1014
|
+
flag: "STABLECOIN_CREATE",
|
|
1015
|
+
ft_data: JSON.stringify({
|
|
1016
|
+
name: "USD Test",
|
|
1017
|
+
symbol: "USDT",
|
|
1018
|
+
decimal: 6,
|
|
1019
|
+
amount: 100000000,
|
|
1020
|
+
}),
|
|
1021
|
+
address: "",
|
|
1022
|
+
mint_message: "SourceChain: BSC, TXID: 34434...",
|
|
1023
|
+
broadcastEnabled: true,
|
|
1024
|
+
domain: "",
|
|
1025
|
+
},
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
method: "signMessage",
|
|
1029
|
+
params: {
|
|
1030
|
+
message: JSON.stringify({
|
|
1031
|
+
action: "create_stablecoin",
|
|
1032
|
+
}),
|
|
1033
|
+
encoding: "utf8",
|
|
1034
|
+
},
|
|
1035
|
+
dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
|
|
1036
|
+
},
|
|
1037
|
+
];
|
|
1038
|
+
|
|
1039
|
+
const results = await wallet.sendBatchRequest(requests);
|
|
1040
|
+
|
|
1041
|
+
// results[0] => sendTransaction 的结果: { txid: "txid1,txid2" }
|
|
1042
|
+
// results[1] => signMessage 的结果: { address, pubkey, sig, message }
|
|
1043
|
+
// 其中 message 为包含 txids 的完整 JSON,例如:
|
|
1044
|
+
// { "action": "create_stablecoin", "txids": ["txid1", "txid2"] }
|
|
1045
|
+
```
|
|
1046
|
+
|
|
990
1047
|
#### 执行流程
|
|
991
1048
|
|
|
992
|
-
1.
|
|
993
|
-
2.
|
|
1049
|
+
1. 执行第一个请求(`signAssociatedTransaction` 或 `sendTransaction`)
|
|
1050
|
+
2. 从结果中提取 txid 数组:
|
|
1051
|
+
- `signAssociatedTransaction`:从 `txraws` 计算每个 txraw 的 txid
|
|
1052
|
+
- `sendTransaction`(`broadcastEnabled: true`):将 `txid` 按逗号拆分
|
|
1053
|
+
- `sendTransaction`(`broadcastEnabled: false`):将 `txraw` 按逗号拆分后计算 txid
|
|
994
1054
|
3. 解析 `signMessage` 的 `message` JSON,将 txid 数组注入到 `dependsOn` 指定的字段
|
|
995
1055
|
4. 使用注入后的完整消息执行 `signMessage`
|
|
996
1056
|
|
|
997
1057
|
#### 约束
|
|
998
1058
|
|
|
999
|
-
- 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction`,第二个为 `signMessage`
|
|
1059
|
+
- 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction` 或 `sendTransaction`,第二个为 `signMessage`
|
|
1000
1060
|
- `dependsOn` 的值为字符串,表示注入到 message JSON 中的字段名
|
|
1001
|
-
-
|
|
1061
|
+
- 如果第一个请求执行失败,`signMessage` 也会失败
|
|
1002
1062
|
- `signMessage` 的 `message` 参数必须是合法的 JSON 字符串
|
|
1003
1063
|
|
|
1004
1064
|
## evm.sendTransaction
|