@harmoniclabs/buildooor 0.1.31 → 0.2.0
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/TxBuilder/TxBuilder.d.ts +2 -2
- package/dist/TxBuilder/TxBuilder.js +13 -21
- package/dist/TxBuilder/TxBuilderRunner/TxBuilderRunner.js +1 -1
- package/dist/txBuild/ITxBuildInput/ITxBuildInput.js +1 -1
- package/dist/txBuild/ITxBuildOptions.d.ts +2 -3
- package/dist/utils/CanBeData.js +5 -4
- package/package.json +8 -8
|
@@ -3,7 +3,7 @@ import { CostModelsToLanguageViewCborOpts } from "@harmoniclabs/cardano-costmode
|
|
|
3
3
|
import { Tx, Value, TxOut, TxRedeemerTag, ScriptType, UTxO, TxRedeemer, TxWitnessSet, ScriptDataHash, ITxOut, ValueUnits } from "@harmoniclabs/cardano-ledger-ts";
|
|
4
4
|
import { CanBeCborString } from "@harmoniclabs/cbor";
|
|
5
5
|
import { Data } from "@harmoniclabs/plutus-data";
|
|
6
|
-
import { ExBudget,
|
|
6
|
+
import { ExBudget, CEKValueObj } from "@harmoniclabs/plutus-machine";
|
|
7
7
|
import { ITxBuildArgs, ITxBuildOptions, ITxBuildInput, ITxBuildSyncOptions } from "../txBuild/index.js";
|
|
8
8
|
import { CanBeUInteger } from "../utils/ints.js";
|
|
9
9
|
import { TxBuilderRunner } from "./TxBuilderRunner/TxBuilderRunner.js";
|
|
@@ -58,7 +58,7 @@ export declare class TxBuilder {
|
|
|
58
58
|
overrideTxRedeemers(tx: Tx, newRedeemers: TxRedeemer[], opts?: CostModelsToLanguageViewCborOpts): Tx;
|
|
59
59
|
buildSync(buildArgs: ITxBuildArgs, { onScriptInvalid, onScriptResult, ...otps }?: ITxBuildSyncOptions): Tx;
|
|
60
60
|
validatePhaseTwoVerbose(tx: Tx): {
|
|
61
|
-
result:
|
|
61
|
+
result: CEKValueObj;
|
|
62
62
|
budgetSpent: ExBudget;
|
|
63
63
|
logs: string[];
|
|
64
64
|
rdmr: TxRedeemer;
|
|
@@ -169,7 +169,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
169
169
|
};
|
|
170
170
|
TxBuilder.prototype.calcLinearFee = function (tx) {
|
|
171
171
|
return ((0, ints_1.forceBigUInt)(this.protocolParamters.txFeePerByte) *
|
|
172
|
-
BigInt((tx instanceof cardano_ledger_ts_1.Tx ? tx.toCbor() : tx).
|
|
172
|
+
BigInt((tx instanceof cardano_ledger_ts_1.Tx ? tx.toCbor() : tx).length
|
|
173
173
|
+ 2 // for good measure
|
|
174
174
|
) +
|
|
175
175
|
(0, ints_1.forceBigUInt)(this.protocolParamters.txFeeFixed));
|
|
@@ -179,7 +179,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
179
179
|
var totRefScriptBytes = ((_a = tx.body.refInputs) !== null && _a !== void 0 ? _a : [])
|
|
180
180
|
.reduce(function (sum, refIn) {
|
|
181
181
|
if (refIn.resolved.refScript)
|
|
182
|
-
return sum + BigInt(refIn.resolved.refScript.toCbor().
|
|
182
|
+
return sum + BigInt(refIn.resolved.refScript.toCbor().length
|
|
183
183
|
+ 10 // second Cbor wrap
|
|
184
184
|
);
|
|
185
185
|
return sum;
|
|
@@ -207,18 +207,10 @@ var TxBuilder = /** @class */ (function () {
|
|
|
207
207
|
TxBuilder.prototype.getMinimumOutputLovelaces = function (tx_out) {
|
|
208
208
|
var size = BigInt(0);
|
|
209
209
|
if (tx_out instanceof cardano_ledger_ts_1.TxOut)
|
|
210
|
-
tx_out = tx_out.toCbor()
|
|
210
|
+
tx_out = tx_out.toCbor();
|
|
211
211
|
if (typeof tx_out === "string")
|
|
212
212
|
size = BigInt(Math.ceil(tx_out.length / 2));
|
|
213
|
-
else if (
|
|
214
|
-
if ((0, obj_utils_1.isObject)(tx_out) &&
|
|
215
|
-
(0, obj_utils_1.hasOwn)(tx_out, "toBuffer") &&
|
|
216
|
-
typeof tx_out.toBuffer === "function")
|
|
217
|
-
tx_out = tx_out.toBuffer();
|
|
218
|
-
if (!(tx_out instanceof Uint8Array))
|
|
219
|
-
tx_out = (0, uint8array_utils_1.fromHex)(tx_out.toString());
|
|
220
|
-
}
|
|
221
|
-
if (tx_out instanceof Uint8Array)
|
|
213
|
+
else if (tx_out instanceof Uint8Array)
|
|
222
214
|
size = BigInt(tx_out.length);
|
|
223
215
|
// overestimating the size a bit
|
|
224
216
|
return BigInt(this.protocolParamters.utxoCostPerByte) * (size + BigInt(10));
|
|
@@ -306,7 +298,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
306
298
|
if (opts === void 0) { opts = { mustHaveV3: true }; }
|
|
307
299
|
// datums passed by hash
|
|
308
300
|
var datums = (_a = tx.witnesses.datums) !== null && _a !== void 0 ? _a : [];
|
|
309
|
-
return new cardano_ledger_ts_1.Tx(__assign(__assign({}, tx), { body: new cardano_ledger_ts_1.TxBody(__assign(__assign({}, tx.body), { scriptDataHash: getScriptDataHash(tx.witnesses, (0, cardano_costmodels_ts_1.costModelsToLanguageViewCbor)(this.protocolParamters.costModels, opts)
|
|
301
|
+
return new cardano_ledger_ts_1.Tx(__assign(__assign({}, tx), { body: new cardano_ledger_ts_1.TxBody(__assign(__assign({}, tx.body), { scriptDataHash: getScriptDataHash(tx.witnesses, (0, cardano_costmodels_ts_1.costModelsToLanguageViewCbor)(this.protocolParamters.costModels, opts)) })), witnesses: new cardano_ledger_ts_1.TxWitnessSet(__assign(__assign({}, tx.witnesses), { vkeyWitnesses: [], redeemers: newRedeemers })) }));
|
|
310
302
|
};
|
|
311
303
|
TxBuilder.prototype.buildSync = function (buildArgs, _a) {
|
|
312
304
|
var _b;
|
|
@@ -491,7 +483,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
491
483
|
var onlyRedeemerArg = function (script) {
|
|
492
484
|
if (!(script instanceof cardano_ledger_ts_1.Script)) {
|
|
493
485
|
evalResults.push({
|
|
494
|
-
result: new
|
|
486
|
+
result: new plutus_machine_1.CEKError("missig script"),
|
|
495
487
|
budgetSpent: new plutus_machine_1.ExBudget({ mem: 0, cpu: 0 }),
|
|
496
488
|
logs: [],
|
|
497
489
|
rdmr: rdmr,
|
|
@@ -514,7 +506,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
514
506
|
var entry = (0, getScript_1.getSpendingScript)(tx, index);
|
|
515
507
|
if (!entry) {
|
|
516
508
|
evalResults.push({
|
|
517
|
-
result: new
|
|
509
|
+
result: new plutus_machine_1.CEKError("missig script"),
|
|
518
510
|
budgetSpent: new plutus_machine_1.ExBudget({ mem: 0, cpu: 0 }),
|
|
519
511
|
logs: [],
|
|
520
512
|
rdmr: rdmr,
|
|
@@ -588,7 +580,7 @@ var TxBuilder = /** @class */ (function () {
|
|
|
588
580
|
var minLovelaces = this.getMinimumOutputLovelaces(out);
|
|
589
581
|
if (out.value.lovelaces < minLovelaces)
|
|
590
582
|
throw new Error("tx output at index ".concat(i, " did not have enough lovelaces to meet the minimum allowed by protocol parameters.\n") +
|
|
591
|
-
"output size: ".concat(out.toCbor().
|
|
583
|
+
"output size: ".concat(out.toCbor().length, " bytes\n") +
|
|
592
584
|
"protocol paramters \"utxoCostPerByte\": ".concat(this.protocolParamters.utxoCostPerByte, "\n") +
|
|
593
585
|
"minimum lovelaces required: ".concat(minLovelaces.toString(), "\n") +
|
|
594
586
|
"output lovelaces : ".concat(out.value.lovelaces.toString(), "\n") +
|
|
@@ -996,13 +988,13 @@ var TxBuilder = /** @class */ (function () {
|
|
|
996
988
|
plutusV3Scripts: plutusV3ScriptsWitnesses
|
|
997
989
|
});
|
|
998
990
|
var datumsScriptData = datums.length > 0 ?
|
|
999
|
-
Array.from(cbor_1.Cbor.encode(new cbor_1.CborArray(datums.map(plutus_data_1.dataToCborObj)))
|
|
991
|
+
Array.from(cbor_1.Cbor.encode(new cbor_1.CborArray(datums.map(plutus_data_1.dataToCborObj))))
|
|
1000
992
|
: [];
|
|
1001
993
|
var languageViews = (0, cardano_costmodels_ts_1.costModelsToLanguageViewCbor)(this.protocolParamters.costModels, {
|
|
1002
994
|
mustHaveV1: _hasV1Scripts,
|
|
1003
995
|
mustHaveV2: _hasV2Scripts,
|
|
1004
996
|
mustHaveV3: _hasV3Scripts
|
|
1005
|
-
})
|
|
997
|
+
});
|
|
1006
998
|
invalidBefore = invalidBefore === undef ? undef : (0, ints_1.forceBigUInt)(invalidBefore);
|
|
1007
999
|
// if( invalidAfter !== undef )
|
|
1008
1000
|
// {
|
|
@@ -1324,13 +1316,13 @@ function getScriptDataHash(witnesses, languageViews) {
|
|
|
1324
1316
|
*/
|
|
1325
1317
|
scriptData = new Uint8Array(__spreadArray(__spreadArray([
|
|
1326
1318
|
0xa0
|
|
1327
|
-
], __read(cbor_1.Cbor.encode(dats)
|
|
1319
|
+
], __read(cbor_1.Cbor.encode(dats)), false), [
|
|
1328
1320
|
0xa0
|
|
1329
1321
|
], false));
|
|
1330
1322
|
}
|
|
1331
1323
|
else {
|
|
1332
|
-
var rdmrsBuff = rdmrs ? cbor_1.Cbor.encode(rdmrs)
|
|
1333
|
-
var datsBuff = dats ? cbor_1.Cbor.encode(dats)
|
|
1324
|
+
var rdmrsBuff = rdmrs ? cbor_1.Cbor.encode(rdmrs) : new Uint8Array([0x80]);
|
|
1325
|
+
var datsBuff = dats ? cbor_1.Cbor.encode(dats) : new Uint8Array([]);
|
|
1334
1326
|
scriptData = new Uint8Array(rdmrsBuff.length + datsBuff.length + languageViews.length);
|
|
1335
1327
|
scriptData.set(rdmrsBuff, 0);
|
|
1336
1328
|
scriptData.set(datsBuff, rdmrsBuff.length);
|
|
@@ -124,7 +124,7 @@ var _datumsHashes = [];
|
|
|
124
124
|
var _MAX_DATUMS_CACHE_SIZE = 20;
|
|
125
125
|
function _saveResolvedDatum(datum, hash) {
|
|
126
126
|
var theData = (0, plutus_data_1.cloneData)(datum);
|
|
127
|
-
var actualHash = (0, uint8array_utils_1.toHex)(new Uint8Array((0, crypto_1.sha2_256_sync)((0, plutus_data_1.dataToCbor)(datum)
|
|
127
|
+
var actualHash = (0, uint8array_utils_1.toHex)(new Uint8Array((0, crypto_1.sha2_256_sync)((0, plutus_data_1.dataToCbor)(datum))));
|
|
128
128
|
var actualHashIdx = _datumsHashes.lastIndexOf(actualHash);
|
|
129
129
|
if (actualHashIdx < 0) {
|
|
130
130
|
_datumsHashes.push(actualHash);
|
|
@@ -44,7 +44,7 @@ function normalizeNativeScriptEntry(scr) {
|
|
|
44
44
|
if (!scr)
|
|
45
45
|
return undefined;
|
|
46
46
|
if (isNativeScript(scr)) {
|
|
47
|
-
return new cardano_ledger_ts_1.Script("NativeScript", (0, cardano_ledger_ts_1.nativeScriptToCbor)(scr)
|
|
47
|
+
return new cardano_ledger_ts_1.Script("NativeScript", (0, cardano_ledger_ts_1.nativeScriptToCbor)(scr));
|
|
48
48
|
}
|
|
49
49
|
if (scr instanceof cardano_ledger_ts_1.Script && scr.type === cardano_ledger_ts_1.ScriptType.NativeScript)
|
|
50
50
|
return scr.clone();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Tx, TxRedeemer } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
2
|
import { Data } from "@harmoniclabs/plutus-data";
|
|
3
|
-
import { ExBudget } from "@harmoniclabs/plutus-machine";
|
|
4
|
-
import { PureUPLCTerm } from "@harmoniclabs/uplc";
|
|
3
|
+
import { ExBudget, CEKValueObj } from "@harmoniclabs/plutus-machine";
|
|
5
4
|
export interface ITxBuildSyncOptions {
|
|
6
5
|
/**
|
|
7
6
|
* @default 1
|
|
@@ -9,7 +8,7 @@ export interface ITxBuildSyncOptions {
|
|
|
9
8
|
**/
|
|
10
9
|
nScriptExecitionRounds?: number;
|
|
11
10
|
onScriptInvalid?: (rdmr: TxRedeemer, logs: string[], callArgs: Data[], tx: Tx) => void;
|
|
12
|
-
onScriptResult?: (rdmr: TxRedeemer, result:
|
|
11
|
+
onScriptResult?: (rdmr: TxRedeemer, result: CEKValueObj, exBudget: ExBudget, logs: string[], callArgs: Data[], scriptHash: string, tx: Tx) => void;
|
|
13
12
|
}
|
|
14
13
|
export interface ITxBuildOptions extends ITxBuildSyncOptions {
|
|
15
14
|
keepWorkersAlive?: boolean;
|
package/dist/utils/CanBeData.js
CHANGED
|
@@ -9,8 +9,9 @@ var plutus_machine_1 = require("@harmoniclabs/plutus-machine");
|
|
|
9
9
|
function cloneCanBeData(stuff) {
|
|
10
10
|
if (typeof stuff === "string")
|
|
11
11
|
return stuff;
|
|
12
|
-
if (stuff instanceof
|
|
13
|
-
|
|
12
|
+
if (stuff instanceof Uint8Array)
|
|
13
|
+
return Uint8Array.prototype.slice.call(stuff);
|
|
14
|
+
if ((0, cbor_1.isCborObj)(stuff) ||
|
|
14
15
|
(0, plutus_data_1.isData)(stuff))
|
|
15
16
|
return stuff.clone();
|
|
16
17
|
var result = plutus_machine_1.Machine.evalSimple(stuff.toUPLC());
|
|
@@ -34,7 +35,7 @@ function canBeData(something) {
|
|
|
34
35
|
(typeof something === "object" &&
|
|
35
36
|
(0, obj_utils_1.hasOwn)(something, "toUPLC") &&
|
|
36
37
|
typeof something.toUPLC === "function") ||
|
|
37
|
-
something instanceof
|
|
38
|
+
something instanceof Uint8Array ||
|
|
38
39
|
(0, cbor_1.isCborObj)(something));
|
|
39
40
|
}
|
|
40
41
|
exports.canBeData = canBeData;
|
|
@@ -57,7 +58,7 @@ function forceData(data) {
|
|
|
57
58
|
}
|
|
58
59
|
return _data;
|
|
59
60
|
}
|
|
60
|
-
if (data instanceof
|
|
61
|
+
if (data instanceof Uint8Array) {
|
|
61
62
|
return (0, plutus_data_1.dataFromCbor)(data);
|
|
62
63
|
}
|
|
63
64
|
if ((0, cbor_1.isCborObj)(data)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmoniclabs/buildooor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Cardano transaction builder in typescript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"@harmoniclabs/bigint-utils": "^1.0.0",
|
|
48
48
|
"@harmoniclabs/bip32_ed25519": "^0.1.3",
|
|
49
49
|
"@harmoniclabs/bytestring": "^1.0.0",
|
|
50
|
-
"@harmoniclabs/cardano-costmodels-ts": "^1.
|
|
51
|
-
"@harmoniclabs/cardano-ledger-ts": "^0.
|
|
52
|
-
"@harmoniclabs/cbor": "^
|
|
50
|
+
"@harmoniclabs/cardano-costmodels-ts": "^1.4.0",
|
|
51
|
+
"@harmoniclabs/cardano-ledger-ts": "^0.5.0",
|
|
52
|
+
"@harmoniclabs/cbor": "^2.0.1",
|
|
53
53
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
54
54
|
"@harmoniclabs/obj-utils": "^1.0.0",
|
|
55
55
|
"@harmoniclabs/pair": "^1.0.0",
|
|
56
|
-
"@harmoniclabs/plutus-data": "^
|
|
57
|
-
"@harmoniclabs/plutus-machine": "^
|
|
56
|
+
"@harmoniclabs/plutus-data": "^2.0.1",
|
|
57
|
+
"@harmoniclabs/plutus-machine": "^3.0.0",
|
|
58
58
|
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
59
|
-
"@harmoniclabs/uplc": "^
|
|
59
|
+
"@harmoniclabs/uplc": "^2.0.5"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/preset-env": "^7.18.6",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/jest": "^30.0.0",
|
|
65
65
|
"@types/node": "^18.14.6",
|
|
66
66
|
"jest": "^30.2.0",
|
|
67
|
-
"jest-environment-jsdom": "^
|
|
67
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
68
68
|
"tsc-alias": "^1.7.1",
|
|
69
69
|
"typescript": "^4.6.3"
|
|
70
70
|
},
|