@odatano/core 2.0.0-rc.46 → 2.0.0-rc.47
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/package.json +1 -1
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +1 -1
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +5 -3
- package/srv/blockchain/transaction-building/buildooor-tx.js +2 -0
- package/srv/cbor/parse.js +2 -0
- package/srv/cbor/redeemer-tag-patch.d.ts +3 -0
- package/srv/cbor/redeemer-tag-patch.js +61 -0
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export interface Rational {
|
|
|
6
6
|
den: bigint;
|
|
7
7
|
}
|
|
8
8
|
export declare function tierRefScriptFee(totalBytes: bigint, pricePerByte: Rational): bigint;
|
|
9
|
-
/** Reference-script bytes of the inputs and reference inputs
|
|
9
|
+
/** Reference-script bytes of the inputs and reference inputs as one set. A UTxO in both counts once, the same script on two UTxOs twice. */
|
|
10
10
|
export declare function refScriptBytesOf(tx: Tx): bigint;
|
|
11
11
|
/** Replace `TxBuilder.prototype.calcMinFee` once per process. */
|
|
12
12
|
export declare function installReferenceScriptFeePatch(): void;
|
|
@@ -31,10 +31,12 @@ function tierRefScriptFee(totalBytes, pricePerByte) {
|
|
|
31
31
|
add(remaining);
|
|
32
32
|
return accNum / accDen;
|
|
33
33
|
}
|
|
34
|
-
/** Reference-script bytes of the inputs and reference inputs
|
|
34
|
+
/** Reference-script bytes of the inputs and reference inputs as one set. A UTxO in both counts once, the same script on two UTxOs twice. */
|
|
35
35
|
function refScriptBytesOf(tx) {
|
|
36
|
-
const utxos =
|
|
37
|
-
|
|
36
|
+
const utxos = new Map();
|
|
37
|
+
for (const u of [...tx.body.inputs, ...(tx.body.refInputs ?? [])])
|
|
38
|
+
utxos.set(u.utxoRef.toString(), u);
|
|
39
|
+
return [...utxos.values()].reduce((sum, u) => sum + BigInt(u.resolved.refScript ? (0, reference_script_1.referenceScriptSize)(u.resolved.refScript) : 0), 0n);
|
|
38
40
|
}
|
|
39
41
|
function refScriptPrice(pp) {
|
|
40
42
|
const r = (0, cardano_ledger_ts_1.cborFromRational)(pp.minfeeRefScriptCostPerByte ?? cardano_ledger_ts_1.defaultProtocolParameters.minfeeRefScriptCostPerByte);
|
|
@@ -19,6 +19,7 @@ const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
|
19
19
|
const caller_datums_1 = require("./caller-datums");
|
|
20
20
|
const const_1 = require("../../utils/const");
|
|
21
21
|
const buildooor_fee_patch_1 = require("./buildooor-fee-patch");
|
|
22
|
+
const redeemer_tag_patch_1 = require("../../cbor/redeemer-tag-patch");
|
|
22
23
|
const reference_script_1 = require("../../utils/reference-script");
|
|
23
24
|
const logger = cds_1.default.log('BuildooorTxBuilder');
|
|
24
25
|
/**
|
|
@@ -116,6 +117,7 @@ if (!Object.prototype.hasOwnProperty.call(cardano_ledger_ts_1.Hash32.prototype,
|
|
|
116
117
|
cardano_ledger_ts_1.Hash32.prototype.clone = function () { return new cardano_ledger_ts_1.Hash32(this.toString()); };
|
|
117
118
|
}
|
|
118
119
|
(0, buildooor_fee_patch_1.installReferenceScriptFeePatch)();
|
|
120
|
+
(0, redeemer_tag_patch_1.installRedeemerTagPatch)();
|
|
119
121
|
/** CardanoTxBuilder implementation on top of Buildooor. */
|
|
120
122
|
class BuildooorTxBuilder {
|
|
121
123
|
name = 'BuildooorTxBuilder';
|
package/srv/cbor/parse.js
CHANGED
|
@@ -6,6 +6,8 @@ const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
|
6
6
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
7
7
|
const errors_1 = require("../utils/errors");
|
|
8
8
|
const error_codes_1 = require("../utils/error-codes");
|
|
9
|
+
const redeemer_tag_patch_1 = require("./redeemer-tag-patch");
|
|
10
|
+
(0, redeemer_tag_patch_1.installRedeemerTagPatch)();
|
|
9
11
|
// Pure, no network call. Callers validate size and format with `isValidTxCborHex` first.
|
|
10
12
|
// Throws TX_PARSE_FAILED on malformed CBOR.
|
|
11
13
|
function parseTransaction(cborHex) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installRedeemerTagPatch = installRedeemerTagPatch;
|
|
4
|
+
const cbor_1 = require("@harmoniclabs/cbor");
|
|
5
|
+
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
6
|
+
// The TxRedeemer constructor accepts only tags 0 to 3, so Tx.fromCbor throws on Conway voting and
|
|
7
|
+
// proposing redeemers. Decode and clone them with tag 0, then set the real tag.
|
|
8
|
+
const CONWAY_TAGS = new Set([cardano_ledger_ts_1.TxRedeemerTag.Voting, cardano_ledger_ts_1.TxRedeemerTag.Proposing]);
|
|
9
|
+
const PLACEHOLDER = new cbor_1.CborUInt(cardano_ledger_ts_1.TxRedeemerTag.Spend);
|
|
10
|
+
function conwayTag(head) {
|
|
11
|
+
const first = head.array[0];
|
|
12
|
+
if (!(first instanceof cbor_1.CborUInt))
|
|
13
|
+
return undefined;
|
|
14
|
+
const tag = Number(first.num);
|
|
15
|
+
return CONWAY_TAGS.has(tag) ? tag : undefined;
|
|
16
|
+
}
|
|
17
|
+
// Swaps the tag in the parsed CBOR for the call only. The CBOR object keeps its byte reference.
|
|
18
|
+
function decodeWithPlaceholder(head, decode) {
|
|
19
|
+
const tag = conwayTag(head);
|
|
20
|
+
if (tag === undefined)
|
|
21
|
+
return decode();
|
|
22
|
+
const original = head.array[0];
|
|
23
|
+
head.array[0] = PLACEHOLDER;
|
|
24
|
+
try {
|
|
25
|
+
const redeemer = decode();
|
|
26
|
+
redeemer.tag = tag;
|
|
27
|
+
return redeemer;
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
head.array[0] = original;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const PATCHED = Symbol.for('odatano.ledger-ts.redeemerTags');
|
|
34
|
+
/** Let `TxRedeemer` decode and clone Voting and Proposing redeemers. Once per process. */
|
|
35
|
+
function installRedeemerTagPatch() {
|
|
36
|
+
const cls = cardano_ledger_ts_1.TxRedeemer;
|
|
37
|
+
if (cls[PATCHED])
|
|
38
|
+
return;
|
|
39
|
+
const fromCborObj = cls.fromCborObj;
|
|
40
|
+
const fromCborMapEntry = cls.fromCborMapEntry;
|
|
41
|
+
const clone = cardano_ledger_ts_1.TxRedeemer.prototype.clone;
|
|
42
|
+
cls.fromCborObj = (cObj) => cObj instanceof cbor_1.CborArray ? decodeWithPlaceholder(cObj, () => fromCborObj(cObj)) : fromCborObj(cObj);
|
|
43
|
+
cls.fromCborMapEntry = (entry) => entry?.k instanceof cbor_1.CborArray ? decodeWithPlaceholder(entry.k, () => fromCborMapEntry(entry)) : fromCborMapEntry(entry);
|
|
44
|
+
cardano_ledger_ts_1.TxRedeemer.prototype.clone = function () {
|
|
45
|
+
const self = this;
|
|
46
|
+
const tag = self.tag;
|
|
47
|
+
if (!CONWAY_TAGS.has(tag))
|
|
48
|
+
return clone.call(this);
|
|
49
|
+
self.tag = cardano_ledger_ts_1.TxRedeemerTag.Spend;
|
|
50
|
+
try {
|
|
51
|
+
const copy = clone.call(this);
|
|
52
|
+
copy.tag = tag;
|
|
53
|
+
return copy;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
self.tag = tag;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
cls[PATCHED] = true;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=redeemer-tag-patch.js.map
|