From 184be8d4cbf765aa881fdf1a74853c9816e4e74d Mon Sep 17 00:00:00 2001 From: ricomiles Date: Tue, 3 Dec 2024 02:05:44 +0800 Subject: [PATCH 1/3] fix: make kupmios provider configurable --- docs/pages/guides/creating_ship.mdx | 6 ++++++ docs/pages/guides/gathering_fuel.mdx | 6 ++++++ docs/pages/guides/mining_asteria.mdx | 6 ++++++ docs/pages/guides/moving_ship.mdx | 6 ++++++ sdk/blaze/examples/create-ship.ts | 10 ++++++++-- sdk/blaze/examples/gather-fuel.ts | 9 ++++++--- sdk/blaze/examples/mine-asteria.ts | 10 ++++++++-- sdk/blaze/examples/move-ship.ts | 8 +++++++- sdk/blaze/examples/quit.ts | 10 ++++++++-- sdk/blaze/src/asteria.ts | 16 +++++++++++----- sdk/blaze/src/types.ts | 8 +++++++- sdk/blaze/src/utils.ts | 12 +++++------- 12 files changed, 84 insertions(+), 23 deletions(-) diff --git a/docs/pages/guides/creating_ship.mdx b/docs/pages/guides/creating_ship.mdx index d212263..1ef341d 100644 --- a/docs/pages/guides/creating_ship.mdx +++ b/docs/pages/guides/creating_ship.mdx @@ -14,6 +14,11 @@ import { GameIdentifier, OutRef } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + + const kupmios_config: KupmiosConfig ={ + kupo_url: process.env.KUPO_URL, + ogmios_url: process.env.OGMIOS_URL, + }; const spacetime_script_reference: OutRef = { tx_hash: @@ -43,6 +48,7 @@ async function main() { }; const tx = await createShip( + kupmios_config, address, gameIdentifier, pos_x, diff --git a/docs/pages/guides/gathering_fuel.mdx b/docs/pages/guides/gathering_fuel.mdx index 3a31fb7..aaa25e9 100644 --- a/docs/pages/guides/gathering_fuel.mdx +++ b/docs/pages/guides/gathering_fuel.mdx @@ -6,6 +6,11 @@ async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + const kupmios_config: KupmiosConfig ={ + kupo_url: process.env.KUPO_URL, + ogmios_url: process.env.OGMIOS_URL, + }; + const ship_utxo: OutRef = { tx_hash: "3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a", @@ -31,6 +36,7 @@ async function main() { const gather_fuel_identifier: GameIdentifier = { + kupmios_config, ship_utxo, pellet_utxo, spacetime_script_reference, diff --git a/docs/pages/guides/mining_asteria.mdx b/docs/pages/guides/mining_asteria.mdx index de536f2..be49e3b 100644 --- a/docs/pages/guides/mining_asteria.mdx +++ b/docs/pages/guides/mining_asteria.mdx @@ -5,6 +5,11 @@ async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + const kupmios_config: KupmiosConfig ={ + kupo_url: process.env.KUPO_URL, + ogmios_url: process.env.OGMIOS_URL, + }; + const spacetime_script_reference: OutRef = { tx_hash: "41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", @@ -31,6 +36,7 @@ async function main() { const gameIdentifier: GameIdentifier = { + kupmios_config, ship_utxo, spacetime_script_reference, pellet_script_reference, diff --git a/docs/pages/guides/moving_ship.mdx b/docs/pages/guides/moving_ship.mdx index d01234b..2277375 100644 --- a/docs/pages/guides/moving_ship.mdx +++ b/docs/pages/guides/moving_ship.mdx @@ -4,6 +4,11 @@ import { OutRef, GameIdentifier } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + + const kupmios_config: KupmiosConfig ={ + kupo_url: process.env.KUPO_URL, + ogmios_url: process.env.OGMIOS_URL, + }; const ship_utxo: OutRef = { tx_hash: @@ -33,6 +38,7 @@ async function main() { }; const tx = await moveShip( + kupmios_config, address, move_ship_identifier, delta_x, diff --git a/sdk/blaze/examples/create-ship.ts b/sdk/blaze/examples/create-ship.ts index 6e3e4b2..0f8014a 100644 --- a/sdk/blaze/examples/create-ship.ts +++ b/sdk/blaze/examples/create-ship.ts @@ -1,10 +1,15 @@ import { createShip } from "../src"; -import { GameIdentifier, OutRef } from "../src/types"; +import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - + + const kupmios_config: KupmiosConfig ={ + kupo_url: process.env.KUPO_URL!, + ogmios_url: process.env.OGMIOS_URL!, + }; + const spacetime_script_reference: OutRef = { tx_hash: "41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", @@ -33,6 +38,7 @@ async function main() { }; const tx = await createShip( + kupmios_config, address, gameIdentifier, pos_x, diff --git a/sdk/blaze/examples/gather-fuel.ts b/sdk/blaze/examples/gather-fuel.ts index e4720ea..db3a0a4 100644 --- a/sdk/blaze/examples/gather-fuel.ts +++ b/sdk/blaze/examples/gather-fuel.ts @@ -1,11 +1,13 @@ -import { max } from "rxjs"; -import { GameIdentifier, OutRef } from "../src/types"; +import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; import { gatherFuel } from "../src"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - + const kupmios_config: KupmiosConfig = { + kupo_url: "https://kupo1dce45wncnj6zgxxext7.preview-v2.kupo-m1.demeter.run", + ogmios_url: "https://ogmios13lw5mnhwypg5shrt9eh.preview-v5.ogmios-m1.demeter.run", + } const ship_utxo: OutRef = { tx_hash: "3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a", @@ -38,6 +40,7 @@ async function main() { }; const tx = await gatherFuel( + kupmios_config, address, gather_fuel_identifier, ); diff --git a/sdk/blaze/examples/mine-asteria.ts b/sdk/blaze/examples/mine-asteria.ts index 3a96907..340d81d 100644 --- a/sdk/blaze/examples/mine-asteria.ts +++ b/sdk/blaze/examples/mine-asteria.ts @@ -1,10 +1,15 @@ import { mineAsteria } from "../src"; -import { GameIdentifier, OutRef } from "../src/types"; +import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - + + const kupmios_config: KupmiosConfig = { + kupo_url: process.env.KUPO_URL!, + ogmios_url: process.env.OGMIOS_URL!, + }; + const spacetime_script_reference: OutRef = { tx_hash: "41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", @@ -38,6 +43,7 @@ async function main() { }; const tx = await mineAsteria( + kupmios_config, address, gameIdentifier, ); diff --git a/sdk/blaze/examples/move-ship.ts b/sdk/blaze/examples/move-ship.ts index d01234b..3b70948 100644 --- a/sdk/blaze/examples/move-ship.ts +++ b/sdk/blaze/examples/move-ship.ts @@ -1,10 +1,15 @@ import { createShip, moveShip } from "../src"; -import { OutRef, GameIdentifier } from "../src/types"; +import { OutRef, GameIdentifier, KupmiosConfig } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + const kupmios_config: KupmiosConfig = { + kupo_url: process.env.KUPO_URL!, + ogmios_url: process.env.OGMIOS_URL!, + }; + const ship_utxo: OutRef = { tx_hash: "41f2a593e131a3c5db878bbe7753b89c8c6de555b7127e812c0f488d1a898368", @@ -33,6 +38,7 @@ async function main() { }; const tx = await moveShip( + kupmios_config, address, move_ship_identifier, delta_x, diff --git a/sdk/blaze/examples/quit.ts b/sdk/blaze/examples/quit.ts index db92fee..290cc98 100644 --- a/sdk/blaze/examples/quit.ts +++ b/sdk/blaze/examples/quit.ts @@ -1,10 +1,15 @@ import { createShip, moveShip, quit } from "../src"; -import { OutRef, GameIdentifier } from "../src/types"; +import { OutRef, GameIdentifier, KupmiosConfig } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + const kupmios_config: KupmiosConfig = { + kupo_url: process.env.KUPO_URL!, + ogmios_url: process.env.OGMIOS_URL!, + }; + const ship_utxo: OutRef = { tx_hash: "870b37da4cc82a16eb47db293713d81fe9abfe183055341174405e94768264c5", @@ -23,7 +28,7 @@ async function main() { tx_index: 0n, }; - + const quit_game_identifier: GameIdentifier = { ship_utxo, @@ -32,6 +37,7 @@ async function main() { }; const tx = await quit( + kupmios_config, address, quit_game_identifier, ); diff --git a/sdk/blaze/src/asteria.ts b/sdk/blaze/src/asteria.ts index 5b8b7a5..e890ece 100644 --- a/sdk/blaze/src/asteria.ts +++ b/sdk/blaze/src/asteria.ts @@ -27,6 +27,7 @@ import { AsteriaDatum, AsteriaScriptDatum, GameIdentifier, + KupmiosConfig, PelletDatum, PelletScriptDatum, ShipDatum, @@ -35,12 +36,13 @@ import { import { max } from "rxjs"; async function createShip( + kupmios_config: KupmiosConfig, address: string, game_identifier: GameIdentifier, pos_x: bigint, pos_y: bigint, ): Promise { - const blaze = await blazeInit(address); + const blaze = await blazeInit(address, kupmios_config); const spacetime_ref_input = outRefToTransactionInput( game_identifier.spacetime_script_reference!, @@ -177,12 +179,13 @@ async function createShip( } async function moveShip( + kupmios_config: KupmiosConfig, address: string, game_identifier: GameIdentifier, delta_x: bigint, delta_y: bigint, ): Promise { - const blaze = await blazeInit(address); + const blaze = await blazeInit(address, kupmios_config); const ship_input = outRefToTransactionInput(game_identifier.ship_utxo!); const spacetime_ref_input = outRefToTransactionInput( @@ -314,10 +317,11 @@ async function moveShip( } async function gatherFuel( + kupmios_config: KupmiosConfig, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address); + const blaze = await blazeInit(address, kupmios_config); const ship_input = outRefToTransactionInput( game_identifier.ship_utxo!, @@ -482,10 +486,11 @@ async function gatherFuel( } async function mineAsteria( + kupmios_config: KupmiosConfig, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address); + const blaze = await blazeInit(address, kupmios_config); const asteria_ref_input = outRefToTransactionInput( game_identifier.asteria_script_reference!, @@ -603,10 +608,11 @@ async function mineAsteria( } async function quit( + kupmios_config: KupmiosConfig, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address); + const blaze = await blazeInit(address, kupmios_config); const ship_input = outRefToTransactionInput( game_identifier.ship_utxo!, diff --git a/sdk/blaze/src/types.ts b/sdk/blaze/src/types.ts index 684154e..3dc6600 100644 --- a/sdk/blaze/src/types.ts +++ b/sdk/blaze/src/types.ts @@ -87,6 +87,10 @@ type GameIdentifier = { asteria_script_reference?: OutRef; }; +type KupmiosConfig = { + kupo_url: string; + ogmios_url: string; +} export { AsteriaDatum, AsteriaScriptDatum, @@ -95,5 +99,7 @@ export { PelletDatum, ShipDatum, SpaceTimeScriptDatum, - PelletScriptDatum + PelletScriptDatum, + KupmiosConfig, }; + diff --git a/sdk/blaze/src/utils.ts b/sdk/blaze/src/utils.ts index 123af42..4816600 100644 --- a/sdk/blaze/src/utils.ts +++ b/sdk/blaze/src/utils.ts @@ -1,16 +1,14 @@ import { Address, AssetId, NetworkId, TransactionId, TransactionInput } from "@blaze-cardano/core"; import { Unwrapped } from "@blaze-cardano/ogmios"; import { Blaze, ColdWallet, Core, Kupmios } from "@blaze-cardano/sdk"; -import { GameIdentifier, OutRef } from "./types"; +import { GameIdentifier, KupmiosConfig, OutRef } from "./types"; -async function blazeInit(address: string): Promise> { +async function blazeInit(address: string, kupmios_config: KupmiosConfig): Promise> { const blaze_address = Core.Address.fromBech32(address); const provider = new Kupmios( - "https://kupo1dce45wncnj6zgxxext7.preview-v2.kupo-m1.demeter.run", - await Unwrapped.Ogmios.new( - "https://ogmios13lw5mnhwypg5shrt9eh.preview-v5.ogmios-m1.demeter.run", - ), - ); + kupmios_config.kupo_url, + await Unwrapped.Ogmios.new(kupmios_config.ogmios_url) + ) const wallet = new ColdWallet(blaze_address, NetworkId.Testnet, provider); return Blaze.from(provider, wallet); From ff015707c73f8c48b61693e79008f3656bff998b Mon Sep 17 00:00:00 2001 From: ricomiles Date: Tue, 3 Dec 2024 02:12:39 +0800 Subject: [PATCH 2/3] fix: remove hardcoded config on gather fuel example --- sdk/blaze/examples/gather-fuel.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sdk/blaze/examples/gather-fuel.ts b/sdk/blaze/examples/gather-fuel.ts index db3a0a4..fcae8a6 100644 --- a/sdk/blaze/examples/gather-fuel.ts +++ b/sdk/blaze/examples/gather-fuel.ts @@ -4,10 +4,12 @@ import { gatherFuel } from "../src"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; + const kupmios_config: KupmiosConfig = { - kupo_url: "https://kupo1dce45wncnj6zgxxext7.preview-v2.kupo-m1.demeter.run", - ogmios_url: "https://ogmios13lw5mnhwypg5shrt9eh.preview-v5.ogmios-m1.demeter.run", - } + kupo_url: process.env.KUPO_URL!, + ogmios_url: process.env.OGMIOS_URL!, + }; + const ship_utxo: OutRef = { tx_hash: "3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a", From adf90988e86c892b3cd8c5bc8f29b2145fd7d2f9 Mon Sep 17 00:00:00 2001 From: ricomiles Date: Tue, 3 Dec 2024 17:33:25 +0800 Subject: [PATCH 3/3] refactor: adjust function requirements from config to the entire provider --- docs/pages/guides/creating_ship.mdx | 12 +++++++----- docs/pages/guides/gathering_fuel.mdx | 13 +++++++------ docs/pages/guides/mining_asteria.mdx | 12 +++++++----- docs/pages/guides/moving_ship.mdx | 14 ++++++++------ sdk/blaze/examples/create-ship.ts | 18 ++++++++++-------- sdk/blaze/examples/gather-fuel.ts | 17 ++++++++++------- sdk/blaze/examples/mine-asteria.ts | 15 +++++++++------ sdk/blaze/examples/move-ship.ts | 17 ++++++++++------- sdk/blaze/examples/quit.ts | 19 ++++++++++--------- sdk/blaze/src/asteria.ts | 22 +++++++++++----------- sdk/blaze/src/types.ts | 5 ----- sdk/blaze/src/utils.ts | 9 ++------- 12 files changed, 91 insertions(+), 82 deletions(-) diff --git a/docs/pages/guides/creating_ship.mdx b/docs/pages/guides/creating_ship.mdx index 1ef341d..9e1fe0e 100644 --- a/docs/pages/guides/creating_ship.mdx +++ b/docs/pages/guides/creating_ship.mdx @@ -8,17 +8,19 @@ Creates a `ShipState` UTxO locking min ada and a `ShipToken` (minted in this tx) ## Lucid Example ```ts +import { Kupmios } from "@blaze-cardano/sdk"; import { createShip } from "../src"; import { GameIdentifier, OutRef } from "../src/types"; +import { Unwrapped } from "@blaze-cardano/ogmios"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig ={ - kupo_url: process.env.KUPO_URL, - ogmios_url: process.env.OGMIOS_URL, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); const spacetime_script_reference: OutRef = { tx_hash: @@ -48,7 +50,7 @@ async function main() { }; const tx = await createShip( - kupmios_config, + provider, address, gameIdentifier, pos_x, diff --git a/docs/pages/guides/gathering_fuel.mdx b/docs/pages/guides/gathering_fuel.mdx index aaa25e9..30fc3c0 100644 --- a/docs/pages/guides/gathering_fuel.mdx +++ b/docs/pages/guides/gathering_fuel.mdx @@ -1,15 +1,16 @@ -import { max } from "rxjs"; import { GameIdentifier, OutRef } from "../src/types"; import { gatherFuel } from "../src"; +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig ={ - kupo_url: process.env.KUPO_URL, - ogmios_url: process.env.OGMIOS_URL, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); const ship_utxo: OutRef = { tx_hash: @@ -36,7 +37,6 @@ async function main() { const gather_fuel_identifier: GameIdentifier = { - kupmios_config, ship_utxo, pellet_utxo, spacetime_script_reference, @@ -44,6 +44,7 @@ async function main() { }; const tx = await gatherFuel( + provider, address, gather_fuel_identifier, ); diff --git a/docs/pages/guides/mining_asteria.mdx b/docs/pages/guides/mining_asteria.mdx index be49e3b..91df221 100644 --- a/docs/pages/guides/mining_asteria.mdx +++ b/docs/pages/guides/mining_asteria.mdx @@ -1,3 +1,5 @@ +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; import { mineAsteria } from "../src"; import { GameIdentifier, OutRef } from "../src/types"; @@ -5,10 +7,10 @@ async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig ={ - kupo_url: process.env.KUPO_URL, - ogmios_url: process.env.OGMIOS_URL, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); const spacetime_script_reference: OutRef = { tx_hash: @@ -36,7 +38,6 @@ async function main() { const gameIdentifier: GameIdentifier = { - kupmios_config, ship_utxo, spacetime_script_reference, pellet_script_reference, @@ -44,6 +45,7 @@ async function main() { }; const tx = await mineAsteria( + provider, address, gameIdentifier, ); diff --git a/docs/pages/guides/moving_ship.mdx b/docs/pages/guides/moving_ship.mdx index 2277375..c04be39 100644 --- a/docs/pages/guides/moving_ship.mdx +++ b/docs/pages/guides/moving_ship.mdx @@ -1,14 +1,16 @@ -import { createShip, moveShip } from "../src"; +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; +import { moveShip } from "../src"; import { OutRef, GameIdentifier } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig ={ - kupo_url: process.env.KUPO_URL, - ogmios_url: process.env.OGMIOS_URL, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); const ship_utxo: OutRef = { tx_hash: @@ -38,7 +40,7 @@ async function main() { }; const tx = await moveShip( - kupmios_config, + provider, address, move_ship_identifier, delta_x, diff --git a/sdk/blaze/examples/create-ship.ts b/sdk/blaze/examples/create-ship.ts index 0f8014a..6e52b30 100644 --- a/sdk/blaze/examples/create-ship.ts +++ b/sdk/blaze/examples/create-ship.ts @@ -1,15 +1,17 @@ +import { Kupmios } from "@blaze-cardano/sdk"; import { createShip } from "../src"; -import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; +import { GameIdentifier, OutRef } from "../src/types"; +import { Unwrapped } from "@blaze-cardano/ogmios"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - - const kupmios_config: KupmiosConfig ={ - kupo_url: process.env.KUPO_URL!, - ogmios_url: process.env.OGMIOS_URL!, - }; - + + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); + const spacetime_script_reference: OutRef = { tx_hash: "41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", @@ -38,7 +40,7 @@ async function main() { }; const tx = await createShip( - kupmios_config, + provider, address, gameIdentifier, pos_x, diff --git a/sdk/blaze/examples/gather-fuel.ts b/sdk/blaze/examples/gather-fuel.ts index fcae8a6..4bb66ed 100644 --- a/sdk/blaze/examples/gather-fuel.ts +++ b/sdk/blaze/examples/gather-fuel.ts @@ -1,15 +1,18 @@ -import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; +import { GameIdentifier, OutRef } from "../src/types"; import { gatherFuel } from "../src"; +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig = { - kupo_url: process.env.KUPO_URL!, - ogmios_url: process.env.OGMIOS_URL!, - }; - + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); + + const ship_utxo: OutRef = { tx_hash: "3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a", @@ -42,7 +45,7 @@ async function main() { }; const tx = await gatherFuel( - kupmios_config, + provider, address, gather_fuel_identifier, ); diff --git a/sdk/blaze/examples/mine-asteria.ts b/sdk/blaze/examples/mine-asteria.ts index 340d81d..161f1ff 100644 --- a/sdk/blaze/examples/mine-asteria.ts +++ b/sdk/blaze/examples/mine-asteria.ts @@ -1,14 +1,17 @@ +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; import { mineAsteria } from "../src"; -import { GameIdentifier, KupmiosConfig, OutRef } from "../src/types"; +import { GameIdentifier, OutRef } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig = { - kupo_url: process.env.KUPO_URL!, - ogmios_url: process.env.OGMIOS_URL!, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); + const spacetime_script_reference: OutRef = { tx_hash: @@ -43,7 +46,7 @@ async function main() { }; const tx = await mineAsteria( - kupmios_config, + provider, address, gameIdentifier, ); diff --git a/sdk/blaze/examples/move-ship.ts b/sdk/blaze/examples/move-ship.ts index 3b70948..bf9e3ed 100644 --- a/sdk/blaze/examples/move-ship.ts +++ b/sdk/blaze/examples/move-ship.ts @@ -1,14 +1,17 @@ -import { createShip, moveShip } from "../src"; -import { OutRef, GameIdentifier, KupmiosConfig } from "../src/types"; +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; +import { moveShip } from "../src"; +import { OutRef, GameIdentifier } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig = { - kupo_url: process.env.KUPO_URL!, - ogmios_url: process.env.OGMIOS_URL!, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); + const ship_utxo: OutRef = { tx_hash: @@ -38,7 +41,7 @@ async function main() { }; const tx = await moveShip( - kupmios_config, + provider, address, move_ship_identifier, delta_x, diff --git a/sdk/blaze/examples/quit.ts b/sdk/blaze/examples/quit.ts index 290cc98..be9bc13 100644 --- a/sdk/blaze/examples/quit.ts +++ b/sdk/blaze/examples/quit.ts @@ -1,14 +1,17 @@ -import { createShip, moveShip, quit } from "../src"; -import { OutRef, GameIdentifier, KupmiosConfig } from "../src/types"; +import { Unwrapped } from "@blaze-cardano/ogmios"; +import { Kupmios } from "@blaze-cardano/sdk"; +import { quit } from "../src"; +import { OutRef, GameIdentifier } from "../src/types"; async function main() { const address = "addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; - const kupmios_config: KupmiosConfig = { - kupo_url: process.env.KUPO_URL!, - ogmios_url: process.env.OGMIOS_URL!, - }; + const provider = new Kupmios( + process.env.KUPO_URL!, + await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!) + ); + const ship_utxo: OutRef = { tx_hash: @@ -28,8 +31,6 @@ async function main() { tx_index: 0n, }; - - const quit_game_identifier: GameIdentifier = { ship_utxo, spacetime_script_reference, @@ -37,7 +38,7 @@ async function main() { }; const tx = await quit( - kupmios_config, + provider, address, quit_game_identifier, ); diff --git a/sdk/blaze/src/asteria.ts b/sdk/blaze/src/asteria.ts index e890ece..a00b06a 100644 --- a/sdk/blaze/src/asteria.ts +++ b/sdk/blaze/src/asteria.ts @@ -12,6 +12,7 @@ import { Constr, Core, Data, + Kupmios, makeValue, Static, } from "@blaze-cardano/sdk"; @@ -27,7 +28,6 @@ import { AsteriaDatum, AsteriaScriptDatum, GameIdentifier, - KupmiosConfig, PelletDatum, PelletScriptDatum, ShipDatum, @@ -36,13 +36,13 @@ import { import { max } from "rxjs"; async function createShip( - kupmios_config: KupmiosConfig, + provider: Kupmios, address: string, game_identifier: GameIdentifier, pos_x: bigint, pos_y: bigint, ): Promise { - const blaze = await blazeInit(address, kupmios_config); + const blaze = await blazeInit(address, provider); const spacetime_ref_input = outRefToTransactionInput( game_identifier.spacetime_script_reference!, @@ -179,13 +179,13 @@ async function createShip( } async function moveShip( - kupmios_config: KupmiosConfig, + provider: Kupmios, address: string, game_identifier: GameIdentifier, delta_x: bigint, delta_y: bigint, ): Promise { - const blaze = await blazeInit(address, kupmios_config); + const blaze = await blazeInit(address, provider); const ship_input = outRefToTransactionInput(game_identifier.ship_utxo!); const spacetime_ref_input = outRefToTransactionInput( @@ -317,11 +317,11 @@ async function moveShip( } async function gatherFuel( - kupmios_config: KupmiosConfig, + provider: Kupmios, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address, kupmios_config); + const blaze = await blazeInit(address, provider); const ship_input = outRefToTransactionInput( game_identifier.ship_utxo!, @@ -486,11 +486,11 @@ async function gatherFuel( } async function mineAsteria( - kupmios_config: KupmiosConfig, + provider: Kupmios, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address, kupmios_config); + const blaze = await blazeInit(address, provider); const asteria_ref_input = outRefToTransactionInput( game_identifier.asteria_script_reference!, @@ -608,11 +608,11 @@ async function mineAsteria( } async function quit( - kupmios_config: KupmiosConfig, + provider: Kupmios, address: string, game_identifier: GameIdentifier, ): Promise { - const blaze = await blazeInit(address, kupmios_config); + const blaze = await blazeInit(address, provider); const ship_input = outRefToTransactionInput( game_identifier.ship_utxo!, diff --git a/sdk/blaze/src/types.ts b/sdk/blaze/src/types.ts index 3dc6600..0ea0dfc 100644 --- a/sdk/blaze/src/types.ts +++ b/sdk/blaze/src/types.ts @@ -87,10 +87,6 @@ type GameIdentifier = { asteria_script_reference?: OutRef; }; -type KupmiosConfig = { - kupo_url: string; - ogmios_url: string; -} export { AsteriaDatum, AsteriaScriptDatum, @@ -100,6 +96,5 @@ export { ShipDatum, SpaceTimeScriptDatum, PelletScriptDatum, - KupmiosConfig, }; diff --git a/sdk/blaze/src/utils.ts b/sdk/blaze/src/utils.ts index 4816600..a5cd6e4 100644 --- a/sdk/blaze/src/utils.ts +++ b/sdk/blaze/src/utils.ts @@ -1,14 +1,9 @@ import { Address, AssetId, NetworkId, TransactionId, TransactionInput } from "@blaze-cardano/core"; -import { Unwrapped } from "@blaze-cardano/ogmios"; import { Blaze, ColdWallet, Core, Kupmios } from "@blaze-cardano/sdk"; -import { GameIdentifier, KupmiosConfig, OutRef } from "./types"; +import { OutRef } from "./types"; -async function blazeInit(address: string, kupmios_config: KupmiosConfig): Promise> { +async function blazeInit(address: string, provider: Kupmios): Promise> { const blaze_address = Core.Address.fromBech32(address); - const provider = new Kupmios( - kupmios_config.kupo_url, - await Unwrapped.Ogmios.new(kupmios_config.ogmios_url) - ) const wallet = new ColdWallet(blaze_address, NetworkId.Testnet, provider); return Blaze.from(provider, wallet);