Skip to content

Commit

Permalink
reading pellet params from csv. (#58)
Browse files Browse the repository at this point in the history
* reading pellet params from csv.

* removed asteria tx ref assuming unique UTxO.

* added pellets tx indexing.

* removed unused parsing option.

* fixed type annotation.
  • Loading branch information
franciscojoray authored May 6, 2024
1 parent ae41bcb commit ed03123
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 64 deletions.
30 changes: 13 additions & 17 deletions offchain/tests/admin/create-pellets.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { admin_token } from "../../constants.ts";
import { createPellets } from "../../transactions/admin/create-pellets.ts";
import { printTxURL } from "../../utils.ts";
import { parse } from "jsr:@std/csv";

const params = [
{
fuel: 90n,
pos_x: 12n,
pos_y: -50n,
},
{
fuel: 40n,
pos_x: -7n,
pos_y: 3n,
},
{
fuel: 25n,
pos_x: 20n,
pos_y: 19n,
},
];
const text = await Deno.readTextFile("tests/admin/pellets.csv");
const data = parse(text, {
skipFirstRow: true,
columns: ["fuel", "pos_x", "pos_y"],
});
const params: { fuel: bigint; pos_x: bigint; pos_y: bigint }[] = data.map(
(p) => ({
fuel: BigInt(p.fuel),
pos_x: BigInt(p.pos_x),
pos_y: BigInt(p.pos_y),
})
);

const txHash = await createPellets(admin_token, params);
printTxURL(txHash);
6 changes: 6 additions & 0 deletions offchain/tests/admin/pellets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fuel,x,y
90,12,-35
40,-8,3
25,20,16
36,-4,-17
68,19,-10
10 changes: 2 additions & 8 deletions offchain/tests/user/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import {
import { createShip } from "../../transactions/user/create-ship.ts";
import { printTxURL } from "../../utils.ts";

const pos_x = -7n;
const pos_x = -8n;
const pos_y = 3n;
const asteria_tx_hash =
"8884b2ccbb0d2cd5192459609f775f5b4e5681f5de8d6a4b6f9fc109ea601605";
const asteria_tx_index = 0;

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

printTxURL(txHash);
8 changes: 5 additions & 3 deletions offchain/tests/user/gather-fuel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { printTxURL } from "../../utils.ts";

const gather_amount = 20n;
const ship_tx_hash =
"6ca378639a51b1283ec2c84deb772f62bff59603eca230aeb711fedee8389d69";
"f1079755f32839c7c55796335e6835a0aafa8ce9b3e15fed287e0d971826881c";
const pellet_tx_hash =
"b1d5dedc6c9ba333d8eab4c9f05edda4563fc313fc9b124393ec3b64e3676fb0";
"f7f8f8298876cabb81357c1d7e89e2e01bf8956a566063f12ceee7b6901d0334";
const pellet_tx_index = 1;

const txHash = await gatherFuel(
admin_token,
gather_amount,
ship_tx_hash,
pellet_tx_hash
pellet_tx_hash,
pellet_tx_index
);

printTxURL(txHash);
14 changes: 2 additions & 12 deletions offchain/tests/user/mine-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@ import { mineAsteria } from "../../transactions/user/mine-asteria.ts";
import { printTxURL } from "../../utils.ts";

const ship_tx_hash =
"a528f7e89227b16d769e46b81fae20ba223b3f8fd23d82bb61aa6298f53eb5be";
const asteria_tx_hash =
"aff7cd18d9bf623cdf94544837a450323db2298913b7f6d353e51d9ac109a72a";
const asteria_tx_index = 1;

const txHash = await mineAsteria(
admin_token,
max_asteria_mining,
ship_tx_hash,
asteria_tx_hash,
asteria_tx_index
);
"63213819a91009d48fda251fa5d735ba7fc17ff2d64558c167aa037919adcd05";

const txHash = await mineAsteria(admin_token, max_asteria_mining, ship_tx_hash);
printTxURL(txHash);
13 changes: 2 additions & 11 deletions offchain/transactions/user/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ async function createShip(
ship_mint_lovelace_fee: bigint,
initial_fuel: bigint,
pos_x: bigint,
pos_y: bigint,
asteria_tx_hash: TxHash,
asteria_tx_index: number
pos_y: bigint
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand Down Expand Up @@ -51,14 +49,7 @@ async function createShip(
const spacetimeAddressBech32 =
lucid.utils.validatorToAddress(spacetimeValidator);

const asteria: UTxO = (
await lucid.utxosByOutRef([
{
txHash: asteria_tx_hash,
outputIndex: asteria_tx_index,
},
])
)[0];
const asteria: UTxO = (await lucid.utxosAt(asteriaAddressBech32))[0];
if (!asteria.datum) {
throw Error("Asteria datum not found");
}
Expand Down
5 changes: 3 additions & 2 deletions offchain/transactions/user/gather-fuel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async function gatherFuel(
admin_token: AssetClassT,
gather_amount: bigint,
ship_tx_hash: TxHash,
pellet_tx_hash: TxHash
pellet_tx_hash: TxHash,
pellet_tx_index: number
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand Down Expand Up @@ -64,7 +65,7 @@ async function gatherFuel(
await lucid.utxosByOutRef([
{
txHash: pellet_tx_hash,
outputIndex: 0,
outputIndex: pellet_tx_index,
},
])
)[0];
Expand Down
13 changes: 2 additions & 11 deletions offchain/transactions/user/mine-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import {
async function mineAsteria(
admin_token: AssetClassT,
max_asteria_mining: bigint,
ship_tx_hash: TxHash,
asteria_tx_hash: TxHash,
asteria_tx_index: number
ship_tx_hash: TxHash
): Promise<TxHash> {
const lucid = await lucidBase();
const seed = Deno.env.get("SEED");
Expand Down Expand Up @@ -63,14 +61,7 @@ async function mineAsteria(
ShipDatum as unknown as ShipDatumT
);

const asteria: UTxO = (
await lucid.utxosByOutRef([
{
txHash: asteria_tx_hash,
outputIndex: asteria_tx_index,
},
])
)[0];
const asteria: UTxO = (await lucid.utxosAt(asteriaAddressBech32))[0];
if (!asteria.datum) {
throw Error("Asteria datum not found");
}
Expand Down

0 comments on commit ed03123

Please sign in to comment.