marlowe-ts-sdk
marlowe-ts-sdk copied to clipboard
`Withdraw` Function should not `waitConfirmation`
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)
);