@harmoniclabs/buildooor 0.1.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/LICENSE +201 -0
- package/README.md +22 -0
- package/dist/TxBuilder/CanResolveToUTxO/CanResolveToUTxO.d.ts +5 -0
- package/dist/TxBuilder/CanResolveToUTxO/CanResolveToUTxO.js +62 -0
- package/dist/TxBuilder/CanResolveToUTxO/index.d.ts +1 -0
- package/dist/TxBuilder/CanResolveToUTxO/index.js +17 -0
- package/dist/TxBuilder/GenesisInfos.d.ts +54 -0
- package/dist/TxBuilder/GenesisInfos.js +56 -0
- package/dist/TxBuilder/IProvider/IProvider.d.ts +42 -0
- package/dist/TxBuilder/IProvider/IProvider.js +2 -0
- package/dist/TxBuilder/IProvider/index.d.ts +1 -0
- package/dist/TxBuilder/IProvider/index.js +17 -0
- package/dist/TxBuilder/TxBuilder.d.ts +106 -0
- package/dist/TxBuilder/TxBuilder.js +1251 -0
- package/dist/TxBuilder/TxBuilderProtocolParams.d.ts +42 -0
- package/dist/TxBuilder/TxBuilderProtocolParams.js +121 -0
- package/dist/TxBuilder/TxBuilderRunner/CanBePoolKeyHash.d.ts +3 -0
- package/dist/TxBuilder/TxBuilderRunner/CanBePoolKeyHash.js +33 -0
- package/dist/TxBuilder/TxBuilderRunner/CanBeStakeCreds.d.ts +3 -0
- package/dist/TxBuilder/TxBuilderRunner/CanBeStakeCreds.js +25 -0
- package/dist/TxBuilder/TxBuilderRunner/TxBuilderRunner.d.ts +280 -0
- package/dist/TxBuilder/TxBuilderRunner/TxBuilderRunner.js +1366 -0
- package/dist/TxBuilder/TxBuilderRunner/forceAddr.d.ts +2 -0
- package/dist/TxBuilder/TxBuilderRunner/forceAddr.js +8 -0
- package/dist/TxBuilder/TxBuilderRunner/index.d.ts +2 -0
- package/dist/TxBuilder/TxBuilderRunner/index.js +18 -0
- package/dist/TxBuilder/TxBuilderRunner/jsonToMetadata.d.ts +2 -0
- package/dist/TxBuilder/TxBuilderRunner/jsonToMetadata.js +35 -0
- package/dist/TxBuilder/index.d.ts +5 -0
- package/dist/TxBuilder/index.js +21 -0
- package/dist/TxBuilder/keepRelevant.d.ts +4 -0
- package/dist/TxBuilder/keepRelevant.js +79 -0
- package/dist/TxBuilder/utils.d.ts +4 -0
- package/dist/TxBuilder/utils.js +66 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/toOnChain/getSpendingPurposeData.d.ts +5 -0
- package/dist/toOnChain/getSpendingPurposeData.js +98 -0
- package/dist/toOnChain/getTxInfos.d.ts +8 -0
- package/dist/toOnChain/getTxInfos.js +126 -0
- package/dist/toOnChain/getTxIntervalData.d.ts +19 -0
- package/dist/toOnChain/getTxIntervalData.js +85 -0
- package/dist/toOnChain/index.d.ts +2 -0
- package/dist/toOnChain/index.js +18 -0
- package/dist/txBuild/ChangeInfos/ChangeInfos.d.ts +15 -0
- package/dist/txBuild/ChangeInfos/ChangeInfos.js +27 -0
- package/dist/txBuild/ITxBuildArgs.d.ts +74 -0
- package/dist/txBuild/ITxBuildArgs.js +71 -0
- package/dist/txBuild/ITxBuildCert.d.ts +13 -0
- package/dist/txBuild/ITxBuildCert.js +37 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInput.d.ts +25 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInput.js +70 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInputInlineScript.d.ts +14 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInputInlineScript.js +14 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInputRefScript.d.ts +14 -0
- package/dist/txBuild/ITxBuildInput/ITxBuildInputRefScript.js +15 -0
- package/dist/txBuild/ITxBuildMint.d.ts +30 -0
- package/dist/txBuild/ITxBuildMint.js +54 -0
- package/dist/txBuild/ITxBuildOptions.d.ts +11 -0
- package/dist/txBuild/ITxBuildOptions.js +2 -0
- package/dist/txBuild/ITxBuildOutput.d.ts +10 -0
- package/dist/txBuild/ITxBuildOutput.js +27 -0
- package/dist/txBuild/ITxBuildProposalProcedure.d.ts +11 -0
- package/dist/txBuild/ITxBuildProposalProcedure.js +13 -0
- package/dist/txBuild/ITxBuildVotingProcedure.d.ts +13 -0
- package/dist/txBuild/ITxBuildVotingProcedure.js +40 -0
- package/dist/txBuild/ITxBuildWithdrawal.d.ts +29 -0
- package/dist/txBuild/ITxBuildWithdrawal.js +34 -0
- package/dist/txBuild/ScriptWithRedeemer.d.ts +18 -0
- package/dist/txBuild/ScriptWithRedeemer.js +16 -0
- package/dist/txBuild/index.d.ts +7 -0
- package/dist/txBuild/index.js +23 -0
- package/dist/utils/CanBeData.d.ts +7 -0
- package/dist/utils/CanBeData.js +68 -0
- package/dist/utils/Rational.d.ts +8 -0
- package/dist/utils/Rational.js +34 -0
- package/dist/utils/assert.d.ts +1 -0
- package/dist/utils/assert.js +44 -0
- package/dist/utils/ints.d.ts +4 -0
- package/dist/utils/ints.js +25 -0
- package/dist/utils/stringify.d.ts +2 -0
- package/dist/utils/stringify.js +38 -0
- package/package.json +72 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Coin } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
|
+
import { CanBeUInteger } from "../utils/ints.js";
|
|
3
|
+
import { CborPositiveRational } from "@harmoniclabs/cbor";
|
|
4
|
+
import { ExBudget, ExBudgetJson } from "@harmoniclabs/plutus-machine";
|
|
5
|
+
import { Rational } from "../utils/Rational.js";
|
|
6
|
+
import { CostModels } from "@harmoniclabs/cardano-costmodels-ts";
|
|
7
|
+
export interface ValidatedTxBuilderProtocolParams {
|
|
8
|
+
txFeePerByte: bigint;
|
|
9
|
+
txFeeFixed: bigint;
|
|
10
|
+
utxoCostPerByte: bigint;
|
|
11
|
+
maxTxSize: bigint;
|
|
12
|
+
maxTxExecutionUnits: ExBudget;
|
|
13
|
+
maxCollateralInputs: bigint;
|
|
14
|
+
collateralPercentage: bigint;
|
|
15
|
+
minfeeRefScriptCostPerByte: CborPositiveRational;
|
|
16
|
+
executionUnitPrices: [
|
|
17
|
+
mem_price: CborPositiveRational,
|
|
18
|
+
step_price: CborPositiveRational
|
|
19
|
+
];
|
|
20
|
+
costModels: CostModels;
|
|
21
|
+
}
|
|
22
|
+
export interface TxBuilderProtocolParams {
|
|
23
|
+
txFeePerByte: CanBeUInteger;
|
|
24
|
+
txFeeFixed: CanBeUInteger;
|
|
25
|
+
utxoCostPerByte: Coin;
|
|
26
|
+
maxTxSize: CanBeUInteger;
|
|
27
|
+
maxTxExecutionUnits: ExBudget | ExBudgetJson;
|
|
28
|
+
maxCollateralInputs: CanBeUInteger;
|
|
29
|
+
collateralPercentage: CanBeUInteger;
|
|
30
|
+
minfeeRefScriptCostPerByte: Rational;
|
|
31
|
+
executionUnitPrices: [
|
|
32
|
+
mem_price: CborPositiveRational,
|
|
33
|
+
step_price: CborPositiveRational
|
|
34
|
+
] | {
|
|
35
|
+
priceMemory: number;
|
|
36
|
+
priceSteps: number;
|
|
37
|
+
};
|
|
38
|
+
costModels: CostModels;
|
|
39
|
+
}
|
|
40
|
+
export declare const defaultTxBuilderProtocolParameters: Readonly<ValidatedTxBuilderProtocolParams>;
|
|
41
|
+
export declare function isValidatedTxBuilderProtocolParams(stuff: any): stuff is ValidatedTxBuilderProtocolParams;
|
|
42
|
+
export declare function completeTxBuilderProtocolParams(partial: TxBuilderProtocolParams | undefined): ValidatedTxBuilderProtocolParams;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.completeTxBuilderProtocolParams = exports.isValidatedTxBuilderProtocolParams = exports.defaultTxBuilderProtocolParameters = void 0;
|
|
16
|
+
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
17
|
+
var ints_1 = require("../utils/ints.js");
|
|
18
|
+
var cbor_1 = require("@harmoniclabs/cbor");
|
|
19
|
+
var plutus_machine_1 = require("@harmoniclabs/plutus-machine");
|
|
20
|
+
var Rational_1 = require("../utils/Rational.js");
|
|
21
|
+
var cardano_costmodels_ts_1 = require("@harmoniclabs/cardano-costmodels-ts");
|
|
22
|
+
var obj_utils_1 = require("@harmoniclabs/obj-utils");
|
|
23
|
+
exports.defaultTxBuilderProtocolParameters = Object.freeze({
|
|
24
|
+
txFeePerByte: BigInt((_a = cardano_ledger_ts_1.defaultProtocolParameters.txFeePerByte) !== null && _a !== void 0 ? _a : 0),
|
|
25
|
+
txFeeFixed: BigInt((_b = cardano_ledger_ts_1.defaultProtocolParameters.txFeeFixed) !== null && _b !== void 0 ? _b : 0),
|
|
26
|
+
utxoCostPerByte: BigInt((_c = cardano_ledger_ts_1.defaultProtocolParameters.utxoCostPerByte) !== null && _c !== void 0 ? _c : 0),
|
|
27
|
+
maxTxSize: BigInt((_d = cardano_ledger_ts_1.defaultProtocolParameters.maxTxSize) !== null && _d !== void 0 ? _d : 0),
|
|
28
|
+
maxTxExecutionUnits: forceExBudget((_e = cardano_ledger_ts_1.defaultProtocolParameters.maxTxExecutionUnits) !== null && _e !== void 0 ? _e : { steps: 0, memory: 0 }),
|
|
29
|
+
maxCollateralInputs: BigInt((_f = cardano_ledger_ts_1.defaultProtocolParameters.maxCollateralInputs) !== null && _f !== void 0 ? _f : 0),
|
|
30
|
+
collateralPercentage: BigInt((_g = cardano_ledger_ts_1.defaultProtocolParameters.collateralPercentage) !== null && _g !== void 0 ? _g : 0),
|
|
31
|
+
minfeeRefScriptCostPerByte: (0, Rational_1.cborFromRational)((_h = cardano_ledger_ts_1.defaultProtocolParameters.minfeeRefScriptCostPerByte) !== null && _h !== void 0 ? _h : 0),
|
|
32
|
+
executionUnitPrices: forceExecUnitPricesArray((_j = cardano_ledger_ts_1.defaultProtocolParameters.executionUnitPrices) !== null && _j !== void 0 ? _j : [0, 0]),
|
|
33
|
+
costModels: (_k = cardano_ledger_ts_1.defaultProtocolParameters.costModels) !== null && _k !== void 0 ? _k : {
|
|
34
|
+
PlutusScriptV1: cardano_costmodels_ts_1.defaultV1Costs,
|
|
35
|
+
PlutusScriptV2: cardano_costmodels_ts_1.defaultV2Costs,
|
|
36
|
+
PlutusScriptV3: cardano_costmodels_ts_1.defaultV3Costs
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
function forceExBudget(ex) {
|
|
40
|
+
return ex instanceof plutus_machine_1.ExBudget ? ex.clone() : plutus_machine_1.ExBudget.fromJson(ex);
|
|
41
|
+
}
|
|
42
|
+
function forceExecUnitPricesArray(ex) {
|
|
43
|
+
return Array.isArray(ex) ? ex.slice() : [
|
|
44
|
+
cbor_1.CborPositiveRational.fromNumber(ex.priceMemory),
|
|
45
|
+
cbor_1.CborPositiveRational.fromNumber(ex.priceSteps),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
var keysOfTxBuilderProtocolParameters = Object.freeze(Object.keys(exports.defaultTxBuilderProtocolParameters));
|
|
49
|
+
function isValidatedTxBuilderProtocolParams(stuff) {
|
|
50
|
+
if (!(0, obj_utils_1.isObject)(stuff))
|
|
51
|
+
return false;
|
|
52
|
+
var keys = Object.keys(stuff);
|
|
53
|
+
// all keys must be present
|
|
54
|
+
if (!keysOfTxBuilderProtocolParameters.every(function (key) { return keys.includes(key); }))
|
|
55
|
+
return false;
|
|
56
|
+
var ppexecCosts = stuff.executionUnitPrices;
|
|
57
|
+
if (!((Array.isArray(ppexecCosts) &&
|
|
58
|
+
ppexecCosts.length >= 2 &&
|
|
59
|
+
ppexecCosts[0] instanceof cbor_1.CborPositiveRational &&
|
|
60
|
+
ppexecCosts[1] instanceof cbor_1.CborPositiveRational) ||
|
|
61
|
+
((0, obj_utils_1.isObject)(ppexecCosts) &&
|
|
62
|
+
typeof ppexecCosts.priceSteps === "number" &&
|
|
63
|
+
typeof ppexecCosts.priceMemory === "number")))
|
|
64
|
+
return false;
|
|
65
|
+
return ((0, ints_1.canBeUInteger)(stuff.txFeePerByte) &&
|
|
66
|
+
(0, ints_1.canBeUInteger)(stuff.txFeeFixed) &&
|
|
67
|
+
(0, ints_1.canBeUInteger)(stuff.utxoCostPerByte) &&
|
|
68
|
+
(0, ints_1.canBeUInteger)(stuff.maxTxSize) &&
|
|
69
|
+
(stuff.maxTxExecutionUnits instanceof plutus_machine_1.ExBudget || plutus_machine_1.ExBudget.isJson(stuff.maxTxExecutionUnits)) &&
|
|
70
|
+
(0, ints_1.canBeUInteger)(stuff.maxCollateralInputs) &&
|
|
71
|
+
(0, ints_1.canBeUInteger)(stuff.collateralPercentage) &&
|
|
72
|
+
(0, Rational_1.isRational)(stuff.minfeeRefScriptCostPerByte) &&
|
|
73
|
+
(0, cardano_costmodels_ts_1.isCostModels)(stuff.costModels));
|
|
74
|
+
}
|
|
75
|
+
exports.isValidatedTxBuilderProtocolParams = isValidatedTxBuilderProtocolParams;
|
|
76
|
+
function completeTxBuilderProtocolParams(partial) {
|
|
77
|
+
if (partial === undefined)
|
|
78
|
+
return __assign({}, exports.defaultTxBuilderProtocolParameters);
|
|
79
|
+
var result = {};
|
|
80
|
+
result.executionUnitPrices = (partial.executionUnitPrices ?
|
|
81
|
+
forceExecUnitPricesArray(partial.executionUnitPrices) :
|
|
82
|
+
undefined);
|
|
83
|
+
var ppexecCosts = result.executionUnitPrices;
|
|
84
|
+
if (!(Array.isArray(ppexecCosts) &&
|
|
85
|
+
ppexecCosts.length >= 2 &&
|
|
86
|
+
ppexecCosts[0] instanceof cbor_1.CborPositiveRational &&
|
|
87
|
+
ppexecCosts[1] instanceof cbor_1.CborPositiveRational))
|
|
88
|
+
result.executionUnitPrices = exports.defaultTxBuilderProtocolParameters.executionUnitPrices.slice();
|
|
89
|
+
result.txFeePerByte = ((0, ints_1.canBeUInteger)(partial.txFeePerByte) ?
|
|
90
|
+
BigInt(partial.txFeePerByte) :
|
|
91
|
+
exports.defaultTxBuilderProtocolParameters.txFeePerByte);
|
|
92
|
+
result.txFeeFixed = ((0, ints_1.canBeUInteger)(partial.txFeeFixed) ?
|
|
93
|
+
BigInt(partial.txFeeFixed) :
|
|
94
|
+
exports.defaultTxBuilderProtocolParameters.txFeeFixed);
|
|
95
|
+
result.utxoCostPerByte = ((0, ints_1.canBeUInteger)(partial.utxoCostPerByte) ?
|
|
96
|
+
BigInt(partial.utxoCostPerByte) :
|
|
97
|
+
exports.defaultTxBuilderProtocolParameters.utxoCostPerByte);
|
|
98
|
+
result.maxTxSize = ((0, ints_1.canBeUInteger)(partial.maxTxSize) ?
|
|
99
|
+
BigInt(partial.maxTxSize) :
|
|
100
|
+
exports.defaultTxBuilderProtocolParameters.maxTxSize);
|
|
101
|
+
result.maxTxExecutionUnits = ((partial.maxTxExecutionUnits instanceof plutus_machine_1.ExBudget || plutus_machine_1.ExBudget.isJson(partial.maxTxExecutionUnits)) ?
|
|
102
|
+
forceExBudget(partial.maxTxExecutionUnits) :
|
|
103
|
+
exports.defaultTxBuilderProtocolParameters.maxTxExecutionUnits.clone());
|
|
104
|
+
result.maxCollateralInputs = ((0, ints_1.canBeUInteger)(partial.maxCollateralInputs) ?
|
|
105
|
+
BigInt(partial.maxCollateralInputs) :
|
|
106
|
+
exports.defaultTxBuilderProtocolParameters.maxCollateralInputs);
|
|
107
|
+
result.collateralPercentage = ((0, ints_1.canBeUInteger)(partial.collateralPercentage) ?
|
|
108
|
+
BigInt(partial.collateralPercentage) :
|
|
109
|
+
exports.defaultTxBuilderProtocolParameters.collateralPercentage);
|
|
110
|
+
result.collateralPercentage = ((0, ints_1.canBeUInteger)(partial.collateralPercentage) ?
|
|
111
|
+
BigInt(partial.collateralPercentage) :
|
|
112
|
+
exports.defaultTxBuilderProtocolParameters.collateralPercentage);
|
|
113
|
+
result.minfeeRefScriptCostPerByte = ((0, Rational_1.isRational)(partial.minfeeRefScriptCostPerByte) ?
|
|
114
|
+
(0, Rational_1.cborFromRational)(partial.minfeeRefScriptCostPerByte) :
|
|
115
|
+
exports.defaultTxBuilderProtocolParameters.minfeeRefScriptCostPerByte);
|
|
116
|
+
result.costModels = ((0, cardano_costmodels_ts_1.isCostModels)(partial.costModels) ?
|
|
117
|
+
partial.costModels :
|
|
118
|
+
exports.defaultTxBuilderProtocolParameters.costModels);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
exports.completeTxBuilderProtocolParams = completeTxBuilderProtocolParams;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.forcePoolKeyHash = void 0;
|
|
20
|
+
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
21
|
+
var crypto_1 = require("@harmoniclabs/crypto");
|
|
22
|
+
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
23
|
+
function forcePoolKeyHash(canBe) {
|
|
24
|
+
if (typeof canBe === "string") {
|
|
25
|
+
if (canBe.startsWith("pool")) {
|
|
26
|
+
var _a = __read((0, crypto_1.decodeBech32)(canBe), 2), _hrp = _a[0], decoded = _a[1];
|
|
27
|
+
return new cardano_ledger_ts_1.PoolKeyHash(new Uint8Array(decoded));
|
|
28
|
+
}
|
|
29
|
+
return new cardano_ledger_ts_1.PoolKeyHash((0, uint8array_utils_1.fromHex)(canBe));
|
|
30
|
+
}
|
|
31
|
+
return new cardano_ledger_ts_1.PoolKeyHash(canBe);
|
|
32
|
+
}
|
|
33
|
+
exports.forcePoolKeyHash = forcePoolKeyHash;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { StakeAddress, Credential, StakeAddressBech32, StakeCredentials, Script, PlutusScriptType } from "@harmoniclabs/cardano-ledger-ts";
|
|
2
|
+
export type CanBeStakeCreds = StakeAddress | StakeAddressBech32 | StakeCredentials | Script<PlutusScriptType> | Credential;
|
|
3
|
+
export declare function forceStakeCreds(creds: CanBeStakeCreds): Credential;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forceStakeCreds = void 0;
|
|
4
|
+
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
5
|
+
function forceStakeCreds(creds) {
|
|
6
|
+
if (creds instanceof cardano_ledger_ts_1.Credential)
|
|
7
|
+
return creds;
|
|
8
|
+
if (typeof creds === "string") {
|
|
9
|
+
if (!creds.startsWith("stake")) {
|
|
10
|
+
throw new Error("invalid bech32 stake address");
|
|
11
|
+
}
|
|
12
|
+
creds = cardano_ledger_ts_1.StakeAddress.fromString(creds);
|
|
13
|
+
}
|
|
14
|
+
if (creds instanceof cardano_ledger_ts_1.StakeAddress) {
|
|
15
|
+
return creds.toCredential();
|
|
16
|
+
}
|
|
17
|
+
if (creds instanceof cardano_ledger_ts_1.Script) {
|
|
18
|
+
return cardano_ledger_ts_1.Credential.script(new cardano_ledger_ts_1.StakeValidatorHash(creds.hash));
|
|
19
|
+
}
|
|
20
|
+
if (creds.type === "pointer") {
|
|
21
|
+
throw new Error("pointer stake credentials not supported");
|
|
22
|
+
}
|
|
23
|
+
return new cardano_ledger_ts_1.Credential(creds.type === "script" ? cardano_ledger_ts_1.CredentialType.Script : cardano_ledger_ts_1.CredentialType.KeyHash, creds.hash);
|
|
24
|
+
}
|
|
25
|
+
exports.forceStakeCreds = forceStakeCreds;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import type { ITxRunnerProvider } from "../IProvider/index.js";
|
|
2
|
+
import type { TxBuilder } from "../TxBuilder.js";
|
|
3
|
+
import { NormalizedITxBuildArgs } from "../../txBuild/index.js";
|
|
4
|
+
import { Address, AddressStr, Hash28, ITxOut, ITxOutRef, IUTxO, IValuePolicyEntry, PlutusScriptType, Script, ScriptType, StakeAddress, StakeAddressBech32, Credential, Tx, TxIn, TxMetadatum, TxOutRefStr, UTxO, Value, IPoolParams, CanBeHash28, Vote, IAnchor, IVoter, ProtocolParameters, IProposalProcedure, ITxWithdrawals, TxWithdrawals, INewCommitteeEntry, IConstitution } from "@harmoniclabs/cardano-ledger-ts";
|
|
5
|
+
import { CanBeUInteger } from "../../utils/ints.js";
|
|
6
|
+
import { CanResolveToUTxO } from "../CanResolveToUTxO/CanResolveToUTxO.js";
|
|
7
|
+
import { CanBeData } from "../../utils/CanBeData.js";
|
|
8
|
+
import { CanBePoolKeyHash } from "./CanBePoolKeyHash.js";
|
|
9
|
+
import { CanBeStakeCreds } from "./CanBeStakeCreds.js";
|
|
10
|
+
import { IProtocolVerision } from "@harmoniclabs/cardano-ledger-ts/dist/ledger/protocol/protocolVersion";
|
|
11
|
+
import { Rational } from "../../utils/Rational.js";
|
|
12
|
+
declare const enum TxBuilderTaskKind {
|
|
13
|
+
ResolveUTxO = 0,
|
|
14
|
+
ResolveTxIn = 1,
|
|
15
|
+
ValidFromPOSIX = 2,
|
|
16
|
+
ValidToPOSIX = 3,
|
|
17
|
+
DelegateTo = 4,
|
|
18
|
+
DeregisterStake = 5,
|
|
19
|
+
Withdraw = 6,
|
|
20
|
+
RegisterStake = 7
|
|
21
|
+
}
|
|
22
|
+
/** async */
|
|
23
|
+
interface TxBuilderPromiseTask {
|
|
24
|
+
kind: TxBuilderTaskKind;
|
|
25
|
+
getPromise: () => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
interface TxBuilderResolveUTxOTask {
|
|
28
|
+
kind: TxBuilderTaskKind.ResolveUTxO;
|
|
29
|
+
arg: ITxOutRef | TxOutRefStr | IUTxO;
|
|
30
|
+
onResolved: (utxo: UTxO) => void;
|
|
31
|
+
}
|
|
32
|
+
interface TxBuilderResolveTxInTask {
|
|
33
|
+
kind: TxBuilderTaskKind.ResolveTxIn;
|
|
34
|
+
arg: ITxOutRef | TxOutRefStr | IUTxO;
|
|
35
|
+
onResolved: (utxo: TxIn) => void;
|
|
36
|
+
}
|
|
37
|
+
type TxBuilderTask = TxBuilderPromiseTask | TxBuilderResolveUTxOTask | TxBuilderResolveTxInTask;
|
|
38
|
+
export declare class TxBuilderRunner {
|
|
39
|
+
/**
|
|
40
|
+
* if any unresolved data was passed it is resolved via the provider passed;
|
|
41
|
+
*
|
|
42
|
+
* if the method needed are not present on the provider throws an `Error`;
|
|
43
|
+
*
|
|
44
|
+
* finalizes the `TxBuilderRunner` instance,
|
|
45
|
+
* so that it can be re-used for other transactions,
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<Tx>} a `Tx` instance
|
|
48
|
+
*/
|
|
49
|
+
readonly build: () => Promise<Tx>;
|
|
50
|
+
/**
|
|
51
|
+
* clears the `TxBuilderRunner` instance,
|
|
52
|
+
* so that it can be re-used for other transactions,
|
|
53
|
+
* making sure no other action where specified
|
|
54
|
+
*
|
|
55
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
56
|
+
*/
|
|
57
|
+
readonly reset: () => TxBuilderRunner;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use `addRequiredSigner` instead
|
|
60
|
+
*/
|
|
61
|
+
readonly addSigner: (signer: Address | StakeAddress | AddressStr | StakeAddressBech32) => TxBuilderRunner;
|
|
62
|
+
/**
|
|
63
|
+
* adds the **all** credentials of the address to the `requiredSigners`
|
|
64
|
+
* field of a `Tx` instance.
|
|
65
|
+
*
|
|
66
|
+
* only the signers included in that field are passed to a contract's `ScriptContext`.
|
|
67
|
+
*
|
|
68
|
+
* that includes payment credentials and, if present, stake credentials.
|
|
69
|
+
*
|
|
70
|
+
* if you have an address with both payment and stake credentials,
|
|
71
|
+
* but wish only to include one of them,
|
|
72
|
+
* consider using the `addRequiredSignerKey` method
|
|
73
|
+
*
|
|
74
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
75
|
+
*/
|
|
76
|
+
readonly addRequiredSigner: (signer: Address | StakeAddress | AddressStr | StakeAddressBech32) => TxBuilderRunner;
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated use `addRequiredSignerKey` instead
|
|
79
|
+
*/
|
|
80
|
+
readonly addSignerKey: (signerKey: Hash28) => TxBuilderRunner;
|
|
81
|
+
/**
|
|
82
|
+
* adds the given key hash to the `requiredSigners` field of a `Tx` instance.
|
|
83
|
+
*
|
|
84
|
+
* only the signers included in that field are passed to a contract's `ScriptContext`.
|
|
85
|
+
*
|
|
86
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
87
|
+
*/
|
|
88
|
+
readonly addRequiredSignerKey: (signerKey: Hash28) => TxBuilderRunner;
|
|
89
|
+
/** adds a metadata message according to cip 20 */
|
|
90
|
+
readonly attachMemo: (memo: string) => TxBuilderRunner;
|
|
91
|
+
/** alias for `attachValidator` */
|
|
92
|
+
readonly attachCertificateValidator: (validator: Script<PlutusScriptType>) => TxBuilderRunner;
|
|
93
|
+
/** alias for `attachValidator` */
|
|
94
|
+
readonly attachMintingValidator: (validator: Script<PlutusScriptType>) => TxBuilderRunner;
|
|
95
|
+
/** alias for `attachValidator` */
|
|
96
|
+
readonly attachSpendingValidator: (validator: Script<PlutusScriptType>) => TxBuilderRunner;
|
|
97
|
+
/** alias for `attachValidator` */
|
|
98
|
+
readonly attachWithdrawalValidator: (validator: Script<PlutusScriptType>) => TxBuilderRunner;
|
|
99
|
+
/**
|
|
100
|
+
* includes the script in the witnessSet field of the resulting `Tx`
|
|
101
|
+
*
|
|
102
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
103
|
+
*/
|
|
104
|
+
readonly attachValidator: (validator: Script<PlutusScriptType>) => TxBuilderRunner;
|
|
105
|
+
/**
|
|
106
|
+
* adds a metadata entry for the given `label`,
|
|
107
|
+
* or overrides if the same `label` was already present.
|
|
108
|
+
*
|
|
109
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
110
|
+
*/
|
|
111
|
+
readonly attachMetadata: (label: CanBeUInteger, metadata: TxMetadatum) => TxBuilderRunner;
|
|
112
|
+
/**
|
|
113
|
+
* alias for `attachMetadata`
|
|
114
|
+
*
|
|
115
|
+
* adds a metadata entry for the given `label`,
|
|
116
|
+
* or overrides if the same `label` was already present.
|
|
117
|
+
*
|
|
118
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
119
|
+
*/
|
|
120
|
+
readonly setMetadata: (label: CanBeUInteger, metadata: TxMetadatum) => TxBuilderRunner;
|
|
121
|
+
/**
|
|
122
|
+
* like [`attachMetadata`](./attachMetadata),
|
|
123
|
+
* adds a metadata entry for the given `label`,
|
|
124
|
+
* or overrides if the same `label` was already present.
|
|
125
|
+
*
|
|
126
|
+
* `metadataJson` is a jsavascript value converted as follows
|
|
127
|
+
*
|
|
128
|
+
* - `object` -> `TxMetadatumMap`
|
|
129
|
+
* - `array` -> `TxMetadatumList`
|
|
130
|
+
* - `string` -> `TxMetadatumText`
|
|
131
|
+
* (use `attachMetadataJsonWithConversion`
|
|
132
|
+
* for explicit conversion to `TxMetadatumBytes`
|
|
133
|
+
* or consider using `attachMetadata`)
|
|
134
|
+
* - `number` -> `TxMetadatumInt`
|
|
135
|
+
* - `bigint` -> `TxMetadatumInt`
|
|
136
|
+
*
|
|
137
|
+
* @returns a reference to the same [`TxBuilderRunner`](./TxBuilderRunner).
|
|
138
|
+
*/
|
|
139
|
+
readonly attachMetadataJson: (label: CanBeUInteger, metadataJson: any) => TxBuilderRunner;
|
|
140
|
+
/** like `attachMetadataJson` but if a string starts with `0x` is treated as an hexadecimal byte string */
|
|
141
|
+
readonly attachMetadataJsonWithConversion: (label: CanBeUInteger, metadataJson: any) => TxBuilderRunner;
|
|
142
|
+
/**
|
|
143
|
+
* explicitly sets the change address;
|
|
144
|
+
*
|
|
145
|
+
* if missing, an attempt to call the `ITxRunnerProvider` `getChangeAddress` method is done
|
|
146
|
+
*
|
|
147
|
+
* if still missing the first input's address with `PubKeyHash`
|
|
148
|
+
* payment credentials (not script) will be used
|
|
149
|
+
*
|
|
150
|
+
* if all the above fail, a call to the `build` method will throw an `Error`.
|
|
151
|
+
*
|
|
152
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
153
|
+
*/
|
|
154
|
+
readonly setChangeAddress: (changeAddr: Address | AddressStr) => TxBuilderRunner;
|
|
155
|
+
/**
|
|
156
|
+
* Sets the collateral input, and optionally output, for a transaction.
|
|
157
|
+
*
|
|
158
|
+
* If this method is not used,
|
|
159
|
+
* but the transaction needs collateral due to the presence of a plutus script,
|
|
160
|
+
* the `TxBuilderRunner` instance will try to use one of the normal inputs as collateral,
|
|
161
|
+
* see `setCollateralAmount`./setCollateralAmount for more infos.
|
|
162
|
+
*
|
|
163
|
+
* `collateral` can either be a resolved `UTxO`
|
|
164
|
+
* or an unresolved `ITxOutRef`
|
|
165
|
+
*
|
|
166
|
+
* in case it is an unresolved `ITxOutRef`
|
|
167
|
+
* a call to the `ITxRunnerProvider` `resolveUtxos` method
|
|
168
|
+
* is done in the `build` method;
|
|
169
|
+
* if `resolveUtxos` is missing on the provider the `build` method will throw an `Error`.
|
|
170
|
+
*
|
|
171
|
+
* an additional `collateralOutput` may be specified.
|
|
172
|
+
*
|
|
173
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
174
|
+
*/
|
|
175
|
+
readonly setCollateral: (collateral: CanResolveToUTxO, collateralOutput?: ITxOut) => TxBuilderRunner;
|
|
176
|
+
/**
|
|
177
|
+
* Sets the collateral amount for a transaction.
|
|
178
|
+
*
|
|
179
|
+
* If `setCollateral` is not used,
|
|
180
|
+
* but the transaction needs collateral due to the presence of a plutus script,
|
|
181
|
+
* the `TxBuilderRunner` instance will try to use one of the normal inputs as collateral.
|
|
182
|
+
*
|
|
183
|
+
* In case this happens, it is possible to limit the amount of the collateral using this method.
|
|
184
|
+
*
|
|
185
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
186
|
+
**/
|
|
187
|
+
readonly setCollateralAmount: (lovelaces: CanBeUInteger) => TxBuilderRunner;
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated `collectFrom` is unclear; use `addInputs` instead.
|
|
190
|
+
*/
|
|
191
|
+
readonly collectFrom: (utxos: CanResolveToUTxO[], redeemer?: CanBeData) => TxBuilderRunner;
|
|
192
|
+
/**
|
|
193
|
+
* adds the given `utxos` to the transaction inputs;
|
|
194
|
+
* the elements of the array that don't satisfy the `IUTxO` interface
|
|
195
|
+
* will be resolved using the provider `resolveUtxos` method.
|
|
196
|
+
*
|
|
197
|
+
* this method does not allow to specify plutus realated arguments.
|
|
198
|
+
*
|
|
199
|
+
* for inputs that need redeemers, scripts and datums use `addInput`.
|
|
200
|
+
*
|
|
201
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
202
|
+
**/
|
|
203
|
+
readonly addInputs: (utxos: CanResolveToUTxO[]) => TxBuilderRunner;
|
|
204
|
+
/**
|
|
205
|
+
* adds the given `utxo` to the transaction inputs;
|
|
206
|
+
* if`utxo` doesn't satisfy the `IUTxO` interface
|
|
207
|
+
* it will be resolved using the provider `resolveUtxos` method.
|
|
208
|
+
*
|
|
209
|
+
* `redeemer` and `script_or_ref` must be specified together;
|
|
210
|
+
* if `datum` is missing defaults to `"inline"`.
|
|
211
|
+
*
|
|
212
|
+
* if `script_or_ref` is a `Script`
|
|
213
|
+
* it will be included in the `witnesses`
|
|
214
|
+
* field of the resulting `Tx`;
|
|
215
|
+
*
|
|
216
|
+
* if `script_or_ref` satisfies the `IUTxO` interface
|
|
217
|
+
* it will be used as reference input to provide the attached reference script
|
|
218
|
+
* (`build` fails if missing)
|
|
219
|
+
*
|
|
220
|
+
* if `script_or_ref` satisfies the `ITxOutRef` interface
|
|
221
|
+
* or the `TxOutRefStr` type alias
|
|
222
|
+
* it will be resolved using the provider `resolveUtxos` method and
|
|
223
|
+
* it will be used as reference input to provide the attached reference script
|
|
224
|
+
* (`build` fails if missing)
|
|
225
|
+
*
|
|
226
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
227
|
+
**/
|
|
228
|
+
readonly addInput: (utxos: CanResolveToUTxO, redeemer?: CanBeData, script_or_ref?: CanResolveToUTxO | Script<PlutusScriptType>, datum?: CanBeData | "inline") => TxBuilderRunner;
|
|
229
|
+
/**
|
|
230
|
+
* adds a transaction output.
|
|
231
|
+
*
|
|
232
|
+
* if `amount` is `number` or `bigint` it is intended to be lovelaces only.
|
|
233
|
+
*
|
|
234
|
+
* if `datum` is present is always added as inline datum.
|
|
235
|
+
*
|
|
236
|
+
* @param address receiver address
|
|
237
|
+
* @param amount Value to sent
|
|
238
|
+
* @param datum optional inline datum to attach
|
|
239
|
+
* @param refScript optional reference script to attach
|
|
240
|
+
* @returns a reference to the same `TxBuilderRunner`.
|
|
241
|
+
*/
|
|
242
|
+
readonly payTo: (address: Address | AddressStr, amount: CanBeUInteger | Value, datum?: CanBeData, refScript?: Script<ScriptType.PlutusV2>) => TxBuilderRunner;
|
|
243
|
+
readonly mintAssets: (assets: IValuePolicyEntry, script_or_ref: Script | CanResolveToUTxO, redeemer?: CanBeData) => TxBuilderRunner;
|
|
244
|
+
readonly withdraw: (stakeAddress: CanBeStakeCreds, amount: CanBeUInteger, redeemer?: CanBeData, script_or_ref?: Script | CanResolveToUTxO) => TxBuilderRunner;
|
|
245
|
+
readonly delegateTo: (delegator: CanBeStakeCreds, poolId: CanBePoolKeyHash, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
246
|
+
readonly registerPool: (params: IPoolParams) => TxBuilderRunner;
|
|
247
|
+
readonly retirePool: (poolId: CanBeHash28, epoch: CanBeUInteger) => TxBuilderRunner;
|
|
248
|
+
readonly registerStake: (delegator: CanBeStakeCreds, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
249
|
+
readonly registerStakeAddress: (delegator: CanBeStakeCreds, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
250
|
+
readonly deregisterStake: (delegator: CanBeStakeCreds, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
251
|
+
/**
|
|
252
|
+
* @deprecated `readFrom` is an ugly name; use `referenceUtxos` instead
|
|
253
|
+
*/
|
|
254
|
+
readonly readFrom: (utxos: CanResolveToUTxO[]) => TxBuilderRunner;
|
|
255
|
+
readonly referenceUtxos: (utxos: CanResolveToUTxO[]) => TxBuilderRunner;
|
|
256
|
+
readonly validFrom: (POSIX: CanBeUInteger) => TxBuilderRunner;
|
|
257
|
+
readonly validFromSlot: (slot: CanBeUInteger) => TxBuilderRunner;
|
|
258
|
+
readonly invalidBeforeSlot: (slot: CanBeUInteger) => TxBuilderRunner;
|
|
259
|
+
readonly validTo: (POSIX: CanBeUInteger) => TxBuilderRunner;
|
|
260
|
+
readonly validToSlot: (slot: CanBeUInteger) => TxBuilderRunner;
|
|
261
|
+
readonly invalidAfterSlot: (slot: CanBeUInteger) => TxBuilderRunner;
|
|
262
|
+
readonly vote: (voter: IVoter, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
263
|
+
readonly voteDRep: (drepKeyHash: CanBeHash28, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined) => TxBuilderRunner;
|
|
264
|
+
readonly voteScriptDRep: (drepScriptHash: CanBeHash28, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
265
|
+
readonly voteConstitutionalComittee: (memberKeyHash: CanBeHash28, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined) => TxBuilderRunner;
|
|
266
|
+
readonly voteScriptConstitutionalComittee: (memberScriptHash: CanBeHash28, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
267
|
+
readonly voteStakePool: (poolId: CanBeHash28, governanceActionId: ITxOutRef | TxOutRefStr, vote: Vote, anchor?: IAnchor | undefined) => TxBuilderRunner;
|
|
268
|
+
readonly propose: (proposal: IProposalProcedure, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
269
|
+
readonly proposeParametersChanges: (changes: Partial<ProtocolParameters>, procedureInfos: Omit<IProposalProcedure, "govAction">, govActionId?: ITxOutRef | TxOutRefStr, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
270
|
+
readonly proposeHardForkInitiation: (nextProtocolVersion: IProtocolVerision, procedureInfos: Omit<IProposalProcedure, "govAction">, govActionId?: ITxOutRef | TxOutRefStr, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
271
|
+
readonly proposeTreasuryWithdrawal: (withdrawals: ITxWithdrawals | TxWithdrawals, procedureInfos: Omit<IProposalProcedure, "govAction">, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
272
|
+
readonly proposeNoConfidence: (procedureInfos: Omit<IProposalProcedure, "govAction">, govActionId?: ITxOutRef | TxOutRefStr, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
273
|
+
readonly proposeComitteeUpdate: (toRemove: Credential[], toAdd: INewCommitteeEntry[], threshold: Rational, procedureInfos: Omit<IProposalProcedure, "govAction">, govActionId?: ITxOutRef | TxOutRefStr, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
274
|
+
readonly proposeNewConstitution: (constitution: IConstitution, procedureInfos: Omit<IProposalProcedure, "govAction">, govActionId?: ITxOutRef | TxOutRefStr, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
275
|
+
readonly proposeInfos: (procedureInfos: Omit<IProposalProcedure, "govAction">, redeemer?: CanBeData, script_or_ref?: Script<PlutusScriptType> | CanResolveToUTxO) => TxBuilderRunner;
|
|
276
|
+
readonly tasks: TxBuilderTask[];
|
|
277
|
+
readonly buildArgs: NormalizedITxBuildArgs;
|
|
278
|
+
constructor(txBuilder: TxBuilder, provider: Partial<ITxRunnerProvider>);
|
|
279
|
+
}
|
|
280
|
+
export {};
|