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

Withdraw Function should not waitConfirmation #170

Open
nhenin opened this issue Jan 15, 2024 · 0 comments
Open

Withdraw Function should not waitConfirmation #170

nhenin opened this issue Jan 15, 2024 · 0 comments

Comments

@nhenin
Copy link
Collaborator

nhenin commented Jan 15, 2024

in the package marlowe.io/runtime-lifecycle, we have a couple of function that built, sign and submit Cardano Tx, but not wait till the confirmation of this Tx... 2 of them are :

  createContract(
    createContractRequest: CreateContractRequest
  ): Promise<[ContractId, TxId]>;

  applyInputs(
    contractId: ContractId,
    applyInputsRequest: ApplyInputsRequest
  ): Promise<TxId>;

As you can see, they are all returning a TxId. This gives the flexibility to handle waitConfirmation later on.

withdraw(payoutIds: PayoutId[]): Promise<void>; in the Payout Lifecycle should follow the same pattern, but at the moment, it is waiting a confirmation.

The goal of this issue is to remove waitConfimration from the body of this function and return the TxId instead.

export const withdrawPayoutsFpTs: (
  client: FPTSRestAPI
) => (
  wallet: WalletAPI
) => (payoutIds: PayoutId[]) => TE.TaskEither<Error | DecodingError, void> =
  (client) => (wallet) => (payoutIds) =>
    pipe(
      tryCatchDefault(() => getAddressesAndCollaterals(wallet)),
      TE.chain((addressesAndCollaterals) =>
        client.withdrawals.post(payoutIds, addressesAndCollaterals)
      ),
      TE.chainW((withdrawalTextEnvelope) =>
        pipe(
          tryCatchDefault(() =>
            wallet.signTx(withdrawalTextEnvelope.tx.cborHex)
          ),
          TE.chain((hexTransactionWitnessSet) =>
            client.withdrawals.withdrawal.put(
              withdrawalTextEnvelope.withdrawalId,
              hexTransactionWitnessSet
            )
          ),
          TE.map(() => withdrawalTextEnvelope.withdrawalId)
        )
      ),
      TE.chainFirstW((withdrawalId) =>
        tryCatchDefault(() =>
          wallet.waitConfirmation(pipe(withdrawalId, withdrawalIdToTxId))
        )
      ),
      TE.map(constVoid)
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant