@meshsdk/transaction 1.6.0-alpha.21 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/{index.d.mts → index.d.cts} +6 -35
- package/dist/index.d.ts +6 -35
- package/dist/index.js +1 -2029
- package/package.json +28 -11
- package/.turbo/turbo-build$colon$docs.log +0 -9
- package/.turbo/turbo-build$colon$mesh.log +0 -19
- package/.turbo/turbo-build.log +0 -19
- package/dist/index.mjs +0 -2014
- package/src/index.ts +0 -4
- package/src/mesh-tx-builder/index.ts +0 -259
- package/src/mesh-tx-builder/tx-builder-core.ts +0 -1180
- package/src/scripts/forge.script.ts +0 -63
- package/src/scripts/index.ts +0 -1
- package/src/transaction/index.ts +0 -609
- package/src/transaction/transaction-v2.ts +0 -81
- package/src/utxo-selection/common.ts +0 -113
- package/src/utxo-selection/experimental.ts +0 -137
- package/src/utxo-selection/index.ts +0 -69
- package/src/utxo-selection/keepRelevant.ts +0 -35
- package/src/utxo-selection/largestFirst.ts +0 -31
- package/src/utxo-selection/largestFirstMultiAsset.ts +0 -37
- package/tsconfig.json +0 -5
- package/types/index.ts +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var P=Object.create;var x=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var R=(a,t)=>{for(var e in t)x(a,e,{get:t[e],enumerable:!0})},y=(a,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of v(t))!E.call(a,r)&&r!==e&&x(a,r,{get:()=>t[r],enumerable:!(i=b(t,r))||i.enumerable});return a};var M=(a,t,e)=>(e=a!=null?P(V(a)):{},y(t||!a||!a.__esModule?x(e,"default",{value:a,enumerable:!0}):e,a)),O=a=>y(x({},"__esModule",{value:!0}),a);var A={};R(A,{ForgeScript:()=>w,MeshTxBuilder:()=>m,Transaction:()=>S});module.exports=O(A);var B=require("@meshsdk/core-csl");var T=M(require("json-bigint"),1),o=require("@meshsdk/common"),I=class{txEvaluationMultiplier=1.1;txOutput;addingPlutusScriptInput=!1;plutusSpendingScriptVersion;addingPlutusMint=!1;plutusMintingScriptVersion;addingPlutusWithdrawal=!1;plutusWithdrawalScriptVersion;_protocolParams=o.DEFAULT_PROTOCOL_PARAMETERS;mintItem;txInQueueItem;withdrawalItem;collateralQueueItem;refScriptTxInQueueItem;meshTxBuilderBody;constructor(){this.meshTxBuilderBody=(0,o.emptyTxBuilderBody)()}txIn=(t,e,i,r)=>(this.txInQueueItem&&this.queueInput(),this.addingPlutusScriptInput?this.txInQueueItem={type:"Script",txIn:{txHash:t,txIndex:e,amount:i,address:r},scriptTxIn:{}}:this.txInQueueItem={type:"PubKey",txIn:{txHash:t,txIndex:e,amount:i,address:r}},this.addingPlutusScriptInput=!1,this);txInScript=t=>{if(!this.txInQueueItem)throw Error("Undefined input");return this.txInQueueItem.type==="PubKey"&&(this.txInQueueItem={type:"SimpleScript",txIn:this.txInQueueItem.txIn,simpleScriptTxIn:{scriptSource:{type:"Provided",script:t}}}),this.txInQueueItem.type==="Script"&&(this.txInQueueItem.scriptTxIn.scriptSource={type:"Provided",script:{code:t,version:this.plutusSpendingScriptVersion||"V2"}}),this};txInDatumValue=(t,e="Mesh")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Datum value attempted to be called a non script input");if(this.txInQueueItem.type==="SimpleScript")throw Error("Datum value attempted to be called on a simple script input");let i=t;return e==="JSON"&&(i=this.castRawDataToJsonString(t)),e==="Mesh"?(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:e,content:t}},this):(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:e,content:i}},this)};txInInlineDatumPresent=()=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Inline datum present attempted to be called a non script input");if(this.txInQueueItem.type==="SimpleScript")throw Error("Inline datum present attempted to be called on a simple script input");let{txHash:t,txIndex:e}=this.txInQueueItem.txIn;return t&&e.toString()&&(this.txInQueueItem.scriptTxIn.datumSource={type:"Inline",txHash:t,txIndex:e}),this};txInRedeemerValue=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference redeemer attempted to be called a non script input");if(this.txInQueueItem.type==="SimpleScript")throw Error("Spending tx in reference redeemer attempted to be called on a simple script input");return this.txInQueueItem.scriptTxIn.redeemer=this.castBuilderDataToRedeemer(t,e,i),this};txOut=(t,e)=>(this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txOutput={address:t,amount:e},this);txOutDatumHashValue=(t,e="Mesh")=>{let i=t;if(this.txOutput){if(e==="Mesh")return this.txOutput.datum={type:"Hash",data:{type:e,content:i}},this;e==="JSON"&&(i=this.castRawDataToJsonString(t)),this.txOutput.datum={type:"Hash",data:{type:e,content:i}}}return this};txOutInlineDatumValue=(t,e="Mesh")=>{let i=t;if(this.txOutput){if(e==="Mesh")return this.txOutput.datum={type:"Inline",data:{type:e,content:i}},this;e==="JSON"&&(i=this.castRawDataToJsonString(t)),this.txOutput.datum={type:"Inline",data:{type:e,content:i}}}return this};txOutReferenceScript=(t,e="V2")=>(this.txOutput&&(this.txOutput.referenceScript={code:t,version:e}),this);spendingPlutusScriptV1=()=>(this.addingPlutusScriptInput=!0,this.plutusSpendingScriptVersion="V1",this);spendingPlutusScriptV2=()=>(this.addingPlutusScriptInput=!0,this.plutusSpendingScriptVersion="V2",this);spendingPlutusScriptV3=()=>(this.addingPlutusScriptInput=!0,this.plutusSpendingScriptVersion="V3",this);spendingTxInReference=(t,e,i)=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference attempted to be called a non script input");if(this.txInQueueItem.type==="SimpleScript")throw Error("Spending tx in reference attempted to be called on a simple script input");return this.txInQueueItem.scriptTxIn.scriptSource={type:"Inline",txHash:t,txIndex:e,scriptHash:i,version:this.plutusSpendingScriptVersion||"V2",scriptSize:"0"},this};spendingReferenceTxInInlineDatumPresent=()=>(this.txInInlineDatumPresent(),this);spendingReferenceTxInRedeemerValue=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>(this.txInRedeemerValue(t,e,i),this);readOnlyTxInReference=(t,e)=>(this.meshTxBuilderBody.referenceInputs.push({txHash:t,txIndex:e}),this);mintPlutusScriptV1=()=>(this.addingPlutusMint=!0,this.plutusMintingScriptVersion="V1",this);mintPlutusScriptV2=()=>(this.addingPlutusMint=!0,this.plutusMintingScriptVersion="V2",this);mintPlutusScriptV3=()=>(this.addingPlutusMint=!0,this.plutusMintingScriptVersion="V3",this);mint=(t,e,i)=>(this.mintItem&&this.queueMint(),this.mintItem={type:this.addingPlutusMint?"Plutus":"Native",policyId:e,assetName:i,amount:t},this.addingPlutusMint=!1,this);mintingScript=t=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");return this.mintItem.type==="Native"&&(this.mintItem.scriptSource={type:"Provided",scriptCode:t}),this.mintItem.type==="Plutus"&&(this.mintItem.scriptSource={type:"Provided",script:{code:t,version:this.plutusMintingScriptVersion||"V2"}}),this};mintTxInReference=(t,e)=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");return this.mintItem.scriptSource={type:"Inline",txHash:t,txIndex:e,version:this.plutusMintingScriptVersion,scriptSize:"0",scriptHash:""},this};mintReferenceTxInRedeemerValue=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>{if(!this.mintItem)throw Error("Undefined mint");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(this.mintItem.type=="Plutus"&&!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");return this.mintItem.redeemer=this.castBuilderDataToRedeemer(t,e,i),this};mintRedeemerValue=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>(this.mintReferenceTxInRedeemerValue(t,e,i),this);requiredSignerHash=t=>(this.meshTxBuilderBody.requiredSignatures.push(t),this);txInCollateral=(t,e,i,r)=>(this.collateralQueueItem&&this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem={type:"PubKey",txIn:{txHash:t,txIndex:e,amount:i,address:r}},this);withdrawalPlutusScriptV1=()=>(this.addingPlutusWithdrawal=!0,this.plutusWithdrawalScriptVersion="V1",this);withdrawalPlutusScriptV2=()=>(this.addingPlutusWithdrawal=!0,this.plutusWithdrawalScriptVersion="V2",this);withdrawalPlutusScriptV3=()=>(this.addingPlutusWithdrawal=!0,this.plutusWithdrawalScriptVersion="V3",this);withdrawal=(t,e)=>{if(this.withdrawalItem&&this.queueWithdrawal(),this.addingPlutusWithdrawal){let r={plutusScriptWithdrawal:{address:t,coin:e}};return this.meshTxBuilderBody.withdrawals.push(r),this}let i={pubKeyWithdrawal:{address:t,coin:e}};return this.meshTxBuilderBody.withdrawals.push(i),this};withdrawalScript=(t,e)=>{if(!this.withdrawalItem)throw Error("withdrawalScript: Undefined withdrawal");if(!("plutusScriptWithdrawal"in this.withdrawalItem))throw Error("withdrawalScript: Adding script to non plutus withdrawal");return this.withdrawalItem.plutusScriptWithdrawal.scriptSource={type:"Provided",script:{code:t,version:this.plutusWithdrawalScriptVersion||"V2"}},this};withdrawalTxInReference=(t,e,i,r)=>{if(!this.withdrawalItem)throw Error("withdrawalTxInReference: Undefined withdrawal");if(!("plutusScriptWithdrawal"in this.withdrawalItem))throw Error("withdrawalTxInReference: Adding script reference to non plutus withdrawal");this.withdrawalItem.plutusScriptWithdrawal.scriptSource={type:"Inline",txHash:t,txIndex:e,scriptHash:i,version:this.plutusWithdrawalScriptVersion||"V2",scriptSize:r||"0"}};withdrawalRedeemerValue=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>{if(!this.withdrawalItem)throw Error("withdrawalRedeemerValue: Undefined withdrawal");if(!("plutusScriptWithdrawal"in this.withdrawalItem))throw Error("withdrawalRedeemerValue: Adding redeemer to non plutus withdrawal");return this.withdrawalItem.plutusScriptWithdrawal.redeemer=this.castBuilderDataToRedeemer(t,e,i),this};registerPoolCertificate=t=>(this.meshTxBuilderBody.certificates.push({type:"RegisterPool",poolParams:t}),this);registerStakeCertificate=t=>(this.meshTxBuilderBody.certificates.push({type:"RegisterStake",stakeKeyHash:t}),this);delegateStakeCertificate=(t,e)=>(this.meshTxBuilderBody.certificates.push({type:"DelegateStake",stakeKeyHash:t,poolId:e}),this);deregisterStakeCertificate=t=>(this.meshTxBuilderBody.certificates.push({type:"DeregisterStake",stakeKeyHash:t}),this);retirePoolCertificate=(t,e)=>(this.meshTxBuilderBody.certificates.push({type:"RetirePool",poolId:t,epoch:e}),this);changeAddress=t=>(this.meshTxBuilderBody.changeAddress=t,this);invalidBefore=t=>(this.meshTxBuilderBody.validityRange.invalidBefore=t,this);invalidHereafter=t=>(this.meshTxBuilderBody.validityRange.invalidHereafter=t,this);metadataValue=(t,e)=>{let i=T.default.stringify(e);return this.meshTxBuilderBody.metadata.push({tag:t,metadata:i}),this};signingKey=t=>(this.meshTxBuilderBody.signingKey.push(t),this);selectUtxosFrom=(t,e="experimental",i="5000000",r=!0)=>{this.meshTxBuilderBody.extraInputs=t;let s={threshold:i,strategy:e,includeTxFees:r};return this.meshTxBuilderBody.selectionConfig={...this.meshTxBuilderBody.selectionConfig,...s},this};protocolParams=t=>{let e={...o.DEFAULT_PROTOCOL_PARAMETERS,...t};return this._protocolParams=e,this};queueAllLastItem=()=>{this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txInQueueItem&&this.queueInput(),this.collateralQueueItem&&(this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem=void 0),this.mintItem&&this.queueMint(),this.withdrawalItem&&this.queueWithdrawal()};queueInput=()=>{if(!this.txInQueueItem)throw Error("queueInput: Undefined input");if(this.txInQueueItem.type==="Script")if(this.txInQueueItem.scriptTxIn){if(!this.txInQueueItem.scriptTxIn.datumSource)throw Error("queueInput: Script input does not contain datum information");if(!this.txInQueueItem.scriptTxIn.redeemer)throw Error("queueInput: Script input does not contain redeemer information");if(!this.txInQueueItem.scriptTxIn.scriptSource)throw Error("queueInput: Script input does not contain script information")}else throw Error("queueInput: Script input does not contain script, datum, or redeemer information");this.meshTxBuilderBody.inputs.push(this.txInQueueItem),this.txInQueueItem=void 0};queueMint=()=>{if(!this.mintItem)throw Error("queueMint: Undefined mint");if(!this.mintItem.scriptSource)throw Error("queueMint: Missing mint script information");this.meshTxBuilderBody.mints.push(this.mintItem),this.mintItem=void 0};queueWithdrawal=()=>{if(!this.withdrawalItem)throw Error("queueWithdrawal: Undefined withdrawal");if("plutusScriptWithdrawal"in this.withdrawalItem){if(!this.withdrawalItem.plutusScriptWithdrawal.scriptSource)throw Error("queueWithdrawal: Missing withdrawal script information");if(!this.withdrawalItem.plutusScriptWithdrawal.redeemer)throw Error("queueWithdrawal: Missing withdrawal redeemer information")}this.meshTxBuilderBody.withdrawals.push(this.withdrawalItem),this.withdrawalItem=void 0};castRawDataToJsonString=t=>typeof t=="object"?T.default.stringify(t):t;castBuilderDataToRedeemer=(t,e="Mesh",i={...o.DEFAULT_REDEEMER_BUDGET})=>{let r,s=t;return e==="Mesh"?(r={data:{type:e,content:s},exUnits:i},r):(e==="JSON"&&(s=this.castRawDataToJsonString(t)),r={data:{type:e,content:s},exUnits:i},r)};updateRedeemer=(t,e)=>{e.forEach(i=>{switch(i.tag){case"SPEND":{let r=t.inputs[i.index];r.type=="Script"&&r.scriptTxIn.redeemer&&(r.scriptTxIn.redeemer.exUnits.mem=Math.floor(i.budget.mem*this.txEvaluationMultiplier),r.scriptTxIn.redeemer.exUnits.steps=Math.floor(i.budget.steps*this.txEvaluationMultiplier));break}case"MINT":{let r=t.mints[i.index];r.type=="Plutus"&&r.redeemer&&(r.redeemer.exUnits.mem=Math.floor(i.budget.mem*this.txEvaluationMultiplier),r.redeemer.exUnits.steps=Math.floor(i.budget.steps*this.txEvaluationMultiplier));break}case"CERT":break;case"REWARD":break}})};addUtxosFromSelection=()=>{let t=this.meshTxBuilderBody.outputs.reduce((s,n)=>(n.amount.forEach(h=>{let{unit:c,quantity:f}=h,g=Number(s.get(c))||0;s.set(c,String(g+Number(f)))}),s),new Map);this.meshTxBuilderBody.inputs.reduce((s,n)=>(n.txIn.amount?.forEach(h=>{let{unit:c,quantity:f}=h,g=Number(s.get(c))||0;s.set(c,String(g-Number(f)))}),s),t),this.meshTxBuilderBody.mints.reduce((s,n)=>{let u={unit:n.policyId+n.assetName,quantity:String(n.amount)},h=Number(s.get(u.unit))||0;return s.set(u.unit,String(h-Number(u.quantity))),s},t);let e=this.meshTxBuilderBody.selectionConfig,i=new o.UtxoSelection(e.threshold,e.includeTxFees),r=[];switch(e.strategy){case"keepRelevant":r=i.keepRelevant(t,this.meshTxBuilderBody.extraInputs);case"largestFirst":r=i.largestFirst(t,this.meshTxBuilderBody.extraInputs);break;case"largestFirstMultiAsset":r=i.largestFirstMultiAsset(t,this.meshTxBuilderBody.extraInputs);break;default:r=i.experimental(t,this.meshTxBuilderBody.extraInputs);break}r.forEach(s=>{let n={type:"PubKey",txIn:{txHash:s.input.txHash,txIndex:s.input.outputIndex,amount:s.output.amount,address:s.output.address}};this.meshTxBuilderBody.inputs.push(n)})};removeDuplicateInputs=()=>{let{inputs:t}=this.meshTxBuilderBody,e=s=>`${s.txHash}#${s.txIndex}`,i=[],r=[];for(let s=0;s<t.length;s+=1){let n=t[s],u=e(n.txIn);i.includes(u)?(t.splice(s,1),s-=1):r.push(n)}this.meshTxBuilderBody.inputs=r};emptyTxBuilderBody=()=>(this.meshTxBuilderBody=(0,o.emptyTxBuilderBody)(),o.emptyTxBuilderBody);reset=()=>{this.meshTxBuilderBody=(0,o.emptyTxBuilderBody)(),this.txEvaluationMultiplier=1.1,this.txOutput=void 0,this.addingPlutusScriptInput=!1,this.plutusSpendingScriptVersion=void 0,this.addingPlutusMint=!1,this.plutusMintingScriptVersion=void 0,this.addingPlutusWithdrawal=!1,this.plutusWithdrawalScriptVersion=void 0,this._protocolParams=o.DEFAULT_PROTOCOL_PARAMETERS,this.mintItem=void 0,this.txInQueueItem=void 0,this.withdrawalItem=void 0,this.collateralQueueItem=void 0,this.refScriptTxInQueueItem=void 0}};var m=class extends I{serializer;fetcher;submitter;evaluator;txHex="";queriedTxHashes=new Set;queriedUTxOs={};constructor({serializer:t,fetcher:e,submitter:i,evaluator:r,params:s,isHydra:n=!1}={}){super(),t?this.serializer=t:this.serializer=new B.CSLSerializer,e&&(this.fetcher=e),i&&(this.submitter=i),r&&(this.evaluator=r),s&&this.protocolParams(s),n&&this.protocolParams({minFeeA:0,minFeeB:0,priceMem:0,priceStep:0,collateralPercent:0,coinsPerUtxoSize:0})}complete=async t=>{t?this.meshTxBuilderBody={...this.meshTxBuilderBody,...t}:this.queueAllLastItem(),this.removeDuplicateInputs();let{inputs:e,collaterals:i}=this.meshTxBuilderBody,r=[...e,...i].filter(n=>!this.isInputComplete(n));await this.queryAllTxInfo(r),r.forEach(n=>{this.completeTxInformation(n)}),this.addUtxosFromSelection();let s=this.serializer.serializeTxBody(this.meshTxBuilderBody,this._protocolParams);if(this.evaluator){let n=await this.evaluator.evaluateTx(s).catch(u=>{throw Error(`Tx evaluation failed: ${u}`)});this.updateRedeemer(this.meshTxBuilderBody,n),s=this.serializer.serializeTxBody(this.meshTxBuilderBody,this._protocolParams)}return console.log(s),this.txHex=s,s};completeSync=t=>(t?this.meshTxBuilderBody=t:this.queueAllLastItem(),this.serializer.serializeTxBody(this.meshTxBuilderBody,this._protocolParams));completeSigning=()=>{let t=this.serializer.addSigningKeys(this.txHex,this.meshTxBuilderBody.signingKey);return this.txHex=t,t};submitTx=async t=>await this.submitter?.submitTx(t);getUTxOInfo=async t=>{let e=[];this.queriedTxHashes.has(t)||(this.queriedTxHashes.add(t),e=await this.fetcher?.fetchUTxOs(t)||[],this.queriedUTxOs[t]=e)};queryAllTxInfo=t=>{let e=[];if(t.length>0&&!this.fetcher)throw Error("Transaction information is incomplete while no fetcher instance is provided");for(let i=0;i<t.length;i++){let r=t[i];this.isInputInfoComplete(r)||e.push(this.getUTxOInfo(r.txIn.txHash)),r.type==="Script"&&r.scriptTxIn.scriptSource?.type==="Inline"&&!this.isRefScriptInfoComplete(r)&&e.push(this.getUTxOInfo(r.scriptTxIn.scriptSource.txHash))}return Promise.all(e)};completeTxInformation=t=>{if(!this.isInputInfoComplete(t)){let i=this.queriedUTxOs[t.txIn.txHash]?.find(n=>n.input.outputIndex===t.txIn.txIndex),r=i?.output.amount,s=i?.output.address;if(!r||r.length===0)throw Error(`Couldn't find value information for ${t.txIn.txHash}#${t.txIn.txIndex}`);if(t.txIn.amount=r,t.type==="PubKey"){if(!s||s==="")throw Error(`Couldn't find address information for ${t.txIn.txHash}#${t.txIn.txIndex}`);t.txIn.address=s}}if(t.type==="Script"&&t.scriptTxIn.scriptSource?.type=="Inline"&&!this.isRefScriptInfoComplete(t)){let e=t.scriptTxIn.scriptSource,r=this.queriedUTxOs[e.txHash].find(s=>s.input.outputIndex===e.txIndex);if(!r)throw Error(`Couldn't find script reference utxo for ${e.txHash}#${e.txIndex}`);e.scriptHash=r?.output.scriptHash}};isInputComplete=t=>t.type==="PubKey"?this.isInputInfoComplete(t):t.type==="Script"?this.isInputInfoComplete(t)&&this.isRefScriptInfoComplete(t):!0;isInputInfoComplete=t=>{let{amount:e,address:i}=t.txIn;return!(t.type==="PubKey"&&(!e||!i)||t.type==="Script"&&!e)};isRefScriptInfoComplete=t=>{let{scriptSource:e}=t.scriptTxIn;return!(e?.type==="Inline"&&!e?.scriptHash)}};var l=require("@meshsdk/core-cst"),w=class{static withOneSignature(t){let e=(0,l.deserializeEd25519KeyHash)((0,l.resolvePaymentKeyHash)(t));return(0,l.buildScriptPubkey)(e).toCbor()}static fromNativeScript(t){return(0,l.toNativeScript)(t).toCbor()}};var d=require("@meshsdk/common");var p=require("@meshsdk/core-cst"),S=class{txBuilder;initiator;isCollateralNeeded=!1;constructor(t){this.txBuilder=new m(t),this.initiator=t.initiator}sendAssets(t,e){return typeof e=="string"&&(e=[{unit:"lovelace",quantity:e}]),typeof t=="string"&&this.txBuilder.txOut(t,e),typeof t=="object"&&(this.txBuilder.txOut(t.address,e),t.datum&&(t.datum.inline?this.txBuilder.txOutInlineDatumValue(t.datum.value):this.txBuilder.txOutDatumHashValue(t.datum.value))),this}sendLovelace(t,e){return this.sendAssets(t,e)}sendToken(t,e,i){let r=[{unit:d.SUPPORTED_TOKENS[e],quantity:i}];return this.sendAssets(t,r)}sendValue(t,e){let i=e.output.amount;return this.sendAssets(t,i)}setTxInputs(t){return t.forEach(e=>{this.txBuilder.txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address)}),this}setTxRefInputs(t){return t.forEach(e=>{this.txBuilder.readOnlyTxInReference(e.input.txHash,e.input.outputIndex)}),this}setNativeScriptInput(t,e){let{scriptCbor:i}=this.txBuilder.serializer.deserializer.script.deserializeNativeScript(t);return this.txBuilder.txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).txInScript(i),this}redeemValue(t){let{value:e,script:i,datum:r,redeemer:s}=t,n=s||{data:{alternative:0,fields:["mesh"]},budget:d.DEFAULT_REDEEMER_BUDGET};if("code"in i&&(this.isCollateralNeeded=!0,this.spendingPlutusScript(i).txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).txInScript(i.code).txInRedeemerValue(n.data,"Mesh",n.budget)),"output"in i){if(!i.output.scriptRef)throw new Error("redeemValue: No script reference found in UTxO");let u=(0,p.fromScriptRef)(i.output.scriptRef);if(!u||!("code"in u))throw new Error("redeemValue: Script reference not found");this.isCollateralNeeded=!0,this.spendingPlutusScript(u).txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingTxInReference(i.input.txHash,i.input.outputIndex,i.output.scriptHash).txInRedeemerValue(n.data,"Mesh",n.budget)}return r?this.txBuilder.txInDatumValue(r):this.txBuilder.txInInlineDatumPresent(),this}mintAsset(t,e,i){let r=e.assetQuantity,s=(0,d.stringToHex)(e.assetName),n=(0,d.CIP68_100)(s);e.cip68ScriptAddress&&(s=(0,d.CIP68_222)(s));let u="";switch(typeof t){case"string":u=(0,p.deserializeNativeScript)(t).hash().toString(),this.txBuilder.mint(r,u,s).mintingScript(t),e.cip68ScriptAddress&&this.txBuilder.mint(r,u,n).mintingScript(t);break;case"object":if(!i)throw new Error("burnAsset: Redeemer data is required for Plutus minting");if("code"in t){u=(0,p.deserializePlutusScript)(t.code,t.version).hash().toString(),this.isCollateralNeeded=!0,this.mintPlutusScript(t).mint(r,u,s).mintingScript(t.code).mintRedeemerValue(i.data,"Mesh",i.budget),e.cip68ScriptAddress&&this.mintPlutusScript(t).mint(r,u,n).mintingScript(t.code).mintRedeemerValue(i.data,"Mesh",i.budget);break}if("output"in t){if(!t.output.scriptRef)throw new Error("mintAsset: No script reference found in UTxO");let h=(0,p.fromScriptRef)(t.output.scriptRef);if(!h)throw new Error("mintAsset: Script reference not found");if("code"in h){if(u=(0,p.deserializePlutusScript)(h.code,h.version).hash().toString(),this.isCollateralNeeded=!0,this.mintPlutusScript(h).mint(r,u,s).mintTxInReference(t.input.txHash,t.input.outputIndex).mintRedeemerValue(i.data,"Mesh",i.budget),e.cip68ScriptAddress){this.mintPlutusScript(h).mint(r,u,n).mintTxInReference(t.input.txHash,t.input.outputIndex).mintRedeemerValue(i.data,"Mesh",i.budget);break}break}else throw new Error("mintAsset: Reference script minting not implemented")}break}return e.metadata&&e.label&&this.setMetadata(Number(e.label),{[u]:{[e.assetName]:e.metadata},version:1}),e.recipient&&this.sendAssets(e.recipient,[{unit:u+s,quantity:e.assetQuantity}]),e.cip68ScriptAddress&&this.sendAssets({address:e.cip68ScriptAddress,datum:{inline:!0,value:(0,d.metadataToCip68)(e.metadata)}},[{unit:u+n,quantity:e.assetQuantity}]),this}burnAsset(t,e,i){let r="-"+e.quantity,s={assetName:(0,d.hexToString)(e.unit.slice(d.POLICY_ID_LENGTH)),assetQuantity:r};try{this.mintAsset(t,s,i)}catch(n){throw new Error("burnAsset: "+n)}return this}setChangeAddress(t){return this.txBuilder.changeAddress(t),this}setCollateral(t){return t.forEach(e=>{this.txBuilder.txInCollateral(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address)}),this}setRequiredSigners(t){return t.forEach(e=>{let{pubKeyHash:i}=this.txBuilder.serializer.deserializer.key.deserializeAddress(e);this.txBuilder.requiredSignerHash(i)}),this}setTimeToExpire(t){return this.txBuilder.invalidHereafter(Number(t)),this}setTimeToStart(t){return this.txBuilder.invalidBefore(Number(t)),this}setMetadata(t,e){return this.txBuilder.metadataValue(t.toString(),e),this}withdrawRewards(t,e){return this.txBuilder.withdrawal(t,e),this}delegateStake(t,e){return this.txBuilder.delegateStakeCertificate(this.txBuilder.serializer.resolver.keys.resolveStakeKeyHash(t),this.txBuilder.serializer.resolver.keys.resolveEd25519KeyHash(e)),this}deregisterStake(t){return this.txBuilder.deregisterStakeCertificate(this.txBuilder.serializer.resolver.keys.resolveStakeKeyHash(t)),this}registerStake(t){return this.txBuilder.registerStakeCertificate(this.txBuilder.serializer.resolver.keys.resolveStakeKeyHash(t)),this}registerPool(t){return this.txBuilder.registerPoolCertificate(t),this}retirePool(t,e){return this.txBuilder.retirePoolCertificate(t,e),this}async build(){try{return await this.addCollateralIfNeeded(),await this.addTxInputsAsNeeded(),await this.addChangeAddress(),this.txBuilder.complete()}catch(t){throw new Error(`[Transaction] An error occurred during build: ${t}.`)}}mintPlutusScript(t){switch(t.version){case"V1":this.txBuilder.mintPlutusScriptV1();break;case"V2":this.txBuilder.mintPlutusScriptV2();break;case"V3":this.txBuilder.mintPlutusScriptV3();break}return this.txBuilder}spendingPlutusScript(t){switch(t.version){case"V1":this.txBuilder.spendingPlutusScriptV1();break;case"V2":this.txBuilder.spendingPlutusScriptV2();break;case"V3":this.txBuilder.spendingPlutusScriptV3();break}return this.txBuilder}async addCollateralIfNeeded(){if(this.isCollateralNeeded){let t=await this.initiator.getCollateral();this.setCollateral(t)}}async addTxInputsAsNeeded(){let t=await this.initiator.getUtxos();this.txBuilder.selectUtxosFrom(t)}async addChangeAddress(){if(this.txBuilder.meshTxBuilderBody.changeAddress===""){let t=await this.initiator.getChangeAddress();this.setChangeAddress(t)}}};0&&(module.exports={ForgeScript,MeshTxBuilder,Transaction});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint, Unit, Quantity } from '@meshsdk/common';
|
|
1
|
+
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
3
2
|
|
|
4
3
|
declare class MeshTxBuilderCore {
|
|
5
4
|
txEvaluationMultiplier: number;
|
|
@@ -319,11 +318,12 @@ declare class MeshTxBuilderCore {
|
|
|
319
318
|
*/
|
|
320
319
|
signingKey: (skeyHex: string) => this;
|
|
321
320
|
/**
|
|
322
|
-
*
|
|
321
|
+
* Selects utxos to fill output value and puts them into inputs
|
|
323
322
|
* @param extraInputs The inputs already placed into the object will remain, these extra inputs will be used to fill the remaining value needed
|
|
323
|
+
* @param strategy The strategy to be used in utxo selection
|
|
324
324
|
* @param threshold Extra value needed to be selected for, usually for paying fees and min UTxO value of change output
|
|
325
325
|
*/
|
|
326
|
-
selectUtxosFrom: (extraInputs: UTxO[], threshold?:
|
|
326
|
+
selectUtxosFrom: (extraInputs: UTxO[], strategy?: UtxoSelectionStrategy, threshold?: string, includeTxFees?: boolean) => this;
|
|
327
327
|
/**
|
|
328
328
|
* Set the protocol parameters to be used for the transaction other than the default one
|
|
329
329
|
* @param params (Part of) the protocol parameters to be used for the transaction
|
|
@@ -368,7 +368,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
368
368
|
* @param customizedTx The optional customized transaction body
|
|
369
369
|
* @returns The signed transaction in hex ready to submit / signed by client
|
|
370
370
|
*/
|
|
371
|
-
complete: (customizedTx?: MeshTxBuilderBody) => Promise<string>;
|
|
371
|
+
complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
372
372
|
/**
|
|
373
373
|
* It builds the transaction without dependencies
|
|
374
374
|
* @param customizedTx The optional customized transaction body
|
|
@@ -562,33 +562,4 @@ declare class Transaction {
|
|
|
562
562
|
private addChangeAddress;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
declare const largestFirst: (lovelace: Quantity, initialUTxOSet: UTxO[], includeTxFees?: boolean, { maxTxSize, minFeeA, minFeeB }?: _meshsdk_common.Protocol) => UTxO[];
|
|
568
|
-
|
|
569
|
-
declare const largestFirstMultiAsset: (requestedOutputSet: Map<Unit, Quantity>, initialUTxOSet: UTxO[], includeTxFees?: boolean, parameters?: _meshsdk_common.Protocol) => UTxO[];
|
|
570
|
-
|
|
571
|
-
declare const experimentalSelectUtxos: (requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity) => UTxO[];
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* All UTxO selection algorithms follows below's interface
|
|
575
|
-
*
|
|
576
|
-
* Supported algorithms:
|
|
577
|
-
* - largestFirst - CIP2 suggested algorithm
|
|
578
|
-
* - largestFirstMultiAsset - CIP2 suggested algorithm
|
|
579
|
-
* - keepRelevant - CIP2 suggested algorithm
|
|
580
|
-
* - experimental - The always evolving algorithm according to the latest research
|
|
581
|
-
*
|
|
582
|
-
* @param requestedOutputSet
|
|
583
|
-
* @param initialUTxOSet
|
|
584
|
-
* @returns
|
|
585
|
-
*/
|
|
586
|
-
declare class UtxoSelection {
|
|
587
|
-
constructor();
|
|
588
|
-
largestFirst(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold?: string): UTxO[];
|
|
589
|
-
keepRelevant(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold?: string): UTxO[];
|
|
590
|
-
largestFirstMultiAsset(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity): UTxO[];
|
|
591
|
-
experimental(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity): UTxO[];
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export { ForgeScript, MeshTxBuilder, type MeshTxBuilderOptions, Transaction, type TransactionOptions, UtxoSelection, experimentalSelectUtxos, keepRelevant, largestFirst, largestFirstMultiAsset };
|
|
565
|
+
export { ForgeScript, MeshTxBuilder, type MeshTxBuilderOptions, Transaction, type TransactionOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint, Unit, Quantity } from '@meshsdk/common';
|
|
1
|
+
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
3
2
|
|
|
4
3
|
declare class MeshTxBuilderCore {
|
|
5
4
|
txEvaluationMultiplier: number;
|
|
@@ -319,11 +318,12 @@ declare class MeshTxBuilderCore {
|
|
|
319
318
|
*/
|
|
320
319
|
signingKey: (skeyHex: string) => this;
|
|
321
320
|
/**
|
|
322
|
-
*
|
|
321
|
+
* Selects utxos to fill output value and puts them into inputs
|
|
323
322
|
* @param extraInputs The inputs already placed into the object will remain, these extra inputs will be used to fill the remaining value needed
|
|
323
|
+
* @param strategy The strategy to be used in utxo selection
|
|
324
324
|
* @param threshold Extra value needed to be selected for, usually for paying fees and min UTxO value of change output
|
|
325
325
|
*/
|
|
326
|
-
selectUtxosFrom: (extraInputs: UTxO[], threshold?:
|
|
326
|
+
selectUtxosFrom: (extraInputs: UTxO[], strategy?: UtxoSelectionStrategy, threshold?: string, includeTxFees?: boolean) => this;
|
|
327
327
|
/**
|
|
328
328
|
* Set the protocol parameters to be used for the transaction other than the default one
|
|
329
329
|
* @param params (Part of) the protocol parameters to be used for the transaction
|
|
@@ -368,7 +368,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
368
368
|
* @param customizedTx The optional customized transaction body
|
|
369
369
|
* @returns The signed transaction in hex ready to submit / signed by client
|
|
370
370
|
*/
|
|
371
|
-
complete: (customizedTx?: MeshTxBuilderBody) => Promise<string>;
|
|
371
|
+
complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
372
372
|
/**
|
|
373
373
|
* It builds the transaction without dependencies
|
|
374
374
|
* @param customizedTx The optional customized transaction body
|
|
@@ -562,33 +562,4 @@ declare class Transaction {
|
|
|
562
562
|
private addChangeAddress;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
declare const largestFirst: (lovelace: Quantity, initialUTxOSet: UTxO[], includeTxFees?: boolean, { maxTxSize, minFeeA, minFeeB }?: _meshsdk_common.Protocol) => UTxO[];
|
|
568
|
-
|
|
569
|
-
declare const largestFirstMultiAsset: (requestedOutputSet: Map<Unit, Quantity>, initialUTxOSet: UTxO[], includeTxFees?: boolean, parameters?: _meshsdk_common.Protocol) => UTxO[];
|
|
570
|
-
|
|
571
|
-
declare const experimentalSelectUtxos: (requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity) => UTxO[];
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* All UTxO selection algorithms follows below's interface
|
|
575
|
-
*
|
|
576
|
-
* Supported algorithms:
|
|
577
|
-
* - largestFirst - CIP2 suggested algorithm
|
|
578
|
-
* - largestFirstMultiAsset - CIP2 suggested algorithm
|
|
579
|
-
* - keepRelevant - CIP2 suggested algorithm
|
|
580
|
-
* - experimental - The always evolving algorithm according to the latest research
|
|
581
|
-
*
|
|
582
|
-
* @param requestedOutputSet
|
|
583
|
-
* @param initialUTxOSet
|
|
584
|
-
* @returns
|
|
585
|
-
*/
|
|
586
|
-
declare class UtxoSelection {
|
|
587
|
-
constructor();
|
|
588
|
-
largestFirst(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold?: string): UTxO[];
|
|
589
|
-
keepRelevant(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold?: string): UTxO[];
|
|
590
|
-
largestFirstMultiAsset(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity): UTxO[];
|
|
591
|
-
experimental(requiredAssets: Map<Unit, Quantity>, inputs: UTxO[], threshold: Quantity): UTxO[];
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
export { ForgeScript, MeshTxBuilder, type MeshTxBuilderOptions, Transaction, type TransactionOptions, UtxoSelection, experimentalSelectUtxos, keepRelevant, largestFirst, largestFirstMultiAsset };
|
|
565
|
+
export { ForgeScript, MeshTxBuilder, type MeshTxBuilderOptions, Transaction, type TransactionOptions };
|