Skip to content

Commit

Permalink
Chat smart contract - replace ID to address types
Browse files Browse the repository at this point in the history
  • Loading branch information
kchalkias committed May 18, 2022
1 parent a6ae2cc commit 9bbfadf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 9 additions & 8 deletions sui_programmability/examples/nfts/sources/Chat.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module NFTs::Chat {
use Sui::ID::{Self, ID, VersionedID};
use Std::ASCII::{Self, String};
use Std::Option::Option;
use Sui::Transfer;
use Sui::TxContext::{Self, TxContext};

Expand All @@ -23,7 +22,8 @@ module NFTs::Chat {
text: String,
// Set if referencing an another object (i.e., due to a Like, Retweet, Reply etc).
// We allow referencing any object type, not ony Chat NFTs.
ref_id: Option<ID>,
// By convention applications can use the all zeros address, when no reference is required.
ref_id: ID,
// app-specific metadata.
metadata: vector<u8>,
}
Expand All @@ -34,23 +34,24 @@ module NFTs::Chat {
}

/// Mint (post) a Chat object.
/// TODO: Using `address` as `app_identifier` & `ref_identifier` type, because we cannot pass `ID` to entry
/// functions.
public(script) fun mint(
app_id: ID,
app_identifier: address,
text: String,
ref_id: Option<ID>,
ref_identifier: address,
metadata: vector<u8>,
ctx: &mut TxContext,
) {
assert!(ASCII::length(&text) <= MAX_TEXT_LENGTH, ETextOverflow);
let sender = TxContext::sender(ctx);
let chat = Chat {
id: TxContext::new_id(ctx),
app_id,
app_id: ID::new(app_identifier),
text,
ref_id,
ref_id: ID::new(ref_identifier),
metadata,
};
Transfer::transfer(chat, sender);
Transfer::transfer(chat, TxContext::sender(ctx));
}

/// Burn a Chat object.
Expand Down
6 changes: 2 additions & 4 deletions sui_programmability/examples/nfts/tests/ChatTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module NFTs::ChatTests {
use NFTs::Chat::{Self, Chat};
use Std::ASCII::Self;
use Sui::ID::Self;
use Std::Option::Self;
use Sui::TestScenario::Self;

const USER1_ADDRESS: address = @0xA001;
Expand All @@ -18,9 +16,9 @@ module NFTs::ChatTests {
let scenario = &mut TestScenario::begin(&USER1_ADDRESS);
{
Chat::mint(
ID::new(@0xC001), // This should be an application object ID.
@0xC001, // This should be an application object ID.
ASCII::string(HELLO),
Option::none(), // We're not referencing another Object (it's not a retweet or reply).
@0x0000, // We're referencing the all-zero bytes object (i.e., it's not a retweet or reply).
METADATA, // Some metadata (it could be empty).
TestScenario::ctx(scenario)
);
Expand Down

0 comments on commit 9bbfadf

Please sign in to comment.