-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Script receiver on V2 & V2 transactions (#26)
* Support Script receiver on V1 swap transaction * support V2 custom receiver * fix format
- Loading branch information
Showing
3 changed files
with
183 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Address, Assets, Lucid, OutputData } from "lucid-cardano"; | ||
|
||
/** | ||
* Return a Output that pay back to @sender and include @datum | ||
* This function is used for @receiver of an order can be a script | ||
* @param lucid | ||
* @param sender | ||
* @param receiver | ||
* @param datum | ||
*/ | ||
export function buildUtxoToStoreDatum( | ||
lucid: Lucid, | ||
sender: Address, | ||
receiver: Address, | ||
datum: string | ||
): { | ||
address: Address; | ||
outputData: OutputData; | ||
assets: Assets; | ||
} | null { | ||
const receivePaymentCred = | ||
lucid.utils.getAddressDetails(receiver).paymentCredential; | ||
// If receiver is not a script address, we no need to store this datum On-chain because it's useless | ||
if (!receivePaymentCred || receivePaymentCred.type === "Key") { | ||
return null; | ||
} | ||
|
||
return { | ||
address: sender, | ||
assets: {}, | ||
outputData: { | ||
inline: datum, | ||
}, | ||
}; | ||
} |