@harmoniclabs/buildooor 0.1.5 → 0.1.7
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.
|
@@ -13,10 +13,19 @@ function getScriptByHash(tx, hash) {
|
|
|
13
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
14
|
}
|
|
15
15
|
function getSpendingScript(tx, index) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (tx.body.inputs.length <= index)
|
|
17
|
+
return undefined;
|
|
18
|
+
var sortedIns = tx.body.inputs.slice().sort(function (a, b) {
|
|
19
|
+
var ord = (0, uint8array_utils_1.lexCompare)(a.utxoRef.id.toBuffer(), b.utxoRef.id.toBuffer());
|
|
20
|
+
// if equal tx id order based on tx output index
|
|
21
|
+
if (ord === 0)
|
|
22
|
+
return a.utxoRef.index - b.utxoRef.index;
|
|
23
|
+
// else order by tx id
|
|
24
|
+
return ord;
|
|
25
|
+
});
|
|
26
|
+
var scriptInput = sortedIns[index];
|
|
27
|
+
if (!scriptInput)
|
|
18
28
|
return undefined;
|
|
19
|
-
var scriptInput = allScriptInputs[index];
|
|
20
29
|
var scriptHash = scriptInput.resolved.address.paymentCreds.hash.toBuffer();
|
|
21
30
|
var script = getScriptByHash(tx, scriptHash);
|
|
22
31
|
if (!script)
|
|
@@ -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.7",
|
|
4
4
|
"description": "Cardano transaction builder in typescript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
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
57
|
"@harmoniclabs/plutus-data": "^1.2.6",
|
|
58
58
|
"@harmoniclabs/plutus-machine": "^2.1.0",
|