-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial prototype for asteria blaze sdk * feat: asteria blaze sdk * docs: update ship movement and fuel gathering examples --------- Co-authored-by: Rico Miles <ricoquiblat@gmail.com>
- Loading branch information
Showing
17 changed files
with
5,962 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ target | |
**/.env | ||
|
||
.mono | ||
**/.DS_Store | ||
**/.DS_Store | ||
|
||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { max } from "rxjs"; | ||
import { GameIdentifier, OutRef } from "../src/types"; | ||
import { gatherFuel } from "../src"; | ||
|
||
async function main() { | ||
const address = | ||
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; | ||
|
||
const ship_utxo: OutRef = { | ||
tx_hash: | ||
"3e04a7a3e4a1015705c44822feaf5f2da1e9609eebd68310c87b7eba7923739a", | ||
tx_index: 0n, | ||
}; | ||
const pellet_utxo: OutRef = { | ||
tx_hash: | ||
"22af0198b4e6e9c8306392c7ac0ea97b8a2f659a6312708b22b7717805554b97", | ||
tx_index: 0n, | ||
}; | ||
|
||
const spacetime_script_reference: OutRef = { | ||
tx_hash: | ||
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", | ||
tx_index: 0n, | ||
}; | ||
|
||
const pellet_script_reference: OutRef = { | ||
tx_hash: | ||
"ba6fab625d70a81f5d1b699e7efde4b74922d06224bef1f6b84f3adf0a61f3f3", | ||
tx_index: 0n, | ||
}; | ||
|
||
|
||
const gather_fuel_identifier: GameIdentifier = { | ||
ship_utxo, | ||
pellet_utxo, | ||
spacetime_script_reference, | ||
pellet_script_reference, | ||
}; | ||
|
||
const tx = await gatherFuel( | ||
address, | ||
gather_fuel_identifier, | ||
); | ||
|
||
return tx; | ||
} | ||
|
||
main().then((tx) => { | ||
console.log(tx.toCbor()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { mineAsteria } from "../src"; | ||
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", | ||
tx_index: 0n, | ||
}; | ||
|
||
const pellet_script_reference: OutRef = { | ||
tx_hash: | ||
"ba6fab625d70a81f5d1b699e7efde4b74922d06224bef1f6b84f3adf0a61f3f3", | ||
tx_index: 0n, | ||
}; | ||
|
||
const asteria_script_reference: OutRef = { | ||
tx_hash: | ||
"39871aab15b7c5ab1075ba431d7475f3977fe40fbb8d654b6bdf6f6726659277", | ||
tx_index: 0n, | ||
}; | ||
const asteria_utxo: OutRef = { | ||
tx_hash: | ||
"bbcdff5ed1c0dd78c58c42dab8356c161f865d0c3efc1ea281026140a0d38516", | ||
tx_index: 1n, | ||
}; | ||
|
||
const ship_utxo: OutRef = { | ||
tx_hash: | ||
"594fb0c4baff88873d15d5973103efc667052deec3315ba4bc89aeaaf53dd407", | ||
tx_index: 0n, | ||
}; | ||
|
||
|
||
const gameIdentifier: GameIdentifier = { | ||
asteria_utxo, | ||
ship_utxo, | ||
spacetime_script_reference, | ||
pellet_script_reference, | ||
asteria_script_reference, | ||
}; | ||
|
||
const tx = await mineAsteria( | ||
address, | ||
gameIdentifier, | ||
); | ||
|
||
return tx; | ||
} | ||
|
||
main().then((tx) => { | ||
console.log(tx.toCbor()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,47 @@ | ||
|
||
# Moving a Ship | ||
|
||
Updates the `pos_x`, `pos_y` and `fuel` datum fields of the `ShipState` UTxO by adding the `delta_x` and `delta_y` values specified in the redeemer, and subtracting the fuel amount needed for the displacement. | ||
|
||
 | ||
|
||
```ts | ||
import { | ||
Data, | ||
toUnit, | ||
TxHash, | ||
Constr, | ||
UTxO, | ||
} from "https://deno.land/x/lucid@0.10.7/mod.ts"; | ||
import { distance, lucidBase, required_fuel } from "../utils.ts"; | ||
import { ShipDatum, ShipDatumT } from "../types.ts"; | ||
|
||
// look up these values for the specific challenge you're particpating | ||
const FUEL_PER_STEP = 5; | ||
|
||
async function moveShip( | ||
fuel_per_step: bigint, | ||
delta_x: bigint, | ||
delta_y: bigint, | ||
ship_token_name: string, | ||
pilot_token_name: string, | ||
shipTxHash: TxHash | ||
): Promise<TxHash> { | ||
const lucid = await lucidBase(); | ||
|
||
const spacetimeRefTxHash: { txHash: string } = JSON.parse( | ||
await Deno.readTextFile("./spacetime-ref.json") | ||
); | ||
const spacetimeRef = await lucid.utxosByOutRef([ | ||
{ | ||
txHash: spacetimeRefTxHash.txHash, | ||
outputIndex: 0, | ||
}, | ||
]); | ||
const spacetimeValidator = spacetimeRef[0].scriptRef; | ||
if (!spacetimeValidator) { | ||
throw Error("Could not read spacetime validator from ref UTxO"); | ||
} | ||
const spacetimeAddressBech32 = | ||
lucid.utils.validatorToAddress(spacetimeValidator); | ||
|
||
const shipyardPolicyId = lucid.utils.mintingPolicyToId(spacetimeValidator); | ||
const shipTokenUnit = toUnit(shipyardPolicyId, ship_token_name); | ||
const pilotTokenUnit = toUnit(shipyardPolicyId, pilot_token_name); | ||
|
||
const ship: UTxO = ( | ||
await lucid.utxosByOutRef([ | ||
{ | ||
txHash: shipTxHash, | ||
outputIndex: 0, | ||
}, | ||
]) | ||
)[0]; | ||
if (!ship.datum) { | ||
throw Error("Ship datum not found"); | ||
} | ||
const shipAda = ship.assets.lovelace; | ||
|
||
const shipInputDatum = Data.from<ShipDatumT>( | ||
ship.datum as string, | ||
ShipDatum as unknown as ShipDatumT | ||
); | ||
|
||
const moved_distance = distance(delta_x, delta_y); | ||
const spent_fuel = required_fuel(moved_distance, fuel_per_step); | ||
const shipInfo = { | ||
fuel: shipInputDatum.fuel - spent_fuel, | ||
pos_x: shipInputDatum.pos_x + delta_x, | ||
pos_y: shipInputDatum.pos_y + delta_y, | ||
ship_token_name: shipInputDatum.ship_token_name, | ||
pilot_token_name: shipInputDatum.pilot_token_name, | ||
}; | ||
const shipOutputDatum = Data.to<ShipDatumT>( | ||
shipInfo, | ||
ShipDatum as unknown as ShipDatumT | ||
); | ||
|
||
const moveShipRedeemer = Data.to( | ||
new Constr(1, [new Constr(0, [delta_x, delta_y])]) | ||
); | ||
|
||
const tx = await lucid | ||
.newTx() | ||
.collectFrom([ship], moveShipRedeemer) | ||
.readFrom(spacetimeRef) | ||
.payToContract( | ||
spacetimeAddressBech32, | ||
{ inline: shipOutputDatum }, | ||
{ | ||
[shipTokenUnit]: BigInt(1), | ||
lovelace: shipAda, | ||
} | ||
) | ||
.payToAddress(await lucid.wallet.address(), { | ||
[pilotTokenUnit]: BigInt(1), | ||
}) | ||
.complete(); | ||
import { createShip, moveShip } from "../src"; | ||
import { OutRef, GameIdentifier } from "../src/types"; | ||
|
||
async function main() { | ||
const address = | ||
"addr_test1qzjpgxkhe06gxzstfhywg02ggy5ltuwne6mfr406dlf0mpwp9a07r34cwsnkpn44tllxuydw4wp0xvstw5jqv5q9lszsk2qynn"; | ||
|
||
const ship_utxo: OutRef = { | ||
tx_hash: | ||
"41f2a593e131a3c5db878bbe7753b89c8c6de555b7127e812c0f488d1a898368", | ||
tx_index: 0n, | ||
}; | ||
|
||
const spacetime_script_reference: OutRef = { | ||
tx_hash: | ||
"41e5881cd3bdc3f08bcf341796347e9027e3bcd8d58608b4fcfca5c16cbf5921", | ||
tx_index: 0n, | ||
}; | ||
|
||
const pellet_script_reference: OutRef = { | ||
tx_hash: | ||
"ba6fab625d70a81f5d1b699e7efde4b74922d06224bef1f6b84f3adf0a61f3f3", | ||
tx_index: 0n, | ||
}; | ||
|
||
const delta_x = -1n; | ||
const delta_y = -1n | ||
|
||
const move_ship_identifier: GameIdentifier = { | ||
ship_utxo, | ||
spacetime_script_reference, | ||
pellet_script_reference, | ||
}; | ||
|
||
const tx = await moveShip( | ||
address, | ||
move_ship_identifier, | ||
delta_x, | ||
delta_y, | ||
); | ||
|
||
return tx; | ||
} | ||
``` | ||
|
||
main().then((tx) => { | ||
console.log(tx.toCbor()); | ||
}); |
Oops, something went wrong.