Skip to content

Commit

Permalink
v0.0.1-metadata-as-struct-no-convertation-to-cell
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Nov 17, 2023
1 parent 6c2fce8 commit 01f238c
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 47 deletions.
9 changes: 7 additions & 2 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: String;
collection_content: NftCollectionMetadata;

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

get fun get_account_info(): AccountInfo {
Expand Down
13 changes: 9 additions & 4 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-metadata-no-convertation-to-cell";
version: String = "v0.0.1-metadata-as-struct-no-convertation-to-cell";
owner: Address;
next_account_index: Int as uint32 = 0;

Expand All @@ -14,11 +14,11 @@ contract DSocialNetworkMaster with Deployable, OwnableTransferable, Accounting
self.owner = ctx.sender;
}

get fun get_version(): String {
get fun get_version(): String {
return self.version;
}

get fun get_accounts_count(): Int {
get fun get_accounts_count(): Int {
return self.next_account_index;
}

Expand All @@ -39,7 +39,12 @@ contract DSocialNetworkMaster with Deployable, OwnableTransferable, Accounting
body: InitializeAccount {
query_id: 0,
owner: ctx.sender,
collection_content: msg.account_metadata_json
collection_content: NftCollectionMetadata {
image: "https://d0rich.me/og/image.jpg",
name: msg.account_name,
description: msg.account_description,
social_links: emptyMap()
}
}.toCell(),
code: account_init.code,
data: account_init.data
Expand Down
10 changes: 8 additions & 2 deletions contracts/contracts/d_social_network_post.tact
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ contract DSocialNetworkPost with NftItem {
item_index: Int;
owner: Address;
is_initialized: Bool;
individual_content: String;
individual_content: NftMetadata;

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 = "{}";
self.individual_content = NftMetadata {
name: "",
description: "",
image: "",
content_url: "",
attributes: emptyMap()
};
self.is_initialized = false;
}

Expand Down
10 changes: 6 additions & 4 deletions contracts/contracts/lib/messages_nft.tact
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

struct CollectionData {
next_item_index: Int;
collection_content: String;
collection_content: NftCollectionMetadata;
owner_address: Address;
}

struct NftCollectionMetadata {
image: String;
name: String;
description: String;
social_links: map<Int, Cell>;
}

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

// NFT collection: Royalty exntention
Expand Down Expand Up @@ -48,13 +49,14 @@ struct NftMetadata {
description: String;
image: String;
content_url: String;
attributes: map<Int, NftMetadataAttribute>;
}

message InitializeNft {
query_id: Int as uint64;
owner: Address;
response_destination: Address;
individual_content: String;
individual_content: NftMetadata;
}

message(0x5fcc3d14) Transfer {
Expand Down Expand Up @@ -91,5 +93,5 @@ struct GetNftData {
index: Int;
collection_address: Address;
owner_address: Address;
individual_content: String;
individual_content: NftMetadata;
}
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,11 +6,11 @@ import "./trait_accounting.tact";
trait NftCollection with Deployable, Ownable, Accounting {
next_item_index: Int;
owner: Address;
collection_content: String;
collection_content: NftCollectionMetadata;

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

virtual fun getNftCollectionContent(): String {
virtual fun getNftCollectionContent(): NftCollectionMetadata {
// let b: StringBuilder = beginString();
// let collectionDataString: String = self.collection_content.asSlice().asString();
// b.append(collectionDataString);
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,11 +8,11 @@ trait NftItem with Deployable, Ownable, Accounting {
item_index: Int;
owner: Address;
is_initialized: Bool;
individual_content: String;
individual_content: NftMetadata;

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

virtual fun getNftItemIndividualContent(): String {
virtual fun getNftItemIndividualContent(): NftMetadata {
// let b: StringBuilder = beginString();
// let collectionData: String = self.individual_content.asSlice().asString();
// b.append(collectionData);
Expand Down
9 changes: 5 additions & 4 deletions contracts/contracts/messages_d.tact
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import "./lib/messages_nft.tact";

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

// Account contract

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

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

Expand All @@ -29,5 +30,5 @@ struct PostInfo {
account: Address;
id: Int;
owner: Address;
nft_content: String;
nft_content: NftMetadata;
}
2 changes: 1 addition & 1 deletion contracts/scripts/deployTestSocialNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DSocialNetworkPost } from '../wrappers/DSocialNetworkPost'
import {
createTestPostMessage,
registerTestAccountMessage
} from '../utils/test'
} from '../utils/test-fixtures'

export async function run(provider: NetworkProvider) {
const dMaster = provider.open(await DSocialNetworkMaster.fromInit())
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/DSocialNetworkAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DSocialNetworkPost } from '../wrappers/DSocialNetworkPost'
import {
createTestPostMessage,
registerTestAccountMessage
} from '../utils/test'
} from '../utils/test-fixtures'

describe('DSocialNetworkMaster', () => {
let blockchain: Blockchain
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/DSocialNetworkMaster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toNano } from 'ton-core'
import { DSocialNetworkMaster } from '../wrappers/DSocialNetworkMaster'
import { DSocialNetworkAccount } from '../wrappers/DSocialNetworkAccount'
import '@ton-community/test-utils'
import { registerTestAccountMessage } from '../utils/test'
import { registerTestAccountMessage } from '../utils/test-fixtures'

describe('DSocialNetworkMaster', () => {
let blockchain: Blockchain
Expand Down
45 changes: 45 additions & 0 deletions contracts/utils/test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Dictionary } from 'ton-core'
import { RegisterAccount } from '../wrappers/DSocialNetworkMaster'
import {
MintNft,
NftMetadataAttribute
} from '../wrappers/DSocialNetworkAccount'

export const registerTestAccountMessage: RegisterAccount = {
$$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']
// })
}

const testNftAttributes = Dictionary.empty<bigint, NftMetadataAttribute>()
testNftAttributes.set(0n, {
$$type: 'NftMetadataAttribute',
trait_type: 'content',
value: 'My first post'
})

export const createTestPostMessage: MintNft = {
$$type: 'MintNft',
query_id: 0n,
individual_content: {
$$type: 'NftMetadata',
name: 'Test post',
description: 'Test post description',
image: 'https://d0rich.me/og/image.jpg',
content_url: 'https://test.com/content.txt',
attributes: testNftAttributes
}
// individual_content: JSON.stringify({
// name: 'Test post',
// description: 'Test post description',
// image: 'https://d0rich.me/og/image.jpg',
// content_url: 'https://test.com/content.txt'
// })
}
24 changes: 0 additions & 24 deletions contracts/utils/test.ts

This file was deleted.

0 comments on commit 01f238c

Please sign in to comment.