chore: cleanup

This commit is contained in:
bartosz-lipinski 2021-04-04 20:36:45 -05:00
parent a2e0902da8
commit 8e72841ebc
2 changed files with 2 additions and 136 deletions

View File

@ -16,7 +16,7 @@ import { TokenAccount } from '../models/account';
import { cache, TokenAccountParser } from '../contexts/accounts';
// @ts-ignore
import * as BufferLayout from 'buffer-layout';
import borsh from 'borsh';
import { serialize, deserialize } from 'borsh';
export function ensureSplAccount(
instructions: TransactionInstruction[],
@ -277,17 +277,7 @@ export async function createMetadata(
],
]);
const value = new CreateMetadataArgs(name, symbol, uri);
debugger;
const data = Buffer.from(borsh.serialize(schema, value));
const test = borsh.deserialize(
schema,
CreateMetadataArgs,
Buffer.alloc(1024),
);
console.log(test);
const data = Buffer.from(serialize(schema, value));
const keys = [
{

View File

@ -15,130 +15,6 @@ import {
TransactionInstruction,
} from '@solana/web3.js';
import { serialize, deserialize } from 'borsh';
class CreateMetadataArgs {
instruction: number = 0;
allow_duplicates: boolean = false;
name: string = '';
symbol: string = '';
uri: string = '';
constructor(name: string, symbol: string, uri: string) {
this.name = name;
this.symbol = symbol;
this.uri = uri;
}
}
export async function createMetadata(
symbol: string,
name: string,
uri: string,
mintKey: PublicKey,
mintAuthorityKey: PublicKey,
instructions: TransactionInstruction[],
payer: PublicKey,
owner: PublicKey,
signers: Account[],
) {
const metadataProgramId = programIds().metadata;
const metadataAccount = (
await PublicKey.findProgramAddress(
[
Buffer.from('metadata'),
metadataProgramId.toBuffer(),
mintKey.toBuffer(),
],
metadataProgramId,
)
)[0];
const metadataOwnerAccount = (
await PublicKey.findProgramAddress(
[
Buffer.from('metadata'),
metadataProgramId.toBuffer(),
Buffer.from(name),
Buffer.from(symbol),
],
metadataProgramId,
)
)[0];
const schema = new Map([
[
CreateMetadataArgs,
{
kind: 'struct',
fields: [
['instruction', 'u8'],
['allow_duplicates', 'u8'],
['name', 'string'],
['symbol', 'string'],
['uri', 'string'],
],
},
],
]);
const value = new CreateMetadataArgs(name, symbol, uri);
const data = Buffer.from(serialize(schema, value));
//const test = deserialize(schema, CreateMetadataArgs, Buffer.alloc(data.length));
//console.log(test);
debugger;
const keys = [
{
pubkey: metadataOwnerAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: metadataAccount,
isSigner: false,
isWritable: true,
},
{
pubkey: mintKey,
isSigner: false,
isWritable: false,
},
{
pubkey: mintAuthorityKey,
isSigner: true,
isWritable: false,
},
{
pubkey: payer,
isSigner: true,
isWritable: false,
},
{
pubkey: payer,
isSigner: true,
isWritable: false,
},
{
pubkey: SystemProgram.programId,
isSigner: false,
isWritable: false,
},
{
pubkey: SYSVAR_RENT_PUBKEY,
isSigner: false,
isWritable: false,
},
];
instructions.push(
new TransactionInstruction({
keys,
programId: metadataProgramId,
data,
}),
);
}
export const mintNFT = async (
connection: Connection,
wallet: WalletAdapter | undefined,