diff --git a/Solnet.Metaplex.Examples/MetadataCreate.cs b/Solnet.Metaplex.Examples/MetadataCreate.cs index 60a213e..e4bc7a6 100644 --- a/Solnet.Metaplex.Examples/MetadataCreate.cs +++ b/Solnet.Metaplex.Examples/MetadataCreate.cs @@ -33,7 +33,7 @@ public void Run() if ( balanceRes.WasSuccessful ) Console.WriteLine("Account balance: {0}", balanceRes.Result.Value); - var mint = wallet.GetAccount(20); + var mint = wallet.GetAccount(55); //PDA METADATA @@ -132,15 +132,15 @@ out nonce true ) ) - .AddInstruction( - MetadataProgram.UpdateMetadataAccount( - new PublicKey(metadataAddress), - wallet.Account.PublicKey, - null, - data2, - null - ) - ) + // .AddInstruction( + // MetadataProgram.UpdateMetadataAccount( + // new PublicKey(metadataAddress), + // wallet.Account.PublicKey, + // null, + // data2, + // null + // ) + // ) .Build(new List { wallet.Account , mint}); var simTX = client.SimulateTransactionAsync(TX).Result; diff --git a/Solnet.Metaplex.Test/MetadataTest.cs b/Solnet.Metaplex.Test/MetadataTest.cs index 49160d2..48dafaf 100644 --- a/Solnet.Metaplex.Test/MetadataTest.cs +++ b/Solnet.Metaplex.Test/MetadataTest.cs @@ -121,7 +121,7 @@ public void MintToken() } - //[TestMethod] + [TestMethod] public void TestCreateMetadataAccount() { var rpcClient = ClientFactory.GetClient(Cluster.DevNet); //, logger); @@ -197,12 +197,12 @@ out nonce true //ISMUTABLE ) ) - // .AddInstruction( - // MetadataProgram.SignMetada( - // new PublicKey(metadataAddress), - // c2.key - // ) - // ) + .AddInstruction( + MetadataProgram.SignMetada( + new PublicKey(metadataAddress), + c2.key + ) + ) .AddInstruction( MetadataProgram.PuffMetada( new PublicKey(metadataAddress) @@ -221,12 +221,14 @@ out nonce ) .Build(new List { fromAccount, wallet.GetAccount(101) }); - //var txSim2 = rpcClient.SimulateTransaction(TX2); + var txSim2 = rpcClient.SimulateTransaction(TX2); //InstructionDecoder.Register(MetadataProgram.ProgramIdKey, MetadataProgram.Decode); //List decodedInstructions = InstructionDecoder.DecodeInstructions( TX2 ); - //Console.WriteLine($"Transaction sim: \n { txSim2.RawRpcResponse }"); + Console.WriteLine($"Transaction sim: \n { txSim2.RawRpcResponse }"); + + Assert.IsFalse( txSim2.RawRpcResponse.Contains("Error")); } diff --git a/Solnet.Metaplex/MetadataAccount.cs b/Solnet.Metaplex/MetadataAccount.cs index b915e68..7df88d5 100644 --- a/Solnet.Metaplex/MetadataAccount.cs +++ b/Solnet.Metaplex/MetadataAccount.cs @@ -91,9 +91,14 @@ public static Data ParseData( List data) byte[] bytes = Convert.FromBase64String(data[0]); ReadOnlySpan binData = new(bytes); - (string name,_) = binData.DecodeRustString( MetadataAccountLayout.nameOffset); - (string symbol,_) = binData.DecodeRustString( MetadataAccountLayout.symbolOffset); - (string uri,_) = binData.DecodeRustString( MetadataAccountLayout.uriOffset); + string name; + string symbol; + string uri; + + binData.GetString( MetadataAccountLayout.nameOffset, out name); + binData.GetString( MetadataAccountLayout.symbolOffset, out symbol); + binData.GetString( MetadataAccountLayout.uriOffset, out uri); + uint sellerFee = binData.GetU16( MetadataAccountLayout.feeBasisOffset ); var numOfCreators = binData.GetU16( MetadataAccountLayout.creatorsOffset ); diff --git a/Solnet.Metaplex/MetadataProgramData.cs b/Solnet.Metaplex/MetadataProgramData.cs index 682f588..e07d9c3 100644 --- a/Solnet.Metaplex/MetadataProgramData.cs +++ b/Solnet.Metaplex/MetadataProgramData.cs @@ -120,23 +120,27 @@ internal static byte[] EncodeCreateMetadataAccountData ( ) { - byte[] encodedName = Serialization.EncodeRustString(parameters.name); - byte[] encodedSymbol = Serialization.EncodeRustString(parameters.symbol); - byte[] encodedUri = Serialization.EncodeRustString(parameters.uri); + byte[] encodedName = Encoding.UTF8.GetBytes(parameters.name); + byte[] encodedSymbol = Encoding.UTF8.GetBytes(parameters.symbol); + byte[] encodedUri = Encoding.UTF8.GetBytes(parameters.uri); var buffer = new MemoryStream(); BinaryWriter writer = new BinaryWriter(buffer); writer.Write( (byte) MetadataProgramInstructions.Values.CreateMetadataAccount ); + writer.Write( encodedName.Length ); writer.Write( encodedName) ; + writer.Write( encodedSymbol.Length ); writer.Write( encodedSymbol ); + writer.Write( encodedUri.Length ); writer.Write( encodedUri ); writer.Write( (ushort) parameters.sellerFeeBasisPoints); if ( parameters.creators == null || parameters.creators?.Count < 1 ) { writer.Write( (byte) 0); //Option() - } else + } + else { writer.Write( (byte) 1); writer.Write( parameters.creators.Count ); @@ -170,13 +174,17 @@ internal static byte[] EncodeUpdateMetadataData ( { writer.Write((byte)1); - byte[] encodedName = Serialization.EncodeRustString(parameters.name); - byte[] encodedSymbol = Serialization.EncodeRustString(parameters.symbol); - byte[] encodedUri = Serialization.EncodeRustString(parameters.uri); + byte[] encodedName = Encoding.UTF8.GetBytes(parameters.name); + byte[] encodedSymbol = Encoding.UTF8.GetBytes(parameters.symbol); + byte[] encodedUri = Encoding.UTF8.GetBytes(parameters.uri); + + writer.Write(encodedName.Length); + writer.Write(encodedName); + writer.Write(encodedSymbol.Length); + writer.Write(encodedSymbol); + writer.Write(encodedUri.Length); + writer.Write(encodedUri); - writer.Write( encodedName) ; - writer.Write( encodedSymbol ); - writer.Write( encodedUri ); writer.Write( (ushort) parameters.sellerFeeBasisPoints); if ( parameters.creators == null || parameters.creators?.Count < 1 ) @@ -271,10 +279,15 @@ byte[] keyIndices decodedInstruction.Values.Add("updateAuthorityKey", keys[keyIndices[4]]); decodedInstruction.Values.Add("SysProgramId", keys[keyIndices[5]]); decodedInstruction.Values.Add("SysVarRentKey", keys[keyIndices[6]]); + + string name; + string symbol; + string uri; + + int nameLength = data.GetString( 1 , out name); + int symbolLength = data.GetString( 1 + nameLength , out symbol); + int uriLength = data.GetString( 1 + nameLength + symbolLength ,out uri); - (string name , int nameLength) = data.DecodeRustString(1); - (string symbol, int symbolLength) = data.DecodeRustString(1 + nameLength); - (string uri, int uriLength) = data.DecodeRustString(1 + nameLength+symbolLength); int sellerFeeBasisPoints = data.GetU16(1 + nameLength + symbolLength + uriLength); decodedInstruction.Values.Add("name", name ); @@ -335,9 +348,15 @@ byte[] keyIndices if ( data.GetU8(offset) == 1 ) { offset++; - (string name , int nameLength) = data.DecodeRustString(offset); - (string symbol, int symbolLength) = data.DecodeRustString(offset+nameLength); - (string uri, int uriLength) = data.DecodeRustString(offset+nameLength+symbolLength); + + string name; + string symbol; + string uri; + + int nameLength = data.GetString(offset, out name); + int symbolLength = data.GetString(offset + nameLength, out symbol); + int uriLength = data.GetString(offset + nameLength + symbolLength, out uri); + int sellerFeeBasisPoints = data.GetU16(offset + nameLength + symbolLength + uriLength); decodedInstruction.Values.Add("name", name );