Skip to content

Commit

Permalink
Fix schema issue, token id improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo committed Nov 23, 2023
1 parent f3d8c1e commit 5f5ae92
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/endpoints/Mint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import LSPSelect from '@/components/shared/LSPSelect.vue'
import { TokenInfo, LSPType, padTokenId } from '@/helpers/tokenUtils'
import useWeb3Connection from '@/compositions/useWeb3Connection'
import useErc725 from '@/compositions/useErc725'
import LSP8IdentifiableDigitalAsset from '@erc725/erc725.js/schemas/LSP8IdentifiableDigitalAsset.json'
// TODO for now we use local schema before erc725 is fixed
// import LSP8IdentifiableDigitalAsset from '@erc725/erc725.js/schemas/LSP8IdentifiableDigitalAsset.json'
import LSP8IdentifiableDigitalAsset from '@/schema/LSP8IdentifiableDigitalAsset.json'
import { isHex } from 'web3-utils'
import { isAddress } from 'ethers/lib/utils'
import { LSP8_TOKEN_ID_TYPES } from '@lukso/lsp-smart-contracts'
Expand Down Expand Up @@ -108,6 +110,10 @@ const handleChangeTokenId = (event: Event) => {
}
break
case LSP8_TOKEN_ID_TYPES.UNIQUE_ID:
if (!isHex(value)) {
return (tokenIdTypeError.value = 'Must be a byte string')
}
break
case LSP8_TOKEN_ID_TYPES.HASH:
if (value.length !== 66 || !isHex(value)) {
return (tokenIdTypeError.value = 'Must be a 32byte hash')
Expand Down Expand Up @@ -158,6 +164,7 @@ const mint = async () => {
return
}
// mint asset
myToken.value = contract(LSP8Mintable.abi as any, mintToken.value)
const tokenIdPadded = padTokenId(tokenIdType.value, tokenId.value)
await myToken.value.methods
Expand All @@ -170,6 +177,7 @@ const mint = async () => {
console.log(JSON.stringify(payload, null, 2))
})
// set asset metadata
const tokenIdTypeData = LSP8TokenIdTypesData[tokenIdType.value]
const metadataKey = ERC725.encodeKeyName(
`LSP8MetadataTokenURI:<${tokenIdTypeData}>`,
Expand Down
2 changes: 1 addition & 1 deletion src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const LSP8TokenIdTypes = [
export const LSP8TokenIdTypesData = [
'uint256',
'string',
'bytes32',
'bytes',
'bytes32',
'address',
]
3 changes: 2 additions & 1 deletion src/helpers/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ export const padTokenId = (tokenIdType: number, tokenId: string) => {
case LSP8_TOKEN_ID_TYPES.STRING:
return rightPad(fromUtf8(tokenId), 64)
case LSP8_TOKEN_ID_TYPES.UNIQUE_ID:
case LSP8_TOKEN_ID_TYPES.HASH:
return rightPad(tokenId, 64)
case LSP8_TOKEN_ID_TYPES.HASH:
return tokenId // it's 32 bytes already
case LSP8_TOKEN_ID_TYPES.ADDRESS:
return leftPad(tokenId, 64)
default:
Expand Down
51 changes: 51 additions & 0 deletions src/schema/LSP8IdentifiableDigitalAsset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"name": "LSP8TokenIdType",
"key": "0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4",
"keyType": "Singleton",
"valueType": "uint256",
"valueContent": "Number"
},
{
"name": "LSP8MetadataTokenURI:<address>",
"key": "0x1339e76a390b7b9ec9010000<address>",
"keyType": "Mapping",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8MetadataTokenURI:<uint256>",
"key": "0x1339e76a390b7b9ec9010000<uint256>",
"keyType": "Mapping",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8MetadataTokenURI:<bytes32>",
"key": "0x1339e76a390b7b9ec9010000<bytes32>",
"keyType": "Mapping",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8MetadataTokenURI:<string>",
"key": "0x1339e76a390b7b9ec9010000<string>",
"keyType": "Mapping",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8TokenMetadataBaseURI",
"key": "0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843",
"keyType": "Singleton",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8ReferenceContract",
"key": "0x708e7b881795f2e6b6c2752108c177ec89248458de3bf69d0d43480b3e5034e6",
"keyType": "Singleton",
"valueType": "(address,bytes32)",
"valueContent": "(Address,bytes32)"
}
]

0 comments on commit 5f5ae92

Please sign in to comment.