Skip to content

Commit

Permalink
fix: add wallet address to payee list to allow the initiator to trigg…
Browse files Browse the repository at this point in the history
…er the payout
  • Loading branch information
fabianbormann committed May 9, 2024
1 parent bff1305 commit 24fac27
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/contracts/src/payment-splitter/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,42 @@ import {
} from '@meshsdk/core';
import {
serializeBech32Address,
applyParamsToScript,
applyObjParamsToScript,
ByteArray,
conStr0,
list,
} from '@meshsdk/mesh-csl';
import blueprint from './aiken-workspace/plutus.json';

export class MeshPaymentSplitterContract extends MeshTxInitiator {
scriptCbor = () =>
applyParamsToScript(blueprint.validators[0].compiledCode, this.payees);
payees: string[] = [];

constructor(inputs: MeshTxInitiatorInput, payees: string[]) {
super(inputs);
wrapPayees = (payees: string[]) =>
conStr0([
list(
payees.map(
(payee) => new ByteArray(serializeBech32Address(payee).pubKeyHash)
)
),
]);
scriptCbor = () =>
applyObjParamsToScript(blueprint.validators[0].compiledCode, [
this.wrapPayees(this.payees),
]);
payees: string[] = [];

constructor(inputs: MeshTxInitiatorInput, payees: string[]) {
super(inputs);

this.payees = payees;
if (inputs.wallet) {
// We add the initiator to the payees list, as only the payees can trigger the payout in the next steps
inputs.wallet!.getUsedAddress().then((address) => {
this.payees = [address, ...payees];
});
} else {
this.payees = payees;
console.warn(
'Wallet not provided. Therefore the payment address will not be added to the payees list which makes it impossible to trigger the payout.'
);
}
}

sendLovelaceToSplitter = async (lovelaceAmount: number) => {
Expand Down

0 comments on commit 24fac27

Please sign in to comment.