Skip to content

Commit

Permalink
add collateral only when using plutus
Browse files Browse the repository at this point in the history
  • Loading branch information
baymac committed Apr 10, 2024
1 parent 7af6dc8 commit d4eb936
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/translucent/src/translucent/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class Tx {
private UTxOs: CTransactionUnspentOutput[] = [];
private referencedUTxOs: CTransactionUnspentOutput[] = [];

private isUsingPlutus = false;

constructor(translucent: Translucent) {
this.translucent = translucent;
this.txBuilder = C.TransactionBuilder.new(this.translucent.txBuilderConfig);
Expand Down Expand Up @@ -115,6 +117,7 @@ export class Tx {
let address = coreUtxo.output().address();
let paymentCredential = address.payment_cred();
if (redeemer && paymentCredential?.to_scripthash()) {
this.isUsingPlutus = true;
let paymentCredential = address.payment_cred();
if (!paymentCredential) {
throw "Address has no payment credential";
Expand Down Expand Up @@ -193,6 +196,7 @@ export class Tx {
let mintBuilder = C.SingleMintBuilder.new(mintAssets);
let mr: CMintBuilderResult;
if (redeemer) {
this.isUsingPlutus = true;
let script = this.scripts[policyId];
if (!script) {
throw "Scripts must be attached BEFORE they are used";
Expand Down Expand Up @@ -298,6 +302,7 @@ export class Tx {
} else if (outputData.asHash) {
throw "no support for as hash";
} else if (outputData.inline) {
this.isUsingPlutus = true;
const plutusData = C.PlutusData.from_bytes(fromHex(outputData.inline));
outputBuilder = outputBuilder.with_data(C.Datum.new_data(plutusData));
}
Expand Down Expand Up @@ -378,6 +383,7 @@ export class Tx {
);
let cr: CCertificateBuilderResult;
if (redeemer) {
this.isUsingPlutus = true;
let script = this.scripts[credential.to_scripthash()?.to_hex()!];
if (!script) {
throw "Scripts must be attached BEFORE they are used";
Expand Down Expand Up @@ -471,6 +477,7 @@ export class Tx {
);
let cr: CCertificateBuilderResult;
if (redeemer) {
this.isUsingPlutus = true;
let script = this.scripts[credential.to_scripthash()?.to_hex()!];
if (!script) {
throw "Scripts must be attached BEFORE they are used";
Expand Down Expand Up @@ -574,6 +581,7 @@ export class Tx {
);
let wr: CWithdrawalBuilderResult;
if (redeemer) {
this.isUsingPlutus = true;
let script =
this.scripts[rewAdd.payment_cred()?.to_scripthash()?.to_hex()!];
if (!script) {
Expand Down Expand Up @@ -761,6 +769,7 @@ export class Tx {
let ns = C.NativeScript.from_bytes(fromHex(script));
this.native_scripts[ns.hash().to_hex()] = ns;
} else if (type === "PlutusV1" || type === "PlutusV2") {
this.isUsingPlutus = true;
let ps: CPlutusScript;
if (type === "PlutusV1") {
ps = C.PlutusScript.from_v1(
Expand Down Expand Up @@ -841,7 +850,7 @@ export class Tx {
}
this.txBuilder.select_utxos(2);

{
if (this.isUsingPlutus) {
let foundUtxo = walletUTxOs.find(
(x) =>
BigInt(x.output().amount().coin().to_str()) >=
Expand Down

0 comments on commit d4eb936

Please sign in to comment.