@stacks/clarinet-sdk-browser 3.23.1 → 3.24.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/dist/esm/browser/src/index.d.ts +1 -1
- package/dist/esm/browser/src/sdkProxy.d.ts +3 -10
- package/dist/esm/browser/src/sdkProxy.js +8 -99
- package/dist/esm/browser/src/sdkProxy.js.map +1 -1
- package/dist/esm/browser/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/common/src/sdkProxy.d.ts +32 -0
- package/dist/esm/common/src/sdkProxy.js +85 -0
- package/dist/esm/common/src/sdkProxy.js.map +1 -0
- package/dist/esm/common/src/sdkProxyHelpers.d.ts +34 -12
- package/dist/esm/common/src/sdkProxyHelpers.js +40 -9
- package/dist/esm/common/src/sdkProxyHelpers.js.map +1 -1
- package/package.json +3 -3
|
@@ -3,4 +3,4 @@ import { Simnet, getSessionProxy } from "./sdkProxy.js";
|
|
|
3
3
|
export { tx, type ClarityEvent, type ParsedTransactionResult, type DeployContractOptions, type Tx, type TransferSTX, } from "../../common/src/sdkProxyHelpers.js";
|
|
4
4
|
export { init, SDK, getSessionProxy, type Simnet };
|
|
5
5
|
export { defaultVfs, defaultFileStore } from "./defaultVfs.js";
|
|
6
|
-
export declare const initSimnet: (virtualFileSystem?: Function) => Promise<
|
|
6
|
+
export declare const initSimnet: (virtualFileSystem?: Function) => Promise<import("../../common/src/sdkProxy.js").ProxiedSimnet<SDK>>;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { type SDK } from "@stacks/clarinet-sdk-wasm-browser";
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type Simnet = {
|
|
6
|
-
[K in keyof SDK]: K extends "callReadOnlyFn" | "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "runSnippet" ? RunSnippet : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : SDK[K];
|
|
7
|
-
};
|
|
8
|
-
export declare function getSessionProxy(): {
|
|
9
|
-
get(session: SDK, prop: keyof SDK, receiver: any): string | number | CallFn | DeployContract | TransferSTX | MineBlock | GetMapEntry | ((include_boot_contracts: boolean, boot_contracts_path: string) => import("@stacks/clarinet-sdk-wasm-browser").SessionReport) | ((cost_field: string) => void) | ((cwd: string, manifest_path: string, api_base_url: any) => Promise<void>) | ((count?: number | null) => number) | ((token: string, recipient: string, amount: bigint) => string) | ((recipient: string, amount: bigint) => string) | ((addresses: string[]) => void);
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
2
|
+
import { type ProxiedSimnet } from "../../common/src/sdkProxy.js";
|
|
3
|
+
export type Simnet = ProxiedSimnet<SDK>;
|
|
4
|
+
export declare function getSessionProxy(): ProxyHandler<SDK>;
|
|
@@ -1,102 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { parseEvents, parseCosts, } from "../../common/src/sdkProxyHelpers.js";
|
|
4
|
-
function parseTxResponse(response) {
|
|
5
|
-
return {
|
|
6
|
-
result: Cl.deserialize(response.result),
|
|
7
|
-
events: parseEvents(response.events),
|
|
8
|
-
costs: parseCosts(response.costs),
|
|
9
|
-
performance: response.performance,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
1
|
+
import { CallFnArgs, ContractOptions, DeployContractArgs, TransferSTXArgs, } from "@stacks/clarinet-sdk-wasm-browser";
|
|
2
|
+
import { createSessionProxy } from "../../common/src/sdkProxy.js";
|
|
12
3
|
export function getSessionProxy() {
|
|
13
|
-
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const callFn = (contract, method, args, sender) => {
|
|
20
|
-
const response = session[prop](new CallFnArgs(contract, method, args.map(serializeCVBytes), sender));
|
|
21
|
-
return parseTxResponse(response);
|
|
22
|
-
};
|
|
23
|
-
return callFn;
|
|
24
|
-
}
|
|
25
|
-
if (prop === "execute") {
|
|
26
|
-
const execute = (snippet) => {
|
|
27
|
-
const response = session.execute(snippet);
|
|
28
|
-
return parseTxResponse(response);
|
|
29
|
-
};
|
|
30
|
-
return execute;
|
|
31
|
-
}
|
|
32
|
-
if (prop === "deployContract") {
|
|
33
|
-
const callDeployContract = (name, content, options, sender) => {
|
|
34
|
-
const rustOptions = options
|
|
35
|
-
? new ContractOptions(options.clarityVersion)
|
|
36
|
-
: new ContractOptions();
|
|
37
|
-
const response = session.deployContract(new DeployContractArgs(name, content, rustOptions, sender));
|
|
38
|
-
return parseTxResponse(response);
|
|
39
|
-
};
|
|
40
|
-
return callDeployContract;
|
|
41
|
-
}
|
|
42
|
-
if (prop === "transferSTX") {
|
|
43
|
-
const callTransferSTX = (amount, ...args) => {
|
|
44
|
-
const response = session.transferSTX(new TransferSTXArgs(BigInt(amount), ...args));
|
|
45
|
-
return parseTxResponse(response);
|
|
46
|
-
};
|
|
47
|
-
return callTransferSTX;
|
|
48
|
-
}
|
|
49
|
-
if (prop === "mineBlock") {
|
|
50
|
-
const callMineBlock = (txs) => {
|
|
51
|
-
const serializedTxs = txs.map((tx) => {
|
|
52
|
-
if (tx.callPublicFn) {
|
|
53
|
-
return {
|
|
54
|
-
callPublicFn: {
|
|
55
|
-
...tx.callPublicFn,
|
|
56
|
-
args_maps: tx.callPublicFn.args.map(serializeCVBytes),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (tx.callPrivateFn) {
|
|
61
|
-
return {
|
|
62
|
-
callPrivateFn: {
|
|
63
|
-
...tx.callPrivateFn,
|
|
64
|
-
args_maps: tx.callPrivateFn.args.map(serializeCVBytes),
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (tx.deployContract) {
|
|
69
|
-
return {
|
|
70
|
-
deployContract: {
|
|
71
|
-
...tx.deployContract,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return tx;
|
|
76
|
-
});
|
|
77
|
-
const responses = session.mineBlock(serializedTxs);
|
|
78
|
-
return responses.map(parseTxResponse);
|
|
79
|
-
};
|
|
80
|
-
return callMineBlock;
|
|
81
|
-
}
|
|
82
|
-
if (prop === "getDataVar") {
|
|
83
|
-
const getDataVar = (...args) => {
|
|
84
|
-
const response = session.getDataVar(...args);
|
|
85
|
-
const result = Cl.deserialize(response);
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
return getDataVar;
|
|
89
|
-
}
|
|
90
|
-
if (prop === "getMapEntry") {
|
|
91
|
-
const getMapEntry = (contract, mapName, mapKey) => {
|
|
92
|
-
const response = session.getMapEntry(contract, mapName, serializeCVBytes(mapKey));
|
|
93
|
-
const result = Cl.deserialize(response);
|
|
94
|
-
return result;
|
|
95
|
-
};
|
|
96
|
-
return getMapEntry;
|
|
97
|
-
}
|
|
98
|
-
return Reflect.get(session, prop, receiver);
|
|
99
|
-
},
|
|
100
|
-
};
|
|
4
|
+
return createSessionProxy({
|
|
5
|
+
CallFnArgs,
|
|
6
|
+
ContractOptions,
|
|
7
|
+
DeployContractArgs,
|
|
8
|
+
TransferSTXArgs,
|
|
9
|
+
});
|
|
101
10
|
}
|
|
102
11
|
//# sourceMappingURL=sdkProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../src/sdkProxy.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../src/sdkProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,GAEhB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAsB,MAAM,8BAA8B,CAAC;AAItF,MAAM,UAAU,eAAe;IAC7B,OAAO,kBAAkB,CAAuB;QAC9C,UAAU;QACV,eAAe;QACf,kBAAkB;QAClB,eAAe;KAChB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../../src/defaultVfs.ts","../../../src/index.ts","../../../src/sdkProxy.ts","../../../../common/src/sdkProxyHelpers.ts"],"
|
|
1
|
+
{"version":"7.0.2","root":["../../../src/defaultVfs.ts","../../../src/index.ts","../../../src/sdkProxy.ts","../../../../common/src/sdkProxy.ts","../../../../common/src/sdkProxyHelpers.ts"],"packageJsons":["../../../../../clarinet-sdk-wasm/pkg-browser/package.json","../../../package.json","../../../../common/package.json","../../../../../../node_modules/.pnpm/@noble+secp256k1@1.7.1/node_modules/@noble/secp256k1/package.json","../../../../../../node_modules/.pnpm/@stacks+common@7.6.0/node_modules/@stacks/common/package.json","../../../../../../node_modules/.pnpm/@stacks+network@7.6.0/node_modules/@stacks/network/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/package.json"],"missingPackageJsons":["../../../../../../node_modules/.pnpm/@noble+secp256k1@1.7.1/node_modules/@noble/secp256k1/lib/package.json","../../../../../../node_modules/.pnpm/@stacks+common@7.6.0/node_modules/@stacks/common/dist/package.json","../../../../../../node_modules/.pnpm/@stacks+network@7.6.0/node_modules/@stacks/network/dist/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/dist/clarity/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/dist/clarity/values/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/dist/namespaces/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/dist/package.json","../../../../../../node_modules/.pnpm/@stacks+transactions@7.6.0/node_modules/@stacks/transactions/dist/wire/package.json"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CallFn, type CallReadOnlyFn, type DeployContract, type Execute, type GetDataVar, type GetMapEntry, type MineBlock, type TransferSTX } from "./sdkProxyHelpers.js";
|
|
2
|
+
type WasmTransactionRes = {
|
|
3
|
+
result: string;
|
|
4
|
+
events: string;
|
|
5
|
+
costs: string;
|
|
6
|
+
performance?: string;
|
|
7
|
+
};
|
|
8
|
+
type ProxySdk = {
|
|
9
|
+
callReadOnlyFn(args: unknown): WasmTransactionRes;
|
|
10
|
+
callPublicFn(args: unknown): WasmTransactionRes;
|
|
11
|
+
callPrivateFn(args: unknown): WasmTransactionRes;
|
|
12
|
+
deployContract(args: unknown): WasmTransactionRes;
|
|
13
|
+
execute(snippet: string): WasmTransactionRes;
|
|
14
|
+
getDataVar(contract: string, varName: string): string;
|
|
15
|
+
getMapEntry(contract: string, mapName: string, mapKey: Uint8Array): string;
|
|
16
|
+
mineBlock(txs: unknown[]): WasmTransactionRes[];
|
|
17
|
+
runSnippet(snippet: string): string;
|
|
18
|
+
transferSTX(args: unknown): WasmTransactionRes;
|
|
19
|
+
};
|
|
20
|
+
/** @deprecated use `simnet.execute(command)` instead */
|
|
21
|
+
type RunSnippet<S extends ProxySdk> = S["runSnippet"];
|
|
22
|
+
export type ProxiedSimnet<S extends ProxySdk> = {
|
|
23
|
+
[K in keyof S]: K extends "callReadOnlyFn" ? CallReadOnlyFn : K extends "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "runSnippet" ? RunSnippet<S> : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : S[K];
|
|
24
|
+
};
|
|
25
|
+
type ProxyBindings<ContractOptions> = {
|
|
26
|
+
CallFnArgs: new (contract: string, method: string, args: Uint8Array[], sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
|
|
27
|
+
ContractOptions: new (clarityVersion?: number) => ContractOptions;
|
|
28
|
+
DeployContractArgs: new (name: string, content: string, options: ContractOptions, sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
|
|
29
|
+
TransferSTXArgs: new (amount: bigint, recipient: string, sender: string, postConditions?: string[], postConditionMode?: string) => unknown;
|
|
30
|
+
};
|
|
31
|
+
export declare function createSessionProxy<S extends ProxySdk, ContractOptions>(bindings: ProxyBindings<ContractOptions>): ProxyHandler<S>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Cl, serializeCVBytes } from "@stacks/transactions";
|
|
2
|
+
import { parseCosts, parseEvents, serializePostConditions, } from "./sdkProxyHelpers.js";
|
|
3
|
+
function parseTxResponse(response) {
|
|
4
|
+
return {
|
|
5
|
+
result: Cl.deserialize(response.result),
|
|
6
|
+
events: parseEvents(response.events),
|
|
7
|
+
costs: parseCosts(response.costs),
|
|
8
|
+
performance: response.performance,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function createSessionProxy(bindings) {
|
|
12
|
+
const { CallFnArgs, ContractOptions, DeployContractArgs, TransferSTXArgs } = bindings;
|
|
13
|
+
return {
|
|
14
|
+
get(session, prop, receiver) {
|
|
15
|
+
const sdk = session;
|
|
16
|
+
if (prop === "callReadOnlyFn" || prop === "callPublicFn" || prop === "callPrivateFn") {
|
|
17
|
+
const callFn = (contract, method, args, sender, options) => {
|
|
18
|
+
const { postConditions, postConditionMode } = serializePostConditions(options);
|
|
19
|
+
const response = sdk[prop](new CallFnArgs(contract, method, args.map(serializeCVBytes), sender, postConditions, postConditionMode));
|
|
20
|
+
return parseTxResponse(response);
|
|
21
|
+
};
|
|
22
|
+
return callFn;
|
|
23
|
+
}
|
|
24
|
+
if (prop === "execute") {
|
|
25
|
+
const execute = (snippet) => parseTxResponse(sdk.execute(snippet));
|
|
26
|
+
return execute;
|
|
27
|
+
}
|
|
28
|
+
if (prop === "deployContract") {
|
|
29
|
+
const deployContract = (name, content, options, sender, postConditionOptions) => {
|
|
30
|
+
const rustOptions = options
|
|
31
|
+
? new ContractOptions(options.clarityVersion)
|
|
32
|
+
: new ContractOptions();
|
|
33
|
+
const { postConditions, postConditionMode } = serializePostConditions(postConditionOptions);
|
|
34
|
+
return parseTxResponse(sdk.deployContract(new DeployContractArgs(name, content, rustOptions, sender, postConditions, postConditionMode)));
|
|
35
|
+
};
|
|
36
|
+
return deployContract;
|
|
37
|
+
}
|
|
38
|
+
if (prop === "transferSTX") {
|
|
39
|
+
const transferSTX = (amount, recipient, sender, options) => {
|
|
40
|
+
const { postConditions, postConditionMode } = serializePostConditions(options);
|
|
41
|
+
return parseTxResponse(sdk.transferSTX(new TransferSTXArgs(BigInt(amount), recipient, sender, postConditions, postConditionMode)));
|
|
42
|
+
};
|
|
43
|
+
return transferSTX;
|
|
44
|
+
}
|
|
45
|
+
if (prop === "mineBlock") {
|
|
46
|
+
const mineBlock = (txs) => {
|
|
47
|
+
const serializedTxs = txs.map((tx) => {
|
|
48
|
+
if (tx.callPublicFn) {
|
|
49
|
+
return {
|
|
50
|
+
callPublicFn: {
|
|
51
|
+
...tx.callPublicFn,
|
|
52
|
+
args_maps: tx.callPublicFn.args.map(serializeCVBytes),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (tx.callPrivateFn) {
|
|
57
|
+
return {
|
|
58
|
+
callPrivateFn: {
|
|
59
|
+
...tx.callPrivateFn,
|
|
60
|
+
args_maps: tx.callPrivateFn.args.map(serializeCVBytes),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (tx.deployContract) {
|
|
65
|
+
return { deployContract: { ...tx.deployContract } };
|
|
66
|
+
}
|
|
67
|
+
return tx;
|
|
68
|
+
});
|
|
69
|
+
return sdk.mineBlock(serializedTxs).map(parseTxResponse);
|
|
70
|
+
};
|
|
71
|
+
return mineBlock;
|
|
72
|
+
}
|
|
73
|
+
if (prop === "getDataVar") {
|
|
74
|
+
const getDataVar = (...args) => Cl.deserialize(sdk.getDataVar(...args));
|
|
75
|
+
return getDataVar;
|
|
76
|
+
}
|
|
77
|
+
if (prop === "getMapEntry") {
|
|
78
|
+
const getMapEntry = (contract, mapName, mapKey) => Cl.deserialize(sdk.getMapEntry(contract, mapName, serializeCVBytes(mapKey)));
|
|
79
|
+
return getMapEntry;
|
|
80
|
+
}
|
|
81
|
+
return Reflect.get(session, prop, receiver);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sdkProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,UAAU,EACV,WAAW,EACX,uBAAuB,GAUxB,MAAM,sBAAsB,CAAC;AA0E9B,SAAS,eAAe,CAAC,QAA4B;IACnD,OAAO;QACL,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QACpC,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjC,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,QAAwC;IAExC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC;IAEtF,OAAO;QACL,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACzB,MAAM,GAAG,GAAa,OAAO,CAAC;YAE9B,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;gBACrF,MAAM,MAAM,GAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;oBACj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OAAO,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,MAAM,UAAU,GAAe,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACpF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3B,MAAM,WAAW,GAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7D,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC/E,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClarityValue, ClarityVersion } from "@stacks/transactions";
|
|
1
|
+
import { ClarityValue, ClarityVersion, ContractCallOptions, PostConditionModeName } from "@stacks/transactions";
|
|
2
2
|
export type ClarityEvent = {
|
|
3
3
|
event: string;
|
|
4
4
|
data: {
|
|
@@ -26,19 +26,41 @@ export type ParsedTransactionResult = {
|
|
|
26
26
|
costs: ClarityCosts | null;
|
|
27
27
|
performance: string | undefined;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Post-conditions to enforce on a simnet transaction.
|
|
31
|
+
*
|
|
32
|
+
* Conditions use the same builder, wire, and hex formats as stacks.js. Hex is
|
|
33
|
+
* also the escape hatch for conditions that stacks.js cannot build yet.
|
|
34
|
+
*
|
|
35
|
+
* Passing neither field preserves the SDK's unchecked behavior. Passing either
|
|
36
|
+
* enables enforcement; `postConditionMode` defaults to `"deny"`.
|
|
37
|
+
*/
|
|
38
|
+
export type PostConditionOptions = Pick<ContractCallOptions, "postConditions" | "postConditionMode">;
|
|
39
|
+
/** `PostConditionOptions` as the Wasm SDK takes it: conditions already encoded. */
|
|
40
|
+
export type SerializedPostConditions = {
|
|
41
|
+
postConditions?: string[];
|
|
42
|
+
postConditionMode?: PostConditionModeName;
|
|
43
|
+
};
|
|
44
|
+
export declare function serializePostConditions(options?: PostConditionOptions): SerializedPostConditions;
|
|
45
|
+
export type CallFn = (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => ParsedTransactionResult;
|
|
46
|
+
/** A read-only call moves no assets, so it takes no post-conditions. */
|
|
47
|
+
export type CallReadOnlyFn = (contract: string, method: string, args: ClarityValue[], sender: string) => ParsedTransactionResult;
|
|
30
48
|
export type DeployContractOptions = {
|
|
31
49
|
clarityVersion: ClarityVersion;
|
|
32
50
|
};
|
|
33
|
-
export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string) => ParsedTransactionResult;
|
|
34
|
-
export type TransferSTX = (amount: number | bigint, recipient: string, sender: string) => ParsedTransactionResult;
|
|
51
|
+
export type DeployContract = (name: string, content: string, options: DeployContractOptions | null, sender: string, postConditionOptions?: PostConditionOptions) => ParsedTransactionResult;
|
|
52
|
+
export type TransferSTX = (amount: number | bigint, recipient: string, sender: string, options?: PostConditionOptions) => ParsedTransactionResult;
|
|
53
|
+
/**
|
|
54
|
+
* A transaction in a `mineBlock` batch. Post-conditions are already encoded,
|
|
55
|
+
* because the batch is handed to Wasm as plain JSON.
|
|
56
|
+
*/
|
|
35
57
|
export type Tx = {
|
|
36
58
|
callPublicFn: {
|
|
37
59
|
contract: string;
|
|
38
60
|
method: string;
|
|
39
61
|
args: ClarityValue[];
|
|
40
62
|
sender: string;
|
|
41
|
-
};
|
|
63
|
+
} & SerializedPostConditions;
|
|
42
64
|
callPrivateFn?: never;
|
|
43
65
|
deployContract?: never;
|
|
44
66
|
transferSTX?: never;
|
|
@@ -49,7 +71,7 @@ export type Tx = {
|
|
|
49
71
|
method: string;
|
|
50
72
|
args: ClarityValue[];
|
|
51
73
|
sender: string;
|
|
52
|
-
};
|
|
74
|
+
} & SerializedPostConditions;
|
|
53
75
|
deployContract?: never;
|
|
54
76
|
transferSTX?: never;
|
|
55
77
|
} | {
|
|
@@ -60,7 +82,7 @@ export type Tx = {
|
|
|
60
82
|
content: string;
|
|
61
83
|
options: DeployContractOptions | null;
|
|
62
84
|
sender: string;
|
|
63
|
-
};
|
|
85
|
+
} & SerializedPostConditions;
|
|
64
86
|
transferSTX?: never;
|
|
65
87
|
} | {
|
|
66
88
|
callPublicFn?: never;
|
|
@@ -70,13 +92,13 @@ export type Tx = {
|
|
|
70
92
|
amount: number;
|
|
71
93
|
recipient: string;
|
|
72
94
|
sender: string;
|
|
73
|
-
};
|
|
95
|
+
} & SerializedPostConditions;
|
|
74
96
|
};
|
|
75
97
|
export declare const tx: {
|
|
76
|
-
callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
77
|
-
callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string) => Tx;
|
|
78
|
-
deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string) => Tx;
|
|
79
|
-
transferSTX: (amount: number, recipient: string, sender: string) => Tx;
|
|
98
|
+
callPublicFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
|
|
99
|
+
callPrivateFn: (contract: string, method: string, args: ClarityValue[], sender: string, options?: PostConditionOptions) => Tx;
|
|
100
|
+
deployContract: (name: string, content: string, options: DeployContractOptions | null, sender: string, postConditionOptions?: PostConditionOptions) => Tx;
|
|
101
|
+
transferSTX: (amount: number, recipient: string, sender: string, options?: PostConditionOptions) => Tx;
|
|
80
102
|
};
|
|
81
103
|
export declare function parseEvents(events: string): ClarityEvent[];
|
|
82
104
|
export declare function parseCosts(costs: string): ClarityCosts | null;
|
|
@@ -1,16 +1,47 @@
|
|
|
1
|
-
import { Cl } from "@stacks/transactions";
|
|
1
|
+
import { Cl, PostConditionMode, postConditionToHex, serializePostConditionWire, } from "@stacks/transactions";
|
|
2
|
+
export function serializePostConditions(options) {
|
|
3
|
+
const conditions = options?.postConditions;
|
|
4
|
+
const mode = options?.postConditionMode;
|
|
5
|
+
// Preserve the distinction between an omitted list and an explicit empty one.
|
|
6
|
+
return {
|
|
7
|
+
...(conditions !== undefined && {
|
|
8
|
+
postConditions: conditions.map((pc) => {
|
|
9
|
+
if (typeof pc === "string")
|
|
10
|
+
return pc;
|
|
11
|
+
return typeof pc.type === "string"
|
|
12
|
+
? postConditionToHex(pc)
|
|
13
|
+
: serializePostConditionWire(pc);
|
|
14
|
+
}),
|
|
15
|
+
}),
|
|
16
|
+
...(mode !== undefined && {
|
|
17
|
+
postConditionMode: mode === PostConditionMode.Allow
|
|
18
|
+
? "allow"
|
|
19
|
+
: mode === PostConditionMode.Deny
|
|
20
|
+
? "deny"
|
|
21
|
+
: mode === PostConditionMode.Originator
|
|
22
|
+
? "originator"
|
|
23
|
+
: mode,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
2
27
|
export const tx = {
|
|
3
|
-
callPublicFn: (contract, method, args, sender) => ({
|
|
4
|
-
callPublicFn: { contract, method, args, sender },
|
|
28
|
+
callPublicFn: (contract, method, args, sender, options) => ({
|
|
29
|
+
callPublicFn: { contract, method, args, sender, ...serializePostConditions(options) },
|
|
5
30
|
}),
|
|
6
|
-
callPrivateFn: (contract, method, args, sender) => ({
|
|
7
|
-
callPrivateFn: { contract, method, args, sender },
|
|
31
|
+
callPrivateFn: (contract, method, args, sender, options) => ({
|
|
32
|
+
callPrivateFn: { contract, method, args, sender, ...serializePostConditions(options) },
|
|
8
33
|
}),
|
|
9
|
-
deployContract: (name, content, options, sender) => ({
|
|
10
|
-
deployContract: {
|
|
34
|
+
deployContract: (name, content, options, sender, postConditionOptions) => ({
|
|
35
|
+
deployContract: {
|
|
36
|
+
name,
|
|
37
|
+
content,
|
|
38
|
+
options,
|
|
39
|
+
sender,
|
|
40
|
+
...serializePostConditions(postConditionOptions),
|
|
41
|
+
},
|
|
11
42
|
}),
|
|
12
|
-
transferSTX: (amount, recipient, sender) => ({
|
|
13
|
-
transferSTX: { amount, recipient, sender },
|
|
43
|
+
transferSTX: (amount, recipient, sender, options) => ({
|
|
44
|
+
transferSTX: { amount, recipient, sender, ...serializePostConditions(options) },
|
|
14
45
|
}),
|
|
15
46
|
};
|
|
16
47
|
export function parseEvents(events) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"sdkProxyHelpers.js","sourceRoot":"","sources":["../../../../../common/src/sdkProxyHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAKF,iBAAiB,EAGjB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAiD9B,MAAM,UAAU,uBAAuB,CAAC,OAA8B;IACpE,MAAM,UAAU,GAAG,OAAO,EAAE,cAAc,CAAC;IAC3C,MAAM,IAAI,GAAG,OAAO,EAAE,iBAAiB,CAAC;IAExC,8EAA8E;IAC9E,OAAO;QACL,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI;YAC9B,cAAc,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;gBACpC,IAAI,OAAO,EAAE,KAAK,QAAQ;oBAAE,OAAO,EAAE,CAAC;gBACtC,OAAO,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAC,CAAC,kBAAkB,CAAC,EAAmB,CAAC;oBACzC,CAAC,CAAC,0BAA0B,CAAC,EAAuB,CAAC,CAAC;YAC1D,CAAC,CAAC;SACH,CAAC;QACF,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI;YACxB,iBAAiB,EACf,IAAI,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;aACvB;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacks/clarinet-sdk-browser",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.24.0",
|
|
4
4
|
"author": "Stacks Labs",
|
|
5
5
|
"description": "A SDK to interact with Clarity Smart Contracts in the browser",
|
|
6
6
|
"homepage": "https://stackslabs.com/clarinet",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"license": "GPL-3.0",
|
|
23
23
|
"readme": "./README.md",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@stacks/transactions": "7.
|
|
26
|
-
"@stacks/clarinet-sdk-wasm-browser": "3.
|
|
25
|
+
"@stacks/transactions": "7.6.0",
|
|
26
|
+
"@stacks/clarinet-sdk-wasm-browser": "3.24.0"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"clean": "rimraf dist",
|