Skip to content

Commit 242836f

Browse files
committed
add protocol parameters to lucid constructor to avoid calling ogmios every time we init
1 parent e7391b6 commit 242836f

File tree

11 files changed

+521
-70
lines changed

11 files changed

+521
-70
lines changed

dist/esm/package.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
export default {
22
"name": "@jpg-store/lucid-cardano",
3-
"version": "0.10.9",
3+
"version": "0.10.10",
44
"license": "MIT",
55
"description": "This is a fork of the original Lucid repo compiled into CommonJS. For more information check https://github.com/spacebudz/lucid",
6-
"repository": "https://github.com/jpg-store/lucid"
6+
"repository": "https://github.com/jpg-store/lucid",
7+
"module": "./dist/esm/mod.js",
8+
"main": "./dist/esm/mod.js",
9+
"types": "./dist/types/mod.d.ts",
10+
"engines": {
11+
"node": ">=14"
12+
},
13+
"dependencies": {
14+
"node-fetch": "^3.2.3",
15+
"@peculiar/webcrypto": "^1.4.0",
16+
"ws": "^8.10.0"
17+
},
18+
"type": "module",
19+
"exports": {
20+
".": {
21+
"import": "./dist/esm/mod.js",
22+
"types": "./dist/types/mod.d.ts"
23+
}
24+
}
725
};

dist/esm/src/lucid/lucid.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ export class Lucid {
4747
value: void 0
4848
});
4949
}
50-
static async new(provider, network) {
50+
static async new({ provider, network, protocolParameters, }) {
5151
const lucid = new this();
5252
if (network)
5353
lucid.network = network;
54-
if (provider) {
55-
lucid.provider = provider;
56-
const protocolParameters = await provider.getProtocolParameters();
54+
if (protocolParameters) {
5755
lucid.protocolParameters = protocolParameters;
56+
}
57+
if (provider && !protocolParameters) {
58+
lucid.provider = provider;
59+
const protocolParams = await provider.getProtocolParameters();
60+
lucid.protocolParameters = protocolParams;
5861
if (lucid.provider instanceof Emulator) {
5962
lucid.network = "Custom";
6063
SLOT_CONFIG_NETWORK[lucid.network] = {
@@ -63,18 +66,20 @@ export class Lucid {
6366
slotLength: 1000,
6467
};
6568
}
69+
}
70+
if (lucid.protocolParameters) {
6671
const slotConfig = SLOT_CONFIG_NETWORK[lucid.network];
6772
lucid.txBuilderConfig = C.TransactionBuilderConfigBuilder.new()
68-
.coins_per_utxo_byte(C.BigNum.from_str(protocolParameters.coinsPerUtxoByte.toString()))
69-
.fee_algo(C.LinearFee.new(C.BigNum.from_str(protocolParameters.minFeeA.toString()), C.BigNum.from_str(protocolParameters.minFeeB.toString())))
70-
.key_deposit(C.BigNum.from_str(protocolParameters.keyDeposit.toString()))
71-
.pool_deposit(C.BigNum.from_str(protocolParameters.poolDeposit.toString()))
72-
.max_tx_size(protocolParameters.maxTxSize)
73-
.max_value_size(protocolParameters.maxValSize)
74-
.collateral_percentage(protocolParameters.collateralPercentage)
75-
.max_collateral_inputs(protocolParameters.maxCollateralInputs)
76-
.max_tx_ex_units(C.ExUnits.new(C.BigNum.from_str(protocolParameters.maxTxExMem.toString()), C.BigNum.from_str(protocolParameters.maxTxExSteps.toString())))
77-
.ex_unit_prices(C.ExUnitPrices.from_float(protocolParameters.priceMem, protocolParameters.priceStep))
73+
.coins_per_utxo_byte(C.BigNum.from_str(lucid.protocolParameters.coinsPerUtxoByte.toString()))
74+
.fee_algo(C.LinearFee.new(C.BigNum.from_str(lucid.protocolParameters.minFeeA.toString()), C.BigNum.from_str(lucid.protocolParameters.minFeeB.toString())))
75+
.key_deposit(C.BigNum.from_str(lucid.protocolParameters.keyDeposit.toString()))
76+
.pool_deposit(C.BigNum.from_str(lucid.protocolParameters.poolDeposit.toString()))
77+
.max_tx_size(lucid.protocolParameters.maxTxSize)
78+
.max_value_size(lucid.protocolParameters.maxValSize)
79+
.collateral_percentage(lucid.protocolParameters.collateralPercentage)
80+
.max_collateral_inputs(lucid.protocolParameters.maxCollateralInputs)
81+
.max_tx_ex_units(C.ExUnits.new(C.BigNum.from_str(lucid.protocolParameters.maxTxExMem.toString()), C.BigNum.from_str(lucid.protocolParameters.maxTxExSteps.toString())))
82+
.ex_unit_prices(C.ExUnitPrices.from_float(lucid.protocolParameters.priceMem, lucid.protocolParameters.priceStep))
7883
.slot_config(C.BigNum.from_str(slotConfig.zeroTime.toString()), C.BigNum.from_str(slotConfig.zeroSlot.toString()), slotConfig.slotLength)
7984
.blockfrost(
8085
// We have Aiken now as native plutus core engine (primary), but we still support blockfrost (secondary) in case of bugs.
@@ -83,7 +88,7 @@ export class Lucid {
8388
(provider?.url || "") + "/utils/txs/evaluate",
8489
// deno-lint-ignore no-explicit-any
8590
provider?.projectId || ""))
86-
.costmdls(createCostModels(protocolParameters.costModels))
91+
.costmdls(createCostModels(lucid.protocolParameters.costModels))
8792
.build();
8893
}
8994
lucid.utils = new Utils(lucid);

0 commit comments

Comments
 (0)