@harmoniclabs/buildooor 0.1.4 → 0.1.6
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 +1 -0
- package/dist/TxBuilder/TxBuilder.js +130 -0
- package/dist/TxBuilder/utils/getScript.d.ts +11 -0
- package/dist/TxBuilder/utils/getScript.js +92 -0
- package/dist/txBuild/ITxBuildArgs.d.ts +4 -3
- package/dist/txBuild/ITxBuildArgs.js +58 -17
- package/package.json +3 -3
|
@@ -56,6 +56,7 @@ export declare class TxBuilder {
|
|
|
56
56
|
*/
|
|
57
57
|
overrideTxRedeemers(tx: Tx, newRedeemers: TxRedeemer[], opts?: CostModelsToLanguageViewCborOpts): Tx;
|
|
58
58
|
buildSync(buildArgs: ITxBuildArgs, { onScriptInvalid, onScriptResult }?: ITxBuildSyncOptions): Tx;
|
|
59
|
+
validatePhaseTwo(tx: Tx): boolean;
|
|
59
60
|
assertMinOutLovelaces(txOuts: TxOut[]): void;
|
|
60
61
|
/**
|
|
61
62
|
* extracts the important data from the input
|
|
@@ -116,6 +116,7 @@ var TxBuilderProtocolParams_1 = require("./TxBuilderProtocolParams.js");
|
|
|
116
116
|
var utils_1 = require("./utils.js");
|
|
117
117
|
var Rational_1 = require("../utils/Rational.js");
|
|
118
118
|
var stringify_1 = require("../utils/stringify.js");
|
|
119
|
+
var getScript_1 = require("./utils/getScript.js");
|
|
119
120
|
// const scriptCache: { [x: string]: UPLCTerm } = {};
|
|
120
121
|
function getScriptLikeUplc(scriptLike) {
|
|
121
122
|
return uplc_1.UPLCDecoder.parse(scriptLike.bytes, "flat").body;
|
|
@@ -451,6 +452,135 @@ var TxBuilder = /** @class */ (function () {
|
|
|
451
452
|
this.assertMinOutLovelaces(tx.body.outputs);
|
|
452
453
|
return tx;
|
|
453
454
|
};
|
|
455
|
+
TxBuilder.prototype.validatePhaseTwo = function (tx) {
|
|
456
|
+
var txBody = tx.body;
|
|
457
|
+
var rdmrs = tx.witnesses.redeemers;
|
|
458
|
+
if (!Array.isArray(rdmrs) || rdmrs.length === 0)
|
|
459
|
+
return true;
|
|
460
|
+
var nRdmrs = rdmrs.length;
|
|
461
|
+
var cek = this.cek;
|
|
462
|
+
if (!(cek instanceof plutus_machine_1.Machine))
|
|
463
|
+
throw new Error("protocol params are missing the script evaluation costs");
|
|
464
|
+
var executionUnitPrices = this.protocolParamters.executionUnitPrices;
|
|
465
|
+
executionUnitPrices = Array.isArray(executionUnitPrices) ? executionUnitPrices : [
|
|
466
|
+
executionUnitPrices.priceMemory,
|
|
467
|
+
executionUnitPrices.priceSteps,
|
|
468
|
+
];
|
|
469
|
+
var _a = __read(executionUnitPrices, 2), memRational = _a[0], cpuRational = _a[1];
|
|
470
|
+
memRational = typeof memRational === "number" ? cbor_1.CborPositiveRational.fromNumber(memRational) : memRational;
|
|
471
|
+
cpuRational = typeof cpuRational === "number" ? cbor_1.CborPositiveRational.fromNumber(cpuRational) : cpuRational;
|
|
472
|
+
var _b = (0, toOnChain_1.getTxInfos)(tx, this.genesisInfos), txInfosV1 = _b.v1, txInfosV2 = _b.v2, txInfosV3 = _b.v3;
|
|
473
|
+
var totExBudget = new plutus_machine_1.ExBudget({ mem: 0, cpu: 0 });
|
|
474
|
+
var _loop_3 = function (i) {
|
|
475
|
+
var rdmr = rdmrs[i];
|
|
476
|
+
var tag = rdmr.tag, rdmrData = rdmr.data, rdmr_idx = rdmr.index;
|
|
477
|
+
// "+ 1" because we keep track of lovelaces even if in mint values these are 0
|
|
478
|
+
var index = rdmr_idx + (tag === cardano_ledger_ts_1.TxRedeemerTag.Mint ? 1 : 0);
|
|
479
|
+
var onlyRedeemerArg = function (script) {
|
|
480
|
+
if (!(script instanceof cardano_ledger_ts_1.Script))
|
|
481
|
+
throw new Error("missing script for " + (0, cardano_ledger_ts_1.txRedeemerTagToString)(tag) + " redeemer " + (index - 1));
|
|
482
|
+
var expectedVersion = (0, utils_1.scriptTypeToDataVersion)(script.type);
|
|
483
|
+
if (typeof expectedVersion !== "string")
|
|
484
|
+
throw new Error("unexpected redeemer for native script");
|
|
485
|
+
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), (0, getSpendingPurposeData_1.getScriptInfoData)(rdmr, tx.body, expectedVersion), rdmrData, txInfosV1, txInfosV2, txInfosV3);
|
|
486
|
+
var isV2OrLess = (script.type === cardano_ledger_ts_1.ScriptType.PlutusV1 ||
|
|
487
|
+
script.type === cardano_ledger_ts_1.ScriptType.PlutusV2 ||
|
|
488
|
+
script.type === cardano_ledger_ts_1.ScriptType.NativeScript);
|
|
489
|
+
var _a = cek.eval(isV2OrLess ?
|
|
490
|
+
new uplc_1.Application(new uplc_1.Application((0, uplc_1.parseUPLC)(script.bytes).body, uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData)) :
|
|
491
|
+
new uplc_1.Application((0, uplc_1.parseUPLC)(script.bytes).body, uplc_1.UPLCConst.data(ctxData))), result = _a.result, budgetSpent = _a.budgetSpent, logs = _a.logs;
|
|
492
|
+
var successExec = isV2OrLess ?
|
|
493
|
+
!(result instanceof uplc_1.ErrorUPLC) :
|
|
494
|
+
( // v3 requires to return unit
|
|
495
|
+
result instanceof uplc_1.UPLCConst
|
|
496
|
+
&& Array.isArray(result.type)
|
|
497
|
+
&& result.type.length === 1
|
|
498
|
+
&& result.type[0] === uplc_1.ConstTyTag.unit
|
|
499
|
+
&& result.value === undefined);
|
|
500
|
+
if (!successExec)
|
|
501
|
+
return false;
|
|
502
|
+
if (budgetSpent.cpu > rdmr.execUnits.cpu
|
|
503
|
+
|| budgetSpent.mem > rdmr.execUnits.mem)
|
|
504
|
+
return false;
|
|
505
|
+
totExBudget.add(rdmr.execUnits);
|
|
506
|
+
return true;
|
|
507
|
+
};
|
|
508
|
+
if (tag === cardano_ledger_ts_1.TxRedeemerTag.Spend) {
|
|
509
|
+
var entry = (0, getScript_1.getSpendingScript)(tx, index);
|
|
510
|
+
if (!entry)
|
|
511
|
+
return { value: false };
|
|
512
|
+
var script = entry.script, datum = entry.datum;
|
|
513
|
+
// TODO: check if this is correct
|
|
514
|
+
// I'm assuming native scripts are phase 1
|
|
515
|
+
if (script.type === cardano_ledger_ts_1.ScriptType.NativeScript)
|
|
516
|
+
return { value: true };
|
|
517
|
+
var isV2OrLess = script.type === cardano_ledger_ts_1.ScriptType.PlutusV1 || script.type === cardano_ledger_ts_1.ScriptType.PlutusV2;
|
|
518
|
+
if (datum === undefined && isV2OrLess)
|
|
519
|
+
throw new Error("missing datum for spend redeemer " + index);
|
|
520
|
+
var expectedVersion = (0, utils_1.scriptTypeToDataVersion)(script.type);
|
|
521
|
+
if (typeof expectedVersion !== "string")
|
|
522
|
+
throw new Error("unexpected redeemer for native script");
|
|
523
|
+
var ctxData = getCtx(script.type, (0, getSpendingPurposeData_1.getSpendingPurposeData)(rdmr, tx.body, expectedVersion), (0, getSpendingPurposeData_1.getScriptInfoData)(rdmr, tx.body, expectedVersion, datum), rdmrData, txInfosV1, txInfosV2, txInfosV3);
|
|
524
|
+
var _c = cek.eval(isV2OrLess ?
|
|
525
|
+
new uplc_1.Application(new uplc_1.Application(new uplc_1.Application((0, uplc_1.parseUPLC)(script.bytes).body, uplc_1.UPLCConst.data(datum)), uplc_1.UPLCConst.data(rdmrData)), uplc_1.UPLCConst.data(ctxData)) :
|
|
526
|
+
new uplc_1.Application((0, uplc_1.parseUPLC)(script.bytes).body, uplc_1.UPLCConst.data(ctxData))), result = _c.result, budgetSpent = _c.budgetSpent, logs = _c.logs;
|
|
527
|
+
var successExec = isV2OrLess ?
|
|
528
|
+
!(result instanceof uplc_1.ErrorUPLC) :
|
|
529
|
+
( // v3 requires to return unit
|
|
530
|
+
result instanceof uplc_1.UPLCConst
|
|
531
|
+
&& Array.isArray(result.type)
|
|
532
|
+
&& result.type.length === 1
|
|
533
|
+
&& result.type[0] === uplc_1.ConstTyTag.unit
|
|
534
|
+
&& result.value === undefined);
|
|
535
|
+
if (!successExec)
|
|
536
|
+
return { value: false };
|
|
537
|
+
if (budgetSpent.cpu > rdmr.execUnits.cpu
|
|
538
|
+
|| budgetSpent.mem > rdmr.execUnits.mem)
|
|
539
|
+
return { value: false };
|
|
540
|
+
totExBudget.add(rdmr.execUnits);
|
|
541
|
+
return "continue";
|
|
542
|
+
}
|
|
543
|
+
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Mint) {
|
|
544
|
+
if (onlyRedeemerArg((0, getScript_1.getMintingScript)(tx, index)))
|
|
545
|
+
return "continue";
|
|
546
|
+
else
|
|
547
|
+
return { value: false };
|
|
548
|
+
}
|
|
549
|
+
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Cert) {
|
|
550
|
+
if (onlyRedeemerArg((0, getScript_1.getCeritficateScript)(tx, index)))
|
|
551
|
+
return "continue";
|
|
552
|
+
else
|
|
553
|
+
return { value: false };
|
|
554
|
+
}
|
|
555
|
+
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Withdraw) {
|
|
556
|
+
if (onlyRedeemerArg((0, getScript_1.getWithdrawalScript)(tx, index)))
|
|
557
|
+
return "continue";
|
|
558
|
+
else
|
|
559
|
+
return { value: false };
|
|
560
|
+
}
|
|
561
|
+
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Voting) {
|
|
562
|
+
if (onlyRedeemerArg((0, getScript_1.getVotingScript)(tx, index)))
|
|
563
|
+
return "continue";
|
|
564
|
+
else
|
|
565
|
+
return { value: false };
|
|
566
|
+
}
|
|
567
|
+
else if (tag === cardano_ledger_ts_1.TxRedeemerTag.Proposing) {
|
|
568
|
+
if (onlyRedeemerArg((0, getScript_1.getProposingScript)(tx, index)))
|
|
569
|
+
return "continue";
|
|
570
|
+
else
|
|
571
|
+
return { value: false };
|
|
572
|
+
}
|
|
573
|
+
else
|
|
574
|
+
throw new Error("unrecoignized redeemer tag " + tag);
|
|
575
|
+
return { value: false };
|
|
576
|
+
};
|
|
577
|
+
for (var i = 0; i < nRdmrs; i++) {
|
|
578
|
+
var state_2 = _loop_3(i);
|
|
579
|
+
if (typeof state_2 === "object")
|
|
580
|
+
return state_2.value;
|
|
581
|
+
} // for loop over redeemers
|
|
582
|
+
return true;
|
|
583
|
+
};
|
|
454
584
|
TxBuilder.prototype.assertMinOutLovelaces = function (txOuts) {
|
|
455
585
|
for (var i = 0; i < txOuts.length; i++) {
|
|
456
586
|
var out = txOuts[i];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Script, Tx, ScriptType } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
|
+
import { Data } from "@harmoniclabs/plutus-data";
|
|
3
|
+
export declare function getSpendingScript(tx: Tx, index: number): {
|
|
4
|
+
script: Script;
|
|
5
|
+
datum: Data | undefined;
|
|
6
|
+
} | undefined;
|
|
7
|
+
export declare function getMintingScript(tx: Tx, index: number): Script<ScriptType> | undefined;
|
|
8
|
+
export declare function getCeritficateScript(tx: Tx, index: number): Script<ScriptType> | undefined;
|
|
9
|
+
export declare function getWithdrawalScript(tx: Tx, index: number): Script<ScriptType> | undefined;
|
|
10
|
+
export declare function getVotingScript(tx: Tx, index: number): Script<ScriptType> | undefined;
|
|
11
|
+
export declare function getProposingScript(tx: Tx, index: number): Script<ScriptType> | undefined;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProposingScript = exports.getVotingScript = exports.getWithdrawalScript = exports.getCeritficateScript = exports.getMintingScript = exports.getSpendingScript = void 0;
|
|
4
|
+
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
5
|
+
var plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
6
|
+
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
7
|
+
function getScriptByHash(tx, hash) {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9
|
+
if (!(hash instanceof Uint8Array
|
|
10
|
+
&& hash.length === 28))
|
|
11
|
+
return undefined;
|
|
12
|
+
var witnesses = tx.witnesses;
|
|
13
|
+
return ((_f = (_d = (_b = (_a = witnesses.plutusV1Scripts) === null || _a === void 0 ? void 0 : _a.find(function (s) { return (0, uint8array_utils_1.uint8ArrayEq)(hash, s.hash.toBuffer()); })) !== null && _b !== void 0 ? _b : (_c = witnesses.plutusV2Scripts) === null || _c === void 0 ? void 0 : _c.find(function (s) { return (0, uint8array_utils_1.uint8ArrayEq)(hash, s.hash.toBuffer()); })) !== null && _d !== void 0 ? _d : (_e = witnesses.plutusV3Scripts) === null || _e === void 0 ? void 0 : _e.find(function (s) { return (0, uint8array_utils_1.uint8ArrayEq)(hash, s.hash.toBuffer()); })) !== null && _f !== void 0 ? _f : (_h = (_g = tx.body.refInputs) === null || _g === void 0 ? void 0 : _g.find(function (i) { return i.resolved.refScript && (0, uint8array_utils_1.uint8ArrayEq)(hash, i.resolved.refScript.hash.toBuffer()); })) === null || _h === void 0 ? void 0 : _h.resolved.refScript);
|
|
14
|
+
}
|
|
15
|
+
function getSpendingScript(tx, index) {
|
|
16
|
+
var allScriptInputs = tx.body.inputs.filter(function (i) { return i.resolved.address.paymentCreds.type === cardano_ledger_ts_1.CredentialType.Script; });
|
|
17
|
+
if (allScriptInputs.length === 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
var scriptInput = allScriptInputs[index];
|
|
20
|
+
if (!scriptInput)
|
|
21
|
+
return undefined;
|
|
22
|
+
var scriptHash = scriptInput.resolved.address.paymentCreds.hash.toBuffer();
|
|
23
|
+
var script = getScriptByHash(tx, scriptHash);
|
|
24
|
+
if (!script)
|
|
25
|
+
return undefined;
|
|
26
|
+
if ((0, plutus_data_1.isData)(scriptInput.resolved.datum))
|
|
27
|
+
return { script: script, datum: scriptInput.resolved.datum };
|
|
28
|
+
return { script: script, datum: undefined };
|
|
29
|
+
}
|
|
30
|
+
exports.getSpendingScript = getSpendingScript;
|
|
31
|
+
function getMintingScript(tx, index) {
|
|
32
|
+
var mintedValue = tx.body.mint;
|
|
33
|
+
if (!mintedValue)
|
|
34
|
+
return undefined;
|
|
35
|
+
var allPolicies = mintedValue.map.map(function (entry) { return entry.policy; }).filter(function (p) { return p instanceof cardano_ledger_ts_1.Hash28; });
|
|
36
|
+
if (allPolicies.length === 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
var policyHash = allPolicies[index];
|
|
39
|
+
return getScriptByHash(tx, policyHash.toBuffer());
|
|
40
|
+
}
|
|
41
|
+
exports.getMintingScript = getMintingScript;
|
|
42
|
+
function getCeritficateScript(tx, index) {
|
|
43
|
+
var _a;
|
|
44
|
+
var allCertificates = tx.body.certs;
|
|
45
|
+
if (!allCertificates)
|
|
46
|
+
return undefined;
|
|
47
|
+
var cert = allCertificates[index];
|
|
48
|
+
if (!cert)
|
|
49
|
+
return undefined;
|
|
50
|
+
return getScriptByHash(tx, (_a = getCertStakeCreds(cert)) === null || _a === void 0 ? void 0 : _a.hash.toBuffer());
|
|
51
|
+
}
|
|
52
|
+
exports.getCeritficateScript = getCeritficateScript;
|
|
53
|
+
function getWithdrawalScript(tx, index) {
|
|
54
|
+
var _a;
|
|
55
|
+
var allWithdrawals = tx.body.withdrawals;
|
|
56
|
+
if (!allWithdrawals)
|
|
57
|
+
return undefined;
|
|
58
|
+
var scriptHash = (_a = allWithdrawals.map[index]) === null || _a === void 0 ? void 0 : _a.rewardAccount.credentials.toBuffer();
|
|
59
|
+
if (!scriptHash)
|
|
60
|
+
return undefined;
|
|
61
|
+
return getScriptByHash(tx, scriptHash);
|
|
62
|
+
}
|
|
63
|
+
exports.getWithdrawalScript = getWithdrawalScript;
|
|
64
|
+
function getVotingScript(tx, index) {
|
|
65
|
+
// TODO
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
exports.getVotingScript = getVotingScript;
|
|
69
|
+
function getProposingScript(tx, index) {
|
|
70
|
+
// TODO
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
exports.getProposingScript = getProposingScript;
|
|
74
|
+
function getCertStakeCreds(cert) {
|
|
75
|
+
// CertAuthCommitteeHot | CertResignCommitteeCold | CertRegistrationDrep | CertUnRegistrationDrep | CertUpdateDrep;
|
|
76
|
+
if (cert instanceof cardano_ledger_ts_1.CertStakeRegistration
|
|
77
|
+
|| cert instanceof cardano_ledger_ts_1.CertStakeDeRegistration
|
|
78
|
+
|| cert instanceof cardano_ledger_ts_1.CertStakeDelegation
|
|
79
|
+
|| cert instanceof cardano_ledger_ts_1.CertVoteDeleg
|
|
80
|
+
|| cert instanceof cardano_ledger_ts_1.CertStakeVoteDeleg
|
|
81
|
+
|| cert instanceof cardano_ledger_ts_1.CertRegistrationDeposit
|
|
82
|
+
|| cert instanceof cardano_ledger_ts_1.CertUnRegistrationDeposit
|
|
83
|
+
|| cert instanceof cardano_ledger_ts_1.CertStakeRegistrationDeleg
|
|
84
|
+
|| cert instanceof cardano_ledger_ts_1.CertVoteRegistrationDeleg
|
|
85
|
+
|| cert instanceof cardano_ledger_ts_1.CertStakeVoteRegistrationDeleg)
|
|
86
|
+
return cert.stakeCredential;
|
|
87
|
+
if (cert instanceof cardano_ledger_ts_1.CertRegistrationDrep
|
|
88
|
+
|| cert instanceof cardano_ledger_ts_1.CertUnRegistrationDrep
|
|
89
|
+
|| cert instanceof cardano_ledger_ts_1.CertUpdateDrep)
|
|
90
|
+
return cert.drepCredential;
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
@@ -8,6 +8,7 @@ import { CanBeUInteger } from "../utils/ints.js";
|
|
|
8
8
|
import { ChangeInfos, NormalizedChangeInfos } from "./ChangeInfos/ChangeInfos.js";
|
|
9
9
|
import { ITxBuildVotingProcedure, NormalizedITxBuildVotingProcedure } from "./ITxBuildVotingProcedure.js";
|
|
10
10
|
import { ITxBuildProposalProcedure, NormalizedITxBuildProposalProcedure } from "./ITxBuildProposalProcedure.js";
|
|
11
|
+
import { CanBeCborString } from "@harmoniclabs/cbor";
|
|
11
12
|
export interface ITxBuildArgs {
|
|
12
13
|
inputs: (ITxBuildInput | IUTxO)[];
|
|
13
14
|
/**
|
|
@@ -19,7 +20,7 @@ export interface ITxBuildArgs {
|
|
|
19
20
|
* });
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
|
-
changeAddress?: Address | AddressStr;
|
|
23
|
+
changeAddress?: Address | AddressStr | CanBeCborString;
|
|
23
24
|
change?: ChangeInfos;
|
|
24
25
|
outputs?: ITxBuildOutput[];
|
|
25
26
|
readonlyRefInputs?: IUTxO[];
|
|
@@ -69,8 +70,8 @@ export interface NormalizedITxBuildArgs extends ITxBuildArgs {
|
|
|
69
70
|
metadata?: TxMetadata;
|
|
70
71
|
votingProcedures?: NormalizedITxBuildVotingProcedure[];
|
|
71
72
|
proposalProcedures?: NormalizedITxBuildProposalProcedure[];
|
|
72
|
-
currentTreasuryValue?:
|
|
73
|
-
paymentToTreasury?:
|
|
73
|
+
currentTreasuryValue?: CanBeUInteger;
|
|
74
|
+
paymentToTreasury?: CanBeUInteger;
|
|
74
75
|
}
|
|
75
76
|
export declare function normalizeITxBuildArgs({ inputs, change, changeAddress, outputs, readonlyRefInputs, requiredSigners, collaterals, collateralReturn, mints, invalidBefore, invalidAfter, certificates, withdrawals, fee, memo, metadata, votingProcedures, proposalProcedures, currentTreasuryValue, paymentToTreasury }: ITxBuildArgs): NormalizedITxBuildArgs;
|
|
76
77
|
/** @deprecated use `normalizeITxBuildArgs` instead */
|
|
@@ -11,18 +11,17 @@ var ints_1 = require("../utils/ints.js");
|
|
|
11
11
|
var ChangeInfos_1 = require("./ChangeInfos/ChangeInfos.js");
|
|
12
12
|
var ITxBuildVotingProcedure_1 = require("./ITxBuildVotingProcedure.js");
|
|
13
13
|
var ITxBuildProposalProcedure_1 = require("./ITxBuildProposalProcedure.js");
|
|
14
|
+
var cbor_1 = require("@harmoniclabs/cbor");
|
|
14
15
|
function normalizeITxBuildArgs(_a) {
|
|
15
16
|
var inputs = _a.inputs, change = _a.change, changeAddress = _a.changeAddress, outputs = _a.outputs, readonlyRefInputs = _a.readonlyRefInputs, requiredSigners = _a.requiredSigners, collaterals = _a.collaterals, collateralReturn = _a.collateralReturn, mints = _a.mints, invalidBefore = _a.invalidBefore, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, fee = _a.fee, memo = _a.memo, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury;
|
|
16
17
|
return {
|
|
17
18
|
inputs: inputs.map(normalizeITxBuildArgsInputs),
|
|
18
19
|
change: change ? (0, ChangeInfos_1.normalizeChangeInfos)(change) : undefined,
|
|
19
|
-
changeAddress:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
outputs: outputs === null || outputs === void 0 ? void 0 : outputs.map(ITxBuildOutput_1.txBuildOutToTxOut),
|
|
23
|
-
readonlyRefInputs: readonlyRefInputs === null || readonlyRefInputs === void 0 ? void 0 : readonlyRefInputs.map(toUTxONoClone),
|
|
20
|
+
changeAddress: normalizeChangeAddress(changeAddress),
|
|
21
|
+
outputs: outputs === null || outputs === void 0 ? void 0 : outputs.map(normalizeTxBuildArgsOutputs),
|
|
22
|
+
readonlyRefInputs: readonlyRefInputs === null || readonlyRefInputs === void 0 ? void 0 : readonlyRefInputs.map(nomalizeUTXOInput),
|
|
24
23
|
requiredSigners: requiredSigners === null || requiredSigners === void 0 ? void 0 : requiredSigners.map(toPubKeyHash),
|
|
25
|
-
collaterals: collaterals === null || collaterals === void 0 ? void 0 : collaterals.map(
|
|
24
|
+
collaterals: collaterals === null || collaterals === void 0 ? void 0 : collaterals.map(nomalizeUTXOInput),
|
|
26
25
|
collateralReturn: collateralReturn ? (0, ITxBuildOutput_1.txBuildOutToTxOut)(collateralReturn) : undefined,
|
|
27
26
|
mints: mints === null || mints === void 0 ? void 0 : mints.map(ITxBuildMint_1.normalizeITxBuildMint),
|
|
28
27
|
invalidBefore: invalidBefore === undefined ? undefined : BigInt(invalidBefore),
|
|
@@ -32,36 +31,78 @@ function normalizeITxBuildArgs(_a) {
|
|
|
32
31
|
fee: (0, ints_1.canBeUInteger)(fee) ? BigInt(fee) : undefined,
|
|
33
32
|
memo: memo ? String(memo) : undefined,
|
|
34
33
|
metadata: metadata,
|
|
35
|
-
votingProcedures: Array.isArray(votingProcedures)
|
|
36
|
-
votingProcedures.map(function (entry) {
|
|
34
|
+
votingProcedures: Array.isArray(votingProcedures)
|
|
35
|
+
? votingProcedures.map(function (entry) {
|
|
37
36
|
if ((0, cardano_ledger_ts_1.isIVotingProceduresEntry)(entry))
|
|
38
37
|
entry = {
|
|
39
38
|
votingProcedure: entry,
|
|
40
|
-
script: undefined // for js shape optimization
|
|
39
|
+
script: undefined, // for js shape optimization
|
|
41
40
|
};
|
|
42
41
|
return (0, ITxBuildVotingProcedure_1.normalizeITxBuildVotingProcedure)(entry);
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
})
|
|
43
|
+
: undefined,
|
|
44
|
+
proposalProcedures: Array.isArray(proposalProcedures)
|
|
45
|
+
? proposalProcedures.map(function (entry) {
|
|
46
46
|
if ((0, cardano_ledger_ts_1.isIProposalProcedure)(entry))
|
|
47
47
|
entry = {
|
|
48
48
|
proposalProcedure: entry,
|
|
49
|
-
script: undefined
|
|
49
|
+
script: undefined,
|
|
50
50
|
};
|
|
51
51
|
return (0, ITxBuildProposalProcedure_1.normalizeITxBuildProposalProcedure)(entry);
|
|
52
|
-
})
|
|
52
|
+
})
|
|
53
|
+
: undefined,
|
|
53
54
|
currentTreasuryValue: currentTreasuryValue === undefined ? undefined : BigInt(currentTreasuryValue),
|
|
54
55
|
paymentToTreasury: paymentToTreasury === undefined ? undefined : BigInt(paymentToTreasury),
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
exports.normalizeITxBuildArgs = normalizeITxBuildArgs;
|
|
59
|
+
/** Check input type and convert to NormalizedITxBuildInput */
|
|
58
60
|
function normalizeITxBuildArgsInputs(input) {
|
|
59
|
-
if ((0,
|
|
61
|
+
if ((0, cbor_1.canBeCborString)(input)) {
|
|
62
|
+
var cborData = (0, cbor_1.forceCborString)(input);
|
|
63
|
+
var iUtxo = cardano_ledger_ts_1.UTxO.fromCbor(cborData);
|
|
64
|
+
return (0, ITxBuildInput_1.normalizeITxBuildInput)({ utxo: iUtxo });
|
|
65
|
+
}
|
|
66
|
+
if ((0, cardano_ledger_ts_1.isIUTxO)(input)) {
|
|
60
67
|
return { utxo: new cardano_ledger_ts_1.UTxO(input) };
|
|
68
|
+
}
|
|
61
69
|
return (0, ITxBuildInput_1.normalizeITxBuildInput)(input);
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
/** Check Changeaddress type and convert to normalizeChangeAddress */
|
|
72
|
+
function normalizeChangeAddress(changeAddress) {
|
|
73
|
+
if (changeAddress === undefined) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if ((0, cardano_ledger_ts_1.isAddressStr)(changeAddress)) {
|
|
77
|
+
return cardano_ledger_ts_1.Address.fromString(changeAddress);
|
|
78
|
+
}
|
|
79
|
+
if ((0, cbor_1.canBeCborString)(changeAddress)) {
|
|
80
|
+
var cborData = (0, cbor_1.forceCborString)(changeAddress);
|
|
81
|
+
console.log("address cborData: ", cborData);
|
|
82
|
+
return cardano_ledger_ts_1.Address.fromCbor(cborData);
|
|
83
|
+
}
|
|
84
|
+
if (changeAddress instanceof cardano_ledger_ts_1.Address) {
|
|
85
|
+
return changeAddress;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Check output type and convert to TxOut */
|
|
89
|
+
function normalizeTxBuildArgsOutputs(output) {
|
|
90
|
+
if ((0, cbor_1.canBeCborString)(output)) {
|
|
91
|
+
var cborData = (0, cbor_1.forceCborString)(output);
|
|
92
|
+
var txout = cardano_ledger_ts_1.TxOut.fromCbor(cborData);
|
|
93
|
+
return (0, ITxBuildOutput_1.txBuildOutToTxOut)(txout);
|
|
94
|
+
}
|
|
95
|
+
if ((0, cardano_ledger_ts_1.isITxOut)(output)) {
|
|
96
|
+
return (0, ITxBuildOutput_1.txBuildOutToTxOut)(output);
|
|
97
|
+
}
|
|
98
|
+
return (0, ITxBuildOutput_1.txBuildOutToTxOut)(output);
|
|
99
|
+
}
|
|
100
|
+
function nomalizeUTXOInput(input) {
|
|
101
|
+
if ((0, cbor_1.canBeCborString)(input)) {
|
|
102
|
+
var cborData = (0, cbor_1.forceCborString)(input);
|
|
103
|
+
return cardano_ledger_ts_1.UTxO.fromCbor(cborData);
|
|
104
|
+
}
|
|
105
|
+
return new cardano_ledger_ts_1.UTxO(input);
|
|
65
106
|
}
|
|
66
107
|
function toPubKeyHash(hash) {
|
|
67
108
|
return new cardano_ledger_ts_1.PubKeyHash(hash);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmoniclabs/buildooor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Cardano transaction builder in typescript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"@harmoniclabs/bytestring": "^1.0.0",
|
|
53
53
|
"@harmoniclabs/cardano-costmodels-ts": "^1.3.0",
|
|
54
54
|
"@harmoniclabs/cardano-ledger-ts": "^0.3.2",
|
|
55
|
-
"@harmoniclabs/cbor": "^1.6.
|
|
55
|
+
"@harmoniclabs/cbor": "^1.6.6",
|
|
56
56
|
"@harmoniclabs/pair": "^1.0.0",
|
|
57
|
-
"@harmoniclabs/plutus-data": "^1.2.
|
|
57
|
+
"@harmoniclabs/plutus-data": "^1.2.6",
|
|
58
58
|
"@harmoniclabs/plutus-machine": "^2.1.0",
|
|
59
59
|
"@harmoniclabs/uplc": "^1.4.0"
|
|
60
60
|
},
|