Merge pull request #434 from metaplex-foundation/uploadFile4

Replace uploadFile2 with 4
This commit is contained in:
Adam Jeffries 2021-09-29 21:19:29 -05:00 committed by GitHub
commit f5e7b6975a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 28 deletions

View File

@ -205,7 +205,7 @@ export const getMasterEdition = async (
export function loadWalletKey(keypair): Keypair {
if (!keypair || keypair == '') {
throw new Error("Keypair is required!");
throw new Error('Keypair is required!');
}
const loaded = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync(keypair).toString())),

View File

@ -188,9 +188,8 @@ export const punchTicket = async (
const ticket = fairLaunch.ticket.data;
const fairLaunchLotteryBitmap = ( //@ts-ignore
await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint)
)[0];
const fairLaunchLotteryBitmap = //@ts-ignore
(await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint))[0];
const buyerTokenAccount = (
await getAtaForMint(
@ -520,8 +519,9 @@ export const purchaseTicket = async (
);
if (ticket) {
const fairLaunchLotteryBitmap = //@ts-ignore
(await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint))[0];
const fairLaunchLotteryBitmap = ( //@ts-ignore
await getFairLaunchLotteryBitmap(fairLaunch.state.tokenMint)
)[0];
console.log(
'Anchor wallet',
anchorWallet.publicKey.toBase58(),

View File

@ -28,7 +28,9 @@ import crypto from 'crypto';
import { getAssetCostToStore } from '../utils/assets';
import { AR_SOL_HOLDER_ID } from '../utils/ids';
import BN from 'bn.js';
const RESERVED_TXN_MANIFEST = 'manifest.json';
const RESERVED_METADATA = 'metadata.json';
interface IArweaveResult {
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 (
connection: Connection,
wallet: WalletSigner | undefined,
@ -85,7 +114,7 @@ export const mintNFT = async (
const realFiles: File[] = [
...files,
new File([JSON.stringify(metadataContent)], 'metadata.json'),
new File([JSON.stringify(metadataContent)], RESERVED_METADATA),
];
const { instructions: pushInstructions, signers: pushSigners } =
@ -170,6 +199,7 @@ export const mintNFT = async (
wallet,
instructions,
signers,
'single',
);
try {
@ -184,6 +214,8 @@ export const mintNFT = async (
// this means we're done getting AR txn setup. Ship it off to ARWeave!
const data = new FormData();
data.append('transaction', txid);
data.append('env', env);
const tags = realFiles.reduce(
(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('transaction', txid);
realFiles.map(f => data.append('file[]', f));
// TODO: convert to absolute file name for image
const uploadArweaveResponse = await fetch(
// 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 result: IArweaveResult = await uploadToArweave(data);
const metadataFile = result.messages?.find(
m => m.filename === RESERVED_TXN_MANIFEST,