Skip to content

Commit

Permalink
Store metadata in JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Nov 17, 2023
1 parent 161c434 commit 9ffa416
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 49 deletions.
8 changes: 2 additions & 6 deletions contracts/contracts/d_social_network_account.tact
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract DSocialNetworkAccount with NftCollection, NftCollectionRoyaltyExtention
master_contract: Address;
royalty_params: RoyaltyParams;
is_initialized: Bool = false;
collection_content: NftCollectionMetadata;
collection_content: String;

init(account_id: Int, master_contract: Address){
self.account_id = account_id;
Expand All @@ -23,11 +23,7 @@ contract DSocialNetworkAccount with NftCollection, NftCollectionRoyaltyExtention
destination: master_contract
};
// TODO: set real metadata
self.collection_content = NftCollectionMetadata{
image: "",
name: "",
description: ""
};
self.collection_content = "{}";
}

get fun get_account_info(): AccountInfo {
Expand Down
13 changes: 2 additions & 11 deletions contracts/contracts/d_social_network_master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "./messages_d.tact";
import "./d_social_network_account.tact";

contract DSocialNetworkMaster with Deployable, OwnableTransferable, Accounting {
version: String = "v0.0.1-no-metadata-arrays";
version: String = "v0.0.1-metadata-as-json-string";
owner: Address;
next_account_index: Int as uint32 = 0;

Expand Down Expand Up @@ -39,7 +39,7 @@ contract DSocialNetworkMaster with Deployable, OwnableTransferable, Accounting
body: InitializeAccount {
query_id: 0,
owner: ctx.sender,
collection_content: self.generateAccountCollectionContent(msg)
collection_content: msg.account_metadata_json
}.toCell(),
code: account_init.code,
data: account_init.data
Expand All @@ -50,13 +50,4 @@ contract DSocialNetworkMaster with Deployable, OwnableTransferable, Accounting
fun getAccountInit(account_id: Int): StateInit {
return initOf DSocialNetworkAccount(account_id, myAddress());
}

fun generateAccountCollectionContent(msg: RegisterAccount): NftCollectionMetadata {
// TODO: add image link
return NftCollectionMetadata{
image: "some-image-link",
name: msg.account_name,
description: msg.account_description
};
}
}
9 changes: 2 additions & 7 deletions contracts/contracts/d_social_network_post.tact
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ contract DSocialNetworkPost with NftItem {
item_index: Int;
owner: Address;
is_initialized: Bool;
individual_content: NftMetadata;
individual_content: String;

init(collection_address: Address, item_index: Int, owner: Address){
self.collection_address = collection_address;
self.item_index = item_index;
self.owner = collection_address;
// TODO: set individual_content
self.individual_content = NftMetadata{
image: "",
name: "",
description: "",
content_url: ""
};
self.individual_content = "{}";
self.is_initialized = false;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/lib/messages_nft.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct NftCollectionMetadata {

message MintNft {
query_id: Int as uint64;
individual_content: NftMetadata;
individual_content: String;
}

// NFT collection: Royalty exntention
Expand Down Expand Up @@ -54,7 +54,7 @@ message InitializeNft {
query_id: Int as uint64;
owner: Address;
response_destination: Address;
individual_content: NftMetadata;
individual_content: String;
}

message(0x5fcc3d14) Transfer {
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/lib/trait_nft_collection.tact
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "./trait_accounting.tact";
trait NftCollection with Deployable, Ownable, Accounting {
next_item_index: Int;
owner: Address;
collection_content: NftCollectionMetadata;
collection_content: String;

// ===== Customizable functions ===== //

Expand All @@ -17,7 +17,7 @@ trait NftCollection with Deployable, Ownable, Accounting {
// b.append("meta.json");
// return b.toCell();
// TODO: if following works, remove the above
return self.collection_content.toCell();
return self.collection_content.asSlice().asCell();
}

virtual fun getNftItemInit(item_index: Int): StateInit {
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/lib/trait_nft_item.tact
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait NftItem with Deployable, Ownable, Accounting {
item_index: Int;
owner: Address;
is_initialized: Bool;
individual_content: NftMetadata;
individual_content: String;

// ===== Customizable functions ===== //

Expand All @@ -20,7 +20,7 @@ trait NftItem with Deployable, Ownable, Accounting {
// b.append(".json");
// return b.toCell();
// TODO: if following works, remove the above
return self.individual_content.toCell();
return self.individual_content.asSlice().asCell();
}

// --------- Get Function --------- //
Expand Down
9 changes: 4 additions & 5 deletions contracts/contracts/messages_d.tact
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import "./lib/messages_nft.tact";

message RegisterAccount {
query_id: Int as uint64;
account_name: String;
account_description: String;
account_metadata_json: String;
}

// Account contract

message InitializeAccount {
query_id: Int as uint64;
owner: Address;
collection_content: NftCollectionMetadata;
collection_content: String;
}

struct AccountInfo {
id: Int;
master_contract: Address;
owner: Address;
collection_content: NftCollectionMetadata;
collection_content: String;
is_initialized: Bool;
}

Expand All @@ -30,5 +29,5 @@ struct PostInfo {
account: Address;
id: Int;
owner: Address;
nft_content: NftMetadata;
nft_content: String;
}
15 changes: 9 additions & 6 deletions contracts/scripts/deployTestSocialNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export async function run(provider: NetworkProvider) {
{
$$type: 'RegisterAccount',
query_id: 0n,
account_name: 'test',
account_description: 'Test account description'
account_metadata_json: JSON.stringify({
image: 'https://d0rich.me/og/image.jpg',
name: 'test',
description: 'Test account description',
social_links: ['https://d0rich.t.me']
})
}
)

Expand All @@ -45,13 +49,12 @@ export async function run(provider: NetworkProvider) {
{
$$type: 'MintNft',
query_id: 0n,
individual_content: {
$$type: 'NftMetadata',
individual_content: JSON.stringify({
name: 'Test post',
description: 'Test post description',
image: 'https://test.com/image.png',
image: 'https://d0rich.me/og/image.jpg',
content_url: 'https://test.com/content.txt'
}
})
}
)

Expand Down
15 changes: 9 additions & 6 deletions contracts/tests/DSocialNetworkAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ describe('DSocialNetworkMaster', () => {
{
$$type: 'RegisterAccount',
query_id: 0n,
account_name: 'test',
account_description: 'Test account description'
account_metadata_json: JSON.stringify({
image: 'https://d0rich.me/og/image.jpg',
name: 'test',
description: 'Test account description',
social_links: ['https://d0rich.t.me']
})
}
)

Expand Down Expand Up @@ -72,13 +76,12 @@ describe('DSocialNetworkMaster', () => {
{
$$type: 'MintNft',
query_id: 0n,
individual_content: {
$$type: 'NftMetadata',
individual_content: JSON.stringify({
name: 'Test post',
description: 'Test post description',
image: 'https://test.com/image.png',
image: 'https://d0rich.me/og/image.jpg',
content_url: 'https://test.com/content.txt'
}
})
}
)

Expand Down
8 changes: 6 additions & 2 deletions contracts/tests/DSocialNetworkMaster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ describe('DSocialNetworkMaster', () => {
{
$$type: 'RegisterAccount',
query_id: 0n,
account_name: 'test',
account_description: 'Test account description'
account_metadata_json: JSON.stringify({
image: 'https://d0rich.me/og/image.jpg',
name: 'test',
description: 'Test account description',
social_links: ['https://d0rich.t.me']
})
}
)

Expand Down

0 comments on commit 9ffa416

Please sign in to comment.