Merge pull request #434 from metaplex-foundation/uploadFile4
Replace uploadFile2 with 4
This commit is contained in:
commit
f5e7b6975a
|
@ -205,7 +205,7 @@ export const getMasterEdition = async (
|
||||||
|
|
||||||
export function loadWalletKey(keypair): Keypair {
|
export function loadWalletKey(keypair): Keypair {
|
||||||
if (!keypair || keypair == '') {
|
if (!keypair || keypair == '') {
|
||||||
throw new Error("Keypair is required!");
|
throw new Error('Keypair is required!');
|
||||||
}
|
}
|
||||||
const loaded = Keypair.fromSecretKey(
|
const loaded = Keypair.fromSecretKey(
|
||||||
new Uint8Array(JSON.parse(fs.readFileSync(keypair).toString())),
|
new Uint8Array(JSON.parse(fs.readFileSync(keypair).toString())),
|
||||||
|
|
|
@ -188,9 +188,8 @@ export const punchTicket = async (
|
||||||
|
|
||||||
const ticket = fairLaunch.ticket.data;
|
const ticket = fairLaunch.ticket.data;
|
||||||
|
|
||||||
const fairLaunchLotteryBitmap = ( //@ts-ignore
|
const fairLaunchLotteryBitmap = //@ts-ignore
|
||||||
await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint)
|
(await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint))[0];
|
||||||
)[0];
|
|
||||||
|
|
||||||
const buyerTokenAccount = (
|
const buyerTokenAccount = (
|
||||||
await getAtaForMint(
|
await getAtaForMint(
|
||||||
|
@ -520,8 +519,9 @@ export const purchaseTicket = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
const fairLaunchLotteryBitmap = //@ts-ignore
|
const fairLaunchLotteryBitmap = ( //@ts-ignore
|
||||||
(await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint))[0];
|
await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint)
|
||||||
|
)[0];
|
||||||
console.log(
|
console.log(
|
||||||
'Anchor wallet',
|
'Anchor wallet',
|
||||||
anchorWallet.publicKey.toBase58(),
|
anchorWallet.publicKey.toBase58(),
|
||||||
|
|
|
@ -28,7 +28,9 @@ import crypto from 'crypto';
|
||||||
import { getAssetCostToStore } from '../utils/assets';
|
import { getAssetCostToStore } from '../utils/assets';
|
||||||
import { AR_SOL_HOLDER_ID } from '../utils/ids';
|
import { AR_SOL_HOLDER_ID } from '../utils/ids';
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
|
|
||||||
const RESERVED_TXN_MANIFEST = 'manifest.json';
|
const RESERVED_TXN_MANIFEST = 'manifest.json';
|
||||||
|
const RESERVED_METADATA = 'metadata.json';
|
||||||
|
|
||||||
interface IArweaveResult {
|
interface IArweaveResult {
|
||||||
error?: string;
|
error?: string;
|
||||||
|
@ -40,6 +42,33 @@ interface IArweaveResult {
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uploadToArweave = async (data: FormData): Promise<IArweaveResult> => {
|
||||||
|
const resp = await fetch(
|
||||||
|
'https://us-central1-principal-lane-200702.cloudfunctions.net/uploadFile4',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
// @ts-ignore
|
||||||
|
body: data,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!resp.ok) {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(
|
||||||
|
'Unable to upload the artwork to Arweave. Please wait and then try again.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: IArweaveResult = await resp.json();
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
return Promise.reject(new Error(result.error));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const mintNFT = async (
|
export const mintNFT = async (
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
wallet: WalletSigner | undefined,
|
wallet: WalletSigner | undefined,
|
||||||
|
@ -85,7 +114,7 @@ export const mintNFT = async (
|
||||||
|
|
||||||
const realFiles: File[] = [
|
const realFiles: File[] = [
|
||||||
...files,
|
...files,
|
||||||
new File([JSON.stringify(metadataContent)], 'metadata.json'),
|
new File([JSON.stringify(metadataContent)], RESERVED_METADATA),
|
||||||
];
|
];
|
||||||
|
|
||||||
const { instructions: pushInstructions, signers: pushSigners } =
|
const { instructions: pushInstructions, signers: pushSigners } =
|
||||||
|
@ -170,6 +199,7 @@ export const mintNFT = async (
|
||||||
wallet,
|
wallet,
|
||||||
instructions,
|
instructions,
|
||||||
signers,
|
signers,
|
||||||
|
'single',
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -184,6 +214,8 @@ export const mintNFT = async (
|
||||||
|
|
||||||
// this means we're done getting AR txn setup. Ship it off to ARWeave!
|
// this means we're done getting AR txn setup. Ship it off to ARWeave!
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
|
data.append('transaction', txid);
|
||||||
|
data.append('env', env);
|
||||||
|
|
||||||
const tags = realFiles.reduce(
|
const tags = realFiles.reduce(
|
||||||
(acc: Record<string, Array<{ name: string; value: string }>>, f) => {
|
(acc: Record<string, Array<{ name: string; value: string }>>, f) => {
|
||||||
|
@ -193,30 +225,10 @@ export const mintNFT = async (
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
data.append('tags', JSON.stringify(tags));
|
data.append('tags', JSON.stringify(tags));
|
||||||
data.append('transaction', txid);
|
|
||||||
realFiles.map(f => data.append('file[]', f));
|
realFiles.map(f => data.append('file[]', f));
|
||||||
|
|
||||||
// TODO: convert to absolute file name for image
|
// TODO: convert to absolute file name for image
|
||||||
const uploadArweaveResponse = await fetch(
|
const result: IArweaveResult = await uploadToArweave(data);
|
||||||
// TODO: add CNAME
|
|
||||||
env.startsWith('mainnet-beta')
|
|
||||||
? 'https://us-central1-principal-lane-200702.cloudfunctions.net/uploadFileProd2'
|
|
||||||
: 'https://us-central1-principal-lane-200702.cloudfunctions.net/uploadFile2',
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
body: data,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!uploadArweaveResponse.ok) {
|
|
||||||
return Promise.reject(new Error("Unable to upload the artwork to Arweave. Please wait and then try again."))
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: IArweaveResult = await uploadArweaveResponse.json();
|
|
||||||
|
|
||||||
if (result.error) {
|
|
||||||
return Promise.reject(new Error(result.error))
|
|
||||||
}
|
|
||||||
|
|
||||||
const metadataFile = result.messages?.find(
|
const metadataFile = result.messages?.find(
|
||||||
m => m.filename === RESERVED_TXN_MANIFEST,
|
m => m.filename === RESERVED_TXN_MANIFEST,
|
||||||
|
|
Loading…
Reference in New Issue