diff --git a/lib/src/main/java/com/metaplex/lib/programs/token_metadata/accounts/MetadataAccount.kt b/lib/src/main/java/com/metaplex/lib/programs/token_metadata/accounts/MetadataAccount.kt index 03869a9..b54d0cd 100644 --- a/lib/src/main/java/com/metaplex/lib/programs/token_metadata/accounts/MetadataAccount.kt +++ b/lib/src/main/java/com/metaplex/lib/programs/token_metadata/accounts/MetadataAccount.kt @@ -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 @@ -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 @@ -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 { @@ -115,8 +113,26 @@ object CollectionDetailsSerializer : KSerializer { } 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 { + 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 } } } \ No newline at end of file diff --git a/sample/src/main/java/com/metaplex/sample/FirstFragment.kt b/sample/src/main/java/com/metaplex/sample/FirstFragment.kt index f15d485..5df2e3c 100644 --- a/sample/src/main/java/com/metaplex/sample/FirstFragment.kt +++ b/sample/src/main/java/com/metaplex/sample/FirstFragment.kt @@ -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 /** @@ -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() diff --git a/sample/src/main/java/com/metaplex/sample/NftDetailsActivity.kt b/sample/src/main/java/com/metaplex/sample/NftDetailsActivity.kt index 4ad33c6..c7b9fb3 100644 --- a/sample/src/main/java/com/metaplex/sample/NftDetailsActivity.kt +++ b/sample/src/main/java/com/metaplex/sample/NftDetailsActivity.kt @@ -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() { @@ -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()