From 27f10c4e48f349122ab4e2b9fa450dea0bbfd0a2 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 11 Apr 2024 17:20:54 +0700 Subject: [PATCH 1/4] test pump --- packages/translucent/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/translucent/package.json b/packages/translucent/package.json index 960971d..5f1e9f9 100644 --- a/packages/translucent/package.json +++ b/packages/translucent/package.json @@ -1,6 +1,6 @@ { "name": "@minswap/translucent", - "version": "0.0.6-minswap.5", + "version": "0.0.6-minswap.6", "scripts": { "build": "rimraf build && rollup -c rollup.config.mjs" }, From 2faa0497c66b5726c79f9f445c3cda8374d2485d Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 17 May 2024 16:55:55 +0700 Subject: [PATCH 2/4] update --- packages/translucent/src/translucent/tx.ts | 12 ++++++++---- packages/translucent/src/utils/utils.ts | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/translucent/src/translucent/tx.ts b/packages/translucent/src/translucent/tx.ts index 8399a63..8a05552 100644 --- a/packages/translucent/src/translucent/tx.ts +++ b/packages/translucent/src/translucent/tx.ts @@ -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"; @@ -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"; @@ -76,7 +77,10 @@ export class Tx { // that.txBuilder.add_plutus_data(plutusData); } const coreUtxo = utxoToCore(utxo); - { + const coreUtxoHex = toHex(coreUtxo.to_bytes()); + let isExists = refUtxos.has(coreUtxoHex); + if (!isExists) { + refUtxos.add(coreUtxoHex); let scriptRef = coreUtxo.output().script_ref(); if (scriptRef) { let script = scriptRef.script(); @@ -87,9 +91,9 @@ export class Tx { referenceScript: script.as_plutus_v2()!, }; } + this.referencedUTxOs.push(coreUtxo); + that.txBuilder.add_reference_input(coreUtxo); } - this.referencedUTxOs.push(coreUtxo); - that.txBuilder.add_reference_input(coreUtxo); } }); return this; diff --git a/packages/translucent/src/utils/utils.ts b/packages/translucent/src/utils/utils.ts index 379657e..6c25445 100644 --- a/packages/translucent/src/utils/utils.ts +++ b/packages/translucent/src/utils/utils.ts @@ -655,6 +655,9 @@ export function toUnit( name?: string | null, label?: number | null, ): Unit { + if (policyId === "" && !name) { + return "lovelace"; + } const hexLabel = Number.isInteger(label) ? toLabel(label!) : ""; const n = name ? name : ""; if ((n + hexLabel).length > 64) { From 2b3dc51b41b9922aff1c2e1bf5c5f454679dc8d9 Mon Sep 17 00:00:00 2001 From: dzung pham Date: Wed, 29 May 2024 10:19:25 +0700 Subject: [PATCH 3/4] update --- packages/translucent/src/provider/emulator.ts | 7 +++++ packages/translucent/src/translucent/tx.ts | 28 +++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/translucent/src/provider/emulator.ts b/packages/translucent/src/provider/emulator.ts index 5a8e67d..77e2d91 100644 --- a/packages/translucent/src/provider/emulator.ts +++ b/packages/translucent/src/provider/emulator.ts @@ -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; } diff --git a/packages/translucent/src/translucent/tx.ts b/packages/translucent/src/translucent/tx.ts index 8a05552..96135bc 100644 --- a/packages/translucent/src/translucent/tx.ts +++ b/packages/translucent/src/translucent/tx.ts @@ -78,22 +78,22 @@ export class Tx { } const coreUtxo = utxoToCore(utxo); const coreUtxoHex = toHex(coreUtxo.to_bytes()); - let isExists = refUtxos.has(coreUtxoHex); - if (!isExists) { - 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()!, - }; + 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.referencedUTxOs.push(coreUtxo); - that.txBuilder.add_reference_input(coreUtxo); + this.scripts[script.hash().to_hex()] = { + referenceScript: script.as_plutus_v2()!, + }; } + this.referencedUTxOs.push(coreUtxo); + that.txBuilder.add_reference_input(coreUtxo); } }); return this; From b828a88cde1bf8e54513cc431aa27eda4c242224 Mon Sep 17 00:00:00 2001 From: dzung pham Date: Tue, 4 Jun 2024 17:31:02 +0700 Subject: [PATCH 4/4] revert `toUnit` --- packages/translucent/src/utils/utils.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/translucent/src/utils/utils.ts b/packages/translucent/src/utils/utils.ts index 634fe25..66cd63e 100644 --- a/packages/translucent/src/utils/utils.ts +++ b/packages/translucent/src/utils/utils.ts @@ -655,9 +655,6 @@ export function toUnit( name?: string | null, label?: number | null, ): Unit { - if (policyId === "" && !name) { - return "lovelace"; - } const hexLabel = Number.isInteger(label) ? toLabel(label!) : ""; const n = name ? name : ""; if ((n + hexLabel).length > 64) {