-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: collect metadata from console and upload
- Loading branch information
Showing
11 changed files
with
271 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { put } from "@vercel/blob"; | ||
import { parse, isValid } from "date-fns"; | ||
import { enGB } from "date-fns/locale"; | ||
import dotenv from "dotenv"; | ||
|
||
import path from "path"; | ||
import * as readline from "readline"; | ||
|
||
export interface RoundMetadata { | ||
roundId: string; | ||
description: string; | ||
startsAt: Date; | ||
registrationEndsAt: Date; | ||
votingStartsAt: Date; | ||
votingEndsAt: Date; | ||
} | ||
|
||
interface IUploadMetadataProps { | ||
data: RoundMetadata; | ||
name: string; | ||
} | ||
|
||
dotenv.config({ path: path.resolve(import.meta.dirname, "../.env") }); | ||
|
||
function isValidDate(formattedDateStr: string) { | ||
const splitDate = formattedDateStr.split("-"); | ||
const parsed = parse(`${splitDate[2]}/${splitDate[1]}/${splitDate[0]}`, "P", new Date(), { locale: enGB }); | ||
return isValid(parsed); | ||
} | ||
|
||
export async function uploadRoundMetadata({ data, name }: IUploadMetadataProps): Promise<string> { | ||
const blob = await put(name, JSON.stringify(data), { | ||
access: "public", | ||
token: process.env.BLOB_READ_WRITE_TOKEN, | ||
}); | ||
|
||
return blob.url; | ||
} | ||
|
||
export async function collectMetadata(): Promise<RoundMetadata> { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
const askRoundId = () => | ||
new Promise<string>((resolve) => { | ||
rl.question("How would you name your round? ", (answer) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Your roundId is: ${answer}`); | ||
resolve(answer); | ||
}); | ||
}); | ||
|
||
const askDescription = () => | ||
new Promise<string>((resolve) => { | ||
rl.question("Could you briefly introduce this round? ", (answer) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Your round description is: ${answer}`); | ||
resolve(answer); | ||
}); | ||
}); | ||
|
||
const askStartTime = () => | ||
new Promise<Date>((resolve, reject) => { | ||
rl.question("When would you like to start this round? (Please respond in the format yyyy-mm-dd) ", (answer) => { | ||
const valid = isValidDate(answer); | ||
|
||
if (!valid) { | ||
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors | ||
reject(new Error("Please answer in valid format.")); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log("You would like to start this round at:", answer); | ||
resolve(new Date(answer)); | ||
}); | ||
}); | ||
|
||
const askRegistrationEndTime = () => | ||
new Promise<Date>((resolve, reject) => { | ||
rl.question( | ||
"When would you like to end the registration for applications? (Please respond in the format yyyy-mm-dd) ", | ||
(answer) => { | ||
const valid = isValidDate(answer); | ||
|
||
if (!valid) { | ||
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors | ||
reject(new Error("Please answer in valid format.")); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Your application registration end date for this round is: ${answer}`); | ||
resolve(new Date(answer)); | ||
}, | ||
); | ||
}); | ||
|
||
const askVotingStartTime = () => | ||
new Promise<Date>((resolve, reject) => { | ||
rl.question( | ||
"When would you like to start the voting for this round? (Please respond in the format yyyy-mm-dd) ", | ||
(answer) => { | ||
const valid = isValidDate(answer); | ||
|
||
if (!valid) { | ||
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors | ||
reject(new Error("Please answer in valid format.")); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Your voting start date for this round is: ${answer}`); | ||
resolve(new Date(answer)); | ||
}, | ||
); | ||
}); | ||
|
||
const askVotingEndTime = () => | ||
new Promise<Date>((resolve, reject) => { | ||
rl.question( | ||
"When would you like to end the voting for this round? (Please respond in the format yyyy-mm-dd) ", | ||
(answer) => { | ||
const valid = isValidDate(answer); | ||
|
||
if (!valid) { | ||
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors | ||
reject(new Error("Please answer in valid format.")); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(`Your voting end date for this round is: ${answer}`); | ||
resolve(new Date(answer)); | ||
}, | ||
); | ||
}); | ||
|
||
const roundId = await askRoundId(); | ||
const description = await askDescription(); | ||
const startsAt = await askStartTime(); | ||
const registrationEndsAt = await askRegistrationEndTime(); | ||
const votingStartsAt = await askVotingStartTime(); | ||
const votingEndsAt = await askVotingEndTime(); | ||
|
||
rl.close(); | ||
|
||
return { | ||
roundId, | ||
description, | ||
startsAt, | ||
registrationEndsAt, | ||
votingStartsAt, | ||
votingEndsAt, | ||
}; | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const metadata = await collectMetadata(); | ||
const url = await uploadRoundMetadata({ data: metadata, name: `${metadata.roundId}.json` }); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log("The url of uploaded metadata is:", url); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ build | |
generated | ||
subgraph.yaml | ||
schema.graphql | ||
config/network.json | ||
tests/.bin/ | ||
tests/.latest.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"network": "optimism-sepolia", | ||
"maciContractAddress": "0xac4d16D0541ca7255579b501A2F1D6F3a436521E", | ||
"registryManagerContractAddress": "0xed5875D05DebcDdDbd902f471447dA97c6d26d7E", | ||
"registryManagerContractStartBlock": 17396799, | ||
"maciContractStartBlock": 17396799 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"network": "optimism-sepolia", | ||
"maciContractAddress": "0xac4d16D0541ca7255579b501A2F1D6F3a436521E", | ||
"registryManagerContractAddress": "0xed5875D05DebcDdDbd902f471447dA97c6d26d7E", | ||
"registryManagerContractStartBlock": 17396799, | ||
"maciContractStartBlock": 17396799 | ||
"maciContractAddress": "0xd2A6F62d4d12Fa3552298E8C22F2a08FF0c9771e", | ||
"registryManagerContractAddress": "0xa9C6e12E3F35Cf6F33D3a541f223aa4F70191383", | ||
"registryManagerContractStartBlock": 18071448, | ||
"maciContractStartBlock": 18071444 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.