@meshsdk/transaction 1.6.0-alpha.20 → 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.cts +565 -0
- package/dist/index.d.ts +565 -0
- package/dist/index.js +1 -0
- package/package.json +24 -7
- 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});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
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';
|
|
2
|
+
|
|
3
|
+
declare class MeshTxBuilderCore {
|
|
4
|
+
txEvaluationMultiplier: number;
|
|
5
|
+
private txOutput?;
|
|
6
|
+
private addingPlutusScriptInput;
|
|
7
|
+
private plutusSpendingScriptVersion;
|
|
8
|
+
private addingPlutusMint;
|
|
9
|
+
private plutusMintingScriptVersion;
|
|
10
|
+
private addingPlutusWithdrawal;
|
|
11
|
+
private plutusWithdrawalScriptVersion;
|
|
12
|
+
protected _protocolParams: Protocol;
|
|
13
|
+
protected mintItem?: MintItem;
|
|
14
|
+
protected txInQueueItem?: TxIn;
|
|
15
|
+
protected withdrawalItem?: Withdrawal;
|
|
16
|
+
protected collateralQueueItem?: PubKeyTxIn;
|
|
17
|
+
protected refScriptTxInQueueItem?: RefTxIn;
|
|
18
|
+
meshTxBuilderBody: MeshTxBuilderBody;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Set the input for transaction
|
|
22
|
+
* @param txHash The transaction hash of the input UTxO
|
|
23
|
+
* @param txIndex The transaction index of the input UTxO
|
|
24
|
+
* @param amount The asset amount of index of the input UTxO
|
|
25
|
+
* @param address The address of the input UTxO
|
|
26
|
+
* @returns The MeshTxBuilder instance
|
|
27
|
+
*/
|
|
28
|
+
txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
|
|
29
|
+
/**
|
|
30
|
+
* Set the script for transaction input
|
|
31
|
+
* @param {string} scriptCbor The CborHex of the script
|
|
32
|
+
* @param version Optional - The Plutus script version
|
|
33
|
+
* @returns The MeshTxBuilder instance
|
|
34
|
+
*/
|
|
35
|
+
txInScript: (scriptCbor: string) => this;
|
|
36
|
+
/**
|
|
37
|
+
* Set the input datum for transaction input
|
|
38
|
+
* @param datum The datum in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
39
|
+
* @param type The datum type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
40
|
+
* @returns The MeshTxBuilder instance
|
|
41
|
+
*/
|
|
42
|
+
txInDatumValue: (datum: BuilderData["content"], type?: BuilderData["type"]) => this;
|
|
43
|
+
/**
|
|
44
|
+
* Tell the transaction builder that the input UTxO has inlined datum
|
|
45
|
+
* @returns The MeshTxBuilder instance
|
|
46
|
+
*/
|
|
47
|
+
txInInlineDatumPresent: () => this;
|
|
48
|
+
/**
|
|
49
|
+
* Set the redeemer for the reference input to be spent in same transaction
|
|
50
|
+
* @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
51
|
+
* @param type The redeemer data type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
52
|
+
* @param exUnits The execution units budget for the redeemer
|
|
53
|
+
* @returns The MeshTxBuilder instance
|
|
54
|
+
*/
|
|
55
|
+
txInRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
56
|
+
mem: number;
|
|
57
|
+
steps: number;
|
|
58
|
+
}) => this;
|
|
59
|
+
/**
|
|
60
|
+
* Set the output for transaction
|
|
61
|
+
* @param {string} address The recipient of the output
|
|
62
|
+
* @param {Asset[]} amount The amount of other native assets attached with UTxO
|
|
63
|
+
* @returns The MeshTxBuilder instance
|
|
64
|
+
*/
|
|
65
|
+
txOut: (address: string, amount: Asset[]) => this;
|
|
66
|
+
/**
|
|
67
|
+
* Set the output datum hash for transaction
|
|
68
|
+
* @param datum The datum in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
69
|
+
* @param type The datum type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
70
|
+
* @returns The MeshTxBuilder instance
|
|
71
|
+
*/
|
|
72
|
+
txOutDatumHashValue: (datum: BuilderData["content"], type?: BuilderData["type"]) => this;
|
|
73
|
+
/**
|
|
74
|
+
* Set the output inline datum for transaction
|
|
75
|
+
* @param datum The datum in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
76
|
+
* @param type The datum type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
77
|
+
* @returns The MeshTxBuilder instance
|
|
78
|
+
*/
|
|
79
|
+
txOutInlineDatumValue: (datum: BuilderData["content"], type?: BuilderData["type"]) => this;
|
|
80
|
+
/**
|
|
81
|
+
* Set the reference script to be attached with the output
|
|
82
|
+
* @param scriptCbor The CBOR hex of the script to be attached to UTxO as reference script
|
|
83
|
+
* @param version Optional - The Plutus script version
|
|
84
|
+
* @returns The MeshTxBuilder instance
|
|
85
|
+
*/
|
|
86
|
+
txOutReferenceScript: (scriptCbor: string, version?: LanguageVersion) => this;
|
|
87
|
+
/**
|
|
88
|
+
* Set the instruction that it is currently using V1 Plutus spending scripts
|
|
89
|
+
* @returns The MeshTxBuilder instance
|
|
90
|
+
*/
|
|
91
|
+
spendingPlutusScriptV1: () => this;
|
|
92
|
+
/**
|
|
93
|
+
* Set the instruction that it is currently using V2 Plutus spending scripts
|
|
94
|
+
* @returns The MeshTxBuilder instance
|
|
95
|
+
*/
|
|
96
|
+
spendingPlutusScriptV2: () => this;
|
|
97
|
+
/**
|
|
98
|
+
* Set the instruction that it is currently using V3 Plutus spending scripts
|
|
99
|
+
* @returns The MeshTxBuilder instance
|
|
100
|
+
*/
|
|
101
|
+
spendingPlutusScriptV3: () => this;
|
|
102
|
+
/**
|
|
103
|
+
* Set the reference input where it would also be spent in the transaction
|
|
104
|
+
* @param txHash The transaction hash of the reference UTxO
|
|
105
|
+
* @param txIndex The transaction index of the reference UTxO
|
|
106
|
+
* @param spendingScriptHash The script hash of the spending script
|
|
107
|
+
* @returns The MeshTxBuilder instance
|
|
108
|
+
*/
|
|
109
|
+
spendingTxInReference: (txHash: string, txIndex: number, spendingScriptHash?: string) => this;
|
|
110
|
+
/**
|
|
111
|
+
* [Alias of txInInlineDatumPresent] Set the instruction that the reference input has inline datum
|
|
112
|
+
* @returns The MeshTxBuilder instance
|
|
113
|
+
*/
|
|
114
|
+
spendingReferenceTxInInlineDatumPresent: () => this;
|
|
115
|
+
/**
|
|
116
|
+
* [Alias of txInRedeemerValue] Set the redeemer for the reference input to be spent in same transaction
|
|
117
|
+
* @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
118
|
+
* @param type The redeemer data type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
119
|
+
* @param exUnits The execution units budget for the redeemer
|
|
120
|
+
* @returns The MeshTxBuilder instance
|
|
121
|
+
*/
|
|
122
|
+
spendingReferenceTxInRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
123
|
+
mem: number;
|
|
124
|
+
steps: number;
|
|
125
|
+
}) => this;
|
|
126
|
+
/**
|
|
127
|
+
* Specify a read only reference input. This reference input is not witnessing anything it is simply provided in the plutus script context.
|
|
128
|
+
* @param txHash The transaction hash of the reference UTxO
|
|
129
|
+
* @param txIndex The transaction index of the reference UTxO
|
|
130
|
+
* @returns The MeshTxBuilder instance
|
|
131
|
+
*/
|
|
132
|
+
readOnlyTxInReference: (txHash: string, txIndex: number) => this;
|
|
133
|
+
/**
|
|
134
|
+
* Set the instruction that it is currently using V1 Plutus minting scripts
|
|
135
|
+
* @returns The MeshTxBuilder instance
|
|
136
|
+
*/
|
|
137
|
+
mintPlutusScriptV1: () => this;
|
|
138
|
+
/**
|
|
139
|
+
* Set the instruction that it is currently using V2 Plutus minting scripts
|
|
140
|
+
* @returns The MeshTxBuilder instance
|
|
141
|
+
*/
|
|
142
|
+
mintPlutusScriptV2: () => this;
|
|
143
|
+
/**
|
|
144
|
+
* Set the instruction that it is currently using V3 Plutus minting scripts
|
|
145
|
+
* @returns The MeshTxBuilder instance
|
|
146
|
+
*/
|
|
147
|
+
mintPlutusScriptV3: () => this;
|
|
148
|
+
/**
|
|
149
|
+
* Set the minting value of transaction
|
|
150
|
+
* @param quantity The quantity of asset to be minted
|
|
151
|
+
* @param policy The policy id of the asset to be minted
|
|
152
|
+
* @param name The hex of token name of the asset to be minted
|
|
153
|
+
* @returns The MeshTxBuilder instance
|
|
154
|
+
*/
|
|
155
|
+
mint: (quantity: string, policy: string, name: string) => this;
|
|
156
|
+
/**
|
|
157
|
+
* Set the minting script of current mint
|
|
158
|
+
* @param scriptCBOR The CBOR hex of the minting policy script
|
|
159
|
+
* @param version Optional - The Plutus script version
|
|
160
|
+
* @returns The MeshTxBuilder instance
|
|
161
|
+
*/
|
|
162
|
+
mintingScript: (scriptCBOR: string) => this;
|
|
163
|
+
/**
|
|
164
|
+
* Use reference script for minting
|
|
165
|
+
* @param txHash The transaction hash of the UTxO
|
|
166
|
+
* @param txIndex The transaction index of the UTxO
|
|
167
|
+
* @returns The MeshTxBuilder instance
|
|
168
|
+
*/
|
|
169
|
+
mintTxInReference: (txHash: string, txIndex: number) => this;
|
|
170
|
+
/**
|
|
171
|
+
* Set the redeemer for minting
|
|
172
|
+
* @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
173
|
+
* @param type The redeemer data type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
174
|
+
* @param exUnits The execution units budget for the redeemer
|
|
175
|
+
* @returns The MeshTxBuilder instance
|
|
176
|
+
*/
|
|
177
|
+
mintReferenceTxInRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
178
|
+
mem: number;
|
|
179
|
+
steps: number;
|
|
180
|
+
}) => this;
|
|
181
|
+
/**
|
|
182
|
+
* Set the redeemer for the reference input to be spent in same transaction
|
|
183
|
+
* @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
184
|
+
* @param type The redeemer data type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
185
|
+
* @param exUnits The execution units budget for the redeemer
|
|
186
|
+
* @returns The MeshTxBuilder instance
|
|
187
|
+
*/
|
|
188
|
+
mintRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
189
|
+
mem: number;
|
|
190
|
+
steps: number;
|
|
191
|
+
}) => this;
|
|
192
|
+
/**
|
|
193
|
+
* Set the required signer of the transaction
|
|
194
|
+
* @param pubKeyHash The PubKeyHash of the required signer
|
|
195
|
+
* @returns The MeshTxBuilder instance
|
|
196
|
+
*/
|
|
197
|
+
requiredSignerHash: (pubKeyHash: string) => this;
|
|
198
|
+
/**
|
|
199
|
+
* Set the collateral UTxO for the transaction
|
|
200
|
+
* @param txHash The transaction hash of the collateral UTxO
|
|
201
|
+
* @param txIndex The transaction index of the collateral UTxO
|
|
202
|
+
* @param amount The asset amount of index of the collateral UTxO
|
|
203
|
+
* @param address The address of the collateral UTxO
|
|
204
|
+
* @returns The MeshTxBuilder instance
|
|
205
|
+
*/
|
|
206
|
+
txInCollateral: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
|
|
207
|
+
/**
|
|
208
|
+
* Set the instruction that it is currently using V1 Plutus withdrawal scripts
|
|
209
|
+
* @returns The MeshTxBuilder instance
|
|
210
|
+
*/
|
|
211
|
+
withdrawalPlutusScriptV1: () => this;
|
|
212
|
+
/**
|
|
213
|
+
* Set the instruction that it is currently using V2 Plutus withdrawal scripts
|
|
214
|
+
* @returns The MeshTxBuilder instance
|
|
215
|
+
*/
|
|
216
|
+
withdrawalPlutusScriptV2: () => this;
|
|
217
|
+
/**
|
|
218
|
+
* Set the instruction that it is currently using V3 Plutus withdrawal scripts
|
|
219
|
+
* @returns The MeshTxBuilder instance
|
|
220
|
+
*/
|
|
221
|
+
withdrawalPlutusScriptV3: () => this;
|
|
222
|
+
/**
|
|
223
|
+
* Withdraw stake rewards in the MeshTxBuilder instance
|
|
224
|
+
* @param stakeAddress The address corresponding to the stake key
|
|
225
|
+
* @param coin The amount of lovelaces in the withdrawal
|
|
226
|
+
* @returns The MeshTxBuilder instance
|
|
227
|
+
*/
|
|
228
|
+
withdrawal: (stakeAddress: string, coin: string) => this;
|
|
229
|
+
/**
|
|
230
|
+
* Add a withdrawal script to the MeshTxBuilder instance
|
|
231
|
+
* @param scriptCbor The script in CBOR format
|
|
232
|
+
* @param version The language version
|
|
233
|
+
* @returns The MeshTxBuilder instance
|
|
234
|
+
*/
|
|
235
|
+
withdrawalScript: (scriptCbor: string, version: LanguageVersion) => this;
|
|
236
|
+
/**
|
|
237
|
+
* Add a withdrawal reference to the MeshTxBuilder instance
|
|
238
|
+
* @param txHash The transaction hash of reference UTxO
|
|
239
|
+
* @param txIndex The transaction index of reference UTxO
|
|
240
|
+
* @param withdrawalScriptHash The script hash of the withdrawal script
|
|
241
|
+
* @param scriptSize The script size of the withdrawal script
|
|
242
|
+
* @returns The MeshTxBuilder instance
|
|
243
|
+
*/
|
|
244
|
+
withdrawalTxInReference: (txHash: string, txIndex: number, withdrawalScriptHash?: string, scriptSize?: string) => void;
|
|
245
|
+
/**
|
|
246
|
+
* Set the transaction withdrawal redeemer value in the MeshTxBuilder instance
|
|
247
|
+
* @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
248
|
+
* @param type The redeemer data type, either Mesh Data type, JSON in raw constructor like format, or CBOR hex string
|
|
249
|
+
* @param exUnits The execution units budget for the redeemer
|
|
250
|
+
* @returns The MeshTxBuilder instance
|
|
251
|
+
*/
|
|
252
|
+
withdrawalRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
253
|
+
mem: number;
|
|
254
|
+
steps: number;
|
|
255
|
+
}) => this;
|
|
256
|
+
/**
|
|
257
|
+
* Creates a pool registration certificate, and adds it to the transaction
|
|
258
|
+
* @param poolParams Parameters for pool registration
|
|
259
|
+
* @returns The MeshTxBuilder instance
|
|
260
|
+
*/
|
|
261
|
+
registerPoolCertificate: (poolParams: PoolParams) => this;
|
|
262
|
+
/**
|
|
263
|
+
* Creates a stake registration certificate, and adds it to the transaction
|
|
264
|
+
* @param stakeKeyHash The keyHash of the stake key
|
|
265
|
+
* @returns The MeshTxBuilder instance
|
|
266
|
+
*/
|
|
267
|
+
registerStakeCertificate: (stakeKeyHash: string) => this;
|
|
268
|
+
/**
|
|
269
|
+
* Creates a stake delegation certificate, and adds it to the transaction
|
|
270
|
+
* This will delegate stake from the corresponding stake address to the pool
|
|
271
|
+
* @param stakeKeyHash The keyHash of the stake key
|
|
272
|
+
* @param poolId poolId can be in either bech32 or hex form
|
|
273
|
+
* @returns The MeshTxBuilder instance
|
|
274
|
+
*/
|
|
275
|
+
delegateStakeCertificate: (stakeKeyHash: string, poolId: string) => this;
|
|
276
|
+
/**
|
|
277
|
+
* Creates a stake deregister certificate, and adds it to the transaction
|
|
278
|
+
* @param stakeKeyHash The keyHash of the stake key
|
|
279
|
+
* @returns The MeshTxBuilder instance
|
|
280
|
+
*/
|
|
281
|
+
deregisterStakeCertificate: (stakeKeyHash: string) => this;
|
|
282
|
+
/**
|
|
283
|
+
* Creates a pool retire certificate, and adds it to the transaction
|
|
284
|
+
* @param poolId poolId can be in either bech32 or hex form
|
|
285
|
+
* @param epoch The intended epoch to retire the pool
|
|
286
|
+
* @returns The MeshTxBuilder instance
|
|
287
|
+
*/
|
|
288
|
+
retirePoolCertificate: (poolId: string, epoch: number) => this;
|
|
289
|
+
/**
|
|
290
|
+
* Configure the address to accept change UTxO
|
|
291
|
+
* @param addr The address to accept change UTxO
|
|
292
|
+
* @returns The MeshTxBuilder instance
|
|
293
|
+
*/
|
|
294
|
+
changeAddress: (addr: string) => this;
|
|
295
|
+
/**
|
|
296
|
+
* Set the transaction valid interval to be valid only after the slot
|
|
297
|
+
* @param slot The transaction is valid only after this slot
|
|
298
|
+
* @returns The MeshTxBuilder instance
|
|
299
|
+
*/
|
|
300
|
+
invalidBefore: (slot: number) => this;
|
|
301
|
+
/**
|
|
302
|
+
* Set the transaction valid interval to be valid only before the slot
|
|
303
|
+
* @param slot The transaction is valid only before this slot
|
|
304
|
+
* @returns The MeshTxBuilder instance
|
|
305
|
+
*/
|
|
306
|
+
invalidHereafter: (slot: number) => this;
|
|
307
|
+
/**
|
|
308
|
+
* Add metadata to the transaction
|
|
309
|
+
* @param tag The tag of the metadata
|
|
310
|
+
* @param metadata The metadata in any format
|
|
311
|
+
* @returns The MeshTxBuilder instance
|
|
312
|
+
*/
|
|
313
|
+
metadataValue: (tag: string, metadata: any) => this;
|
|
314
|
+
/**
|
|
315
|
+
* Sign the transaction with the private key
|
|
316
|
+
* @param skeyHex The private key in cborHex (with or without 5820 prefix, i.e. the format when generated from cardano-cli)
|
|
317
|
+
* @returns
|
|
318
|
+
*/
|
|
319
|
+
signingKey: (skeyHex: string) => this;
|
|
320
|
+
/**
|
|
321
|
+
* Selects utxos to fill output value and puts them into inputs
|
|
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
|
+
* @param threshold Extra value needed to be selected for, usually for paying fees and min UTxO value of change output
|
|
325
|
+
*/
|
|
326
|
+
selectUtxosFrom: (extraInputs: UTxO[], strategy?: UtxoSelectionStrategy, threshold?: string, includeTxFees?: boolean) => this;
|
|
327
|
+
/**
|
|
328
|
+
* Set the protocol parameters to be used for the transaction other than the default one
|
|
329
|
+
* @param params (Part of) the protocol parameters to be used for the transaction
|
|
330
|
+
* @returns The MeshTxBuilder instance
|
|
331
|
+
*/
|
|
332
|
+
protocolParams: (params: Partial<Protocol>) => this;
|
|
333
|
+
protected queueAllLastItem: () => void;
|
|
334
|
+
private queueInput;
|
|
335
|
+
private queueMint;
|
|
336
|
+
private queueWithdrawal;
|
|
337
|
+
protected castRawDataToJsonString: (rawData: object | string) => string;
|
|
338
|
+
protected castBuilderDataToRedeemer: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
|
|
339
|
+
mem: number;
|
|
340
|
+
steps: number;
|
|
341
|
+
}) => Redeemer;
|
|
342
|
+
protected updateRedeemer: (meshTxBuilderBody: MeshTxBuilderBody, txEvaluation: Omit<Action, "data">[]) => void;
|
|
343
|
+
addUtxosFromSelection: () => void;
|
|
344
|
+
removeDuplicateInputs: () => void;
|
|
345
|
+
emptyTxBuilderBody: () => () => MeshTxBuilderBody;
|
|
346
|
+
reset: () => void;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface MeshTxBuilderOptions {
|
|
350
|
+
fetcher?: IFetcher;
|
|
351
|
+
submitter?: ISubmitter;
|
|
352
|
+
evaluator?: IEvaluator;
|
|
353
|
+
serializer?: IMeshTxSerializer;
|
|
354
|
+
isHydra?: boolean;
|
|
355
|
+
params?: Partial<Protocol>;
|
|
356
|
+
}
|
|
357
|
+
declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
358
|
+
serializer: IMeshTxSerializer;
|
|
359
|
+
fetcher?: IFetcher;
|
|
360
|
+
submitter?: ISubmitter;
|
|
361
|
+
evaluator?: IEvaluator;
|
|
362
|
+
txHex: string;
|
|
363
|
+
private queriedTxHashes;
|
|
364
|
+
private queriedUTxOs;
|
|
365
|
+
constructor({ serializer, fetcher, submitter, evaluator, params, isHydra, }?: MeshTxBuilderOptions);
|
|
366
|
+
/**
|
|
367
|
+
* It builds the transaction and query the blockchain for missing information
|
|
368
|
+
* @param customizedTx The optional customized transaction body
|
|
369
|
+
* @returns The signed transaction in hex ready to submit / signed by client
|
|
370
|
+
*/
|
|
371
|
+
complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
372
|
+
/**
|
|
373
|
+
* It builds the transaction without dependencies
|
|
374
|
+
* @param customizedTx The optional customized transaction body
|
|
375
|
+
* @returns The signed transaction in hex ready to submit / signed by client
|
|
376
|
+
*/
|
|
377
|
+
completeSync: (customizedTx?: MeshTxBuilderBody) => string;
|
|
378
|
+
/**
|
|
379
|
+
* Complete the signing process
|
|
380
|
+
* @returns The signed transaction in hex
|
|
381
|
+
*/
|
|
382
|
+
completeSigning: () => string;
|
|
383
|
+
/**
|
|
384
|
+
* Submit transactions to the blockchain using the fetcher instance
|
|
385
|
+
* @param txHex The signed transaction in hex
|
|
386
|
+
* @returns
|
|
387
|
+
*/
|
|
388
|
+
submitTx: (txHex: string) => Promise<string | undefined>;
|
|
389
|
+
/**
|
|
390
|
+
* Get the UTxO information from the blockchain
|
|
391
|
+
* @param TxHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
392
|
+
*/
|
|
393
|
+
private getUTxOInfo;
|
|
394
|
+
private queryAllTxInfo;
|
|
395
|
+
private completeTxInformation;
|
|
396
|
+
private isInputComplete;
|
|
397
|
+
private isInputInfoComplete;
|
|
398
|
+
private isRefScriptInfoComplete;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
declare class ForgeScript {
|
|
402
|
+
static withOneSignature(address: string): string;
|
|
403
|
+
static fromNativeScript(script: NativeScript): string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
interface TransactionOptions extends MeshTxBuilderOptions {
|
|
407
|
+
initiator: IInitiator;
|
|
408
|
+
}
|
|
409
|
+
declare class Transaction {
|
|
410
|
+
txBuilder: MeshTxBuilder;
|
|
411
|
+
initiator: IInitiator;
|
|
412
|
+
isCollateralNeeded: boolean;
|
|
413
|
+
constructor(options: TransactionOptions);
|
|
414
|
+
/**
|
|
415
|
+
* Adds an output to the transaction.
|
|
416
|
+
*
|
|
417
|
+
* @param recipient The recipient of the output.
|
|
418
|
+
* @param assets The assets to send. Provide string for lovelace and Asset[] for tokens and/or lovelace.
|
|
419
|
+
* @returns The transaction builder.
|
|
420
|
+
* @see {@link https://meshjs.dev/apis/transaction#sendAssets}
|
|
421
|
+
*/
|
|
422
|
+
sendAssets(recipient: Recipient, assets: Asset[] | string): Transaction;
|
|
423
|
+
/**
|
|
424
|
+
* Suggest deprecated - Adds a transaction output to the transaction.
|
|
425
|
+
* Use sendAssets instead:
|
|
426
|
+
* ```ts
|
|
427
|
+
* this.sendAssets(recipient, lovelace);
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* Deprecation reason - Unnecessary implementation which might cause confusion.
|
|
431
|
+
*
|
|
432
|
+
* @param {Recipient} recipient The recipient of the transaction.
|
|
433
|
+
* @param {string} lovelace The amount of lovelace to send.
|
|
434
|
+
* @returns {Transaction} The Transaction object.
|
|
435
|
+
* @see {@link https://meshjs.dev/apis/transaction#sendAda}
|
|
436
|
+
*/
|
|
437
|
+
sendLovelace(recipient: Recipient, lovelace: string): Transaction;
|
|
438
|
+
/**
|
|
439
|
+
* Suggest deprecated - Adds stable coins transaction output to the transaction.
|
|
440
|
+
* Please use sendAssets with helper function to obtain token unit instead:
|
|
441
|
+
* ```ts
|
|
442
|
+
* const assets = [{ unit: SUPPORTED_TOKENS.GIMBAL, quantity: "100" }]
|
|
443
|
+
* transaction.sendAssets(recipient, assets)
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* Deprecation reason - Required maintenance on tokens.
|
|
447
|
+
*
|
|
448
|
+
* @param {Recipient} recipient The recipient of the transaction.
|
|
449
|
+
* @param {Token} ticker The ticker of the token to send.
|
|
450
|
+
* @param {string} amount The amount of the token to send.
|
|
451
|
+
* @returns {Transaction} The Transaction object.
|
|
452
|
+
* @see {@link https://meshjs.dev/apis/transaction#sendToken}
|
|
453
|
+
*/
|
|
454
|
+
sendToken(recipient: Recipient, ticker: Token, amount: string): Transaction;
|
|
455
|
+
/**
|
|
456
|
+
* Adds an output to the transaction.
|
|
457
|
+
* Suggest deprecated - use sendAssets instead:
|
|
458
|
+
*
|
|
459
|
+
* ```ts
|
|
460
|
+
* const assets = value.output.amount;
|
|
461
|
+
* this.sendAssets(recipient, assets);
|
|
462
|
+
* ```
|
|
463
|
+
* Deprecation reason - Unnecessary implementation which might cause confusion.
|
|
464
|
+
*
|
|
465
|
+
* @param {Recipient} recipient The recipient of the output.
|
|
466
|
+
* @param {UTxO} value The UTxO value of the output.
|
|
467
|
+
* @returns {Transaction} The Transaction object.
|
|
468
|
+
*/
|
|
469
|
+
sendValue(recipient: Recipient, value: UTxO): Transaction;
|
|
470
|
+
/**
|
|
471
|
+
* Sets the inputs for the transaction.
|
|
472
|
+
*
|
|
473
|
+
* @param {UTxO[]} inputs The inputs to set.
|
|
474
|
+
* @returns {Transaction} The transaction.
|
|
475
|
+
*/
|
|
476
|
+
setTxInputs(inputs: UTxO[]): Transaction;
|
|
477
|
+
/**
|
|
478
|
+
* Sets the reference inputs for the transaction.
|
|
479
|
+
*
|
|
480
|
+
* @param {UTxO[]} inputs The reference inputs to set.
|
|
481
|
+
* @returns {Transaction} The transaction.
|
|
482
|
+
*/
|
|
483
|
+
setTxRefInputs(inputs: UTxO[]): Transaction;
|
|
484
|
+
/**
|
|
485
|
+
* Sets the native script for the transaction.
|
|
486
|
+
* @param {NativeScript} script The native script to spend from.
|
|
487
|
+
* @param {UTxO} utxo The UTxO attached to the script.
|
|
488
|
+
* @returns {Transaction} The Transaction object.
|
|
489
|
+
*/
|
|
490
|
+
setNativeScriptInput(script: NativeScript, utxo: UTxO): Transaction;
|
|
491
|
+
redeemValue(options: {
|
|
492
|
+
value: UTxO;
|
|
493
|
+
script: PlutusScript | UTxO;
|
|
494
|
+
redeemer?: Pick<Action, "data"> & {
|
|
495
|
+
budget?: Budget;
|
|
496
|
+
};
|
|
497
|
+
datum?: Data | UTxO;
|
|
498
|
+
}): Transaction;
|
|
499
|
+
mintAsset(forgeScript: string | PlutusScript | UTxO, mint: Mint, redeemer?: Pick<Action, "data"> & {
|
|
500
|
+
budget?: Budget;
|
|
501
|
+
}): Transaction;
|
|
502
|
+
burnAsset(forgeScript: string | PlutusScript | UTxO, asset: Asset, redeemer?: Pick<Action, "data"> & {
|
|
503
|
+
budget?: Budget;
|
|
504
|
+
}): Transaction;
|
|
505
|
+
/**
|
|
506
|
+
* Sets the change address for the transaction.
|
|
507
|
+
*
|
|
508
|
+
* @param {string} changeAddress The change address.
|
|
509
|
+
* @returns {Transaction} The Transaction object.
|
|
510
|
+
*/
|
|
511
|
+
setChangeAddress(changeAddress: string): Transaction;
|
|
512
|
+
/**
|
|
513
|
+
* Sets the collateral for the transaction.
|
|
514
|
+
*
|
|
515
|
+
* @param {UTxO[]} collateral - Set the UTxO for collateral.
|
|
516
|
+
* @returns {Transaction} The Transaction object.
|
|
517
|
+
*/
|
|
518
|
+
setCollateral(collateral: UTxO[]): Transaction;
|
|
519
|
+
/**
|
|
520
|
+
* Sets the required signers for the transaction.
|
|
521
|
+
*
|
|
522
|
+
* @param {string[]} addresses The addresses of the required signers.
|
|
523
|
+
* @returns {Transaction} The Transaction object.
|
|
524
|
+
*/
|
|
525
|
+
setRequiredSigners(addresses: string[]): Transaction;
|
|
526
|
+
/**
|
|
527
|
+
* Set the time to live for the transaction.
|
|
528
|
+
*
|
|
529
|
+
* @param {string} slot The slot number to expire the transaction at.
|
|
530
|
+
* @returns {Transaction} The Transaction object.
|
|
531
|
+
* @see {@link https://meshjs.dev/apis/transaction#setTimeLimit}
|
|
532
|
+
*/
|
|
533
|
+
setTimeToExpire(slot: string): Transaction;
|
|
534
|
+
/**
|
|
535
|
+
* Sets the start slot for the transaction.
|
|
536
|
+
*
|
|
537
|
+
* @param {string} slot The start slot for the transaction.
|
|
538
|
+
* @returns {Transaction} The Transaction object.
|
|
539
|
+
* @see {@link https://meshjs.dev/apis/transaction#setTimeLimit}
|
|
540
|
+
*/
|
|
541
|
+
setTimeToStart(slot: string): Transaction;
|
|
542
|
+
/**
|
|
543
|
+
* Add a JSON metadata entry to the transaction.
|
|
544
|
+
*
|
|
545
|
+
* @param {number} key The key to use for the metadata entry.
|
|
546
|
+
* @param {unknown} value The value to use for the metadata entry.
|
|
547
|
+
* @returns {Transaction} The Transaction object.
|
|
548
|
+
* @see {@link https://meshjs.dev/apis/transaction#setMetadata}
|
|
549
|
+
*/
|
|
550
|
+
setMetadata(key: number, value: unknown): Transaction;
|
|
551
|
+
withdrawRewards(rewardAddress: string, lovelace: string): Transaction;
|
|
552
|
+
delegateStake(rewardAddress: string, poolId: string): Transaction;
|
|
553
|
+
deregisterStake(rewardAddress: string): Transaction;
|
|
554
|
+
registerStake(rewardAddress: string): Transaction;
|
|
555
|
+
registerPool(params: PoolParams): Transaction;
|
|
556
|
+
retirePool(poolId: string, epochNo: number): Transaction;
|
|
557
|
+
build(): Promise<string>;
|
|
558
|
+
protected mintPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
559
|
+
protected spendingPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
560
|
+
private addCollateralIfNeeded;
|
|
561
|
+
private addTxInputsAsNeeded;
|
|
562
|
+
private addChangeAddress;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export { ForgeScript, MeshTxBuilder, type MeshTxBuilderOptions, Transaction, type TransactionOptions };
|