lucid icon indicating copy to clipboard operation
lucid copied to clipboard

feat: chaining of txs

Open will-break-it opened this issue 1 year ago • 2 comments

  • [x] simple extension for tx_complete type API to support chaining of transactions
  • [x] added test case

Example: One can chain any complete transaction by using the newly available chain API, which takes a function to select one or more transaction output(s) of tx1 that shall be used an inputs for tx2. These outputs can be script or wallet outputs.

const tx1 = await lucid.newTx()
   .payToAddress('addr_test...', { lovelace: 2_000_000n })
   .complete();

const tx2 = await tx1
    .chain(utxos => utxos.find(({ address }) => address === 'addr_test...')!) // filter tx1 outputs to be chained by some predicate of your choice
    .payToAddress('addr_test...', { lovelace: 2_000_000n })
    .payToAddress('addr_test...', { lovelace: 2_000_000n })
    .complete();

will-break-it avatar Oct 30 '23 10:10 will-break-it

Hi @will991 - When chaining do you filter out any 'spent' UTxOs from the UTxO set? I appreciate that this is not an RFC, however I was thinking that the complete method should (with an option):

  1. Remove any UTxO(s) that have been spent within the Completed Transaction;
  2. Add into the UTxO set any new UTxO(s) that would be created at the Wallet Address

Node: This is all predicated on the idea that with Lucid selectWallet* methods configure Lucid with a single 'address'.

gavinharris-dev avatar Mar 11 '24 03:03 gavinharris-dev

@gavinharris-dev The current state of available UTxOs is stored here. And it is updated based on the Tx outputs matched by payment credentials here.

Hope that helps!

will-break-it avatar Mar 20 '24 06:03 will-break-it