mirror of
https://github.com/alexgo-io/clarity-codegen.git
synced 2026-01-12 14:34:34 +08:00
bump the Stacks JS SDK to the latest version.
This commit is contained in:
@@ -59,7 +59,7 @@ const xlinkContracts = [
|
||||
Example:
|
||||
|
||||
```typescript
|
||||
import { callReadOnlyFunction } from "@stacks/transactions";
|
||||
import { fetchReadOnlyFunction } from "@stacks/transactions";
|
||||
import { tupleT, stringT } from "clarity-codegen";
|
||||
import { AlexContracts } from "./generated/contracts_Alex";
|
||||
|
||||
@@ -76,7 +76,7 @@ const functionDescriptor = AlexContracts[contractName][readonlyFunctionName];
|
||||
const clarityArgs = functionDescriptor.input.map((arg) =>
|
||||
arg.type.encode(readonlyFunctionArgs[arg.name])
|
||||
);
|
||||
const result = await callReadOnlyFunction({
|
||||
const result = await fetchReadOnlyFunction({
|
||||
contractName,
|
||||
functionName: readonlyFunctionName,
|
||||
functionArgs: clarityArgs,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "clarity-codegen",
|
||||
"version": "0.5.3",
|
||||
"version": "1.0.0-beta.1",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
@@ -34,7 +34,8 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@stacks/transactions": "^6.5.2",
|
||||
"@stacks/transactions": "^7.0.2",
|
||||
"@stacks/common": "^7.0.2",
|
||||
"@types/lodash": "^4.14.194",
|
||||
"@types/node": "^20.1.5",
|
||||
"@types/yargs": "^17.0.24",
|
||||
@@ -49,6 +50,7 @@
|
||||
"yqueue": "^1.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@stacks/transactions": "*"
|
||||
"@stacks/transactions": "^7.0.2",
|
||||
"@stacks/common": "^7.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
46
pnpm-lock.yaml
generated
46
pnpm-lock.yaml
generated
@@ -24,9 +24,12 @@ importers:
|
||||
specifier: ^1.0.1
|
||||
version: 1.0.1
|
||||
devDependencies:
|
||||
'@stacks/common':
|
||||
specifier: ^7.0.2
|
||||
version: 7.0.2
|
||||
'@stacks/transactions':
|
||||
specifier: ^6.5.2
|
||||
version: 6.5.2
|
||||
specifier: ^7.0.2
|
||||
version: 7.0.2
|
||||
'@types/lodash':
|
||||
specifier: ^4.14.194
|
||||
version: 4.14.194
|
||||
@@ -51,27 +54,21 @@ packages:
|
||||
'@noble/secp256k1@1.7.1':
|
||||
resolution: {integrity: sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==}
|
||||
|
||||
'@stacks/common@6.5.5':
|
||||
resolution: {integrity: sha512-6v2AVHTTryvl1Govu5rmBXLywAyen2fU3doMCx/7Lk/tFLc4OjMEx4uf1wzpPx1zw/fwJnvoz74OrT/RSALDYw==}
|
||||
'@stacks/common@7.0.2':
|
||||
resolution: {integrity: sha512-+RSecHdkxOtswmE4tDDoZlYEuULpnTQVeDIG5eZ32opK8cFxf4EugAcK9CsIsHx/Se1yTEaQ21WGATmJGK84lQ==}
|
||||
|
||||
'@stacks/network@6.5.5':
|
||||
resolution: {integrity: sha512-lw7+g6UhOpvWasMeRYMb2OGRKm9ptYkGt27Usg3Eo0z/pu20jZxvHXLBMdDQqxNQOOmwiG4FadICnwTlmnHaqw==}
|
||||
'@stacks/network@7.0.2':
|
||||
resolution: {integrity: sha512-XzHnoWqku/jRrTgMXhmh3c+I0O9vDH24KlhzGDZtBu+8CGGyHNPAZzGwvoUShonMXrXjEnfO9IYQwV5aJhfv6g==}
|
||||
|
||||
'@stacks/stacks-blockchain-api-types@7.1.10':
|
||||
resolution: {integrity: sha512-HGU8Z6YcGyebyKO1s1x5BXVu6dCojyhlKxoGTOzqElLiAB84eP8bs49PS+ttrBM0O7k02oXhDmi6cW3VcfS+/Q==}
|
||||
|
||||
'@stacks/transactions@6.5.2':
|
||||
resolution: {integrity: sha512-xL4XF4xSFFJ+VMzeahBenGdg1T+y0Q0fSNA09jz7knTnnXvdAzzC+RP59xzuIjrAY/IWYO3X1sf0MGm9IIhYOg==}
|
||||
|
||||
'@types/bn.js@5.1.1':
|
||||
resolution: {integrity: sha512-qNrYbZqMx0uJAfKnKclPh+dTwK33KfLHYqtyODwd5HnXOjnkhc4qgn3BrK6RWyGZm5+sIFE7Q7Vz6QQtJB7w7g==}
|
||||
'@stacks/transactions@7.0.2':
|
||||
resolution: {integrity: sha512-m2bvchqUeYv1ttXuC0EukW8UX4xBXTDcYb8bXmfI1RG89HXAvvCCgr5aiadU6zbutgoXvm8mquDt3nww0PO4Jg==}
|
||||
|
||||
'@types/lodash@4.14.194':
|
||||
resolution: {integrity: sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==}
|
||||
|
||||
'@types/node@18.17.12':
|
||||
resolution: {integrity: sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==}
|
||||
|
||||
'@types/node@20.1.5':
|
||||
resolution: {integrity: sha512-IvGD1CD/nego63ySR7vrAKEX3AJTcmrAN2kn+/sDNLi1Ff5kBzDeEdqWDplK+0HAEoLYej137Sk0cUU8OLOlMg==}
|
||||
|
||||
@@ -234,39 +231,30 @@ snapshots:
|
||||
|
||||
'@noble/secp256k1@1.7.1': {}
|
||||
|
||||
'@stacks/common@6.5.5':
|
||||
dependencies:
|
||||
'@types/bn.js': 5.1.1
|
||||
'@types/node': 18.17.12
|
||||
'@stacks/common@7.0.2': {}
|
||||
|
||||
'@stacks/network@6.5.5':
|
||||
'@stacks/network@7.0.2':
|
||||
dependencies:
|
||||
'@stacks/common': 6.5.5
|
||||
'@stacks/common': 7.0.2
|
||||
cross-fetch: 3.1.8
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@stacks/stacks-blockchain-api-types@7.1.10': {}
|
||||
|
||||
'@stacks/transactions@6.5.2':
|
||||
'@stacks/transactions@7.0.2':
|
||||
dependencies:
|
||||
'@noble/hashes': 1.1.5
|
||||
'@noble/secp256k1': 1.7.1
|
||||
'@stacks/common': 6.5.5
|
||||
'@stacks/network': 6.5.5
|
||||
'@stacks/common': 7.0.2
|
||||
'@stacks/network': 7.0.2
|
||||
c32check: 2.0.0
|
||||
lodash.clonedeep: 4.5.0
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@types/bn.js@5.1.1':
|
||||
dependencies:
|
||||
'@types/node': 20.1.5
|
||||
|
||||
'@types/lodash@4.14.194': {}
|
||||
|
||||
'@types/node@18.17.12': {}
|
||||
|
||||
'@types/node@20.1.5': {}
|
||||
|
||||
'@types/yargs-parser@21.0.0': {}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
AnchorMode,
|
||||
ClarityValue,
|
||||
FungiblePostCondition,
|
||||
PostCondition,
|
||||
type ClarityValue,
|
||||
type FungiblePostCondition,
|
||||
type PostCondition,
|
||||
PostConditionMode,
|
||||
STXPostCondition,
|
||||
type StxPostCondition,
|
||||
} from "@stacks/transactions";
|
||||
import { StringOnly } from "../utils/helpers";
|
||||
import {
|
||||
import type { StringOnly } from "../utils/helpers";
|
||||
import type {
|
||||
ContractBaseType,
|
||||
OpenCallFunctionDescriptor,
|
||||
ParameterObjOfDescriptor,
|
||||
@@ -35,7 +35,7 @@ export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
|
||||
: never,
|
||||
options?: {
|
||||
deployerAddress?: string;
|
||||
postConditions?: (FungiblePostCondition | STXPostCondition)[];
|
||||
postConditions?: (FungiblePostCondition | StxPostCondition)[];
|
||||
}
|
||||
) => ContractCallOptions;
|
||||
|
||||
@@ -68,7 +68,7 @@ export const composeTxOptionsFactory =
|
||||
const deployerAddress =
|
||||
options.deployerAddress ?? factoryOptions.deployerAddress;
|
||||
if (deployerAddress == null) {
|
||||
throw new Error(`[composeTxOptionsFactory] deployer address required`);
|
||||
throw new Error("[composeTxOptionsFactory] deployer address required");
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ClarityType,
|
||||
ClarityValue,
|
||||
} from "@stacks/transactions";
|
||||
import {hexToBytes} from '@stacks/common'
|
||||
import { Decoder, Response, UnboxDecoder } from "./types";
|
||||
|
||||
export class ClarityError extends Error {
|
||||
@@ -32,21 +33,21 @@ export const principalResult: Decoder<string> = (result) => {
|
||||
|
||||
export const addressResult: Decoder<string> = (result) => {
|
||||
if (result.type === ClarityType.PrincipalStandard) {
|
||||
return addressToString(result.address);
|
||||
return result.value;
|
||||
}
|
||||
throw new Error(`Expected principal, got ${result.type}`);
|
||||
};
|
||||
|
||||
export const contractResult: Decoder<`${string}.${string}`> = (result) => {
|
||||
if (result.type === ClarityType.PrincipalContract) {
|
||||
return `${addressToString(result.address)}.${result.contractName.content}`;
|
||||
return result.value;
|
||||
}
|
||||
throw new Error(`Expected principal, got ${result.type}`);
|
||||
};
|
||||
|
||||
export const intResult: Decoder<bigint> = (result) => {
|
||||
if (result.type === ClarityType.Int || result.type === ClarityType.UInt) {
|
||||
return result.value;
|
||||
return BigInt(result.value);
|
||||
}
|
||||
throw new Error(`Expected integer, got ${result.type}`);
|
||||
};
|
||||
@@ -56,14 +57,14 @@ export const stringResult: Decoder<string> = (result) => {
|
||||
result.type === ClarityType.StringASCII ||
|
||||
result.type === ClarityType.StringUTF8
|
||||
) {
|
||||
return result.data;
|
||||
return result.value;
|
||||
}
|
||||
throw new Error(`Expected string, got ${result.type}`);
|
||||
};
|
||||
|
||||
export const bufferResult: Decoder<Uint8Array> = (result) => {
|
||||
if (result.type === ClarityType.Buffer) {
|
||||
return result.buffer;
|
||||
return hexToBytes(result.value);
|
||||
}
|
||||
throw new Error(`Expected buffer, got ${result.type}`);
|
||||
};
|
||||
@@ -73,7 +74,7 @@ export const defaultErrorDecoder: Decoder<Error> = (value: ClarityValue) => {
|
||||
value.type === ClarityType.StringASCII ||
|
||||
value.type === ClarityType.StringUTF8
|
||||
) {
|
||||
return new Error(value.data);
|
||||
return new Error(value.value);
|
||||
}
|
||||
if (value.type === ClarityType.UInt || value.type === ClarityType.Int) {
|
||||
return new ClarityError(Number(value.value));
|
||||
@@ -110,7 +111,8 @@ export function optionalDecoder<T>(
|
||||
return (value) => {
|
||||
if (value.type === ClarityType.OptionalNone) {
|
||||
return undefined;
|
||||
} else if (value.type === ClarityType.OptionalSome) {
|
||||
}
|
||||
if (value.type === ClarityType.OptionalSome) {
|
||||
return decoder(value.value);
|
||||
}
|
||||
return decoder(value);
|
||||
@@ -135,7 +137,7 @@ export function tupleDecoder<P extends Record<string, Decoder<any>>>(
|
||||
}
|
||||
const result = {} as any;
|
||||
for (const key of Object.keys(decorators)) {
|
||||
result[key] = decorators[key as keyof P]!(input.data[key]!);
|
||||
result[key] = decorators[key as keyof P]!(input.value[key]!);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -144,7 +146,7 @@ export function tupleDecoder<P extends Record<string, Decoder<any>>>(
|
||||
export function listDecoder<T>(decoder: Decoder<T>): Decoder<T[]> {
|
||||
return (value) => {
|
||||
if (value.type === ClarityType.List) {
|
||||
return value.list.map(decoder);
|
||||
return value.value.map(decoder);
|
||||
}
|
||||
throw new Error(`Expected list, got ${value.type}`);
|
||||
};
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { callReadOnlyFunction } from "@stacks/transactions";
|
||||
import { StringOnly } from "../utils/helpers";
|
||||
import {
|
||||
import { fetchCallReadOnlyFunction } from "@stacks/transactions";
|
||||
import type { StringOnly } from "../utils/helpers";
|
||||
import type {
|
||||
ContractBaseType,
|
||||
ParameterObjOfDescriptor,
|
||||
ReadonlyFunctionDescriptor,
|
||||
ReturnTypeOfDescriptor,
|
||||
} from "./contractBase";
|
||||
|
||||
export type CallReadOnlyFunctionFn = typeof callReadOnlyFunction;
|
||||
export type CallReadOnlyFunctionFn = typeof fetchCallReadOnlyFunction;
|
||||
|
||||
export type ExecuteReadonlyCallFn<Contracts extends ContractBaseType> = <
|
||||
T extends StringOnly<keyof Contracts>,
|
||||
@@ -66,7 +66,7 @@ export const executeReadonlyCallFactory =
|
||||
const _callReadOnlyFunction =
|
||||
options.callReadOnlyFunction ??
|
||||
factoryOptions.callReadOnlyFunction ??
|
||||
callReadOnlyFunction;
|
||||
fetchCallReadOnlyFunction;
|
||||
|
||||
const result = await _callReadOnlyFunction({
|
||||
contractName,
|
||||
|
||||
Reference in New Issue
Block a user