Skip to content

Commit

Permalink
Merge pull request #36 from mariomatic/master
Browse files Browse the repository at this point in the history
Solnet 5.0.1
  • Loading branch information
mariomatic committed Feb 23, 2022
2 parents 4cf05a6 + a44b2fe commit 2d90241
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 91 deletions.
12 changes: 8 additions & 4 deletions Solnet.Metaplex.Examples/GetMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace Solnet.Metaplex.Examples

public class GetMetadataExample : IRunnableExample
{
string pk = "6W5UQqiUSycsMzpvtQkzApguBFfwqzE3LgNFsh3PBW6J";
public void Run()
string pk = "5CEeeHkyezrVpexdKjGkMv18dDRRW2tbF45yr5YfmAHt";
public async void Run()
{
Console.WriteLine("### Get Metadata example ###");
Console.WriteLine("Getting account {0}", pk );

var client = ClientFactory.GetClient( Cluster.MainNet);
var account = MetadataAccount.GetAccount( client, new PublicKey(pk )).Result;
var account = await MetadataAccount.GetAccount( client, new PublicKey(pk ));

Console.WriteLine( $"Owner: {account.owner}");
Console.WriteLine( $"Authority key: {account.updateAuthority}");
Expand All @@ -34,7 +34,11 @@ public void Run()
Console.WriteLine( $"Creator Share: {c.share}");
Console.WriteLine( $"Creator is verified: {c.verified}");
}
Console.WriteLine( "--------------");
Console.WriteLine( "---Metadata-------");

Console.Write( await account.data.FetchMetadata() );

Console.WriteLine ( "------------------");
}
}

Expand Down
18 changes: 9 additions & 9 deletions Solnet.Metaplex.Examples/MetadataCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public void Run()
if ( balanceRes.WasSuccessful )
Console.WriteLine("Account balance: {0}", balanceRes.Result.Value);

var mint = wallet.GetAccount(55);
var mint = wallet.GetAccount(59);

//PDA METADATA

byte[] metadataAddress = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey metadataAddress;
byte nonce;
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -51,12 +51,12 @@ out nonce
);


Console.WriteLine($"PDA METADATA: {new PublicKey(metadataAddress)}");
Console.WriteLine($"PDA METADATA: {metadataAddress}");

//PDA MASTER EDITION
byte[] masterEditionAddress = new byte[32];
PublicKey masterEditionAddress;
//int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -67,7 +67,7 @@ out nonce
out masterEditionAddress,
out nonce
);
Console.WriteLine($"PDA MASTER: {new PublicKey(masterEditionAddress)}");
Console.WriteLine($"PDA MASTER: {masterEditionAddress}");

//CREATORS

Expand Down Expand Up @@ -122,7 +122,7 @@ out nonce
)
.AddInstruction(
MetadataProgram.CreateMetadataAccount(
new PublicKey(metadataAddress),
metadataAddress,
mint,
wallet.Account.PublicKey,
wallet.Account.PublicKey,
Expand Down
6 changes: 3 additions & 3 deletions Solnet.Metaplex.Examples/Solnet.Metaplex.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Solnet.Programs" Version="0.4.17" />
<PackageReference Include="Solnet.Rpc" Version="0.4.17" />
<PackageReference Include="Solnet.Wallet" Version="0.4.17" />
<PackageReference Include="Solnet.Programs" Version="5.0.1" />
<PackageReference Include="Solnet.Rpc" Version="5.0.1" />
<PackageReference Include="Solnet.Wallet" Version="5.0.1" />
</ItemGroup>

</Project>
36 changes: 18 additions & 18 deletions Solnet.Metaplex.Examples/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
".NETCoreApp,Version=v5.0": {
"Solnet.Programs": {
"type": "Direct",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "uGfOM5zcE2uTTOHFaWiOj1fee/fi+QjgeTc57ETPPNIvkkm4i8PFZJ0HFdfehLNk1uDd2H277ua/ZJdFXwIz3w==",
"requested": "[5.0.1, )",
"resolved": "5.0.1",
"contentHash": "17M7qC8JFWjiYl6cKJUrCmK2CJJmCWIlIfvYukKfnI5G01KYFQ+RFoRFFuXxPo98QAkZ942Cg8pu4MQW+xUnfQ==",
"dependencies": {
"Solnet.Rpc": "0.4.17"
"Solnet.Rpc": "5.0.1"
}
},
"Solnet.Rpc": {
"type": "Direct",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "wrcafmjYq2wUWIzH2e0kRG4+ANy05G+IzuN0/Ka9+4vXtsgv59c1ZozCHlULEER50/deQo0UjIcRcjgaqh7OsA==",
"requested": "[5.0.1, )",
"resolved": "5.0.1",
"contentHash": "uz/qh8AjXTnQpjd5sNd/hZ3COqNaSP6YL5I3nVl6E9vrIeq7XvFErO7esa0MBGIGNCxN/jqmaU5av16bzBfCWg==",
"dependencies": {
"Microsoft.Extensions.Logging": "5.0.0",
"Microsoft.Extensions.Logging.Console": "5.0.0",
"Solnet.Wallet": "0.4.17"
"Solnet.Wallet": "5.0.1"
}
},
"Solnet.Wallet": {
"type": "Direct",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "v/jzBQU52j7Vz9M6wOJlsShl5GUfea0lgt13T+dlbknFe07lceNScAv3uYRxR1cUQWuhIqsRNquLGp3VyhaJ3w==",
"requested": "[5.0.1, )",
"resolved": "5.0.1",
"contentHash": "9pm032WVuh9P1Pfb4I0yR4D5wWuzCVjC2r7POqDPbCZ5z0iRmJ3xiqt/jkO7VbDZWB5vlJ41BTgjRPipCaZQtA==",
"dependencies": {
"Chaos.NaCl.Standard": "1.0.0",
"Portable.BouncyCastle": "1.8.2"
Expand Down Expand Up @@ -153,12 +153,12 @@
},
"Solnet.KeyStore": {
"type": "Transitive",
"resolved": "0.4.17",
"contentHash": "89w1PKk0e9Glzt/dW1vPfoH2utVINdi3+9875+Qh2tpC8iVEeNlGr7tJCY4J5WF8Ht9vCqcuEu1qJ55Mf+myKg==",
"resolved": "5.0.1",
"contentHash": "rz9rewa8IbGKUZOj2PxYOaYlSdqHTvM1ngFfZ8GanLabmb47jOycjwqWyb2nHR15re+CLv+Fv1ND7bjFNywRTg==",
"dependencies": {
"Chaos.NaCl.Standard": "1.0.0",
"Portable.BouncyCastle": "1.8.2",
"Solnet.Wallet": "0.4.17"
"Solnet.Wallet": "5.0.1"
}
},
"solnet.metaplex": {
Expand All @@ -167,10 +167,10 @@
"Microsoft.Extensions.Logging": "5.0.0",
"Microsoft.Extensions.Logging.Abstractions": "5.0.0",
"Microsoft.Extensions.Logging.Console": "5.0.0",
"Solnet.Keystore": "0.4.17",
"Solnet.Programs": "0.4.17",
"Solnet.Rpc": "0.4.17",
"Solnet.Wallet": "0.4.17"
"Solnet.Keystore": "5.0.1",
"Solnet.Programs": "5.0.1",
"Solnet.Rpc": "5.0.1",
"Solnet.Wallet": "5.0.1"
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions Solnet.Metaplex.Test/MetadataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public void TestCreateMetadataAccount()

//PDA METADATA

byte[] metadataAddress = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey metadataAddress;
byte nonce;
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -149,12 +149,12 @@ out nonce
);


Console.WriteLine($"PDA METADATA: {new PublicKey(metadataAddress)}");
Console.WriteLine($"PDA METADATA: { metadataAddress}");

//PDA MASTER EDITION
byte[] masterEditionAddress = new byte[32];
//int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey masterEditionAddress;
//byte nonce;
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -165,7 +165,7 @@ out nonce
out masterEditionAddress,
out nonce
);
Console.WriteLine($"PDA MASTER: {new PublicKey(masterEditionAddress)}");
Console.WriteLine($"PDA MASTER: { masterEditionAddress }");

//CREATORS

Expand All @@ -187,7 +187,7 @@ out nonce
.SetFeePayer(fromAccount)
.AddInstruction(
MetadataProgram.CreateMetadataAccount(
new PublicKey(metadataAddress), //PDA
metadataAddress, //PDA
mintAccount.PublicKey, //MINT
fromAccount.PublicKey, //mint AUTHORITY
fromAccount.PublicKey, //PAYER
Expand All @@ -199,24 +199,24 @@ out nonce
)
.AddInstruction(
MetadataProgram.SignMetada(
new PublicKey(metadataAddress),
metadataAddress,
c2.key
)
)
.AddInstruction(
MetadataProgram.PuffMetada(
new PublicKey(metadataAddress)
metadataAddress
)
)
.AddInstruction(
MetadataProgram.CreateMasterEdition(
1,
new PublicKey(masterEditionAddress),
masterEditionAddress,
mintAccount.PublicKey,
fromAccount.PublicKey,
fromAccount.PublicKey,
fromAccount.PublicKey,
new PublicKey(metadataAddress)
metadataAddress
)
)
.Build(new List<Account> { fromAccount, wallet.GetAccount(101) });
Expand Down
6 changes: 3 additions & 3 deletions Solnet.Metaplex.Test/Solnet.Metaplex.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Solnet.Programs" Version="0.4.17" />
<PackageReference Include="Solnet.Rpc" Version="0.4.17" />
<PackageReference Include="Solnet.Wallet" Version="0.4.17" />
<PackageReference Include="Solnet.Programs" Version="5.0.1" />
<PackageReference Include="Solnet.Rpc" Version="5.0.1" />
<PackageReference Include="Solnet.Wallet" Version="5.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 31 additions & 8 deletions Solnet.Metaplex/MetadataAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
using System;
using System.Text;
using System.Threading.Tasks;

using System.Net.Http;
using System.Net;

namespace Solnet.Metaplex
{
Expand Down Expand Up @@ -69,6 +70,9 @@ public class Data
/// <summary> Creators array </summary>
public IList<Creator> creators;

///<summary> metadata json </summary>
public string metadata;

/// <summary> Constructor </summary>
public Data( string name, string symbol, string uri, uint sellerFee, IList<Creator> creators)
{
Expand All @@ -78,6 +82,22 @@ public Data( string name, string symbol, string uri, uint sellerFee, IList<Creat
this.sellerFeeBasisPoints = sellerFee;
this.creators = creators;
}

/// <summary> Tries to get a json file from the uri </summary>
public async Task<string> FetchMetadata()
{
if ( uri is null)
return null;

if ( metadata is null )
{
using var http = new HttpClient();
var res = await http.GetStringAsync(uri);
metadata = res;
}

return metadata;
}
}

/// <summary> Metadata account class </summary>
Expand Down Expand Up @@ -135,9 +155,9 @@ public static Data ParseData( List<string> data)
string symbol;
string uri;

binData.GetString( MetadataAccountLayout.nameOffset, out name);
binData.GetString( MetadataAccountLayout.symbolOffset, out symbol);
binData.GetString( MetadataAccountLayout.uriOffset, out uri);
int nameLength = binData.GetBorshString( MetadataAccountLayout.nameOffset, out name );
int symbolLength = binData.GetBorshString( MetadataAccountLayout.symbolOffset, out symbol);
int uriLength = binData.GetBorshString( MetadataAccountLayout.uriOffset, out uri);

uint sellerFee = binData.GetU16( MetadataAccountLayout.feeBasisOffset );

Expand All @@ -147,6 +167,9 @@ public static Data ParseData( List<string> data)
numOfCreators * ( 32 + 1 +1)
));

name = name.TrimEnd('\0');
symbol = symbol.TrimEnd('\0');
uri = uri.TrimEnd('\0');
var res = new Data(
name,symbol,uri,sellerFee,creators
);
Expand Down Expand Up @@ -190,9 +213,9 @@ async public static Task<MetadataAccount> GetAccount ( IRpcClient client , Publi
mintAccount = pk;
}

byte[] metadataAddress = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey metadataAddress;
byte nonce;
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -203,7 +226,7 @@ async public static Task<MetadataAccount> GetAccount ( IRpcClient client , Publi
out nonce
);

return await GetAccount(client, new PublicKey(metadataAddress));
return await GetAccount(client, metadataAddress);
}
}
else
Expand Down
8 changes: 4 additions & 4 deletions Solnet.Metaplex/MetadataProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ PublicKey metadataMint
int BIT_SIZE = 248;
int editionNumber = (int)Math.Floor((double)edition / BIT_SIZE);
//EDITION PDA
byte[] editionPda = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(
PublicKey editionPda;
byte nonce;
PublicKey.TryFindProgramAddress(
new List<byte[]>() {
Encoding.UTF8.GetBytes("metadata"),
MetadataProgram.ProgramIdKey,
Expand All @@ -278,7 +278,7 @@ out nonce
AccountMeta.Writable(newEdition, false),
AccountMeta.Writable(masterEdition, false),
AccountMeta.Writable(newMint, false),
AccountMeta.Writable(new PublicKey(editionPda), false),
AccountMeta.Writable(editionPda, false),

AccountMeta.ReadOnly(newMintAuthority, true),
AccountMeta.ReadOnly(payer, true),
Expand Down
12 changes: 6 additions & 6 deletions Solnet.Metaplex/MetadataProgramData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ byte[] keyIndices
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);
int nameLength = data.GetBorshString( 1 , out name );
int symbolLength = data.GetBorshString( 1 + nameLength , out symbol );
int uriLength = data.GetBorshString( 1 + nameLength + symbolLength , out uri );

int sellerFeeBasisPoints = data.GetU16(1 + nameLength + symbolLength + uriLength);

Expand Down Expand Up @@ -353,9 +353,9 @@ byte[] keyIndices
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 nameLength = data.GetBorshString( offset , out name );
int symbolLength = data.GetBorshString( offset + nameLength , out symbol );
int uriLength = data.GetBorshString( offset + nameLength + symbolLength , out uri );

int sellerFeeBasisPoints = data.GetU16(offset + nameLength + symbolLength + uriLength);

Expand Down

0 comments on commit 2d90241

Please sign in to comment.