@meshsdk/core-csl 1.6.0-alpha.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/README.md +9 -0
- package/dist/cjs/core/builder.d.ts +38 -0
- package/dist/cjs/core/builder.js +389 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +17 -0
- package/dist/cjs/deser/builder.d.ts +18 -0
- package/dist/cjs/deser/builder.js +130 -0
- package/dist/cjs/deser/constants.d.ts +12 -0
- package/dist/cjs/deser/constants.js +15 -0
- package/dist/cjs/deser/converter.d.ts +27 -0
- package/dist/cjs/deser/converter.js +352 -0
- package/dist/cjs/deser/csl.d.ts +1 -0
- package/dist/cjs/deser/csl.js +27 -0
- package/dist/cjs/deser/deserializer.d.ts +19 -0
- package/dist/cjs/deser/deserializer.js +40 -0
- package/dist/cjs/deser/index.d.ts +6 -0
- package/dist/cjs/deser/index.js +22 -0
- package/dist/cjs/deser/types.d.ts +146 -0
- package/dist/cjs/deser/types.js +2 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/utils/address.d.ts +12 -0
- package/dist/cjs/utils/address.js +60 -0
- package/dist/cjs/utils/aiken.d.ts +2 -0
- package/dist/cjs/utils/aiken.js +20 -0
- package/dist/cjs/utils/credentials.d.ts +1 -0
- package/dist/cjs/utils/credentials.js +10 -0
- package/dist/cjs/utils/datum.d.ts +4 -0
- package/dist/cjs/utils/datum.js +18 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.js +23 -0
- package/dist/cjs/utils/scripts.d.ts +1 -0
- package/dist/cjs/utils/scripts.js +6 -0
- package/dist/cjs/utils/staking.d.ts +3 -0
- package/dist/cjs/utils/staking.js +25 -0
- package/dist/cjs/utils/transaction.d.ts +2 -0
- package/dist/cjs/utils/transaction.js +15 -0
- package/dist/mjs/core/builder.d.ts +38 -0
- package/dist/mjs/core/builder.js +380 -0
- package/dist/mjs/core/index.d.ts +1 -0
- package/dist/mjs/core/index.js +1 -0
- package/dist/mjs/deser/builder.d.ts +18 -0
- package/dist/mjs/deser/builder.js +118 -0
- package/dist/mjs/deser/constants.d.ts +12 -0
- package/dist/mjs/deser/constants.js +12 -0
- package/dist/mjs/deser/converter.d.ts +27 -0
- package/dist/mjs/deser/converter.js +321 -0
- package/dist/mjs/deser/csl.d.ts +1 -0
- package/dist/mjs/deser/csl.js +1 -0
- package/dist/mjs/deser/deserializer.d.ts +19 -0
- package/dist/mjs/deser/deserializer.js +20 -0
- package/dist/mjs/deser/index.d.ts +6 -0
- package/dist/mjs/deser/index.js +6 -0
- package/dist/mjs/deser/types.d.ts +146 -0
- package/dist/mjs/deser/types.js +1 -0
- package/dist/mjs/index.d.ts +3 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/utils/address.d.ts +12 -0
- package/dist/mjs/utils/address.js +50 -0
- package/dist/mjs/utils/aiken.d.ts +2 -0
- package/dist/mjs/utils/aiken.js +15 -0
- package/dist/mjs/utils/credentials.d.ts +1 -0
- package/dist/mjs/utils/credentials.js +6 -0
- package/dist/mjs/utils/datum.d.ts +4 -0
- package/dist/mjs/utils/datum.js +13 -0
- package/dist/mjs/utils/index.d.ts +7 -0
- package/dist/mjs/utils/index.js +7 -0
- package/dist/mjs/utils/scripts.d.ts +1 -0
- package/dist/mjs/utils/scripts.js +2 -0
- package/dist/mjs/utils/staking.d.ts +3 -0
- package/dist/mjs/utils/staking.js +18 -0
- package/dist/mjs/utils/transaction.d.ts +2 -0
- package/dist/mjs/utils/transaction.js +10 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# mesh-csl
|
|
2
|
+
|
|
3
|
+
It is a Typescript wrapper around [`sidan-csl-rs`](https://github.com/sidan-lab/sidan-csl-rs) to add user-friendliness and useful APIs for building Cardano off-chain transactions. The APIs in this package are mostly low-level, closely tied with `sidan-csl-rs`. This package also serves some new utils functions that are yet to be packaged into `@meshsdk/core`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @meshsdk/mesh-csl
|
|
9
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BuilderData, Certificate, MeshTxBuilderBody, MintItem, Protocol, IMeshSerializer } from '@meshsdk/core';
|
|
2
|
+
import { TransactionBuilder, csl } from '../deser';
|
|
3
|
+
export declare const emptyTxBuilderBody: () => MeshTxBuilderBody;
|
|
4
|
+
export declare class CSLSerializer implements IMeshSerializer {
|
|
5
|
+
txBuilder: TransactionBuilder;
|
|
6
|
+
protocolParams: Protocol;
|
|
7
|
+
meshTxBuilderBody: MeshTxBuilderBody;
|
|
8
|
+
constructor(protocolParams?: Protocol);
|
|
9
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
10
|
+
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
11
|
+
private addUtxosFrom;
|
|
12
|
+
private makePlutusScriptSource;
|
|
13
|
+
protected removeDuplicateInputs: () => void;
|
|
14
|
+
private addAllInputs;
|
|
15
|
+
private addTxIn;
|
|
16
|
+
private addScriptTxIn;
|
|
17
|
+
private addAllOutputs;
|
|
18
|
+
private addOutput;
|
|
19
|
+
private addAllCollaterals;
|
|
20
|
+
private addCollateral;
|
|
21
|
+
private addCollateralReturn;
|
|
22
|
+
private addAllReferenceInputs;
|
|
23
|
+
private addReferenceInput;
|
|
24
|
+
protected addAllMints: (mints: MintItem[]) => void;
|
|
25
|
+
private addPlutusMint;
|
|
26
|
+
private addNativeMint;
|
|
27
|
+
private decimalToFraction;
|
|
28
|
+
private toPoolParams;
|
|
29
|
+
private addCertificate;
|
|
30
|
+
protected addAllCertificates: (allCertificates: Certificate[]) => void;
|
|
31
|
+
protected addCostModels: () => void;
|
|
32
|
+
private addChange;
|
|
33
|
+
private addValidityRange;
|
|
34
|
+
private addAllRequiredSignatures;
|
|
35
|
+
private addAllMetadata;
|
|
36
|
+
protected castRawDataToJsonString: (rawData: object | string) => string;
|
|
37
|
+
protected castDataToPlutusData: ({ type, content }: BuilderData) => csl.PlutusData;
|
|
38
|
+
}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CSLSerializer = exports.emptyTxBuilderBody = void 0;
|
|
7
|
+
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
8
|
+
const common_1 = require("@meshsdk/common");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const deser_1 = require("../deser");
|
|
11
|
+
const emptyTxBuilderBody = () => ({
|
|
12
|
+
inputs: [],
|
|
13
|
+
outputs: [],
|
|
14
|
+
extraInputs: [],
|
|
15
|
+
selectionThreshold: 0,
|
|
16
|
+
collaterals: [],
|
|
17
|
+
requiredSignatures: [],
|
|
18
|
+
referenceInputs: [],
|
|
19
|
+
mints: [],
|
|
20
|
+
changeAddress: '',
|
|
21
|
+
metadata: [],
|
|
22
|
+
validityRange: {},
|
|
23
|
+
certificates: [],
|
|
24
|
+
signingKey: [],
|
|
25
|
+
});
|
|
26
|
+
exports.emptyTxBuilderBody = emptyTxBuilderBody;
|
|
27
|
+
class CSLSerializer {
|
|
28
|
+
constructor(protocolParams) {
|
|
29
|
+
this.meshTxBuilderBody = (0, exports.emptyTxBuilderBody)();
|
|
30
|
+
this.addUtxosFrom = (extraInputs, threshold) => {
|
|
31
|
+
const requiredAssets = this.meshTxBuilderBody.outputs.reduce((map, output) => {
|
|
32
|
+
const outputAmount = output.amount;
|
|
33
|
+
outputAmount.forEach((asset) => {
|
|
34
|
+
const { unit, quantity } = asset;
|
|
35
|
+
const existingQuantity = Number(map.get(unit)) || 0;
|
|
36
|
+
map.set(unit, String(existingQuantity + Number(quantity)));
|
|
37
|
+
});
|
|
38
|
+
return map;
|
|
39
|
+
}, new Map());
|
|
40
|
+
this.meshTxBuilderBody.inputs.reduce((map, input) => {
|
|
41
|
+
const inputAmount = input.txIn.amount;
|
|
42
|
+
inputAmount === null || inputAmount === void 0 ? void 0 : inputAmount.forEach((asset) => {
|
|
43
|
+
const { unit, quantity } = asset;
|
|
44
|
+
const existingQuantity = Number(map.get(unit)) || 0;
|
|
45
|
+
map.set(unit, String(existingQuantity - Number(quantity)));
|
|
46
|
+
});
|
|
47
|
+
return map;
|
|
48
|
+
}, requiredAssets);
|
|
49
|
+
this.meshTxBuilderBody.mints.reduce((map, mint) => {
|
|
50
|
+
const mintAmount = {
|
|
51
|
+
unit: mint.policyId + mint.assetName,
|
|
52
|
+
quantity: String(mint.amount),
|
|
53
|
+
};
|
|
54
|
+
const existingQuantity = Number(map.get(mintAmount.unit)) || 0;
|
|
55
|
+
map.set(mintAmount.unit, String(existingQuantity - Number(mintAmount.quantity)));
|
|
56
|
+
return map;
|
|
57
|
+
}, requiredAssets);
|
|
58
|
+
const selectedInputs = (0, common_1.selectUtxos)(extraInputs, requiredAssets, threshold);
|
|
59
|
+
selectedInputs.forEach((input) => {
|
|
60
|
+
const pubKeyTxIn = {
|
|
61
|
+
type: 'PubKey',
|
|
62
|
+
txIn: {
|
|
63
|
+
txHash: input.input.txHash,
|
|
64
|
+
txIndex: input.input.outputIndex,
|
|
65
|
+
amount: input.output.amount,
|
|
66
|
+
address: input.output.address,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
this.meshTxBuilderBody.inputs.push(pubKeyTxIn);
|
|
70
|
+
this.addTxIn(pubKeyTxIn);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
this.makePlutusScriptSource = (scriptSourceInfo) => {
|
|
74
|
+
const scriptHash = deser_1.csl.ScriptHash.from_hex(scriptSourceInfo.spendingScriptHash);
|
|
75
|
+
const scriptRefInput = deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(scriptSourceInfo.txHash), scriptSourceInfo.txIndex);
|
|
76
|
+
const scriptSource = deser_1.csl.PlutusScriptSource.new_ref_input_with_lang_ver(scriptHash, scriptRefInput, deser_1.LANGUAGE_VERSIONS[scriptSourceInfo.version]);
|
|
77
|
+
return scriptSource;
|
|
78
|
+
};
|
|
79
|
+
// Below protected functions for completing tx building
|
|
80
|
+
this.removeDuplicateInputs = () => {
|
|
81
|
+
const { inputs } = this.meshTxBuilderBody;
|
|
82
|
+
const getTxInId = (txIn) => `${txIn.txHash}#${txIn.txIndex}`;
|
|
83
|
+
const addedInputs = [];
|
|
84
|
+
for (let i = 0; i < inputs.length; i += 1) {
|
|
85
|
+
const currentTxInId = getTxInId(inputs[i].txIn);
|
|
86
|
+
if (addedInputs.includes(currentTxInId)) {
|
|
87
|
+
inputs.splice(i, 1);
|
|
88
|
+
i -= 1;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
addedInputs.push(currentTxInId);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
this.addAllInputs = (inputs) => {
|
|
96
|
+
for (let i = 0; i < inputs.length; i += 1) {
|
|
97
|
+
const currentTxIn = inputs[i]; // TODO: add type
|
|
98
|
+
switch (currentTxIn.type) {
|
|
99
|
+
case 'PubKey':
|
|
100
|
+
this.addTxIn(currentTxIn);
|
|
101
|
+
break;
|
|
102
|
+
case 'Script':
|
|
103
|
+
this.addScriptTxIn(currentTxIn);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.addTxIn = (currentTxIn) => {
|
|
109
|
+
this.txBuilder.add_input(deser_1.csl.Address.from_bech32(currentTxIn.txIn.address), deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(currentTxIn.txIn.txHash), currentTxIn.txIn.txIndex), (0, deser_1.toValue)(currentTxIn.txIn.amount));
|
|
110
|
+
};
|
|
111
|
+
this.addScriptTxIn = ({ scriptTxIn, txIn, }) => {
|
|
112
|
+
let cslDatum;
|
|
113
|
+
const { datumSource, scriptSource, redeemer } = scriptTxIn;
|
|
114
|
+
if (datumSource.type === 'Provided') {
|
|
115
|
+
cslDatum = deser_1.csl.DatumSource.new(this.castDataToPlutusData(datumSource.data));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const refTxIn = deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(datumSource.txHash), datumSource.txIndex);
|
|
119
|
+
cslDatum = deser_1.csl.DatumSource.new_ref_input(refTxIn);
|
|
120
|
+
}
|
|
121
|
+
let cslScript;
|
|
122
|
+
if (scriptSource.type === 'Inline') {
|
|
123
|
+
cslScript = this.makePlutusScriptSource(scriptSource.txInInfo);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
cslScript = deser_1.csl.PlutusScriptSource.new(deser_1.csl.PlutusScript.from_hex_with_version(scriptSource.script.code, deser_1.LANGUAGE_VERSIONS[scriptSource.script.version]));
|
|
127
|
+
}
|
|
128
|
+
const cslRedeemer = deser_1.csl.Redeemer.new(deser_1.csl.RedeemerTag.new_spend(), deser_1.csl.BigNum.from_str('0'), this.castDataToPlutusData(redeemer.data), deser_1.csl.ExUnits.new(deser_1.csl.BigNum.from_str(String(redeemer.exUnits.mem)), deser_1.csl.BigNum.from_str(String(redeemer.exUnits.steps))));
|
|
129
|
+
this.txBuilder.add_plutus_script_input(deser_1.csl.PlutusWitness.new_with_ref(cslScript, cslDatum, cslRedeemer), deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(txIn.txHash), txIn.txIndex), (0, deser_1.toValue)(txIn.amount));
|
|
130
|
+
};
|
|
131
|
+
this.addAllOutputs = (outputs) => {
|
|
132
|
+
for (let i = 0; i < outputs.length; i += 1) {
|
|
133
|
+
const currentOutput = outputs[i];
|
|
134
|
+
this.addOutput(currentOutput);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
this.addOutput = ({ amount, address, datum, referenceScript }) => {
|
|
138
|
+
const txValue = (0, deser_1.toValue)(amount);
|
|
139
|
+
const multiAsset = txValue.multiasset();
|
|
140
|
+
if (txValue.is_zero() && multiAsset === undefined)
|
|
141
|
+
throw Error('Invalid output amount');
|
|
142
|
+
let outputBuilder = deser_1.csl.TransactionOutputBuilder.new().with_address((0, deser_1.toAddress)(address));
|
|
143
|
+
if (datum && datum.type === 'Hash') {
|
|
144
|
+
outputBuilder = outputBuilder.with_data_hash(deser_1.csl.hash_plutus_data(this.castDataToPlutusData(datum.data)));
|
|
145
|
+
}
|
|
146
|
+
if (datum && datum.type === 'Inline') {
|
|
147
|
+
outputBuilder = outputBuilder.with_plutus_data(this.castDataToPlutusData(datum.data));
|
|
148
|
+
}
|
|
149
|
+
if (referenceScript) {
|
|
150
|
+
outputBuilder = outputBuilder.with_script_ref(deser_1.csl.ScriptRef.new_plutus_script(deser_1.csl.PlutusScript.from_hex_with_version(referenceScript.code, deser_1.LANGUAGE_VERSIONS[referenceScript.version])));
|
|
151
|
+
}
|
|
152
|
+
const amountBuilder = outputBuilder.next();
|
|
153
|
+
if (multiAsset) {
|
|
154
|
+
const output = txValue.coin().is_zero()
|
|
155
|
+
? amountBuilder
|
|
156
|
+
.with_asset_and_min_required_coin_by_utxo_cost(multiAsset, (0, deser_1.buildDataCost)(this.protocolParams.coinsPerUTxOSize))
|
|
157
|
+
.build()
|
|
158
|
+
: amountBuilder.with_coin_and_asset(txValue.coin(), multiAsset).build();
|
|
159
|
+
this.txBuilder.add_output(output);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const output = amountBuilder.with_coin(txValue.coin()).build();
|
|
163
|
+
this.txBuilder.add_output(output);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
this.addAllCollaterals = (collaterals) => {
|
|
167
|
+
const collateralBuilder = deser_1.csl.TxInputsBuilder.new();
|
|
168
|
+
for (let i = 0; i < collaterals.length; i += 1) {
|
|
169
|
+
const currentCollateral = collaterals[i];
|
|
170
|
+
this.addCollateral(collateralBuilder, currentCollateral);
|
|
171
|
+
}
|
|
172
|
+
this.txBuilder.set_collateral(collateralBuilder);
|
|
173
|
+
};
|
|
174
|
+
this.addCollateral = (collateralBuilder, currentCollateral) => {
|
|
175
|
+
collateralBuilder.add_input(deser_1.csl.Address.from_bech32(currentCollateral.txIn.address), deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(currentCollateral.txIn.txHash), currentCollateral.txIn.txIndex), (0, deser_1.toValue)(currentCollateral.txIn.amount));
|
|
176
|
+
};
|
|
177
|
+
this.addCollateralReturn = (returnAddress) => {
|
|
178
|
+
var _a;
|
|
179
|
+
const currentFee = (_a = this.txBuilder.get_fee_if_set()) === null || _a === void 0 ? void 0 : _a.to_js_value();
|
|
180
|
+
if (currentFee) {
|
|
181
|
+
const collateralAmount = Math.ceil((this.protocolParams.collateralPercent * Number(currentFee)) / 100);
|
|
182
|
+
this.txBuilder.set_total_collateral_and_return(deser_1.csl.BigNum.from_str(String(collateralAmount)), deser_1.csl.Address.from_bech32(returnAddress));
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
this.addAllReferenceInputs = (refInputs) => {
|
|
186
|
+
refInputs.forEach((refInput) => {
|
|
187
|
+
this.addReferenceInput(refInput);
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
this.addReferenceInput = ({ txHash, txIndex }) => {
|
|
191
|
+
const refInput = deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(txHash), txIndex);
|
|
192
|
+
this.txBuilder.add_reference_input(refInput);
|
|
193
|
+
};
|
|
194
|
+
this.addAllMints = (mints) => {
|
|
195
|
+
const mintBuilder = deser_1.csl.MintBuilder.new();
|
|
196
|
+
let plutusMintCount = 0;
|
|
197
|
+
for (let i = 0; i < mints.length; i += 1) {
|
|
198
|
+
const mintItem = mints[i];
|
|
199
|
+
if (!mintItem.scriptSource)
|
|
200
|
+
throw Error('Mint script is expected to be provided');
|
|
201
|
+
if (mintItem.type === 'Plutus') {
|
|
202
|
+
if (!mintItem.redeemer)
|
|
203
|
+
throw Error('Missing mint redeemer information');
|
|
204
|
+
this.addPlutusMint(mintBuilder, mintItem, plutusMintCount); // TODO: Update after csl update
|
|
205
|
+
plutusMintCount += 1; // TODO: Remove after csl update
|
|
206
|
+
}
|
|
207
|
+
else if (mintItem.type === 'Native') {
|
|
208
|
+
this.addNativeMint(mintBuilder, mintItem);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
this.txBuilder.set_mint_builder(mintBuilder);
|
|
212
|
+
};
|
|
213
|
+
this.addPlutusMint = (mintBuilder, { redeemer, policyId, scriptSource, assetName, amount }, redeemerIndex) => {
|
|
214
|
+
const newRedeemer = deser_1.csl.Redeemer.new(deser_1.csl.RedeemerTag.new_mint(), deser_1.csl.BigNum.from_str(String(redeemerIndex)), this.castDataToPlutusData(redeemer.data), deser_1.csl.ExUnits.new(deser_1.csl.BigNum.from_str(String(redeemer.exUnits.mem)), deser_1.csl.BigNum.from_str(String(redeemer.exUnits.steps))));
|
|
215
|
+
const script = scriptSource.type === 'Reference Script'
|
|
216
|
+
? deser_1.csl.PlutusScriptSource.new_ref_input_with_lang_ver(deser_1.csl.ScriptHash.from_hex(policyId), deser_1.csl.TransactionInput.new(deser_1.csl.TransactionHash.from_hex(scriptSource.txHash), scriptSource.txIndex), deser_1.LANGUAGE_VERSIONS[scriptSource.version])
|
|
217
|
+
: deser_1.csl.PlutusScriptSource.new(deser_1.csl.PlutusScript.from_hex_with_version(scriptSource.script.code, deser_1.LANGUAGE_VERSIONS[scriptSource.script.version]));
|
|
218
|
+
mintBuilder.add_asset(deser_1.csl.MintWitness.new_plutus_script(script, newRedeemer), deser_1.csl.AssetName.new(Buffer.from(assetName, 'hex')), deser_1.csl.Int.from_str(amount));
|
|
219
|
+
};
|
|
220
|
+
this.addNativeMint = (mintBuilder, { scriptSource, assetName, amount }) => {
|
|
221
|
+
if (scriptSource.type === 'Reference Script')
|
|
222
|
+
throw Error('Native mint cannot have reference script');
|
|
223
|
+
mintBuilder.add_asset(deser_1.csl.MintWitness.new_native_script(deser_1.csl.NativeScript.from_hex(scriptSource.script.code)), deser_1.csl.AssetName.new(Buffer.from(assetName, 'hex')), deser_1.csl.Int.from_str(amount));
|
|
224
|
+
};
|
|
225
|
+
this.toPoolParams = (poolParams) => {
|
|
226
|
+
const marginFraction = this.decimalToFraction(poolParams.margin);
|
|
227
|
+
const relays = deser_1.csl.Relays.new();
|
|
228
|
+
poolParams.relays.forEach((relay) => {
|
|
229
|
+
relays.add((0, deser_1.toRelay)(relay));
|
|
230
|
+
});
|
|
231
|
+
const rewardAddress = deser_1.csl.RewardAddress.from_address(deser_1.csl.Address.from_bech32(poolParams.rewardAddress));
|
|
232
|
+
if (rewardAddress === undefined) {
|
|
233
|
+
throw new Error('Reward address is invalid');
|
|
234
|
+
}
|
|
235
|
+
const poolOwners = deser_1.csl.Ed25519KeyHashes.new();
|
|
236
|
+
poolParams.owners.forEach((owner) => {
|
|
237
|
+
poolOwners.add(deser_1.csl.Ed25519KeyHash.from_hex(owner));
|
|
238
|
+
});
|
|
239
|
+
return deser_1.csl.PoolParams.new(deser_1.csl.Ed25519KeyHash.from_hex(poolParams.operator), deser_1.csl.VRFKeyHash.from_hex(poolParams.VRFKeyHash), deser_1.csl.BigNum.from_str(poolParams.pledge), deser_1.csl.BigNum.from_str(poolParams.cost), deser_1.csl.UnitInterval.new(deser_1.csl.BigNum.from_str(marginFraction[0].toString()), deser_1.csl.BigNum.from_str(marginFraction[1].toString())), rewardAddress, poolOwners, relays, poolParams.metadata
|
|
240
|
+
? deser_1.csl.PoolMetadata.from_json(json_bigint_1.default.stringify(poolParams.metadata))
|
|
241
|
+
: undefined);
|
|
242
|
+
};
|
|
243
|
+
this.addCertificate = (certificates, cert) => {
|
|
244
|
+
switch (cert.type) {
|
|
245
|
+
case 'RegisterPool':
|
|
246
|
+
certificates.add(deser_1.csl.Certificate.new_pool_registration(deser_1.csl.PoolRegistration.new(this.toPoolParams(cert.poolParams))));
|
|
247
|
+
break;
|
|
248
|
+
case 'RegisterStake':
|
|
249
|
+
certificates.add(deser_1.csl.Certificate.new_stake_registration(deser_1.csl.StakeRegistration.new(deser_1.csl.StakeCredential.from_keyhash(deser_1.csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash)))));
|
|
250
|
+
break;
|
|
251
|
+
case 'DelegateStake':
|
|
252
|
+
certificates.add(deser_1.csl.Certificate.new_stake_delegation(deser_1.csl.StakeDelegation.new(deser_1.csl.StakeCredential.from_keyhash(deser_1.csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash)), cert.poolId.startsWith('pool')
|
|
253
|
+
? deser_1.csl.Ed25519KeyHash.from_bech32(cert.poolId)
|
|
254
|
+
: deser_1.csl.Ed25519KeyHash.from_hex(cert.poolId))));
|
|
255
|
+
break;
|
|
256
|
+
case 'DeregisterStake':
|
|
257
|
+
certificates.add(deser_1.csl.Certificate.new_stake_deregistration(deser_1.csl.StakeDeregistration.new(deser_1.csl.StakeCredential.from_keyhash(deser_1.csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash)))));
|
|
258
|
+
break;
|
|
259
|
+
case 'RetirePool':
|
|
260
|
+
certificates.add(deser_1.csl.Certificate.new_pool_retirement(deser_1.csl.PoolRetirement.new(cert.poolId.startsWith('pool')
|
|
261
|
+
? deser_1.csl.Ed25519KeyHash.from_bech32(cert.poolId)
|
|
262
|
+
: deser_1.csl.Ed25519KeyHash.from_hex(cert.poolId), cert.epoch)));
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
this.addAllCertificates = (allCertificates) => {
|
|
266
|
+
const certificates = deser_1.csl.Certificates.new();
|
|
267
|
+
allCertificates.forEach((cert) => {
|
|
268
|
+
this.addCertificate(certificates, cert);
|
|
269
|
+
});
|
|
270
|
+
this.txBuilder.set_certs(certificates);
|
|
271
|
+
};
|
|
272
|
+
this.addCostModels = () => {
|
|
273
|
+
this.txBuilder.calc_script_data_hash(deser_1.csl.TxBuilderConstants.plutus_vasil_cost_models());
|
|
274
|
+
};
|
|
275
|
+
this.addChange = (changeAddress) => {
|
|
276
|
+
this.txBuilder.add_change_if_needed(deser_1.csl.Address.from_bech32(changeAddress));
|
|
277
|
+
};
|
|
278
|
+
this.addValidityRange = ({ invalidBefore, invalidHereafter }) => {
|
|
279
|
+
if (invalidBefore) {
|
|
280
|
+
this.txBuilder.set_validity_start_interval_bignum(deser_1.csl.BigNum.from_str(invalidBefore.toString()));
|
|
281
|
+
}
|
|
282
|
+
if (invalidHereafter) {
|
|
283
|
+
this.txBuilder.set_ttl_bignum(deser_1.csl.BigNum.from_str(invalidHereafter.toString()));
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
this.addAllRequiredSignatures = (requiredSignatures) => {
|
|
287
|
+
requiredSignatures.forEach((pubKeyHash) => {
|
|
288
|
+
this.txBuilder.add_required_signer(deser_1.csl.Ed25519KeyHash.from_hex(pubKeyHash));
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
this.addAllMetadata = (allMetadata) => {
|
|
292
|
+
allMetadata.forEach(({ tag, metadata }) => {
|
|
293
|
+
this.txBuilder.add_json_metadatum(deser_1.csl.BigNum.from_str(tag), json_bigint_1.default.stringify(metadata));
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
this.castRawDataToJsonString = (rawData) => {
|
|
297
|
+
if (typeof rawData === 'object') {
|
|
298
|
+
return json_bigint_1.default.stringify(rawData);
|
|
299
|
+
}
|
|
300
|
+
return rawData;
|
|
301
|
+
};
|
|
302
|
+
this.castDataToPlutusData = ({ type, content }) => {
|
|
303
|
+
if (type === 'Mesh') {
|
|
304
|
+
return (0, deser_1.toPlutusData)(content);
|
|
305
|
+
}
|
|
306
|
+
if (type === 'CBOR') {
|
|
307
|
+
return deser_1.csl.PlutusData.from_hex(content);
|
|
308
|
+
}
|
|
309
|
+
return deser_1.csl.PlutusData.from_json(content, deser_1.csl.PlutusDatumSchema.DetailedSchema);
|
|
310
|
+
};
|
|
311
|
+
this.protocolParams = protocolParams || common_1.DEFAULT_PROTOCOL_PARAMETERS;
|
|
312
|
+
this.txBuilder = (0, deser_1.buildTxBuilder)(protocolParams);
|
|
313
|
+
}
|
|
314
|
+
serializeTxBody(txBody, protocolParams) {
|
|
315
|
+
if (protocolParams) {
|
|
316
|
+
this.protocolParams = protocolParams;
|
|
317
|
+
}
|
|
318
|
+
this.txBuilder = (0, deser_1.buildTxBuilder)(protocolParams);
|
|
319
|
+
const { inputs, outputs, extraInputs, selectionThreshold, collaterals, referenceInputs, mints, changeAddress, certificates, validityRange, requiredSignatures, metadata, } = txBody;
|
|
320
|
+
if (extraInputs.length > 0) {
|
|
321
|
+
this.addUtxosFrom(extraInputs, String(selectionThreshold));
|
|
322
|
+
}
|
|
323
|
+
this.removeDuplicateInputs();
|
|
324
|
+
mints.sort((a, b) => a.policyId.localeCompare(b.policyId));
|
|
325
|
+
inputs.sort((a, b) => {
|
|
326
|
+
if (a.txIn.txHash === b.txIn.txHash) {
|
|
327
|
+
return a.txIn.txIndex - b.txIn.txIndex;
|
|
328
|
+
}
|
|
329
|
+
return a.txIn.txHash.localeCompare(b.txIn.txHash);
|
|
330
|
+
});
|
|
331
|
+
this.addAllInputs(inputs);
|
|
332
|
+
this.addAllOutputs(outputs);
|
|
333
|
+
this.addAllCollaterals(collaterals);
|
|
334
|
+
this.addAllReferenceInputs(referenceInputs);
|
|
335
|
+
this.addAllMints(mints);
|
|
336
|
+
this.addAllCertificates(certificates);
|
|
337
|
+
this.addValidityRange(validityRange);
|
|
338
|
+
this.addAllRequiredSignatures(requiredSignatures);
|
|
339
|
+
this.addAllMetadata(metadata);
|
|
340
|
+
this.addCostModels();
|
|
341
|
+
if (changeAddress) {
|
|
342
|
+
// Hacky fix to set a dummy collateral return so fees are calculated correctly
|
|
343
|
+
const totalCollateral = collaterals
|
|
344
|
+
.map((collateral) => {
|
|
345
|
+
var _a, _b;
|
|
346
|
+
return ((_b = (_a = collateral.txIn.amount) === null || _a === void 0 ? void 0 : _a.find((asset) => asset.unit === 'lovelace')) === null || _b === void 0 ? void 0 : _b.quantity) || '0';
|
|
347
|
+
})
|
|
348
|
+
.reduce((acc, curr) => acc + parseInt(curr), 0);
|
|
349
|
+
const collateralEstimate = Math.ceil((this.protocolParams.collateralPercent *
|
|
350
|
+
Number(Number(this.txBuilder
|
|
351
|
+
.min_fee()
|
|
352
|
+
.checked_add(deser_1.csl.BigNum.from_str('10000'))
|
|
353
|
+
.to_js_value()))) /
|
|
354
|
+
100);
|
|
355
|
+
let collateralReturnNeeded = false;
|
|
356
|
+
if (totalCollateral - collateralEstimate > 0) {
|
|
357
|
+
const collateralEstimateOutput = deser_1.csl.TransactionOutput.new(deser_1.csl.Address.from_bech32(changeAddress), deser_1.csl.Value.new(deser_1.csl.BigNum.from_str(String(collateralEstimate))));
|
|
358
|
+
if (totalCollateral - collateralEstimate >
|
|
359
|
+
Number(deser_1.csl
|
|
360
|
+
.min_ada_for_output(collateralEstimateOutput, deser_1.csl.DataCost.new_coins_per_byte(deser_1.csl.BigNum.from_str(this.protocolParams.coinsPerUTxOSize)))
|
|
361
|
+
.to_js_value())) {
|
|
362
|
+
this.txBuilder.set_collateral_return(deser_1.csl.TransactionOutput.new(deser_1.csl.Address.from_bech32(changeAddress), deser_1.csl.Value.new(deser_1.csl.BigNum.from_str(String(totalCollateral)))));
|
|
363
|
+
this.txBuilder.set_total_collateral(deser_1.csl.BigNum.from_str(String(totalCollateral)));
|
|
364
|
+
collateralReturnNeeded = true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
this.addChange(changeAddress);
|
|
368
|
+
if (collateralReturnNeeded)
|
|
369
|
+
this.addCollateralReturn(changeAddress);
|
|
370
|
+
}
|
|
371
|
+
const tx = this.txBuilder.build_tx();
|
|
372
|
+
// const txJson = JSON.parse(tx.to_json());
|
|
373
|
+
const txHex = tx.to_hex();
|
|
374
|
+
return txHex;
|
|
375
|
+
}
|
|
376
|
+
addSigningKeys(txHex, signingKeys) {
|
|
377
|
+
if (signingKeys.length > 0) {
|
|
378
|
+
return (0, utils_1.signTransaction)(txHex, signingKeys);
|
|
379
|
+
}
|
|
380
|
+
return txHex;
|
|
381
|
+
}
|
|
382
|
+
decimalToFraction(decimal) {
|
|
383
|
+
const powerOf10 = Math.pow(10, decimal.toString().split('.')[1].length);
|
|
384
|
+
const numerator = decimal * powerOf10;
|
|
385
|
+
const denominator = powerOf10;
|
|
386
|
+
return [numerator, denominator];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
exports.CSLSerializer = CSLSerializer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './builder';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./builder"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Action, Data, PlutusScript, Recipient, UTxO } from '@meshsdk/core';
|
|
2
|
+
import { csl } from './csl';
|
|
3
|
+
import type { BaseAddress, Bip32PrivateKey, DataCost, DatumSource, Ed25519KeyHash, EnterpriseAddress, MintWitness, PlutusScriptSource, RewardAddress, TransactionBuilder, TransactionOutputBuilder, TxInputsBuilder } from './types';
|
|
4
|
+
export declare const buildBaseAddress: (networkId: number, paymentKeyHash: Ed25519KeyHash, stakeKeyHash: Ed25519KeyHash) => BaseAddress;
|
|
5
|
+
export declare const buildBip32PrivateKey: (entropy: string, password?: string) => Bip32PrivateKey;
|
|
6
|
+
export declare const buildDataCost: (coinsPerByte: string) => DataCost;
|
|
7
|
+
export declare const buildDatumSource: (datum: Data | UTxO) => DatumSource;
|
|
8
|
+
export declare const buildEnterpriseAddress: (networkId: number, paymentKeyHash: Ed25519KeyHash) => EnterpriseAddress;
|
|
9
|
+
export declare const buildGeneralTxMetadata: (metadata: Record<string, unknown>) => csl.GeneralTransactionMetadata;
|
|
10
|
+
export declare const buildMintWitness: (script: string | PlutusScript | UTxO, redeemer?: Partial<Action>) => MintWitness;
|
|
11
|
+
export declare const buildRewardAddress: (networkId: number, stakeKeyHash: Ed25519KeyHash) => RewardAddress;
|
|
12
|
+
export declare const buildPlutusScriptSource: (script: PlutusScript | UTxO) => PlutusScriptSource;
|
|
13
|
+
export declare const buildScriptPubkey: (keyHash: Ed25519KeyHash) => csl.NativeScript;
|
|
14
|
+
export declare const buildTimelockExpiry: (slot: string) => csl.NativeScript;
|
|
15
|
+
export declare const buildTimelockStart: (slot: string) => csl.NativeScript;
|
|
16
|
+
export declare const buildTxBuilder: (parameters?: import("@meshsdk/core").Protocol) => TransactionBuilder;
|
|
17
|
+
export declare const buildTxInputsBuilder: (utxos: unknown[]) => TxInputsBuilder;
|
|
18
|
+
export declare const buildTxOutputBuilder: (recipient: Recipient) => TransactionOutputBuilder;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTxOutputBuilder = exports.buildTxInputsBuilder = exports.buildTxBuilder = exports.buildTimelockStart = exports.buildTimelockExpiry = exports.buildScriptPubkey = exports.buildPlutusScriptSource = exports.buildRewardAddress = exports.buildMintWitness = exports.buildGeneralTxMetadata = exports.buildEnterpriseAddress = exports.buildDatumSource = exports.buildDataCost = exports.buildBip32PrivateKey = exports.buildBaseAddress = void 0;
|
|
4
|
+
const common_1 = require("@meshsdk/common");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const csl_1 = require("./csl");
|
|
7
|
+
const converter_1 = require("./converter");
|
|
8
|
+
const deserializer_1 = require("./deserializer");
|
|
9
|
+
const buildBaseAddress = (networkId, paymentKeyHash, stakeKeyHash) => csl_1.csl.BaseAddress.new(networkId, csl_1.csl.StakeCredential.from_keyhash(paymentKeyHash), csl_1.csl.StakeCredential.from_keyhash(stakeKeyHash));
|
|
10
|
+
exports.buildBaseAddress = buildBaseAddress;
|
|
11
|
+
const buildBip32PrivateKey = (entropy, password = '') => csl_1.csl.Bip32PrivateKey.from_bip39_entropy((0, converter_1.toBytes)(entropy), (0, converter_1.toBytes)((0, converter_1.fromUTF8)(password)));
|
|
12
|
+
exports.buildBip32PrivateKey = buildBip32PrivateKey;
|
|
13
|
+
const buildDataCost = (coinsPerByte) => csl_1.csl.DataCost.new_coins_per_byte(csl_1.csl.BigNum.from_str(coinsPerByte));
|
|
14
|
+
exports.buildDataCost = buildDataCost;
|
|
15
|
+
const buildDatumSource = (datum) => {
|
|
16
|
+
if (typeof datum !== 'object' || !('input' in datum)) {
|
|
17
|
+
return csl_1.csl.DatumSource.new((0, converter_1.toPlutusData)(datum));
|
|
18
|
+
}
|
|
19
|
+
const utxo = (0, converter_1.toTxUnspentOutput)(datum);
|
|
20
|
+
if (utxo.output().has_plutus_data()) {
|
|
21
|
+
return csl_1.csl.DatumSource.new_ref_input(utxo.input());
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`No inline datum found in UTxO: ${utxo.input().transaction_id().to_hex()}`);
|
|
24
|
+
};
|
|
25
|
+
exports.buildDatumSource = buildDatumSource;
|
|
26
|
+
const buildEnterpriseAddress = (networkId, paymentKeyHash) => csl_1.csl.EnterpriseAddress.new(networkId, csl_1.csl.StakeCredential.from_keyhash(paymentKeyHash));
|
|
27
|
+
exports.buildEnterpriseAddress = buildEnterpriseAddress;
|
|
28
|
+
const buildGeneralTxMetadata = (metadata) => {
|
|
29
|
+
const generalTxMetadata = csl_1.csl.GeneralTransactionMetadata.new();
|
|
30
|
+
Object.entries(metadata).forEach(([MetadataLabel, Metadata]) => {
|
|
31
|
+
generalTxMetadata.insert(csl_1.csl.BigNum.from_str(MetadataLabel), csl_1.csl.encode_json_str_to_metadatum(JSON.stringify(Metadata), csl_1.csl.MetadataJsonSchema.NoConversions));
|
|
32
|
+
});
|
|
33
|
+
return generalTxMetadata;
|
|
34
|
+
};
|
|
35
|
+
exports.buildGeneralTxMetadata = buildGeneralTxMetadata;
|
|
36
|
+
const buildMintWitness = (script, redeemer) => {
|
|
37
|
+
if (typeof script === 'string') {
|
|
38
|
+
return csl_1.csl.MintWitness.new_native_script((0, deserializer_1.deserializeNativeScript)(script));
|
|
39
|
+
}
|
|
40
|
+
if (redeemer === undefined)
|
|
41
|
+
throw new Error('Minting with plutus requires a redeemer to be defined');
|
|
42
|
+
if (redeemer.tag !== 'MINT')
|
|
43
|
+
throw new Error("Minting redeemer's tag must be defined as 'MINT'");
|
|
44
|
+
return csl_1.csl.MintWitness.new_plutus_script((0, exports.buildPlutusScriptSource)(script), (0, converter_1.toRedeemer)(Object.assign({ tag: 'MINT', index: 0, budget: common_1.DEFAULT_REDEEMER_BUDGET, data: {
|
|
45
|
+
alternative: 0,
|
|
46
|
+
fields: [],
|
|
47
|
+
} }, redeemer)));
|
|
48
|
+
};
|
|
49
|
+
exports.buildMintWitness = buildMintWitness;
|
|
50
|
+
const buildRewardAddress = (networkId, stakeKeyHash) => csl_1.csl.RewardAddress.new(networkId, csl_1.csl.StakeCredential.from_keyhash(stakeKeyHash));
|
|
51
|
+
exports.buildRewardAddress = buildRewardAddress;
|
|
52
|
+
const buildPlutusScriptSource = (script) => {
|
|
53
|
+
if ('code' in script) {
|
|
54
|
+
return csl_1.csl.PlutusScriptSource.new((0, deserializer_1.deserializePlutusScript)(script.code, script.version));
|
|
55
|
+
}
|
|
56
|
+
const utxo = (0, converter_1.toTxUnspentOutput)(script);
|
|
57
|
+
if (utxo.output().has_script_ref()) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
+
const scriptRef = utxo.output().script_ref();
|
|
60
|
+
if (scriptRef.is_plutus_script()) {
|
|
61
|
+
const plutusScript = (0, converter_1.fromScriptRef)(scriptRef);
|
|
62
|
+
const scriptHash = (0, deserializer_1.deserializePlutusScript)(plutusScript.code, plutusScript.version).hash();
|
|
63
|
+
return csl_1.csl.PlutusScriptSource.new_ref_input_with_lang_ver(scriptHash, utxo.input(), constants_1.LANGUAGE_VERSIONS[plutusScript.version]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`No plutus script reference found in UTxO: ${utxo.input().transaction_id().to_hex()}`);
|
|
67
|
+
};
|
|
68
|
+
exports.buildPlutusScriptSource = buildPlutusScriptSource;
|
|
69
|
+
const buildScriptPubkey = (keyHash) => {
|
|
70
|
+
const scriptPubkey = csl_1.csl.ScriptPubkey.new(keyHash);
|
|
71
|
+
return csl_1.csl.NativeScript.new_script_pubkey(scriptPubkey);
|
|
72
|
+
};
|
|
73
|
+
exports.buildScriptPubkey = buildScriptPubkey;
|
|
74
|
+
const buildTimelockExpiry = (slot) => {
|
|
75
|
+
const expiry = csl_1.csl.BigNum.from_str(slot);
|
|
76
|
+
const timelockExpiry = csl_1.csl.TimelockExpiry.new_timelockexpiry(expiry);
|
|
77
|
+
return csl_1.csl.NativeScript.new_timelock_expiry(timelockExpiry);
|
|
78
|
+
};
|
|
79
|
+
exports.buildTimelockExpiry = buildTimelockExpiry;
|
|
80
|
+
const buildTimelockStart = (slot) => {
|
|
81
|
+
const start = csl_1.csl.BigNum.from_str(slot);
|
|
82
|
+
const timelockStart = csl_1.csl.TimelockStart.new_timelockstart(start);
|
|
83
|
+
return csl_1.csl.NativeScript.new_timelock_start(timelockStart);
|
|
84
|
+
};
|
|
85
|
+
exports.buildTimelockStart = buildTimelockStart;
|
|
86
|
+
const buildTxBuilder = (parameters = common_1.DEFAULT_PROTOCOL_PARAMETERS) => {
|
|
87
|
+
const txBuilderConfig = csl_1.csl.TransactionBuilderConfigBuilder.new()
|
|
88
|
+
.coins_per_utxo_byte(csl_1.csl.BigNum.from_str(parameters.coinsPerUTxOSize))
|
|
89
|
+
.ex_unit_prices(csl_1.csl.ExUnitPrices.new((0, converter_1.toUnitInterval)(parameters.priceMem.toString()), (0, converter_1.toUnitInterval)(parameters.priceStep.toString())))
|
|
90
|
+
.fee_algo(csl_1.csl.LinearFee.new(csl_1.csl.BigNum.from_str(parameters.minFeeA.toString()), csl_1.csl.BigNum.from_str(parameters.minFeeB.toString())))
|
|
91
|
+
.key_deposit(csl_1.csl.BigNum.from_str(parameters.keyDeposit))
|
|
92
|
+
.max_tx_size(parameters.maxTxSize)
|
|
93
|
+
.max_value_size(parseInt(parameters.maxValSize, 10))
|
|
94
|
+
.pool_deposit(csl_1.csl.BigNum.from_str(parameters.poolDeposit))
|
|
95
|
+
.build();
|
|
96
|
+
return csl_1.csl.TransactionBuilder.new(txBuilderConfig);
|
|
97
|
+
};
|
|
98
|
+
exports.buildTxBuilder = buildTxBuilder;
|
|
99
|
+
const buildTxInputsBuilder = (utxos) => {
|
|
100
|
+
const txInputsBuilder = csl_1.csl.TxInputsBuilder.new();
|
|
101
|
+
utxos
|
|
102
|
+
.map((utxo) => utxo instanceof csl_1.csl.TransactionUnspentOutput
|
|
103
|
+
? utxo
|
|
104
|
+
: (0, converter_1.toTxUnspentOutput)(utxo))
|
|
105
|
+
.forEach((utxo) => {
|
|
106
|
+
txInputsBuilder.add_input(utxo.output().address(), utxo.input(), utxo.output().amount());
|
|
107
|
+
});
|
|
108
|
+
return txInputsBuilder;
|
|
109
|
+
};
|
|
110
|
+
exports.buildTxInputsBuilder = buildTxInputsBuilder;
|
|
111
|
+
const buildTxOutputBuilder = (recipient) => {
|
|
112
|
+
if (typeof recipient === 'string') {
|
|
113
|
+
return csl_1.csl.TransactionOutputBuilder.new().with_address((0, converter_1.toAddress)(recipient));
|
|
114
|
+
}
|
|
115
|
+
let txOutputBuilder = csl_1.csl.TransactionOutputBuilder.new().with_address((0, converter_1.toAddress)(recipient.address));
|
|
116
|
+
if (recipient.datum) {
|
|
117
|
+
const { value, inline } = recipient.datum;
|
|
118
|
+
const plutusData = (0, converter_1.toPlutusData)(value);
|
|
119
|
+
txOutputBuilder = txOutputBuilder.with_data_hash(csl_1.csl.hash_plutus_data(plutusData));
|
|
120
|
+
if (inline) {
|
|
121
|
+
txOutputBuilder = txOutputBuilder.with_plutus_data(plutusData);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (recipient.script) {
|
|
125
|
+
const reference = (0, converter_1.toScriptRef)(recipient.script);
|
|
126
|
+
txOutputBuilder = txOutputBuilder.with_script_ref(reference);
|
|
127
|
+
}
|
|
128
|
+
return txOutputBuilder;
|
|
129
|
+
};
|
|
130
|
+
exports.buildTxOutputBuilder = buildTxOutputBuilder;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { csl } from './csl';
|
|
2
|
+
export declare const LANGUAGE_VERSIONS: {
|
|
3
|
+
V1: csl.Language;
|
|
4
|
+
V2: csl.Language;
|
|
5
|
+
};
|
|
6
|
+
export declare const REDEEMER_TAGS: {
|
|
7
|
+
CERT: csl.RedeemerTag;
|
|
8
|
+
MINT: csl.RedeemerTag;
|
|
9
|
+
REWARD: csl.RedeemerTag;
|
|
10
|
+
SPEND: csl.RedeemerTag;
|
|
11
|
+
};
|
|
12
|
+
export declare const POLICY_ID_LENGTH = 56;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POLICY_ID_LENGTH = exports.REDEEMER_TAGS = exports.LANGUAGE_VERSIONS = void 0;
|
|
4
|
+
const csl_1 = require("./csl");
|
|
5
|
+
exports.LANGUAGE_VERSIONS = {
|
|
6
|
+
V1: csl_1.csl.Language.new_plutus_v1(),
|
|
7
|
+
V2: csl_1.csl.Language.new_plutus_v2(),
|
|
8
|
+
};
|
|
9
|
+
exports.REDEEMER_TAGS = {
|
|
10
|
+
CERT: csl_1.csl.RedeemerTag.new_cert(),
|
|
11
|
+
MINT: csl_1.csl.RedeemerTag.new_mint(),
|
|
12
|
+
REWARD: csl_1.csl.RedeemerTag.new_reward(),
|
|
13
|
+
SPEND: csl_1.csl.RedeemerTag.new_spend(),
|
|
14
|
+
};
|
|
15
|
+
exports.POLICY_ID_LENGTH = 56;
|