Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing props to TokenMetadata #23

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions as/NFT/assembly/__tests__/index.nft.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ describe('- MEDIA -', () => {
'title_example',
'0000000000000',
1,
'media_example'
'media_example',
'extra_example',
'description_example',
'media_hash_example',
'',
'',
'',
'reference_example',
'reference_hash_example',
'media_animation_example',
)

VMContext.setAttached_deposit(DESIGN_PRICE)
Expand All @@ -57,9 +66,18 @@ describe('- MEDIA -', () => {
const newDesignMetadata = nft_token_metadata(newDesign.id)
expect(newDesignMetadata).not.toBeNull()

expect(newDesignMetadata.title).toStrictEqual('condo')
expect(newDesignMetadata.title).toStrictEqual('title_example')
expect(newDesignMetadata.issued_at).toStrictEqual('10')
expect(newDesignMetadata.copies).toStrictEqual(1)
expect(newDesignMetadata.media).toStrictEqual('media_example')
expect(newDesignMetadata.extra).toStrictEqual('extra_example')
expect(newDesignMetadata.description).toStrictEqual('description_example')
expect(newDesignMetadata.media_hash).toStrictEqual('media_hash_example')
expect(newDesignMetadata.expires_at).toStrictEqual('')
expect(newDesignMetadata.updated_at).toStrictEqual('10')
expect(newDesignMetadata.starts_at).toStrictEqual('10')
expect(newDesignMetadata.reference).toStrictEqual('reference_example')
expect(newDesignMetadata.reference_hash).toStrictEqual('reference_hash_example')
expect(newDesignMetadata.media_animation).toStrictEqual('media_animation_example')
})
})
13 changes: 11 additions & 2 deletions as/NFT/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,17 @@ export function claim_media(tokenMetadata: TokenMetadata): Media {
assert_deposit_attached(DESIGN_PRICE)

/** Assert uniqueId is actually unique */

let design = new Media(tokenMetadata.media, tokenMetadata.extra)
let design = new Media(
tokenMetadata.title,
tokenMetadata.copies,
tokenMetadata.media,
sekaiking marked this conversation as resolved.
Show resolved Hide resolved
tokenMetadata.extra,
tokenMetadata.description,
tokenMetadata.media_hash,
tokenMetadata.reference,
tokenMetadata.reference_hash,
tokenMetadata.media_animation,
)
sekaiking marked this conversation as resolved.
Show resolved Hide resolved

owners.add(context.sender)

Expand Down
3 changes: 2 additions & 1 deletion as/NFT/assembly/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class TokenMetadata {
public starts_at: string = '',
public updated_at: string = '',
public reference: string = '',
public reference_hash: string = ''
public reference_hash: string = '',
public media_animation: string = ''
) {}
}

Expand Down
32 changes: 24 additions & 8 deletions as/NFT/assembly/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,45 @@ export class Media {
royalty: Royalty
approvals: Map<string, number>
next_approval_id: number
constructor(media: string, extra: string) {
constructor(
title?: string,
copies: u8 = 1,
media?: string,
extra?: string,
description?: string,
media_hash?: string,
reference?: string,
reference_hash?: string,
media_animation?: string,
) {
this.owner_id = context.sender
this.prev_owner = context.sender
this.creator = ROYALTY_ADDRESS

this.royalty = new Royalty()

const title = context.sender.substring(
0,
context.sender.lastIndexOf('.')
)

title = (title && title !== "") ? title : context.sender.substring(0, context.sender.lastIndexOf(".")),
this.id = title + '-' + context.blockIndex.toString()

const issued_at = context.blockTimestamp.toString()
const copies: u8 = 1
const starts_at = issued_at
const expires_at = ''
const updated_at = issued_at
sekaiking marked this conversation as resolved.
Show resolved Hide resolved

const metadata = new TokenMetadata(
title,
issued_at,
copies,
media,
extra
extra,
description,
media_hash,
expires_at,
starts_at,
updated_at,
reference,
reference_hash,
media_animation,
)
token_metadata_by_id.set(this.id, metadata)
this.approvals = new Map()
Expand Down