Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unclear usage of set_exunits #129

Open
SebastienGllmt opened this issue Sep 12, 2022 · 2 comments
Open

Improve unclear usage of set_exunits #129

SebastienGllmt opened this issue Sep 12, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@SebastienGllmt
Copy link
Contributor

Currently, set_exunits exists both in the regular tx builder & in TxRedeemerBuilder from build_for_evaluation

It's not clear to users that you should call the set_exunits in the main builder from the result of TxRedeemerBuilder and so instead, some people have tried building their own system for dummy witnesses to call the set_exunits in the main builder directly even though TxRedeemerBuilder was meant to handle this for them

Probably the API should be changed to make it clearer what the main path is. For example, make that the set_exunits call in the main builder only accepts a type received from a function in TxRedeemerBuilder

@SebastienGllmt SebastienGllmt added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Sep 12, 2022
@SebastienGllmt SebastienGllmt changed the title Unclear usage of set_exunits Improve unclear usage of set_exunits Sep 12, 2022
@bakon11
Copy link

bakon11 commented Nov 3, 2022

I am just making a simple pool delegation TX, it works great with CSL, but I really want to switch to CML.
However I get the error ex_unit_prices not initialized.

So I tried initializing in the TX builder by adding .ex_unit_prices( ) but I get the following error: expected instance of UnitInterval

Thank you.

// instantiate the tx builder with the Cardano protocol parameters - these may change later on
const txBuilder = await CSLwasm.TransactionBuilder.new(
  CSLwasm.TransactionBuilderConfigBuilder.new()
	.fee_algo( 
		CSLwasm.LinearFee.new(CSLwasm.BigNum.from_str('44'), 
		CSLwasm.BigNum.from_str('155381'))
	)
	.pool_deposit(CSLwasm.BigNum.from_str('500000000'),)
	.key_deposit( CSLwasm.BigNum.from_str('2000000'),)
	.coins_per_utxo_word(CSLwasm.BigNum.from_str('34482'))
	.max_value_size(5000)
	.max_tx_size(16384)
	.prefer_pure_change(true)
	.ex_unit_prices( 
	  CSLwasm.ExUnitPrices.new(
             CSLwasm.BigNum.from_str("1100"), //memory
             CSLwasm.BigNum.from_str("297830") //steps
	  )
	)
	.build()
);

@SebastienGllmt
Copy link
Contributor Author

@bakon11 you get the error because you used the wrong type. The constructor for ExUnitPrices is of type new(mem_price: UnitInterval, step_price: UnitInterval): ExUnitPrices. This is because the memory and steps values are fractions, so you need to specify the numerator and the denominator.

It will look something like this

CSLwasm.ExUnitPrices.new(
  CSLwasm.UnitInterval.new(
    CSLwasm.BigNum.from_str('0'),
    CSLwasm.BigNum.from_str('0')
  ),
    CSLwasm.UnitInterval.new(
    CSLwasm.BigNum.from_str('0'),
    CSLwasm.BigNum.from_str('0')
  )
)

Here are the values for mainnet for example using the JOSN notation

CSLwasm.ExUnitPrices.from_json(JSON.stringify({
  mem_price: {
    denominator: '721',
    numerator: '10000000',
  },
  step_price: {
    denominator: '577',
    numerator: '10000',
  },
})),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants