Skip to content

Commit

Permalink
fixup: TransferPolicy for Deed
Browse files Browse the repository at this point in the history
+ Reference `Display` for `Deed` in README.
  • Loading branch information
amnn committed Aug 29, 2023
1 parent e6b47aa commit 36595e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/turnip-town/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ To keep the initial version of the demonstration focussed, the
following possible extensions have not been implemented, but are left
as an exercise for the reader!

- Defining **Display for Turnips** to illustrate the size and
freshness of Turnips when viewed from the Explorer.
- Defining **Display** for `Turnip` and `Deed` to visualize them in
Explorers.
- Using **on-chain randomness** to control how much rain and sun a
field gets, rather than deciding that off-chain in the game
service.
Expand Down
16 changes: 16 additions & 0 deletions examples/turnip-town/move/sources/field.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ module turnip_town::field {
use std::vector;
use sui::math;
use sui::object::{Self, UID};
use sui::package;
use sui::transfer;
use sui::transfer_policy;
use sui::tx_context::{Self, TxContext};

use turnip_town::turnip::{Self, Turnip};

friend turnip_town::game;

struct FIELD has drop {}

struct Field has store {
slots: vector<Option<Turnip>>,
water: u64,
Expand Down Expand Up @@ -56,6 +61,17 @@ module turnip_town::field {
const WIDTH: u64 = 4;
const HEIGHT: u64 = 4;

fun init(otw: FIELD, ctx: &mut TxContext) {
let publisher = package::claim(otw, ctx);

// Make `Deed`'s transferable between Kiosks, but without any
// additional rules.
let (policy, cap) = transfer_policy::new<Deed>(&publisher, ctx);
transfer::public_share_object(policy);
transfer::public_transfer(cap, tx_context::sender(ctx));
package::burn_publisher(publisher);
}

public fun deed_field(deed: &Deed): address {
deed.field
}
Expand Down

0 comments on commit 36595e0

Please sign in to comment.