@tari-project/tarijs 0.5.2 → 0.5.4
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/docusaurus/tari-docs/docs/signers/wallet-connect.md +0 -4
- package/package.json +1 -1
- package/packages/builders/package.json +1 -1
- package/packages/builders/src/helpers/submitTransaction.ts +34 -11
- package/packages/indexer_provider/package.json +1 -1
- package/packages/metamask_signer/package.json +1 -1
- package/packages/tari_permissions/package.json +1 -1
- package/packages/tari_provider/package.json +1 -1
- package/packages/tari_signer/package.json +1 -1
- package/packages/tari_universe/package.json +1 -1
- package/packages/tari_universe/src/signer.ts +1 -1
- package/packages/tarijs/package.json +3 -3
- package/packages/tarijs/src/index.ts +13 -10
- package/packages/tarijs/src/templates/Coin.ts +58 -0
- package/packages/tarijs/src/templates/Tex.ts +54 -0
- package/packages/tarijs/src/templates/index.ts +2 -0
- package/packages/tarijs/test/integration-tests/.env +1 -0
- package/packages/tarijs/{integration-tests → test/integration-tests}/wallet_daemon/json_rpc_provider.spec.ts +34 -7
- package/packages/tarijs/{src → test/unit-tests}/cbor.spec.ts +3 -3
- package/packages/tarijs/tsconfig.json +1 -3
- package/packages/tarijs/vitest.config.ts +3 -3
- package/packages/tarijs_types/package.json +1 -1
- package/packages/tarijs_types/src/TransactionResult.ts +12 -0
- package/packages/tarijs_types/src/helpers/index.ts +3 -0
- package/packages/tarijs_types/src/helpers/txResult.ts +75 -0
- package/packages/tarijs_types/src/index.ts +17 -1
- package/packages/wallet_daemon/package.json +1 -1
- package/packages/walletconnect/package.json +1 -1
- package/pnpm-workspace.yaml +2 -2
- package/packages/tarijs/integration-tests/.env +0 -1
- /package/packages/{tarijs/src → tarijs_types/src/helpers}/cbor.ts +0 -0
- /package/packages/{tarijs/src/utils.ts → tarijs_types/src/helpers/hexString.ts} +0 -0
- /package/packages/{tarijs → tarijs_types}/src/network.ts +0 -0
|
@@ -16,10 +16,6 @@ npm install @tari-project/wallet-connect-signer
|
|
|
16
16
|
|
|
17
17
|
Establishing connection requires multiple steps.
|
|
18
18
|
|
|
19
|
-
## Obtain WalletConnect Project ID
|
|
20
|
-
|
|
21
|
-
Obtain a WalletConnect Project ID by registering your project on the WalletConnect Cloud. This ID is then used to connect your dApp to the WalletConnect infrastructure, facilitating communication between the dApp and user wallets.
|
|
22
|
-
|
|
23
19
|
## Request a connection and display wallet connect dialog
|
|
24
20
|
|
|
25
21
|
```js
|
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
TransactionStatus,
|
|
7
7
|
DownSubstates,
|
|
8
8
|
UpSubstates,
|
|
9
|
-
FinalizeResultStatus,
|
|
10
|
-
TxResultAccept,
|
|
11
9
|
SubmitTxResult,
|
|
12
10
|
ReqSubstate,
|
|
13
11
|
SubmitTransactionRequest,
|
|
12
|
+
ComponentAddress,
|
|
14
13
|
} from "@tari-project/tarijs-types";
|
|
14
|
+
import { getSubstateValueFromUpSubstates, substateIdToString, txResultCheck } from "@tari-project/tarijs-types";
|
|
15
15
|
|
|
16
16
|
export function buildTransactionRequest(
|
|
17
17
|
transaction: Transaction,
|
|
@@ -46,10 +46,30 @@ export async function submitAndWaitForTransaction(
|
|
|
46
46
|
try {
|
|
47
47
|
const response = await signer.submitTransaction(req);
|
|
48
48
|
const result = await waitForTransactionResult(signer, response.transaction_id);
|
|
49
|
+
const { upSubstates, downSubstates } = getAcceptResultSubstates(result);
|
|
50
|
+
const newComponents = getSubstateValueFromUpSubstates("Component", upSubstates);
|
|
51
|
+
|
|
52
|
+
function getComponentForTemplate(templateAddress: string): ComponentAddress | null {
|
|
53
|
+
for (const [substateId, substate] of upSubstates) {
|
|
54
|
+
if ("Component" in substate.substate) {
|
|
55
|
+
const templateAddr = substate.substate.Component.template_address;
|
|
56
|
+
const templateString =
|
|
57
|
+
typeof templateAddr === "string" ? templateAddr : new TextDecoder().decode(templateAddr);
|
|
58
|
+
if (templateAddress === templateString) {
|
|
59
|
+
return substateIdToString(substateId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
49
65
|
|
|
50
66
|
return {
|
|
51
67
|
response,
|
|
52
68
|
result,
|
|
69
|
+
upSubstates,
|
|
70
|
+
downSubstates,
|
|
71
|
+
newComponents,
|
|
72
|
+
getComponentForTemplate,
|
|
53
73
|
};
|
|
54
74
|
} catch (e) {
|
|
55
75
|
throw new Error(`Transaction failed: ${e}`);
|
|
@@ -81,17 +101,20 @@ export async function waitForTransactionResult(
|
|
|
81
101
|
}
|
|
82
102
|
}
|
|
83
103
|
|
|
84
|
-
export function getAcceptResultSubstates(
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
export function getAcceptResultSubstates(txResult: TransactionResult): {
|
|
105
|
+
upSubstates: UpSubstates;
|
|
106
|
+
downSubstates: DownSubstates;
|
|
107
|
+
} {
|
|
87
108
|
const result = txResult.result?.result;
|
|
88
109
|
|
|
89
|
-
if (result &&
|
|
110
|
+
if (result && txResultCheck.isAcceptFeeRejectRest(result)) {
|
|
111
|
+
return {
|
|
112
|
+
upSubstates: result.AcceptFeeRejectRest[0].up_substates,
|
|
113
|
+
downSubstates: result.AcceptFeeRejectRest[0].down_substates,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (result && txResultCheck.isAccept(result)) {
|
|
90
117
|
return { upSubstates: result.Accept.up_substates, downSubstates: result.Accept.down_substates };
|
|
91
118
|
}
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function isAccept(result: FinalizeResultStatus): result is TxResultAccept {
|
|
96
|
-
return "Accept" in result;
|
|
119
|
+
return { upSubstates: [], downSubstates: [] };
|
|
97
120
|
}
|
|
@@ -75,7 +75,7 @@ export class TariUniverseSigner implements TariSigner {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
public async createFreeTestCoins(): Promise<
|
|
78
|
+
public async createFreeTestCoins(): Promise<AccountData> {
|
|
79
79
|
return this.sendRequest({ methodName: "createFreeTestCoins", args: [] });
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@tari-project/tarijs",
|
|
3
|
-
"version": "0.5.
|
|
2
|
+
"name": "@tari-project/tarijs-all",
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc -b",
|
|
11
|
-
"test": "vitest run
|
|
11
|
+
"test": "vitest run unit-tests",
|
|
12
12
|
"integration-tests": "vitest run integration-tests"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
1
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
2
3
|
import { TariProvider } from "@tari-project/tari-provider";
|
|
3
|
-
import * as utils from "./utils";
|
|
4
|
-
import { Network } from "./network";
|
|
5
4
|
import { MetamaskTariSigner } from "@tari-project/metamask-signer";
|
|
6
|
-
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
7
5
|
import { WalletDaemonTariSigner, WalletDaemonParameters, TariPermissions } from "@tari-project/wallet-daemon-signer";
|
|
8
6
|
import { TariUniverseSigner, TariUniverseSignerParameters } from "@tari-project/tari-universe-signer";
|
|
9
|
-
import * as permissions from "@tari-project/tari-permissions";
|
|
10
7
|
import { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
|
|
11
8
|
import {
|
|
12
9
|
TransactionBuilder,
|
|
@@ -17,9 +14,6 @@ import {
|
|
|
17
14
|
fromWorkspace,
|
|
18
15
|
toWorkspace,
|
|
19
16
|
} from "@tari-project/tarijs-builders";
|
|
20
|
-
import * as templates from "./templates";
|
|
21
|
-
import { parseCbor, getCborValueByPath } from "./cbor";
|
|
22
|
-
import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
|
|
23
17
|
import {
|
|
24
18
|
convertStringToTransactionStatus,
|
|
25
19
|
convertHexStringToU256Array,
|
|
@@ -36,11 +30,20 @@ import {
|
|
|
36
30
|
TemplateDefinition,
|
|
37
31
|
SubstateRequirement,
|
|
38
32
|
Substate,
|
|
33
|
+
Network,
|
|
34
|
+
fromHexString,
|
|
35
|
+
toHexString,
|
|
36
|
+
parseCbor,
|
|
37
|
+
getCborValueByPath,
|
|
39
38
|
} from "@tari-project/tarijs-types";
|
|
39
|
+
import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
|
|
40
|
+
import * as templates from "./templates";
|
|
41
|
+
import * as permissions from "@tari-project/tari-permissions";
|
|
40
42
|
|
|
41
43
|
export * from "@tari-project/tarijs-types";
|
|
42
44
|
export {
|
|
43
|
-
|
|
45
|
+
permissions,
|
|
46
|
+
templates,
|
|
44
47
|
Network,
|
|
45
48
|
TariSigner,
|
|
46
49
|
TariProvider,
|
|
@@ -76,8 +79,8 @@ export {
|
|
|
76
79
|
convertU256ToHexString,
|
|
77
80
|
createNftAddressFromResource,
|
|
78
81
|
createNftAddressFromToken,
|
|
79
|
-
permissions,
|
|
80
|
-
templates,
|
|
81
82
|
parseCbor,
|
|
82
83
|
getCborValueByPath,
|
|
84
|
+
fromHexString,
|
|
85
|
+
toHexString,
|
|
83
86
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Amount, ResourceAddress, TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
|
|
2
|
+
import { TemplateFactory } from "./TemplateFactory";
|
|
3
|
+
|
|
4
|
+
interface NewFunction extends TariFunctionDefinition {
|
|
5
|
+
functionName: "new";
|
|
6
|
+
args?: [number, string];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface MintFunction extends TariFunctionDefinition {
|
|
10
|
+
functionName: "mint";
|
|
11
|
+
args?: [Amount];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface VaultAddressMethod extends TariMethodDefinition {
|
|
15
|
+
functionName: "vault_address";
|
|
16
|
+
args?: [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface TakeFreeCoinsMethod extends TariMethodDefinition {
|
|
20
|
+
methodName: "take_free_coins";
|
|
21
|
+
args?: [number];
|
|
22
|
+
}
|
|
23
|
+
interface BalanceMethod extends TariMethodDefinition {
|
|
24
|
+
methodName: "balance";
|
|
25
|
+
args?: [ResourceAddress];
|
|
26
|
+
}
|
|
27
|
+
interface BurnCoinsMethod extends TariMethodDefinition {
|
|
28
|
+
methodName: "burn_coins";
|
|
29
|
+
args?: [Amount];
|
|
30
|
+
}
|
|
31
|
+
interface TotalSupplyMethod extends TariMethodDefinition {
|
|
32
|
+
methodName: "total_supply";
|
|
33
|
+
args?: [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class CoinTemplate extends TemplateFactory {
|
|
37
|
+
public new: NewFunction;
|
|
38
|
+
public mint: MintFunction;
|
|
39
|
+
public takeFreeCoins: TakeFreeCoinsMethod;
|
|
40
|
+
public balance: BalanceMethod;
|
|
41
|
+
public burnCoins: BurnCoinsMethod;
|
|
42
|
+
public totalSupply: TotalSupplyMethod;
|
|
43
|
+
public vaultAddress: VaultAddressMethod;
|
|
44
|
+
|
|
45
|
+
constructor(public templateAddress: string) {
|
|
46
|
+
super(templateAddress);
|
|
47
|
+
this.new = this._defineFunction<NewFunction>("new");
|
|
48
|
+
this.mint = this._defineFunction<MintFunction>("mint");
|
|
49
|
+
this.takeFreeCoins = this._defineMethod<TakeFreeCoinsMethod>("take_free_coins");
|
|
50
|
+
this.balance = this._defineMethod<BalanceMethod>("balance");
|
|
51
|
+
this.burnCoins = this._defineMethod<BurnCoinsMethod>("burn_coins");
|
|
52
|
+
this.totalSupply = this._defineMethod<TotalSupplyMethod>("total_supply");
|
|
53
|
+
this.vaultAddress = this._defineMethod<VaultAddressMethod>("vault_address");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected _initFunctions(): void {}
|
|
57
|
+
protected _initMethods(): void {}
|
|
58
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ResourceAddress,
|
|
3
|
+
TariFunctionDefinition,
|
|
4
|
+
TariMethodDefinition,
|
|
5
|
+
WorkspaceArg,
|
|
6
|
+
} from "@tari-project/tarijs-builders";
|
|
7
|
+
import { TemplateFactory } from "./TemplateFactory";
|
|
8
|
+
|
|
9
|
+
interface NewFunction extends TariFunctionDefinition {
|
|
10
|
+
functionName: "new";
|
|
11
|
+
args?: [number];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface SwapMethod extends TariMethodDefinition {
|
|
15
|
+
methodName: "swap";
|
|
16
|
+
args?: [WorkspaceArg, ResourceAddress];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface AddLiquidityMethod extends TariMethodDefinition {
|
|
20
|
+
methodName: "add_liquidity";
|
|
21
|
+
args?: WorkspaceArg[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RemoveLiquidityMethod extends TariMethodDefinition {
|
|
25
|
+
methodName: "remove_liquidity";
|
|
26
|
+
args?: WorkspaceArg[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface PoolsMethod extends TariMethodDefinition {
|
|
30
|
+
methodName: "pools";
|
|
31
|
+
args?: WorkspaceArg[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class TexTemplate extends TemplateFactory {
|
|
35
|
+
public new: NewFunction;
|
|
36
|
+
public swap: SwapMethod;
|
|
37
|
+
public addLiquidity: AddLiquidityMethod;
|
|
38
|
+
public removeLiquidity: RemoveLiquidityMethod;
|
|
39
|
+
public pools: PoolsMethod;
|
|
40
|
+
|
|
41
|
+
constructor(public templateAddress: string) {
|
|
42
|
+
super(templateAddress);
|
|
43
|
+
this.new = this._defineFunction<NewFunction>("new");
|
|
44
|
+
this.swap = this._defineMethod<SwapMethod>("swap");
|
|
45
|
+
this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
|
|
46
|
+
this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
|
|
47
|
+
this.pools = this._defineMethod<PoolsMethod>("pools");
|
|
48
|
+
this._initFunctions();
|
|
49
|
+
this._initMethods();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected _initFunctions(): void {}
|
|
53
|
+
protected _initMethods(): void {}
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:9000/json_rpc
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { assert, describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { SubmitTransactionRequest, TariPermissions, WalletDaemonTariSigner } from "
|
|
3
|
+
import { Network, SubmitTransactionRequest, TariPermissions, WalletDaemonTariSigner } from "../../../src";
|
|
4
4
|
|
|
5
5
|
function buildSigner(): Promise<WalletDaemonTariSigner> {
|
|
6
6
|
const permissions = new TariPermissions().addPermission("Admin");
|
|
7
7
|
const serverUrl = process.env.WALLET_DAEMON_JSON_RPC_URL;
|
|
8
|
+
|
|
8
9
|
assert(serverUrl, "WALLET_DAEMON_JSON_RPC_URL must be set");
|
|
9
10
|
return WalletDaemonTariSigner.buildFetchSigner({
|
|
10
11
|
permissions,
|
|
@@ -43,8 +44,14 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
43
44
|
describe("getSubstate", () => {
|
|
44
45
|
it("returns substate details", async () => {
|
|
45
46
|
const signer = await buildSigner();
|
|
46
|
-
const listedSubstates = await signer.listSubstates(
|
|
47
|
+
const listedSubstates = await signer.listSubstates({
|
|
48
|
+
filter_by_template: null,
|
|
49
|
+
filter_by_type: null,
|
|
50
|
+
limit: 1,
|
|
51
|
+
offset: 0,
|
|
52
|
+
});
|
|
47
53
|
const firstSubstate = listedSubstates.substates[0];
|
|
54
|
+
console.log(firstSubstate);
|
|
48
55
|
const substate = await signer.getSubstate(firstSubstate.substate_id);
|
|
49
56
|
|
|
50
57
|
expect(substate).toMatchObject({
|
|
@@ -87,7 +94,7 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
87
94
|
];
|
|
88
95
|
|
|
89
96
|
const request: SubmitTransactionRequest = {
|
|
90
|
-
network:
|
|
97
|
+
network: Network.LocalNet,
|
|
91
98
|
account_id: account.account_id,
|
|
92
99
|
fee_instructions,
|
|
93
100
|
instructions: [],
|
|
@@ -163,27 +170,47 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
163
170
|
describe("listSubstates", () => {
|
|
164
171
|
it("returns substates", async () => {
|
|
165
172
|
const signer = await buildSigner();
|
|
166
|
-
const { substates } = await signer.listSubstates(
|
|
173
|
+
const { substates } = await signer.listSubstates({
|
|
174
|
+
filter_by_template: null,
|
|
175
|
+
filter_by_type: null,
|
|
176
|
+
limit: 10,
|
|
177
|
+
offset: 0,
|
|
178
|
+
});
|
|
167
179
|
|
|
168
180
|
expect(substates.length).toBeGreaterThan(0);
|
|
169
181
|
});
|
|
170
182
|
|
|
171
183
|
it("filters substates by template address", async () => {
|
|
172
184
|
const signer = await buildSigner();
|
|
173
|
-
const { substates } = await signer.listSubstates(
|
|
185
|
+
const { substates } = await signer.listSubstates({
|
|
186
|
+
filter_by_template: null,
|
|
187
|
+
filter_by_type: null,
|
|
188
|
+
limit: 10,
|
|
189
|
+
offset: 0,
|
|
190
|
+
});
|
|
174
191
|
|
|
175
192
|
const substateWithTemplate = substates.find((substate) => substate.template_address);
|
|
176
193
|
assert(substateWithTemplate, "No substate with template found");
|
|
177
194
|
|
|
178
195
|
const templateAddress = substateWithTemplate.template_address;
|
|
179
|
-
const { substates: filteredSubstates } = await signer.listSubstates(
|
|
196
|
+
const { substates: filteredSubstates } = await signer.listSubstates({
|
|
197
|
+
filter_by_template: templateAddress,
|
|
198
|
+
filter_by_type: null,
|
|
199
|
+
limit: 10,
|
|
200
|
+
offset: 0,
|
|
201
|
+
});
|
|
180
202
|
|
|
181
203
|
expect(filteredSubstates.every((substate) => substate.template_address === templateAddress)).toBe(true);
|
|
182
204
|
});
|
|
183
205
|
|
|
184
206
|
it("filters substates by type", async () => {
|
|
185
207
|
const signer = await buildSigner();
|
|
186
|
-
const { substates } = await signer.listSubstates(
|
|
208
|
+
const { substates } = await signer.listSubstates({
|
|
209
|
+
filter_by_template: null,
|
|
210
|
+
filter_by_type: "Component",
|
|
211
|
+
limit: 1,
|
|
212
|
+
offset: 0,
|
|
213
|
+
});
|
|
187
214
|
|
|
188
215
|
expect(substates.every((substate) => substate.module_name)).toBe(true);
|
|
189
216
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "@tari-project/tarijs-types";
|
|
3
3
|
|
|
4
4
|
describe("convertTaggedValue", () => {
|
|
5
5
|
it.each([
|
|
@@ -201,7 +201,7 @@ describe("parseCbor", () => {
|
|
|
201
201
|
expect(parseCbor(value as CborValue)).toEqual(expected);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
it.each([{}, { Unknown: 2 }])("throws, when data in unknown format is found", (value: unknown) => {
|
|
206
206
|
expect(() => parseCbor(value as CborValue)).toThrow();
|
|
207
207
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
import { loadEnv } from
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import { loadEnv } from "vite";
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
-
root:
|
|
5
|
+
root: ".",
|
|
6
6
|
test: {
|
|
7
7
|
env: loadEnv("", "./integration-tests/", ""),
|
|
8
8
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { TransactionStatus } from "./TransactionStatus";
|
|
2
2
|
import { FinalizeResult } from "./FinalizeResult";
|
|
3
|
+
import { DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
4
|
+
import { ComponentAddress } from "@tari-project/typescript-bindings";
|
|
3
5
|
|
|
4
6
|
export type SubmitTransactionResponse = {
|
|
5
7
|
transaction_id: string;
|
|
@@ -8,6 +10,10 @@ export type SubmitTransactionResponse = {
|
|
|
8
10
|
export interface SubmitTxResult {
|
|
9
11
|
response: SubmitTransactionResponse;
|
|
10
12
|
result: TransactionResult;
|
|
13
|
+
upSubstates: UpSubstates;
|
|
14
|
+
downSubstates: DownSubstates;
|
|
15
|
+
newComponents: UpSubstates;
|
|
16
|
+
getComponentForTemplate(templateAddress: string): ComponentAddress | null;
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
export type TransactionResult = {
|
|
@@ -15,3 +21,9 @@ export type TransactionResult = {
|
|
|
15
21
|
status: TransactionStatus;
|
|
16
22
|
result: FinalizeResult | null;
|
|
17
23
|
};
|
|
24
|
+
|
|
25
|
+
export type TransactionResultResponse = {
|
|
26
|
+
transaction_id: string;
|
|
27
|
+
status: TransactionStatus;
|
|
28
|
+
result: FinalizeResult | null;
|
|
29
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
2
|
import { TransactionStatus } from "../TransactionStatus";
|
|
3
|
+
export { fromHexString, toHexString } from "./hexString";
|
|
4
|
+
export { txResultCheck, getSubstateValueFromUpSubstates, getComponentsForTemplate } from "./txResult";
|
|
5
|
+
export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
3
6
|
export {
|
|
4
7
|
substateIdToString,
|
|
5
8
|
stringToSubstateId,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SubstateDiff,
|
|
3
|
+
VaultId,
|
|
4
|
+
Vault,
|
|
5
|
+
SubstateId,
|
|
6
|
+
SubstateValue,
|
|
7
|
+
ResourceContainer,
|
|
8
|
+
ResourceAddress,
|
|
9
|
+
Amount,
|
|
10
|
+
RejectReason,
|
|
11
|
+
substateIdToString,
|
|
12
|
+
ComponentAddress,
|
|
13
|
+
} from "@tari-project/typescript-bindings";
|
|
14
|
+
import { FinalizeResultStatus } from "../FinalizeResult";
|
|
15
|
+
import { UpSubstates } from "../SubstateDiff";
|
|
16
|
+
|
|
17
|
+
function isOfType<T extends object>(obj: T, key: keyof T): boolean {
|
|
18
|
+
return obj !== null && typeof obj === "object" && key in obj;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const txResultCheck = {
|
|
22
|
+
isAccept: (result: FinalizeResultStatus): result is { Accept: SubstateDiff } => {
|
|
23
|
+
return "Accept" in result;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
isVaultId: (substateId: SubstateId): substateId is { Vault: VaultId } => {
|
|
27
|
+
return isOfType(substateId, "Vault" as keyof SubstateId);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
isVaultSubstate: (substate: SubstateValue): substate is { Vault: Vault } => {
|
|
31
|
+
return "Vault" in substate;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
isFungible: (
|
|
35
|
+
resourceContainer: ResourceContainer,
|
|
36
|
+
): resourceContainer is { Fungible: { address: ResourceAddress; amount: Amount; locked_amount: Amount } } => {
|
|
37
|
+
return "Fungible" in resourceContainer;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
isReject: (result: FinalizeResultStatus): result is { Reject: RejectReason } => {
|
|
41
|
+
return "Reject" in result;
|
|
42
|
+
},
|
|
43
|
+
isAcceptFeeRejectRest: (
|
|
44
|
+
result: FinalizeResultStatus,
|
|
45
|
+
): result is { AcceptFeeRejectRest: [SubstateDiff, RejectReason] } => {
|
|
46
|
+
return "AcceptFeeRejectRest" in result;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function getSubstateValueFromUpSubstates(
|
|
51
|
+
substateType: keyof SubstateValue | string,
|
|
52
|
+
upSubstates: UpSubstates,
|
|
53
|
+
): UpSubstates {
|
|
54
|
+
const components: UpSubstates = [];
|
|
55
|
+
for (const [substateId, substate] of upSubstates) {
|
|
56
|
+
if (substateType in substate.substate) {
|
|
57
|
+
components.push([substateId, substate]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return components;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getComponentsForTemplate(templateAddress: string, upSubstates: UpSubstates): ComponentAddress[] | null {
|
|
64
|
+
const components: ComponentAddress[] = [];
|
|
65
|
+
const templateAddressBytes = new TextEncoder().encode(templateAddress);
|
|
66
|
+
for (const [substateId, substate] of upSubstates) {
|
|
67
|
+
if ("Component" in substate.substate) {
|
|
68
|
+
const componentHeader = substate.substate.Component;
|
|
69
|
+
if (componentHeader.template_address === templateAddressBytes) {
|
|
70
|
+
components.push(substateIdToString(substateId));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return components;
|
|
75
|
+
}
|
|
@@ -16,13 +16,19 @@ export { Instruction } from "./Instruction";
|
|
|
16
16
|
export { Transaction } from "./Transaction";
|
|
17
17
|
export { SubstateDiff, DownSubstates, UpSubstates } from "./SubstateDiff";
|
|
18
18
|
export { SubstateRequirement } from "./SubstateRequirement";
|
|
19
|
-
export {
|
|
19
|
+
export {
|
|
20
|
+
TransactionResult,
|
|
21
|
+
SubmitTxResult,
|
|
22
|
+
SubmitTransactionResponse,
|
|
23
|
+
TransactionResultResponse,
|
|
24
|
+
} from "./TransactionResult";
|
|
20
25
|
export { TransactionSignature } from "./TransactionSignature";
|
|
21
26
|
export { TransactionStatus } from "./TransactionStatus";
|
|
22
27
|
export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
23
28
|
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
24
29
|
export { WorkspaceArg } from "./Workspace";
|
|
25
30
|
export { ListAccountNftFromBalancesRequest } from "./ListAccountNftFromBalancesRequest";
|
|
31
|
+
export { Network } from "./network";
|
|
26
32
|
export {
|
|
27
33
|
AccountData,
|
|
28
34
|
ListSubstatesRequest,
|
|
@@ -51,4 +57,14 @@ export {
|
|
|
51
57
|
shortenSubstateId,
|
|
52
58
|
stringToSubstateId,
|
|
53
59
|
substateIdToString,
|
|
60
|
+
fromHexString,
|
|
61
|
+
toHexString,
|
|
62
|
+
convertTaggedValue,
|
|
63
|
+
getCborValueByPath,
|
|
64
|
+
parseCbor,
|
|
65
|
+
getSubstateValueFromUpSubstates,
|
|
66
|
+
getComponentsForTemplate,
|
|
67
|
+
txResultCheck,
|
|
68
|
+
BinaryTag,
|
|
69
|
+
CborValue,
|
|
54
70
|
} from "./helpers";
|
package/pnpm-workspace.yaml
CHANGED
|
@@ -8,8 +8,8 @@ catalog:
|
|
|
8
8
|
vitest: ^3.0.4
|
|
9
9
|
vite: ^6.1.0
|
|
10
10
|
"@types/node": ^22.13.1
|
|
11
|
-
"@tari-project/typescript-bindings": ^1.5.
|
|
12
|
-
"@tari-project/wallet_jrpc_client": ^1.5.
|
|
11
|
+
"@tari-project/typescript-bindings": ^1.5.2
|
|
12
|
+
"@tari-project/wallet_jrpc_client": ^1.5.2
|
|
13
13
|
"@metamask/providers": ^18.2.0
|
|
14
14
|
"@walletconnect/universal-provider": ^2.13.3
|
|
15
15
|
"@walletconnect/modal": ^2.6.2
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:12011/json_rpc
|
|
File without changes
|
|
File without changes
|
|
File without changes
|