Skip to content

Commit

Permalink
refactor: retrieve active asteria data from validator utxo (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricomiles authored Nov 28, 2024
1 parent dd54246 commit 0a4dd2f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 55 deletions.
7 changes: 0 additions & 7 deletions docs/pages/guides/creating_ship.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import { GameIdentifier, OutRef } from "../src/types";
async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";

const asteria_utxo: OutRef = {
tx_hash:
"a8c77645426fc3031f1daedb657dd1e9af03e2883576d694bcd188b653e91a28",
tx_index: 0n,
};

const spacetime_script_reference: OutRef = {
tx_hash:
Expand All @@ -43,7 +37,6 @@ async function main() {
const pos_y = 20n;

const gameIdentifier: GameIdentifier = {
asteria_utxo,
spacetime_script_reference,
pellet_script_reference,
asteria_script_reference,
Expand Down
8 changes: 0 additions & 8 deletions docs/pages/guides/mining_asteria.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { GameIdentifier, OutRef } from "../src/types";
async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";
const admin_token_subject =
"d37ec8944834e0ce98d655820e05a2d0215b725fd2b79562128f79fa417374657269612041646d696e";

const spacetime_script_reference: OutRef = {
tx_hash:
Expand All @@ -24,11 +22,6 @@ async function main() {
"39871aab15b7c5ab1075ba431d7475f3977fe40fbb8d654b6bdf6f6726659277",
tx_index: 0n,
};
const asteria_utxo: OutRef = {
tx_hash:
"bbcdff5ed1c0dd78c58c42dab8356c161f865d0c3efc1ea281026140a0d38516",
tx_index: 1n,
};

const ship_utxo: OutRef = {
tx_hash:
Expand All @@ -38,7 +31,6 @@ async function main() {


const gameIdentifier: GameIdentifier = {
asteria_utxo,
ship_utxo,
spacetime_script_reference,
pellet_script_reference,
Expand Down
7 changes: 0 additions & 7 deletions sdk/blaze/examples/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { GameIdentifier, OutRef } from "../src/types";
async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";

const asteria_utxo: OutRef = {
tx_hash:
"a8c77645426fc3031f1daedb657dd1e9af03e2883576d694bcd188b653e91a28",
tx_index: 0n,
};

const spacetime_script_reference: OutRef = {
tx_hash:
Expand All @@ -33,7 +27,6 @@ async function main() {
const pos_y = 20n;

const gameIdentifier: GameIdentifier = {
asteria_utxo,
spacetime_script_reference,
pellet_script_reference,
asteria_script_reference,
Expand Down
10 changes: 1 addition & 9 deletions sdk/blaze/examples/mine-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GameIdentifier, OutRef } from "../src/types";
async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";
const admin_token_subject =
"d37ec8944834e0ce98d655820e05a2d0215b725fd2b79562128f79fa417374657269612041646d696e";


const spacetime_script_reference: OutRef = {
tx_hash:
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921",
Expand All @@ -24,11 +22,6 @@ async function main() {
"39871aab15b7c5ab1075ba431d7475f3977fe40fbb8d654b6bdf6f6726659277",
tx_index: 0n,
};
const asteria_utxo: OutRef = {
tx_hash:
"bbcdff5ed1c0dd78c58c42dab8356c161f865d0c3efc1ea281026140a0d38516",
tx_index: 1n,
};

const ship_utxo: OutRef = {
tx_hash:
Expand All @@ -38,7 +31,6 @@ async function main() {


const gameIdentifier: GameIdentifier = {
asteria_utxo,
ship_utxo,
spacetime_script_reference,
pellet_script_reference,
Expand Down
34 changes: 11 additions & 23 deletions sdk/blaze/src/asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ async function createShip(
const asteria_ref_input = outRefToTransactionInput(
game_identifier.asteria_script_reference!,
);
const asteria_input = outRefToTransactionInput(
game_identifier.asteria_utxo!,
);

const asteria_utxos = await blaze.provider.resolveUnspentOutputs([
asteria_input,
]);

const asteria_ref_utxos = await blaze.provider.resolveUnspentOutputs([
asteria_ref_input,
Expand All @@ -69,7 +62,6 @@ async function createShip(
spacetime_ref_input,
]);

const asteria_datum = asteria_utxos[0].output().datum()!.asInlineData()!;
const asteria_ref_datum = asteria_ref_utxos[0].output().datum()!
.asInlineData()!;
const spacetime_ref_datum = spacetime_ref_utxos[0].output().datum()!
Expand All @@ -92,6 +84,13 @@ async function createShip(
asteria_ref_datum,
AsteriaScriptDatum,
);

const admin_token_from_datum = asteria_ref_datum_data.admin_token;
const admin_token = AssetId(
admin_token_from_datum.policy_id + admin_token_from_datum.asset_name,
);
const asteria_utxos = await blaze.provider.getUnspentOutputsWithAsset(asteria_validator_address, admin_token);
const asteria_datum = asteria_utxos[0].output().datum()!.asInlineData()!;
const spacetime_ref_datum_data = Data.from(
spacetime_ref_datum,
SpaceTimeScriptDatum,
Expand All @@ -101,11 +100,6 @@ async function createShip(
asteria_datum,
AsteriaDatum,
);
const admin_token_from_datum = asteria_ref_datum_data.admin_token;

const admin_token = AssetId(
admin_token_from_datum.policy_id + admin_token_from_datum.asset_name,
);

const ship_name = "SHIP" + asteria_datum_data.ship_counter.toString();
const pilot_name = "PILOT" + asteria_datum_data.ship_counter.toString();
Expand Down Expand Up @@ -454,8 +448,8 @@ async function gatherFuel(
admin_token,
1n,
])
if(pellet_change > 0) {
value_to_lock = makeValue(0n, [fuel_token, pellet_change], [
if (pellet_change > 0) {
value_to_lock = makeValue(0n, [fuel_token, pellet_change], [
admin_token,
1n,
]);
Expand Down Expand Up @@ -503,9 +497,6 @@ async function mineAsteria(
game_identifier.pellet_script_reference!,
);
const ship_input = outRefToTransactionInput(game_identifier.ship_utxo!);
const asteria_input = outRefToTransactionInput(
game_identifier.asteria_utxo!,
);

const asteria_ref_utxos = await blaze.provider.resolveUnspentOutputs([
asteria_ref_input,
Expand All @@ -517,9 +508,6 @@ async function mineAsteria(
pellet_ref_input,
]);

const asteria_utxos = await blaze.provider.resolveUnspentOutputs([
asteria_input,
]);
const ship_utxo = await blaze.provider.resolveUnspentOutputs([ship_input]);

const asteria_validator_address = asteria_ref_utxos[0].output().address();
Expand All @@ -531,7 +519,7 @@ async function mineAsteria(
spacetime_validator_address,
);

const asteria_ref_datum = asteria_utxos[0].output().datum()!
const asteria_ref_datum = asteria_ref_utxos[0].output().datum()!
.asInlineData()!;
const asteria_ref_datum_data = Data.from(
asteria_ref_datum,
Expand All @@ -546,7 +534,7 @@ async function mineAsteria(
const admin_token = AssetId(
admin_token_from_datum.policy_id + admin_token_from_datum.asset_name,
);

const asteria_utxos = await blaze.provider.getUnspentOutputsWithAsset(asteria_validator_address, admin_token);
const asteria_datum = asteria_utxos[0].output().datum()!.asInlineData()!;

const asteria_datum_data = Data.from(
Expand Down
1 change: 0 additions & 1 deletion sdk/blaze/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type OutRef = {
};

type GameIdentifier = {
asteria_utxo?: OutRef;
ship_utxo?: OutRef;
pellet_utxo?: OutRef;
spacetime_script_reference?: OutRef;
Expand Down

0 comments on commit 0a4dd2f

Please sign in to comment.