Skip to content

Commit

Permalink
Merge pull request #87 from metaplex-foundation/fix/allow-unknow-stan…
Browse files Browse the repository at this point in the history
…dard-and-details

Allow unkown standard and details
  • Loading branch information
ajamaica authored Nov 28, 2022
2 parents 1af0fc0 + 5ddf211 commit a50c61a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
package com.metaplex.lib.programs.token_metadata.accounts

import com.metaplex.lib.modules.nfts.models.MetaplexContstants
import com.metaplex.lib.programs.token_metadata.MetadataKey
import com.metaplex.lib.serialization.serializers.solana.ByteDiscriminatorSerializer
import com.metaplex.lib.serialization.serializers.solana.PublicKeyAs32ByteSerializer
import com.metaplex.lib.shared.OperationError
import com.metaplex.lib.shared.ResultWithCustomError
Expand All @@ -22,11 +20,11 @@ import org.bitcoinj.core.Base58
// this will be replaced with beet kt generated code in the near future

enum class MetaplexTokenStandard {
NonFungible, FungibleAsset, Fungible, NonFungibleEdition
NonFungible, FungibleAsset, Fungible, NonFungibleEdition, Unknown
}

enum class MetaplexCollectionDetails {
V1
V1, Unknown
}

@Serializable
Expand All @@ -44,10 +42,10 @@ data class MetadataAccount(
val primarySaleHappened: Boolean,
val isMutable: Boolean,
val editionNonce: UByte?,
val tokenStandard: MetaplexTokenStandard?,
@Serializable(with = MetaplexTokenStandardSerializer::class) val tokenStandard: MetaplexTokenStandard? = null,
val collection: MetaplexCollection?,
val uses: Uses? = null,
val collectionDetails: MetaplexCollectionDetails? = null
@Serializable(with = CollectionDetailsSerializer::class) val collectionDetails: MetaplexCollectionDetails? = null
) : BorshCodable {
companion object {
fun pda(publicKey: PublicKey): ResultWithCustomError<PublicKey, OperationError> {
Expand Down Expand Up @@ -115,8 +113,26 @@ object CollectionDetailsSerializer : KSerializer<MetaplexCollectionDetails> {
}

override fun deserialize(decoder: Decoder): MetaplexCollectionDetails {
return MetaplexCollectionDetails.values().get(decoder.decodeByte().toInt()).also {
decoder.decodeLong()
return MetaplexCollectionDetails.values().getOrNull(decoder.decodeByte().toInt())?.let {
it
}.run {
MetaplexCollectionDetails.Unknown
}
}
}

object MetaplexTokenStandardSerializer : KSerializer<MetaplexTokenStandard> {
override val descriptor = Byte.serializer().descriptor
override fun serialize(encoder: Encoder, value: MetaplexTokenStandard) {
encoder.encodeByte(value.ordinal.toByte())
encoder.encodeLong(0)
}

override fun deserialize(decoder: Decoder): MetaplexTokenStandard {
return MetaplexTokenStandard.values().getOrNull(decoder.decodeByte().toInt())?.let {
it
}.run {
MetaplexTokenStandard.Unknown
}
}
}
4 changes: 3 additions & 1 deletion sample/src/main/java/com/metaplex/sample/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import com.metaplex.lib.modules.nfts.models.NFT
import com.metaplex.lib.solana.SolanaConnectionDriver
import com.metaplex.sample.databinding.FragmentFirstBinding
import com.solana.core.PublicKey
import com.solana.networking.Network
import com.solana.networking.RPCEndpoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URL


/**
Expand Down Expand Up @@ -64,7 +66,7 @@ class FirstFragment : Fragment() {
activity?.finish()
}

val solanaConnection = SolanaConnectionDriver(RPCEndpoint.mainnetBetaSolana)
val solanaConnection = SolanaConnectionDriver(RPCEndpoint.custom(URL("https://api.metaplex.solana.com"), URL("https://api.metaplex.solana.com"), Network.mainnetBeta))
val solanaIdentityDriver = ReadOnlyIdentityDriver(ownerPublicKey, solanaConnection)
val storageDriver = OkHttpSharedStorageDriver()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import com.metaplex.lib.modules.nfts.models.Value
import com.metaplex.lib.programs.token_metadata.accounts.MetaplexCreator
import com.metaplex.lib.solana.SolanaConnectionDriver
import com.solana.core.PublicKey
import com.solana.networking.Network
import com.solana.networking.RPCEndpoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URL


class NftDetailsActivity : AppCompatActivity() {
Expand Down Expand Up @@ -71,7 +73,9 @@ class NftDetailsActivity : AppCompatActivity() {
ownerPublicKey = PublicKey(nftOwner)
setTitle(nftName)

val solanaConnection = SolanaConnectionDriver(RPCEndpoint.mainnetBetaSolana)
val solanaConnection = SolanaConnectionDriver(
RPCEndpoint.custom(URL("https://api.metaplex.solana.com"), URL("https://api.metaplex.solana.com"), Network.mainnetBeta)
)
val solanaIdentityDriver = ReadOnlyIdentityDriver(ownerPublicKey, solanaConnection)
val storageDriver = OkHttpSharedStorageDriver()

Expand Down

0 comments on commit a50c61a

Please sign in to comment.