-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented shipyard policy. * cleaned pellet code. * fixed shipyard policy. * renamed pellet tests. * shipyard policy tests. * burn tests.
- Loading branch information
1 parent
2b5fd63
commit 7f6a4c3
Showing
8 changed files
with
588 additions
and
64 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
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 |
---|---|---|
|
@@ -43,6 +43,6 @@ pub type AsteriaRedeemer { | |
} | ||
|
||
pub type ShipyardRedeemer { | ||
Mint | ||
Burn | ||
MintShip | ||
BurnShip | ||
} |
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,19 +1,19 @@ | ||
use aiken/bytearray.{length, take} | ||
use aiken/dict.{keys} | ||
use aiken/list.{any} | ||
use aiken/transaction.{Input} | ||
use aiken/transaction/value.{PolicyId, tokens} | ||
use aiken/math | ||
use aiken/transaction.{Output} | ||
use aiken/transaction/value.{AssetName, PolicyId, tokens} | ||
|
||
pub fn is_ship_token_input( | ||
inputs: List<Input>, | ||
shipyard_policy: PolicyId, | ||
) -> Bool { | ||
let ship_name = "SHIP" | ||
any( | ||
inputs, | ||
fn(input) { | ||
let token_names = keys(tokens(input.output.value, shipyard_policy)) | ||
any(token_names, fn(name) { take(name, length(ship_name)) == ship_name }) | ||
}, | ||
) | ||
pub fn is_ship_token_in_utxo(utxo: Output, shipyard_policy: PolicyId) -> Bool { | ||
let token_names = keys(tokens(utxo.value, shipyard_policy)) | ||
any(token_names, fn(name) { has_prefix("SHIP", name) }) | ||
} | ||
|
||
pub fn has_prefix(prefix: ByteArray, name: AssetName) -> Bool { | ||
take(name, length(prefix)) == prefix | ||
} | ||
|
||
pub fn distance(delta_x: Int, delta_y: Int) -> Int { | ||
math.abs(delta_x) + math.abs(delta_y) | ||
} |
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
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,12 +1,103 @@ | ||
use aiken/transaction.{ScriptContext} | ||
use aiken/bytearray | ||
use aiken/dict | ||
use aiken/list | ||
use aiken/string | ||
use aiken/transaction.{InlineDatum, Mint, ScriptContext, Transaction} | ||
use aiken/transaction/credential.{Address} | ||
use asteria/types.{ShipyardRedeemer} | ||
use aiken/transaction/value | ||
use asteria/types.{AsteriaDatum, | ||
BurnShip, MintShip, ShipDatum, ShipyardRedeemer} | ||
use asteria/utils | ||
|
||
validator( | ||
_asteria_validator_address: Address, | ||
_spacetime_validator_address: Address, | ||
asteria_validator_address: Address, | ||
spacetime_validator_address: Address, | ||
initial_fuel: Int, | ||
min_distance: Int, | ||
) { | ||
fn mint(_redeemer: ShipyardRedeemer, _ctx: ScriptContext) -> Bool { | ||
True | ||
pub fn mint(redeemer: ShipyardRedeemer, ctx: ScriptContext) -> Bool { | ||
let ScriptContext { transaction, purpose } = ctx | ||
let Transaction { inputs, outputs, mint, .. } = transaction | ||
expect Mint(policy_id) = purpose | ||
let minted_tokens = | ||
mint | ||
|> value.from_minted_value | ||
|> value.tokens(policy_id) | ||
|> dict.to_list() | ||
|
||
when redeemer is { | ||
MintShip -> { | ||
expect Some(asteria_input) = | ||
list.find( | ||
inputs, | ||
fn(input) { input.output.address == asteria_validator_address }, | ||
) | ||
expect InlineDatum(asteria_datum) = asteria_input.output.datum | ||
expect asteria_datum: AsteriaDatum = asteria_datum | ||
expect [(ship_token_name, 1)] = | ||
list.filter( | ||
minted_tokens, | ||
fn(token) { utils.has_prefix("SHIP", token.1st) }, | ||
) | ||
expect [(pilot_token_name, 1)] = | ||
list.filter( | ||
minted_tokens, | ||
fn(token) { utils.has_prefix("PILOT", token.1st) }, | ||
) | ||
|
||
expect [ship_state] = | ||
list.filter( | ||
outputs, | ||
fn(output) { output.address == spacetime_validator_address }, | ||
) | ||
expect InlineDatum(ship_datum) = ship_state.datum | ||
expect ship_datum: ShipDatum = ship_datum | ||
|
||
let must_respect_ship_name = | ||
ship_token_name == bytearray.concat( | ||
"SHIP", | ||
bytearray.from_string(string.from_int(asteria_datum.ship_counter)), | ||
) | ||
let must_respect_pilot_name = | ||
pilot_token_name == bytearray.concat( | ||
"PILOT", | ||
bytearray.from_string(string.from_int(asteria_datum.ship_counter)), | ||
) | ||
let must_mint_two_assets = list.length(minted_tokens) == 2 | ||
let must_have_initial_fuel = ship_datum.fuel == initial_fuel | ||
let must_respect_min_distance = | ||
utils.distance(ship_datum.pos_x, ship_datum.pos_y) >= min_distance | ||
let must_have_policy = ship_datum.shipyard_policy == policy_id | ||
let must_have_ship_name = ship_datum.ship_token_name == ship_token_name | ||
let must_have_pilot_name = | ||
ship_datum.pilot_token_name == pilot_token_name | ||
let must_hold_ship_token = | ||
value.quantity_of(ship_state.value, policy_id, ship_token_name) == 1 | ||
|
||
and { | ||
must_mint_two_assets, | ||
must_respect_ship_name, | ||
must_respect_pilot_name, | ||
must_have_initial_fuel, | ||
must_respect_min_distance, | ||
must_have_policy, | ||
must_have_ship_name, | ||
must_have_pilot_name, | ||
must_hold_ship_token, | ||
} | ||
} | ||
|
||
BurnShip -> { | ||
expect Some(ship_input) = | ||
list.find( | ||
inputs, | ||
fn(input) { input.output.address == spacetime_validator_address }, | ||
) | ||
expect InlineDatum(ship_datum) = ship_input.output.datum | ||
expect ship_datum: ShipDatum = ship_datum | ||
expect [(_, -1)] = minted_tokens | ||
ship_datum.pos_x == 0 && ship_datum.pos_y == 0 | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.