From d6e045adb74858bbb43c2fd4725f826922120f65 Mon Sep 17 00:00:00 2001 From: Arturo Jamaica Date: Mon, 28 Nov 2022 13:23:08 -0600 Subject: [PATCH] Allow unkown standard and details --- .../accounts/MetadataAccount.kt | 31 +++++++++++++++---- .../java/com/metaplex/sample/FirstFragment.kt | 4 ++- .../com/metaplex/sample/NftDetailsActivity.kt | 6 +++- 3 files changed, 33 insertions(+), 8 deletions(-) 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..ddb02e8 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 @@ -9,6 +9,7 @@ import com.metaplex.lib.serialization.serializers.solana.PublicKeyAs32ByteSerial import com.metaplex.lib.shared.OperationError import com.metaplex.lib.shared.ResultWithCustomError import com.solana.core.PublicKey +import com.solana.networking.serialization.serializers.solana.PublicKeyAsStringSerializer import com.solana.vendor.borshj.* import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable @@ -22,11 +23,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, Unkown } enum class MetaplexCollectionDetails { - V1 + V1, Unkown } @Serializable @@ -44,10 +45,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 +116,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.Unkown + } + } +} + +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.Unkown } } } \ 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()