From 0a4dd2f6b4bda32c9b4e3106ac536cb918a171ff Mon Sep 17 00:00:00 2001 From: Rico Miles Quiblat <120778516+ricomiles@users.noreply.github.com> Date: Fri, 29 Nov 2024 02:13:40 +0800 Subject: [PATCH] refactor: retrieve active asteria data from validator utxo (#104) --- docs/pages/guides/creating_ship.mdx | 7 ------ docs/pages/guides/mining_asteria.mdx | 8 ------- sdk/blaze/examples/create-ship.ts | 7 ------ sdk/blaze/examples/mine-asteria.ts | 10 +------- sdk/blaze/src/asteria.ts | 34 +++++++++------------------- sdk/blaze/src/types.ts | 1 - 6 files changed, 12 insertions(+), 55 deletions(-) diff --git a/docs/pages/guides/creating_ship.mdx b/docs/pages/guides/creating_ship.mdx index 14c2b0b..d212263 100644 --- a/docs/pages/guides/creating_ship.mdx +++ b/docs/pages/guides/creating_ship.mdx @@ -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: @@ -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, diff --git a/docs/pages/guides/mining_asteria.mdx b/docs/pages/guides/mining_asteria.mdx index 6b28006..de536f2 100644 --- a/docs/pages/guides/mining_asteria.mdx +++ b/docs/pages/guides/mining_asteria.mdx @@ -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: @@ -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: @@ -38,7 +31,6 @@ async function main() { const gameIdentifier: GameIdentifier = { - asteria_utxo, ship_utxo, spacetime_script_reference, pellet_script_reference, diff --git a/sdk/blaze/examples/create-ship.ts b/sdk/blaze/examples/create-ship.ts index 2c4b63f..6e3e4b2 100644 --- a/sdk/blaze/examples/create-ship.ts +++ b/sdk/blaze/examples/create-ship.ts @@ -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: @@ -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, diff --git a/sdk/blaze/examples/mine-asteria.ts b/sdk/blaze/examples/mine-asteria.ts index 96d95d9..3a96907 100644 --- a/sdk/blaze/examples/mine-asteria.ts +++ b/sdk/blaze/examples/mine-asteria.ts @@ -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", @@ -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: @@ -38,7 +31,6 @@ async function main() { const gameIdentifier: GameIdentifier = { - asteria_utxo, ship_utxo, spacetime_script_reference, pellet_script_reference, diff --git a/sdk/blaze/src/asteria.ts b/sdk/blaze/src/asteria.ts index 8e049e6..5b8b7a5 100644 --- a/sdk/blaze/src/asteria.ts +++ b/sdk/blaze/src/asteria.ts @@ -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, @@ -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()! @@ -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, @@ -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(); @@ -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, ]); @@ -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, @@ -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(); @@ -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, @@ -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( diff --git a/sdk/blaze/src/types.ts b/sdk/blaze/src/types.ts index 4976f83..684154e 100644 --- a/sdk/blaze/src/types.ts +++ b/sdk/blaze/src/types.ts @@ -80,7 +80,6 @@ type OutRef = { }; type GameIdentifier = { - asteria_utxo?: OutRef; ship_utxo?: OutRef; pellet_utxo?: OutRef; spacetime_script_reference?: OutRef;