@clarigen/core 1.0.0-next.27 → 1.0.0-next.28
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/deno/index.d.ts +7 -3
- package/dist/deno/index.js +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/deno/index.d.ts
CHANGED
|
@@ -438,7 +438,7 @@ declare type FnToContractCall<T> = T extends TypedAbiFunction<infer Arg, infer R
|
|
|
438
438
|
declare type FunctionsToContractCalls<T> = T extends ContractFunctions ? {
|
|
439
439
|
[key in keyof T]: FnToContractCall<T[key]>;
|
|
440
440
|
} : never;
|
|
441
|
-
declare type FullContract<T> = T extends TypedAbi ?
|
|
441
|
+
declare type FullContract<T> = T extends TypedAbi ? FunctionsToContractCalls<T['functions']> & T & {
|
|
442
442
|
identifier: string;
|
|
443
443
|
} & {
|
|
444
444
|
contractFile: string;
|
|
@@ -446,7 +446,11 @@ declare type FullContract<T> = T extends TypedAbi ? T & FunctionsToContractCalls
|
|
|
446
446
|
declare type ContractFactory<T extends AllContracts> = {
|
|
447
447
|
[key in keyof T]: FullContract<T[key]>;
|
|
448
448
|
};
|
|
449
|
-
declare function
|
|
449
|
+
declare function contractsFactory<T extends AllContracts>(contracts: T, deployer: string): ContractFactory<T>;
|
|
450
|
+
declare function functionsFactory<T extends ContractFunctions>(functions: T, identifier: string): FunctionsToContractCalls<T>;
|
|
451
|
+
declare function contractFactory<T extends TypedAbi>(abi: T, identifier: string): {
|
|
452
|
+
[x: string]: ContractCallFunction<unknown[], unknown>;
|
|
453
|
+
} & FullContract<T>;
|
|
450
454
|
declare function deploymentFactory<T extends AllContracts>(contracts: T, deployer: DeploymentPlan): ContractFactory<T>;
|
|
451
455
|
|
|
452
456
|
interface PureContractInfo {
|
|
@@ -485,4 +489,4 @@ declare function broadcast(transaction: StacksTransaction, options: ApiOptions):
|
|
|
485
489
|
stacksTransaction: StacksTransaction;
|
|
486
490
|
}>;
|
|
487
491
|
|
|
488
|
-
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ClarityAbi, ClarityAbiFunction, ClarityAbiMap, ClarityAbiType, ClarityAbiTypeBool, ClarityAbiTypeBuffer, ClarityAbiTypeFungibleToken, ClarityAbiTypeInt128, ClarityAbiTypeList, ClarityAbiTypeNonFungibleToken, ClarityAbiTypeNone, ClarityAbiTypeOptional, ClarityAbiTypePrimitive, ClarityAbiTypePrincipal, ClarityAbiTypeResponse, ClarityAbiTypeStringAscii, ClarityAbiTypeStringUtf8, ClarityAbiTypeTraitReference, ClarityAbiTypeTuple, ClarityAbiTypeUInt128, ClarityAbiVariable, Compact, Contract, ContractBuilder, ContractCall, ContractCallFunction, ContractCallTyped, ContractCalls, ContractFactory, ContractFn, ContractFunctions, ContractInstance, ContractInstances, ContractReturn, ContractReturnErr, ContractReturnOk, Contracts, CoreNodeEvent, CoreNodeEventBase, CoreNodeEventType, DeploymentPlan, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FunctionsToContractCalls, MAINNET_BURN_ADDRESS, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TypedAbi, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, bootContractIdentifier, broadcast, contractFactory, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, makeContracts, ok, parseToCV, pureProxy, ro, roErr, roOk, toCamelCase, transformArgsToCV };
|
|
492
|
+
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ClarityAbi, ClarityAbiFunction, ClarityAbiMap, ClarityAbiType, ClarityAbiTypeBool, ClarityAbiTypeBuffer, ClarityAbiTypeFungibleToken, ClarityAbiTypeInt128, ClarityAbiTypeList, ClarityAbiTypeNonFungibleToken, ClarityAbiTypeNone, ClarityAbiTypeOptional, ClarityAbiTypePrimitive, ClarityAbiTypePrincipal, ClarityAbiTypeResponse, ClarityAbiTypeStringAscii, ClarityAbiTypeStringUtf8, ClarityAbiTypeTraitReference, ClarityAbiTypeTuple, ClarityAbiTypeUInt128, ClarityAbiVariable, Compact, Contract, ContractBuilder, ContractCall, ContractCallFunction, ContractCallTyped, ContractCalls, ContractFactory, ContractFn, ContractFunctions, ContractInstance, ContractInstances, ContractReturn, ContractReturnErr, ContractReturnOk, Contracts, CoreNodeEvent, CoreNodeEventBase, CoreNodeEventType, DeploymentPlan, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FunctionsToContractCalls, MAINNET_BURN_ADDRESS, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TypedAbi, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, bootContractIdentifier, broadcast, contractFactory, contractsFactory, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, functionsFactory, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, makeContracts, ok, parseToCV, pureProxy, ro, roErr, roOk, toCamelCase, transformArgsToCV };
|
package/dist/deno/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/// <reference path="./index.d.ts" />
|
|
2
|
-
import{contractPrincipalCV as
|
|
2
|
+
var M=Object.defineProperty;var E=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var A=(t,e,n)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))D.call(e,n)&&A(t,n,e[n]);if(E)for(var n of E(e))U.call(e,n)&&A(t,n,e[n]);return t};import{contractPrincipalCV as j}from"https://deno.land/x/microstacks/clarity.js";var L="ST000000000000000000002AMW42H",q="SP000000000000000000002Q6VF78",d=(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),l=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{l+=s[0].toUpperCase()+s.slice(1)}),l},K=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},wt=t=>`${t.address}.${t.name}`,Pt=t=>{let e=K(t.contractFile);return j(t.address,e)};function Ft(t,e){return`${e?q:L}.${t}`}var H=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(H||{});function _t(t,e){return t.filter(n=>n.type===e)}function Bt(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,l=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:l,contract:s}}return n}import{addressToString as h,ClarityType as a,uintCV as G,contractPrincipalCV as J,intCV as z,stringAsciiCV as Q,stringUtf8CV as W,noneCV as Z,someCV as X,tupleCV as Y,listCV as tt,hexToCV as et,bufferCV as nt}from"https://deno.land/x/microstacks/clarity.js";import{isClarityAbiList as rt,isClarityAbiOptional as ot,isClarityAbiStringAscii as at,isClarityAbiStringUtf8 as it,isClarityAbiTuple as st,isClarityAbiBuffer as ct,parseToCV as k}from"https://deno.land/x/microstacks/transactions.js";import{bytesToAscii as lt,bytesToHex as pt}from"https://deno.land/x/microstacks/common.js";function ut(t){return{isOk:!0,value:t}}function ft(t){return{isOk:!1,value:t}}function S(t){if(t.type===a.PrincipalStandard)return h(t.address);if(t.type===a.PrincipalContract)return`${h(t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case a.BoolTrue:return!0;case a.BoolFalse:return!1;case a.Int:case a.UInt:return t.value;case a.Buffer:return t.buffer;case a.OptionalNone:return null;case a.OptionalSome:return p(t.value);case a.ResponseErr:return e?ft(p(t.value)):p(t.value);case a.ResponseOk:return e?ut(p(t.value)):p(t.value);case a.PrincipalStandard:case a.PrincipalContract:return S(t);case a.List:return t.list.map(o=>p(o));case a.Tuple:let n={};return Object.keys(t.data).map(o=>[o,p(t.data[o])]).forEach(([o,i])=>{n[o]=i}),n;case a.StringASCII:return t.data;case a.StringUTF8:return t.data}}function Gt(t,e=!1){return p(et(t),e)}function N(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(st(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=t[r.name];n[r.name]=y(o,r.type)}),Y(n)}else if(rt(e)){let r=t.map(o=>y(o,e.list.type));return tt(r)}else{if(ot(e))return t?X(y(t,e.optional)):Z();if(at(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return Q(t)}else if(it(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return W(t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return k(n,e)}else if(e==="uint128"){let n=N(t);return G(n.toString())}else if(e==="int128"){let n=N(t);return z(n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return J(n,r)}else if(ct(e))return nt(t)}return k(t,e)}function C(t,e="hex"){switch(t.type){case a.BoolTrue:return"true";case a.BoolFalse:return"false";case a.Int:return t.value.toString();case a.UInt:return`u${t.value.toString()}`;case a.Buffer:if(e==="tryAscii"){let n=lt(t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${pt(t.buffer)}`;case a.OptionalNone:return"none";case a.OptionalSome:return`(some ${C(t.value,e)})`;case a.ResponseErr:return`(err ${C(t.value,e)})`;case a.ResponseOk:return`(ok ${C(t.value,e)})`;case a.PrincipalStandard:case a.PrincipalContract:return`'${S(t)}`;case a.List:return`(list ${t.list.map(n=>C(n,e)).join(" ")})`;case a.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${C(t.data[n],e)})`).join(" ")})`;case a.StringASCII:return`"${t.data}"`;case a.StringUTF8:return`u"${t.data}"`}}function w(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function P(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function F(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function m(t,e){return w(t,e)}function yt(t,e){let n=t.abi.functions.find(o=>d(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>d(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var dt={get:yt},Ct=t=>new Proxy(t,dt);import{parseReadOnlyResponse as Tt,fetchContractDataMapEntry as mt}from"https://deno.land/x/microstacks/api.js";import{cvToHex as R,hexToCV as xt}from"https://deno.land/x/microstacks/clarity.js";import{fetchPrivate as gt}from"https://deno.land/x/microstacks/common.js";import{broadcastTransaction as vt}from"https://deno.land/x/microstacks/transactions.js";async function _(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:R(s))}),i=await gt(r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch{}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let l=Tt(await i.json());return p(l,!0)}async function ae(t,e){let n=await _(t,e);return P(n)}async function ie(t,e){let n=await _(t,e);return F(n)}async function se(t,e){let n=R(t.key),r=await mt({contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=xt(r.data);return p(o,!0)}async function ce(t,e){let n=await vt(t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function bt(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function O(t){return bt(t).filter(x)}function B(t){if(!x(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function V(t){if(!x(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function x(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}function ge(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,At(r,o)]}))}function Et(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,(...i)=>{let l=m(r,i),[s,u]=e.split(".");return{functionArgs:l,contractAddress:s,contractName:u,function:r,nativeArgs:i}}]))}function At(t,e){let n=T({},t);return n.identifier=e,T(T({},Et(t.functions,e)),n)}function ve(t,e){let n={};return O(e.plan.batches).forEach(o=>{let i=V(o),[l,s]=i.split("."),u=d(s),I=t[u],f=t[u];if(typeof f>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=f,f.contractFile=B(o),f.identifier=i,Object.keys(t[u].functions).forEach(c=>{let g=c,$=(...v)=>{let b=I.functions[g];return{functionArgs:m(b,v),contractAddress:l,contractName:f.contractName,function:b,nativeArgs:v}};f[g]=$})}),n}export{H as CoreNodeEventType,q as MAINNET_BURN_ADDRESS,L as TESTNET_BURN_ADDRESS,Ft as bootContractIdentifier,ce as broadcast,At as contractFactory,ge as contractsFactory,C as cvToString,p as cvToValue,ve as deploymentFactory,ft as err,F as expectErr,P as expectOk,se as fetchMapGet,_t as filterEvents,Et as functionsFactory,wt as getContractIdentifier,K as getContractNameFromPath,Pt as getContractPrincipalCV,Gt as hexToCvValue,Bt as makeContracts,ut as ok,y as parseToCV,Ct as pureProxy,_ as ro,ie as roErr,ae as roOk,d as toCamelCase,w as transformArgsToCV};
|
package/dist/index.d.ts
CHANGED
|
@@ -438,7 +438,7 @@ declare type FnToContractCall<T> = T extends TypedAbiFunction<infer Arg, infer R
|
|
|
438
438
|
declare type FunctionsToContractCalls<T> = T extends ContractFunctions ? {
|
|
439
439
|
[key in keyof T]: FnToContractCall<T[key]>;
|
|
440
440
|
} : never;
|
|
441
|
-
declare type FullContract<T> = T extends TypedAbi ?
|
|
441
|
+
declare type FullContract<T> = T extends TypedAbi ? FunctionsToContractCalls<T['functions']> & T & {
|
|
442
442
|
identifier: string;
|
|
443
443
|
} & {
|
|
444
444
|
contractFile: string;
|
|
@@ -446,7 +446,11 @@ declare type FullContract<T> = T extends TypedAbi ? T & FunctionsToContractCalls
|
|
|
446
446
|
declare type ContractFactory<T extends AllContracts> = {
|
|
447
447
|
[key in keyof T]: FullContract<T[key]>;
|
|
448
448
|
};
|
|
449
|
-
declare function
|
|
449
|
+
declare function contractsFactory<T extends AllContracts>(contracts: T, deployer: string): ContractFactory<T>;
|
|
450
|
+
declare function functionsFactory<T extends ContractFunctions>(functions: T, identifier: string): FunctionsToContractCalls<T>;
|
|
451
|
+
declare function contractFactory<T extends TypedAbi>(abi: T, identifier: string): {
|
|
452
|
+
[x: string]: ContractCallFunction<unknown[], unknown>;
|
|
453
|
+
} & FullContract<T>;
|
|
450
454
|
declare function deploymentFactory<T extends AllContracts>(contracts: T, deployer: DeploymentPlan): ContractFactory<T>;
|
|
451
455
|
|
|
452
456
|
interface PureContractInfo {
|
|
@@ -485,4 +489,4 @@ declare function broadcast(transaction: StacksTransaction, options: ApiOptions):
|
|
|
485
489
|
stacksTransaction: StacksTransaction;
|
|
486
490
|
}>;
|
|
487
491
|
|
|
488
|
-
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ClarityAbi, ClarityAbiFunction, ClarityAbiMap, ClarityAbiType, ClarityAbiTypeBool, ClarityAbiTypeBuffer, ClarityAbiTypeFungibleToken, ClarityAbiTypeInt128, ClarityAbiTypeList, ClarityAbiTypeNonFungibleToken, ClarityAbiTypeNone, ClarityAbiTypeOptional, ClarityAbiTypePrimitive, ClarityAbiTypePrincipal, ClarityAbiTypeResponse, ClarityAbiTypeStringAscii, ClarityAbiTypeStringUtf8, ClarityAbiTypeTraitReference, ClarityAbiTypeTuple, ClarityAbiTypeUInt128, ClarityAbiVariable, Compact, Contract, ContractBuilder, ContractCall, ContractCallFunction, ContractCallTyped, ContractCalls, ContractFactory, ContractFn, ContractFunctions, ContractInstance, ContractInstances, ContractReturn, ContractReturnErr, ContractReturnOk, Contracts, CoreNodeEvent, CoreNodeEventBase, CoreNodeEventType, DeploymentPlan, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FunctionsToContractCalls, MAINNET_BURN_ADDRESS, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TypedAbi, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, bootContractIdentifier, broadcast, contractFactory, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, makeContracts, ok, parseToCV, pureProxy, ro, roErr, roOk, toCamelCase, transformArgsToCV };
|
|
492
|
+
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ClarityAbi, ClarityAbiFunction, ClarityAbiMap, ClarityAbiType, ClarityAbiTypeBool, ClarityAbiTypeBuffer, ClarityAbiTypeFungibleToken, ClarityAbiTypeInt128, ClarityAbiTypeList, ClarityAbiTypeNonFungibleToken, ClarityAbiTypeNone, ClarityAbiTypeOptional, ClarityAbiTypePrimitive, ClarityAbiTypePrincipal, ClarityAbiTypeResponse, ClarityAbiTypeStringAscii, ClarityAbiTypeStringUtf8, ClarityAbiTypeTraitReference, ClarityAbiTypeTuple, ClarityAbiTypeUInt128, ClarityAbiVariable, Compact, Contract, ContractBuilder, ContractCall, ContractCallFunction, ContractCallTyped, ContractCalls, ContractFactory, ContractFn, ContractFunctions, ContractInstance, ContractInstances, ContractReturn, ContractReturnErr, ContractReturnOk, Contracts, CoreNodeEvent, CoreNodeEventBase, CoreNodeEventType, DeploymentPlan, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FunctionsToContractCalls, MAINNET_BURN_ADDRESS, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TypedAbi, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, bootContractIdentifier, broadcast, contractFactory, contractsFactory, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, functionsFactory, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, makeContracts, ok, parseToCV, pureProxy, ro, roErr, roOk, toCamelCase, transformArgsToCV };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _clarity = require('micro-stacks/clarity');var M="ST000000000000000000002AMW42H",D= exports.MAINNET_BURN_ADDRESS ="SP000000000000000000002Q6VF78",d= exports.toCamelCase =(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),l=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{l+=s[0].toUpperCase()+s.slice(1)}),l},U= exports.getContractNameFromPath =t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},vt= exports.getContractIdentifier =t=>`${t.address}.${t.name}`,Et= exports.getContractPrincipalCV =t=>{let e=U(t.contractFile);return _clarity.contractPrincipalCV.call(void 0, t.address,e)};function bt(t,e){return`${e?D:M}.${t}`}var j=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(j||{});function ht(t,e){return t.filter(n=>n.type===e)}function St(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,l=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:l,contract:s}}return n}var _transactions = require('micro-stacks/transactions');var _common = require('micro-stacks/common');function st(t){return{isOk:!0,value:t}}function ct(t){return{isOk:!1,value:t}}function N(t){if(t.type===_clarity.ClarityType.PrincipalStandard)return _clarity.addressToString.call(void 0, t.address);if(t.type===_clarity.ClarityType.PrincipalContract)return`${_clarity.addressToString.call(void 0, t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case _clarity.ClarityType.BoolTrue:return!0;case _clarity.ClarityType.BoolFalse:return!1;case _clarity.ClarityType.Int:case _clarity.ClarityType.UInt:return t.value;case _clarity.ClarityType.Buffer:return t.buffer;case _clarity.ClarityType.OptionalNone:return null;case _clarity.ClarityType.OptionalSome:return p(t.value);case _clarity.ClarityType.ResponseErr:return e?ct(p(t.value)):p(t.value);case _clarity.ClarityType.ResponseOk:return e?st(p(t.value)):p(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return N(t);case _clarity.ClarityType.List:return t.list.map(o=>p(o));case _clarity.ClarityType.Tuple:let n={};return Object.keys(t.data).map(o=>[o,p(t.data[o])]).forEach(([o,i])=>{n[o]=i}),n;case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function Mt(t,e=!1){return p(_clarity.hexToCV.call(void 0, t),e)}function S(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(_transactions.isClarityAbiTuple.call(void 0, e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=t[r.name];n[r.name]=y(o,r.type)}),_clarity.tupleCV.call(void 0, n)}else if(_transactions.isClarityAbiList.call(void 0, e)){let r=t.map(o=>y(o,e.list.type));return _clarity.listCV.call(void 0, r)}else{if(_transactions.isClarityAbiOptional.call(void 0, e))return t?_clarity.someCV.call(void 0, y(t,e.optional)):_clarity.noneCV.call(void 0, );if(_transactions.isClarityAbiStringAscii.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringAsciiCV.call(void 0, t)}else if(_transactions.isClarityAbiStringUtf8.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringUtf8CV.call(void 0, t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return _transactions.parseToCV.call(void 0, n,e)}else if(e==="uint128"){let n=S(t);return _clarity.uintCV.call(void 0, n.toString())}else if(e==="int128"){let n=S(t);return _clarity.intCV.call(void 0, n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return _clarity.contractPrincipalCV.call(void 0, n,r)}else if(_transactions.isClarityAbiBuffer.call(void 0, e))return _clarity.bufferCV.call(void 0, t)}return _transactions.parseToCV.call(void 0, t,e)}function C(t,e="hex"){switch(t.type){case _clarity.ClarityType.BoolTrue:return"true";case _clarity.ClarityType.BoolFalse:return"false";case _clarity.ClarityType.Int:return t.value.toString();case _clarity.ClarityType.UInt:return`u${t.value.toString()}`;case _clarity.ClarityType.Buffer:if(e==="tryAscii"){let n=_common.bytesToAscii.call(void 0, t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${_common.bytesToHex.call(void 0, t.buffer)}`;case _clarity.ClarityType.OptionalNone:return"none";case _clarity.ClarityType.OptionalSome:return`(some ${C(t.value,e)})`;case _clarity.ClarityType.ResponseErr:return`(err ${C(t.value,e)})`;case _clarity.ClarityType.ResponseOk:return`(ok ${C(t.value,e)})`;case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return`'${N(t)}`;case _clarity.ClarityType.List:return`(list ${t.list.map(n=>C(n,e)).join(" ")})`;case _clarity.ClarityType.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${C(t.data[n],e)})`).join(" ")})`;case _clarity.ClarityType.StringASCII:return`"${t.data}"`;case _clarity.ClarityType.StringUTF8:return`u"${t.data}"`}}function w(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function P(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function R(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function m(t,e){return w(t,e)}function lt(t,e){let n=t.abi.functions.find(o=>d(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>d(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var pt={get:lt},ut= exports.pureProxy =t=>new Proxy(t,pt);var _api = require('micro-stacks/api');async function F(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:_clarity.cvToHex.call(void 0, s))}),i=await _common.fetchPrivate.call(void 0, r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch (e2){}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let l=_api.parseReadOnlyResponse.call(void 0, await i.json());return p(l,!0)}async function Zt(t,e){let n=await F(t,e);return P(n)}async function Xt(t,e){let n=await F(t,e);return R(n)}async function Yt(t,e){let n=_clarity.cvToHex.call(void 0, t.key),r=await _api.fetchContractDataMapEntry.call(void 0, {contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=_clarity.hexToCV.call(void 0, r.data);return p(o,!0)}async function te(t,e){let n=await _transactions.broadcastTransaction.call(void 0, t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function O(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function B(t){return O(t).filter(x)}function V(t,e){let n=O(e.plan.batches);for(let r of n)if(!!x(r)){if("requirement-publish"in r){let[o,i]=r["requirement-publish"]["contract-id"].split(".");if(i===t)return r}else if("emulated-contract-publish"in r){if(r["emulated-contract-publish"]["contract-name"]===t)return r}else if("contract-publish"in r&&r["contract-publish"]["contract-name"]===t)return r}throw new Error(`Unable to find deployment tx for contract '${t}'`)}function g(t){if(!x(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function v(t){if(!x(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function x(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}function pe(t,e){let n=t;return Object.keys(t).forEach(r=>{let o=t[r];if(typeof e=="string")n[r].identifier=`${e}.${r}`;else{let i=V(o.contractName,e);n[r].contractFile=g(i),n[r].identifier=v(i)}Object.keys(t[r].functions).forEach(i=>{let l=i,s=(...u)=>{let T=o.functions[l];return{functionArgs:m(T,u),contractAddress:e,contractName:o.contractName,function:T,nativeArgs:u}};n[r][l]=s})}),n}function ue(t,e){let n={};return B(e.plan.batches).forEach(o=>{let i=v(o),[l,s]=i.split("."),u=d(s),T=t[u],f=t[u];if(typeof f>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=f,f.contractFile=g(o),f.identifier=i,Object.keys(t[u].functions).forEach(c=>{let E=c,I=(...b)=>{let A=T.functions[E];return{functionArgs:m(A,b),contractAddress:l,contractName:f.contractName,function:A,nativeArgs:b}};f[E]=I})}),n}exports.CoreNodeEventType = j; exports.MAINNET_BURN_ADDRESS = D; exports.TESTNET_BURN_ADDRESS = M; exports.bootContractIdentifier = bt; exports.broadcast = te; exports.contractFactory = pe; exports.cvToString = C; exports.cvToValue = p; exports.deploymentFactory = ue; exports.err = ct; exports.expectErr = R; exports.expectOk = P; exports.fetchMapGet = Yt; exports.filterEvents = ht; exports.getContractIdentifier = vt; exports.getContractNameFromPath = U; exports.getContractPrincipalCV = Et; exports.hexToCvValue = Mt; exports.makeContracts = St; exports.ok = st; exports.parseToCV = y; exports.pureProxy = ut; exports.ro = F; exports.roErr = Xt; exports.roOk = Zt; exports.toCamelCase = d; exports.transformArgsToCV = w;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var M=Object.defineProperty;var E=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var A=(t,e,n)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))D.call(e,n)&&A(t,n,e[n]);if(E)for(var n of E(e))U.call(e,n)&&A(t,n,e[n]);return t};var _clarity = require('micro-stacks/clarity');var L="ST000000000000000000002AMW42H",q= exports.MAINNET_BURN_ADDRESS ="SP000000000000000000002Q6VF78",d= exports.toCamelCase =(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),l=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{l+=s[0].toUpperCase()+s.slice(1)}),l},K= exports.getContractNameFromPath =t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},wt= exports.getContractIdentifier =t=>`${t.address}.${t.name}`,Pt= exports.getContractPrincipalCV =t=>{let e=K(t.contractFile);return _clarity.contractPrincipalCV.call(void 0, t.address,e)};function Ft(t,e){return`${e?q:L}.${t}`}var H=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(H||{});function _t(t,e){return t.filter(n=>n.type===e)}function Bt(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,l=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:l,contract:s}}return n}var _transactions = require('micro-stacks/transactions');var _common = require('micro-stacks/common');function ut(t){return{isOk:!0,value:t}}function ft(t){return{isOk:!1,value:t}}function S(t){if(t.type===_clarity.ClarityType.PrincipalStandard)return _clarity.addressToString.call(void 0, t.address);if(t.type===_clarity.ClarityType.PrincipalContract)return`${_clarity.addressToString.call(void 0, t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case _clarity.ClarityType.BoolTrue:return!0;case _clarity.ClarityType.BoolFalse:return!1;case _clarity.ClarityType.Int:case _clarity.ClarityType.UInt:return t.value;case _clarity.ClarityType.Buffer:return t.buffer;case _clarity.ClarityType.OptionalNone:return null;case _clarity.ClarityType.OptionalSome:return p(t.value);case _clarity.ClarityType.ResponseErr:return e?ft(p(t.value)):p(t.value);case _clarity.ClarityType.ResponseOk:return e?ut(p(t.value)):p(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return S(t);case _clarity.ClarityType.List:return t.list.map(o=>p(o));case _clarity.ClarityType.Tuple:let n={};return Object.keys(t.data).map(o=>[o,p(t.data[o])]).forEach(([o,i])=>{n[o]=i}),n;case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function Gt(t,e=!1){return p(_clarity.hexToCV.call(void 0, t),e)}function N(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(_transactions.isClarityAbiTuple.call(void 0, e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=t[r.name];n[r.name]=y(o,r.type)}),_clarity.tupleCV.call(void 0, n)}else if(_transactions.isClarityAbiList.call(void 0, e)){let r=t.map(o=>y(o,e.list.type));return _clarity.listCV.call(void 0, r)}else{if(_transactions.isClarityAbiOptional.call(void 0, e))return t?_clarity.someCV.call(void 0, y(t,e.optional)):_clarity.noneCV.call(void 0, );if(_transactions.isClarityAbiStringAscii.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringAsciiCV.call(void 0, t)}else if(_transactions.isClarityAbiStringUtf8.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringUtf8CV.call(void 0, t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return _transactions.parseToCV.call(void 0, n,e)}else if(e==="uint128"){let n=N(t);return _clarity.uintCV.call(void 0, n.toString())}else if(e==="int128"){let n=N(t);return _clarity.intCV.call(void 0, n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return _clarity.contractPrincipalCV.call(void 0, n,r)}else if(_transactions.isClarityAbiBuffer.call(void 0, e))return _clarity.bufferCV.call(void 0, t)}return _transactions.parseToCV.call(void 0, t,e)}function C(t,e="hex"){switch(t.type){case _clarity.ClarityType.BoolTrue:return"true";case _clarity.ClarityType.BoolFalse:return"false";case _clarity.ClarityType.Int:return t.value.toString();case _clarity.ClarityType.UInt:return`u${t.value.toString()}`;case _clarity.ClarityType.Buffer:if(e==="tryAscii"){let n=_common.bytesToAscii.call(void 0, t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${_common.bytesToHex.call(void 0, t.buffer)}`;case _clarity.ClarityType.OptionalNone:return"none";case _clarity.ClarityType.OptionalSome:return`(some ${C(t.value,e)})`;case _clarity.ClarityType.ResponseErr:return`(err ${C(t.value,e)})`;case _clarity.ClarityType.ResponseOk:return`(ok ${C(t.value,e)})`;case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return`'${S(t)}`;case _clarity.ClarityType.List:return`(list ${t.list.map(n=>C(n,e)).join(" ")})`;case _clarity.ClarityType.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${C(t.data[n],e)})`).join(" ")})`;case _clarity.ClarityType.StringASCII:return`"${t.data}"`;case _clarity.ClarityType.StringUTF8:return`u"${t.data}"`}}function w(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function P(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function F(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function m(t,e){return w(t,e)}function yt(t,e){let n=t.abi.functions.find(o=>d(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>d(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var dt={get:yt},Ct= exports.pureProxy =t=>new Proxy(t,dt);var _api = require('micro-stacks/api');async function _(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:_clarity.cvToHex.call(void 0, s))}),i=await _common.fetchPrivate.call(void 0, r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch (e2){}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let l=_api.parseReadOnlyResponse.call(void 0, await i.json());return p(l,!0)}async function ae(t,e){let n=await _(t,e);return P(n)}async function ie(t,e){let n=await _(t,e);return F(n)}async function se(t,e){let n=_clarity.cvToHex.call(void 0, t.key),r=await _api.fetchContractDataMapEntry.call(void 0, {contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=_clarity.hexToCV.call(void 0, r.data);return p(o,!0)}async function ce(t,e){let n=await _transactions.broadcastTransaction.call(void 0, t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function bt(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function O(t){return bt(t).filter(x)}function B(t){if(!x(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function V(t){if(!x(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function x(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}function ge(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,At(r,o)]}))}function Et(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,(...i)=>{let l=m(r,i),[s,u]=e.split(".");return{functionArgs:l,contractAddress:s,contractName:u,function:r,nativeArgs:i}}]))}function At(t,e){let n=T({},t);return n.identifier=e,T(T({},Et(t.functions,e)),n)}function ve(t,e){let n={};return O(e.plan.batches).forEach(o=>{let i=V(o),[l,s]=i.split("."),u=d(s),I=t[u],f=t[u];if(typeof f>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=f,f.contractFile=B(o),f.identifier=i,Object.keys(t[u].functions).forEach(c=>{let g=c,$=(...v)=>{let b=I.functions[g];return{functionArgs:m(b,v),contractAddress:l,contractName:f.contractName,function:b,nativeArgs:v}};f[g]=$})}),n}exports.CoreNodeEventType = H; exports.MAINNET_BURN_ADDRESS = q; exports.TESTNET_BURN_ADDRESS = L; exports.bootContractIdentifier = Ft; exports.broadcast = ce; exports.contractFactory = At; exports.contractsFactory = ge; exports.cvToString = C; exports.cvToValue = p; exports.deploymentFactory = ve; exports.err = ft; exports.expectErr = F; exports.expectOk = P; exports.fetchMapGet = se; exports.filterEvents = _t; exports.functionsFactory = Et; exports.getContractIdentifier = wt; exports.getContractNameFromPath = K; exports.getContractPrincipalCV = Pt; exports.hexToCvValue = Gt; exports.makeContracts = Bt; exports.ok = ut; exports.parseToCV = y; exports.pureProxy = Ct; exports.ro = _; exports.roErr = ie; exports.roOk = ae; exports.toCamelCase = d; exports.transformArgsToCV = w;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{contractPrincipalCV as
|
|
1
|
+
var M=Object.defineProperty;var E=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var A=(t,e,n)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))D.call(e,n)&&A(t,n,e[n]);if(E)for(var n of E(e))U.call(e,n)&&A(t,n,e[n]);return t};import{contractPrincipalCV as j}from"micro-stacks/clarity";var L="ST000000000000000000002AMW42H",q="SP000000000000000000002Q6VF78",d=(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),l=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{l+=s[0].toUpperCase()+s.slice(1)}),l},K=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},wt=t=>`${t.address}.${t.name}`,Pt=t=>{let e=K(t.contractFile);return j(t.address,e)};function Ft(t,e){return`${e?q:L}.${t}`}var H=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(H||{});function _t(t,e){return t.filter(n=>n.type===e)}function Bt(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,l=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:l,contract:s}}return n}import{addressToString as h,ClarityType as a,uintCV as G,contractPrincipalCV as J,intCV as z,stringAsciiCV as Q,stringUtf8CV as W,noneCV as Z,someCV as X,tupleCV as Y,listCV as tt,hexToCV as et,bufferCV as nt}from"micro-stacks/clarity";import{isClarityAbiList as rt,isClarityAbiOptional as ot,isClarityAbiStringAscii as at,isClarityAbiStringUtf8 as it,isClarityAbiTuple as st,isClarityAbiBuffer as ct,parseToCV as k}from"micro-stacks/transactions";import{bytesToAscii as lt,bytesToHex as pt}from"micro-stacks/common";function ut(t){return{isOk:!0,value:t}}function ft(t){return{isOk:!1,value:t}}function S(t){if(t.type===a.PrincipalStandard)return h(t.address);if(t.type===a.PrincipalContract)return`${h(t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case a.BoolTrue:return!0;case a.BoolFalse:return!1;case a.Int:case a.UInt:return t.value;case a.Buffer:return t.buffer;case a.OptionalNone:return null;case a.OptionalSome:return p(t.value);case a.ResponseErr:return e?ft(p(t.value)):p(t.value);case a.ResponseOk:return e?ut(p(t.value)):p(t.value);case a.PrincipalStandard:case a.PrincipalContract:return S(t);case a.List:return t.list.map(o=>p(o));case a.Tuple:let n={};return Object.keys(t.data).map(o=>[o,p(t.data[o])]).forEach(([o,i])=>{n[o]=i}),n;case a.StringASCII:return t.data;case a.StringUTF8:return t.data}}function Gt(t,e=!1){return p(et(t),e)}function N(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(st(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=t[r.name];n[r.name]=y(o,r.type)}),Y(n)}else if(rt(e)){let r=t.map(o=>y(o,e.list.type));return tt(r)}else{if(ot(e))return t?X(y(t,e.optional)):Z();if(at(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return Q(t)}else if(it(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return W(t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return k(n,e)}else if(e==="uint128"){let n=N(t);return G(n.toString())}else if(e==="int128"){let n=N(t);return z(n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return J(n,r)}else if(ct(e))return nt(t)}return k(t,e)}function C(t,e="hex"){switch(t.type){case a.BoolTrue:return"true";case a.BoolFalse:return"false";case a.Int:return t.value.toString();case a.UInt:return`u${t.value.toString()}`;case a.Buffer:if(e==="tryAscii"){let n=lt(t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${pt(t.buffer)}`;case a.OptionalNone:return"none";case a.OptionalSome:return`(some ${C(t.value,e)})`;case a.ResponseErr:return`(err ${C(t.value,e)})`;case a.ResponseOk:return`(ok ${C(t.value,e)})`;case a.PrincipalStandard:case a.PrincipalContract:return`'${S(t)}`;case a.List:return`(list ${t.list.map(n=>C(n,e)).join(" ")})`;case a.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${C(t.data[n],e)})`).join(" ")})`;case a.StringASCII:return`"${t.data}"`;case a.StringUTF8:return`u"${t.data}"`}}function w(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function P(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function F(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function m(t,e){return w(t,e)}function yt(t,e){let n=t.abi.functions.find(o=>d(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>d(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var dt={get:yt},Ct=t=>new Proxy(t,dt);import{parseReadOnlyResponse as Tt,fetchContractDataMapEntry as mt}from"micro-stacks/api";import{cvToHex as R,hexToCV as xt}from"micro-stacks/clarity";import{fetchPrivate as gt}from"micro-stacks/common";import{broadcastTransaction as vt}from"micro-stacks/transactions";async function _(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:R(s))}),i=await gt(r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch{}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let l=Tt(await i.json());return p(l,!0)}async function ae(t,e){let n=await _(t,e);return P(n)}async function ie(t,e){let n=await _(t,e);return F(n)}async function se(t,e){let n=R(t.key),r=await mt({contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=xt(r.data);return p(o,!0)}async function ce(t,e){let n=await vt(t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function bt(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function O(t){return bt(t).filter(x)}function B(t){if(!x(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function V(t){if(!x(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function x(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}function ge(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,At(r,o)]}))}function Et(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,(...i)=>{let l=m(r,i),[s,u]=e.split(".");return{functionArgs:l,contractAddress:s,contractName:u,function:r,nativeArgs:i}}]))}function At(t,e){let n=T({},t);return n.identifier=e,T(T({},Et(t.functions,e)),n)}function ve(t,e){let n={};return O(e.plan.batches).forEach(o=>{let i=V(o),[l,s]=i.split("."),u=d(s),I=t[u],f=t[u];if(typeof f>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=f,f.contractFile=B(o),f.identifier=i,Object.keys(t[u].functions).forEach(c=>{let g=c,$=(...v)=>{let b=I.functions[g];return{functionArgs:m(b,v),contractAddress:l,contractName:f.contractName,function:b,nativeArgs:v}};f[g]=$})}),n}export{H as CoreNodeEventType,q as MAINNET_BURN_ADDRESS,L as TESTNET_BURN_ADDRESS,Ft as bootContractIdentifier,ce as broadcast,At as contractFactory,ge as contractsFactory,C as cvToString,p as cvToValue,ve as deploymentFactory,ft as err,F as expectErr,P as expectOk,se as fetchMapGet,_t as filterEvents,Et as functionsFactory,wt as getContractIdentifier,K as getContractNameFromPath,Pt as getContractPrincipalCV,Gt as hexToCvValue,Bt as makeContracts,ut as ok,y as parseToCV,Ct as pureProxy,_ as ro,ie as roErr,ae as roOk,d as toCamelCase,w as transformArgsToCV};
|
package/package.json
CHANGED