Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE | minor updates to support LBE #8

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/translucent/src/provider/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export class Emulator implements Provider {
this.protocolParameters = protocolParameters;
}

addUTxO(utxo: UTxO) {
this.ledger[utxo.txHash + utxo.outputIndex] = {
utxo,
spent: false,
}
}

now(): UnixTime {
return this.time;
}
Expand Down
26 changes: 15 additions & 11 deletions packages/translucent/src/translucent/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
toScriptRef,
utxoToCore,
} from "../utils/mod";
import { applyDoubleCborEncoding } from "../utils/utils";
import { applyDoubleCborEncoding, toHex } from "../utils/utils";
import { Translucent } from "./translucent";
import { TxComplete } from "./tx_complete";
import { SLOT_CONFIG_NETWORK } from "../plutus/time";
Expand Down Expand Up @@ -67,6 +67,7 @@ export class Tx {
/** Read data from utxos. These utxos are only referenced and not spent. */
readFrom(utxos: UTxO[]): Tx {
this.earlyTasks.push(async (that) => {
const refUtxos = new Set(this.referencedUTxOs.map((u) => toHex(u.to_bytes())));
for (const utxo of utxos) {
if (utxo.datumHash) {
throw "Reference hash not supported";
Expand All @@ -76,17 +77,20 @@ export class Tx {
// that.txBuilder.add_plutus_data(plutusData);
}
const coreUtxo = utxoToCore(utxo);
{
let scriptRef = coreUtxo.output().script_ref();
if (scriptRef) {
let script = scriptRef.script();
if (!script.as_plutus_v2()) {
throw "Reference script wasn't V2 compatible";
}
this.scripts[script.hash().to_hex()] = {
referenceScript: script.as_plutus_v2()!,
};
const coreUtxoHex = toHex(coreUtxo.to_bytes());
if (refUtxos.has(coreUtxoHex)) {
continue;
}
refUtxos.add(coreUtxoHex);
let scriptRef = coreUtxo.output().script_ref();
if (scriptRef) {
let script = scriptRef.script();
if (!script.as_plutus_v2()) {
throw "Reference script wasn't V2 compatible";
}
this.scripts[script.hash().to_hex()] = {
referenceScript: script.as_plutus_v2()!,
};
}
this.referencedUTxOs.push(coreUtxo);
that.txBuilder.add_reference_input(coreUtxo);
Expand Down
Loading