Skip to content

Commit

Permalink
removed need of tx indexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscojoray committed Apr 29, 2024
1 parent 79a00e1 commit 74e79a8
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 52 deletions.
9 changes: 2 additions & 7 deletions offchain/tests/consume-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import { consumeAsteria } from "../transactions/consume-asteria.ts";
import { printTxURL } from "../utils.ts";

const asteria_tx_hash =
"80d24d906251c7a2e6cfdee77eab0ef0c57498da890391df4428a6a6b9992c7c";
const asteria_tx_index = 0;
"eadb2c22039e0371aecb006d0afde6631aa7ce7914a7929879cbbc20ddc1639a";

const txHash = await consumeAsteria(
admin_token,
asteria_tx_hash,
asteria_tx_index,
);
const txHash = await consumeAsteria(admin_token, asteria_tx_hash);

printTxURL(txHash);
10 changes: 2 additions & 8 deletions offchain/tests/consume-pellet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { consumePellet } from "../transactions/consume-pellet.ts";
import { printTxURL } from "../utils.ts";

const pellet_tx_hash =
"27f120e6cabccb9968519b9bf252f0cf9e5d8b69a1e18910a5172c06ba0f35b2";
const pellet_tx_index = 0;

const txHash = await consumePellet(
admin_token,
pellet_tx_hash,
pellet_tx_index,
);
"65328c6dee12b38ec11049554ba91fa8da9b1f3471a849ef63141883cf2b27cf";

const txHash = await consumePellet(admin_token, pellet_tx_hash);
printTxURL(txHash);
10 changes: 4 additions & 6 deletions offchain/tests/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ import {
import { createShip } from "../transactions/create-ship.ts";
import { printTxURL } from "../utils.ts";

const pos_x = 7n;
const pos_y = -10n;
const pos_x = -7n;
const pos_y = 3n;
const asteria_tx_hash =
"2ad4ee7c7cd9156de39f33c5a1c31e701fae299366bf886c85bbb00ac84f210b";
const asteria_tx_index = 0;
"f76bb8c67e99a5fc9e5dff56b5534a1e47e2ca286361ab625d5ff5a21aa13140";

const txHash = await createShip(
admin_token,
ship_mint_lovelace_fee,
initial_fuel,
pos_x,
pos_y,
asteria_tx_hash,
asteria_tx_index
asteria_tx_hash
);

printTxURL(txHash);
7 changes: 3 additions & 4 deletions offchain/transactions/consume-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { AssetClassT } from "../types.ts";

async function consumeAsteria(
admin_token: AssetClassT,
asteria_tx_hash: TxHash,
asteria_tx_index: number,
asteria_tx_hash: TxHash
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand All @@ -21,15 +20,15 @@ async function consumeAsteria(
lucid.selectWalletFromSeed(seed);

const asteriaRefTxHash: { txHash: string } = JSON.parse(
await Deno.readTextFile("./script-refs/asteria-ref.json"),
await Deno.readTextFile("./script-refs/asteria-ref.json")
);
const asteriaRef = await fetchReferenceScript(lucid, asteriaRefTxHash.txHash);

const asteria: UTxO = (
await lucid.utxosByOutRef([
{
txHash: asteria_tx_hash,
outputIndex: asteria_tx_index,
outputIndex: 0,
},
])
)[0];
Expand Down
7 changes: 3 additions & 4 deletions offchain/transactions/consume-pellet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { AssetClassT } from "../types.ts";

async function consumePellet(
admin_token: AssetClassT,
pellet_tx_hash: TxHash,
pellet_tx_index: number,
pellet_tx_hash: TxHash
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand All @@ -21,15 +20,15 @@ async function consumePellet(
lucid.selectWalletFromSeed(seed);

const asteriaRefTxHash: { txHash: string } = JSON.parse(
await Deno.readTextFile("./script-refs/pellet-ref.json"),
await Deno.readTextFile("./script-refs/pellet-ref.json")
);
const asteriaRef = await fetchReferenceScript(lucid, asteriaRefTxHash.txHash);

const pellet: UTxO = (
await lucid.utxosByOutRef([
{
txHash: pellet_tx_hash,
outputIndex: pellet_tx_index,
outputIndex: 0,
},
])
)[0];
Expand Down
21 changes: 10 additions & 11 deletions offchain/transactions/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ async function createShip(
initial_fuel: bigint,
pos_x: bigint,
pos_y: bigint,
asteria_tx_hash: TxHash,
asteria_tx_index: number
asteria_tx_hash: TxHash
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand Down Expand Up @@ -55,7 +54,7 @@ async function createShip(
await lucid.utxosByOutRef([
{
txHash: asteria_tx_hash,
outputIndex: asteria_tx_index,
outputIndex: 0,
},
])
)[0];
Expand Down Expand Up @@ -109,14 +108,6 @@ async function createShip(
mintRedeemer
)
.collectFrom([asteria], addNewShipRedeemer)
.payToContract(
spacetimeAddressBech32,
{ inline: shipDatum },
{
[shipTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
}
)
.payToContract(
asteriaAddressBech32,
{ inline: asteriaOutputDatum },
Expand All @@ -125,6 +116,14 @@ async function createShip(
lovelace: asteriaInputAda + ship_mint_lovelace_fee,
}
)
.payToContract(
spacetimeAddressBech32,
{ inline: shipDatum },
{
[shipTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
}
)
.complete();

const signedTx = await tx.sign().complete();
Expand Down
18 changes: 9 additions & 9 deletions offchain/transactions/gather-fuel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function gatherFuel(
await lucid.utxosByOutRef([
{
txHash: ship_tx_hash,
outputIndex: 0,
outputIndex: 1,
},
])
)[0];
Expand Down Expand Up @@ -121,14 +121,6 @@ async function gatherFuel(
.collectFrom([ship], shipRedeemer)
.collectFrom([pellet], pelletRedeemer)
.readFrom([spacetimeRef, pelletRef])
.payToContract(
spacetimeAddressBech32,
{ inline: shipOutputDatum },
{
[shipTokenUnit]: BigInt(1),
lovelace: shipAda,
}
)
.payToContract(
pelletAddressBech32,
{ inline: pelletOutputDatum },
Expand All @@ -137,6 +129,14 @@ async function gatherFuel(
lovelace: pelletAda,
}
)
.payToContract(
spacetimeAddressBech32,
{ inline: shipOutputDatum },
{
[shipTokenUnit]: BigInt(1),
lovelace: shipAda,
}
)
.payToAddress(await lucid.wallet.address(), {
[pilotTokenUnit]: BigInt(1),
})
Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/mine-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function mineAsteria(
await lucid.utxosByOutRef([
{
txHash: asteria_tx_hash,
outputIndex: 1,
outputIndex: 0,
},
])
)[0];
Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/move-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function moveShip(
await lucid.utxosByOutRef([
{
txHash: ship_tx_hash,
outputIndex: 0,
outputIndex: 1,
},
])
)[0];
Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/quit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function quit(ship_tx_hash: TxHash): Promise<TxHash> {
await lucid.utxosByOutRef([
{
txHash: ship_tx_hash,
outputIndex: 0,
outputIndex: 1,
},
])
)[0];
Expand Down

0 comments on commit 74e79a8

Please sign in to comment.