Skip to content

Commit

Permalink
fix: make kupmios provider configurable (#107)
Browse files Browse the repository at this point in the history
* fix: make kupmios provider configurable

* fix: remove hardcoded config on gather fuel example

* refactor: adjust function requirements from config to the entire provider
  • Loading branch information
ricomiles authored Dec 3, 2024
1 parent 0a4dd2f commit eae88eb
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 24 deletions.
8 changes: 8 additions & 0 deletions docs/pages/guides/creating_ship.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);

const spacetime_script_reference: OutRef = {
tx_hash:
Expand Down Expand Up @@ -43,6 +50,7 @@ async function main() {
};

const tx = await createShip(
provider,
address,
gameIdentifier,
pos_x,
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/guides/gathering_fuel.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);

const ship_utxo: OutRef = {
tx_hash:
"3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a",
Expand Down Expand Up @@ -38,6 +44,7 @@ async function main() {
};

const tx = await gatherFuel(
provider,
address,
gather_fuel_identifier,
);
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/guides/mining_asteria.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Unwrapped } from "@blaze-cardano/ogmios";
import { Kupmios } from "@blaze-cardano/sdk";
import { mineAsteria } from "../src";
import { GameIdentifier, OutRef } from "../src/types";

async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";

const provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);

const spacetime_script_reference: OutRef = {
tx_hash:
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921",
Expand Down Expand Up @@ -38,6 +45,7 @@ async function main() {
};

const tx = await mineAsteria(
provider,
address,
gameIdentifier,
);
Expand Down
10 changes: 9 additions & 1 deletion docs/pages/guides/moving_ship.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);

const ship_utxo: OutRef = {
tx_hash:
Expand Down Expand Up @@ -33,6 +40,7 @@ async function main() {
};

const tx = await moveShip(
provider,
address,
move_ship_identifier,
delta_x,
Expand Down
8 changes: 8 additions & 0 deletions sdk/blaze/examples/create-ship.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);

const spacetime_script_reference: OutRef = {
tx_hash:
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921",
Expand Down Expand Up @@ -33,6 +40,7 @@ async function main() {
};

const tx = await createShip(
provider,
address,
gameIdentifier,
pos_x,
Expand Down
12 changes: 10 additions & 2 deletions sdk/blaze/examples/gather-fuel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);


const ship_utxo: OutRef = {
tx_hash:
"3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a",
Expand Down Expand Up @@ -38,6 +45,7 @@ async function main() {
};

const tx = await gatherFuel(
provider,
address,
gather_fuel_identifier,
);
Expand Down
11 changes: 10 additions & 1 deletion sdk/blaze/examples/mine-asteria.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Unwrapped } from "@blaze-cardano/ogmios";
import { Kupmios } from "@blaze-cardano/sdk";
import { mineAsteria } from "../src";
import { GameIdentifier, OutRef } from "../src/types";

async function main() {
const address =
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn";


const provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);


const spacetime_script_reference: OutRef = {
tx_hash:
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921",
Expand Down Expand Up @@ -38,6 +46,7 @@ async function main() {
};

const tx = await mineAsteria(
provider,
address,
gameIdentifier,
);
Expand Down
11 changes: 10 additions & 1 deletion sdk/blaze/examples/move-ship.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);


const ship_utxo: OutRef = {
tx_hash:
"41f2a593e131a3c5db878bbe7753b89c8c6de555b7127e812c0f488d1a898368",
Expand Down Expand Up @@ -33,6 +41,7 @@ async function main() {
};

const tx = await moveShip(
provider,
address,
move_ship_identifier,
delta_x,
Expand Down
13 changes: 10 additions & 3 deletions sdk/blaze/examples/quit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { createShip, moveShip, quit } from "../src";
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 provider = new Kupmios(
process.env.KUPO_URL!,
await Unwrapped.Ogmios.new(process.env.OGMIOS_URL!)
);


const ship_utxo: OutRef = {
tx_hash:
"870b37da4cc82a16eb47db293713d81fe9abfe183055341174405e94768264c5",
Expand All @@ -23,15 +31,14 @@ async function main() {
tx_index: 0n,
};



const quit_game_identifier: GameIdentifier = {
ship_utxo,
spacetime_script_reference,
pellet_script_reference,
};

const tx = await quit(
provider,
address,
quit_game_identifier,
);
Expand Down
16 changes: 11 additions & 5 deletions sdk/blaze/src/asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Constr,
Core,
Data,
Kupmios,
makeValue,
Static,
} from "@blaze-cardano/sdk";
Expand All @@ -35,12 +36,13 @@ import {
import { max } from "rxjs";

async function createShip(
provider: Kupmios,
address: string,
game_identifier: GameIdentifier,
pos_x: bigint,
pos_y: bigint,
): Promise<Transaction> {
const blaze = await blazeInit(address);
const blaze = await blazeInit(address, provider);

const spacetime_ref_input = outRefToTransactionInput(
game_identifier.spacetime_script_reference!,
Expand Down Expand Up @@ -177,12 +179,13 @@ async function createShip(
}

async function moveShip(
provider: Kupmios,
address: string,
game_identifier: GameIdentifier,
delta_x: bigint,
delta_y: bigint,
): Promise<Transaction> {
const blaze = await blazeInit(address);
const blaze = await blazeInit(address, provider);

const ship_input = outRefToTransactionInput(game_identifier.ship_utxo!);
const spacetime_ref_input = outRefToTransactionInput(
Expand Down Expand Up @@ -314,10 +317,11 @@ async function moveShip(
}

async function gatherFuel(
provider: Kupmios,
address: string,
game_identifier: GameIdentifier,
): Promise<Transaction> {
const blaze = await blazeInit(address);
const blaze = await blazeInit(address, provider);

const ship_input = outRefToTransactionInput(
game_identifier.ship_utxo!,
Expand Down Expand Up @@ -482,10 +486,11 @@ async function gatherFuel(
}

async function mineAsteria(
provider: Kupmios,
address: string,
game_identifier: GameIdentifier,
): Promise<Transaction> {
const blaze = await blazeInit(address);
const blaze = await blazeInit(address, provider);

const asteria_ref_input = outRefToTransactionInput(
game_identifier.asteria_script_reference!,
Expand Down Expand Up @@ -603,10 +608,11 @@ async function mineAsteria(
}

async function quit(
provider: Kupmios,
address: string,
game_identifier: GameIdentifier,
): Promise<Transaction> {
const blaze = await blazeInit(address);
const blaze = await blazeInit(address, provider);

const ship_input = outRefToTransactionInput(
game_identifier.ship_utxo!,
Expand Down
3 changes: 2 additions & 1 deletion sdk/blaze/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ export {
PelletDatum,
ShipDatum,
SpaceTimeScriptDatum,
PelletScriptDatum
PelletScriptDatum,
};

11 changes: 2 additions & 9 deletions sdk/blaze/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +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, OutRef } from "./types";
import { OutRef } from "./types";

async function blazeInit(address: string): Promise<Blaze<Kupmios, ColdWallet>> {
async function blazeInit(address: string, provider: Kupmios): Promise<Blaze<Kupmios, ColdWallet>> {
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",
),
);
const wallet = new ColdWallet(blaze_address, NetworkId.Testnet, provider);

return Blaze.from(provider, wallet);
Expand Down

0 comments on commit eae88eb

Please sign in to comment.