Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check collection owner and already branded identity #6

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -188028,6 +188028,11 @@ const robot = (app) => {
const allOwnersToCheck = [mainOwner, ...extraOwners];
const apiUrl = getApiUrl();
for (const owner of allOwnersToCheck) {
const alreadyExistingBranding = await isProviderAlreadyBranded(apiUrl, asset, owner);
if (alreadyExistingBranding && alreadyExistingBranding.existing && !alreadyExistingBranding.isUpdate) {
await fail(`${owner} is already branded. Only updates are allowed.`);
return [];
}
if (new out_1.Address(owner).isContractAddress()) {
const ownerResult = await axios_1.default.get(`${apiUrl}/accounts/${owner}?extract=ownerAddress`);
allOwners.push(ownerResult.data);
Expand All @@ -188038,6 +188043,19 @@ const robot = (app) => {
}
return [...new Set(allOwners)];
}
async function isProviderAlreadyBranded(apiUrl, identity, provider) {
const providerInfo = await axios_1.default.get(`${apiUrl}/providers/${provider}`);
if (!providerInfo) {
return { existing: false };
}
if (!providerInfo.data?.identity) {
return { existing: false };
}
return {
existing: true,
isUpdate: identity === providerInfo.data?.identity,
};
}
async function getAccountOwner(account) {
const accountOwner = account;
if (new out_1.Address(accountOwner).isContractAddress()) {
Expand Down Expand Up @@ -188065,11 +188083,27 @@ const robot = (app) => {
return tokenOwner;
}
async function getTokenOwnerFromApi(token, apiUrl) {
const tokenOwnerResponse = await axios_1.default.get(`${apiUrl}/tokens/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
try {
const tokenOwnerResponse = await axios_1.default.get(`${apiUrl}/tokens/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
}
return '';
}
catch (error) {
console.log(`Cannot find token owner on the 'tokens' endpoint. Will try the 'collections'`);
}
try {
const tokenOwnerResponse = await axios_1.default.get(`${apiUrl}/collections/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
}
return '';
}
catch (error) {
await fail(`Cannot find token or collection with ID ${token}: ${error}`);
return '';
}
return '';
}
function getApiUrl() {
switch (network) {
Expand Down
48 changes: 44 additions & 4 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export const robot = (app: Probot) => {
const apiUrl = getApiUrl();

for (const owner of allOwnersToCheck) {
const alreadyExistingBranding = await isProviderAlreadyBranded(apiUrl, asset as string, owner);
if (alreadyExistingBranding && alreadyExistingBranding.existing && !alreadyExistingBranding.isUpdate) {
await fail(`${owner} is already branded. Only updates are allowed.`);
return [];
}
if (new Address(owner).isContractAddress()) {
const ownerResult = await axios.get(`${apiUrl}/accounts/${owner}?extract=ownerAddress`);
allOwners.push(ownerResult.data);
Expand All @@ -77,6 +82,25 @@ export const robot = (app: Probot) => {
return [...new Set(allOwners)];
}

async function isProviderAlreadyBranded(apiUrl: string, identity: string, provider: string): Promise<{
existing: boolean,
isUpdate?: boolean
}> {
const providerInfo = await axios.get(`${apiUrl}/providers/${provider}`);
cfaur09 marked this conversation as resolved.
Show resolved Hide resolved
if (!providerInfo) {
return { existing: false };
}

if (!providerInfo.data?.identity) {
return { existing: false };
}

return {
existing: true,
isUpdate: identity === providerInfo.data?.identity,
};
}

async function getAccountOwner(account: string): Promise<string> {
const accountOwner = account;
if (new Address(accountOwner).isContractAddress()) {
Expand Down Expand Up @@ -111,12 +135,28 @@ export const robot = (app: Probot) => {
}

async function getTokenOwnerFromApi(token: string, apiUrl: string): Promise<string> {
cfaur09 marked this conversation as resolved.
Show resolved Hide resolved
const tokenOwnerResponse = await axios.get(`${apiUrl}/tokens/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
try {
const tokenOwnerResponse = await axios.get(`${apiUrl}/tokens/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
}

return '';
} catch (error) {
console.log(`Cannot find token owner on the 'tokens' endpoint. Will try the 'collections'`);
cfaur09 marked this conversation as resolved.
Show resolved Hide resolved
}

return '';
try {
const tokenOwnerResponse = await axios.get(`${apiUrl}/collections/${token}?extract=owner`);
if (tokenOwnerResponse && tokenOwnerResponse.data) {
return tokenOwnerResponse.data;
}

return '';
} catch (error) {
await fail(`Cannot find token or collection with ID ${token}: ${error}`);
return '';
}
}

function getApiUrl() {
Expand Down