Skip to content

Instantly share code, notes, and snippets.

@marco-martins
Last active June 14, 2022 16:31
Show Gist options
  • Select an option

  • Save marco-martins/f25102edf6050fb10908bc956b9d505c to your computer and use it in GitHub Desktop.

Select an option

Save marco-martins/f25102edf6050fb10908bc956b9d505c to your computer and use it in GitHub Desktop.
double-pay.js
{"valueParameterInfo":[["Deposit",{"valueParameterFormat":{"contents":[6,""],"tag":"DecimalFormat"},"valueParameterDescription":""}]],"timeParameterDescriptions":[],"roleDescriptions":[["Giver1",""]],"contractType":"Other","contractShortDescription":"","contractName":"Double Pay","contractLongDescription":"We couldn't find information about this contract","choiceInfo":[]}
function makeDeposit (party: Party, amount: Value): Action {
return Deposit(party, party, ada, amount)
}
function makePayment (giver1: Party, giver2: Party, receiver: Party, amount: Value) : Contract {
return Pay(giver1, Party(receiver), ada, amount,
Pay(giver2, Party(receiver), ada, amount, Close))
}
function mainFunction (giver1: Party, giver2: Party, receiver: Party, amount: Value, deadline: Timeout): Contract {
//const makePayment: Contract = Pay(giver1, Party(receiver), ada, amount, Pay(giver2, Party(receiver), ada, amount, Close))
function deposits (p1: Party, p2: Party): Case {
return Case(
makeDeposit(p1, amount),
When([Case(
makeDeposit(p2, amount),
makePayment(giver1, giver2, receiver, amount)
)],
deadline, Close)
)
}
return When([
deposits(giver1, giver2),
deposits(giver2, giver1)
],
deadline, Close
)
}
return mainFunction(
Role("Giver1"),
Role("Giver2"),
Role("Receiver"),
ConstantParam("Deposit"),
TimeParam("Deadline")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment