Skip to content

Commit

Permalink
single account onwer + added default admin wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Feb 19, 2024
1 parent 6693735 commit 0f97ab2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 70 deletions.
53 changes: 19 additions & 34 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -188044,41 +188044,25 @@ const robot = (app) => {
}
return [...new Set(allOwners)];
}
async function getAccountOwner(files) {
const originalOwner = identity;
let newOwner = '';
const infoJsonFile = files.find(x => x.filename.endsWith(`/${identity}.json`));
if (infoJsonFile) {
const { data: infoFromPullRequest } = await axios_1.default.get(infoJsonFile.raw_url);
if (infoFromPullRequest && typeof infoFromPullRequest === 'object') {
newOwner = identity ?? '';
}
async function getAccountOwner() {
if (!identity) {
return '';
}
const account = identity;
let apiUrl = 'https://next-api.multiversx.com';
if (network === 'devnet') {
apiUrl = 'https://devnet-api.multiversx.com';
}
else if (network === 'testnet') {
apiUrl = 'https://testnet-api.multiversx.com';
}
const allOwners = [];
let allOwnersToCheck = [];
if (newOwner) {
allOwnersToCheck = [...allOwnersToCheck, newOwner];
}
if (originalOwner) {
allOwnersToCheck = [...allOwnersToCheck, originalOwner];
}
for (const owner of allOwnersToCheck) {
if (new out_1.Address(owner).isContractAddress()) {
const ownerResult = await axios_1.default.get(`${apiUrl}/accounts/${owner}?extract=ownerAddress`);
allOwners.push(ownerResult.data);
}
else {
allOwners.push(owner);
}
const ownerResult = await axios_1.default.get(`${apiUrl}/accounts/${account}?extract=ownerAddress`);
const accountOwner = ownerResult.data;
if (new out_1.Address(accountOwner).isContractAddress()) {
const ownerResult = await axios_1.default.get(`${apiUrl}/tokens/${accountOwner}?extract=ownerAddress`);
return ownerResult.data;
}
return [...new Set(allOwners)];
return accountOwner;
}
async function getTokenOwner() {
// since the token owner can be changed at protocol level at any time, it's enough to check the ownership of the token,
Expand Down Expand Up @@ -188257,13 +188241,14 @@ const robot = (app) => {
});
const body = pullRequest.body || '';
const bodies = [...comments.data.map(x => x.body || ''), body];
const adminAddress = process.env.ADMIN_ADDRESS;
if (adminAddress) {
const invalidAddresses = await multiVerify(bodies, [adminAddress], commitShas);
if (invalidAddresses && invalidAddresses.length === 0) {
await createComment(`Signature OK. Verified that the latest commit hash \`${lastCommitSha}\` was signed using the admin wallet address`);
return;
}
let adminAddress = process.env.ADMIN_ADDRESS;
if (!adminAddress) {
adminAddress = 'erd1cevsw7mq5uvqymjqzwqvpqtdrhckehwfz99n7praty3y7q2j7yps842mqh';
}
const invalidAddressesForAdminChecks = await multiVerify(bodies, [adminAddress], commitShas);
if (invalidAddressesForAdminChecks && invalidAddressesForAdminChecks.length === 0) {
await createComment(`Signature OK. Verified that the latest commit hash \`${lastCommitSha}\` was signed using the admin wallet address`);
return;
}
if (distinctIdentities.length > 1) {
await fail('Only one identity must be edited at a time');
Expand All @@ -188281,7 +188266,7 @@ const robot = (app) => {
owners = await getIdentityOwners(changedFiles);
break;
case 'account':
owners = await getAccountOwner(changedFiles);
owners = [...await getAccountOwner()];
break;
case 'token':
owners = [...await getTokenOwner()];
Expand Down
55 changes: 19 additions & 36 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,11 @@ export const robot = (app: Probot) => {
return [...new Set(allOwners)];
}

async function getAccountOwner(files: { filename: string, raw_url: string }[]): Promise<string[]> {
const originalOwner = identity;
let newOwner: string = '';

const infoJsonFile = files.find(x => x.filename.endsWith(`/${identity}.json`));
if (infoJsonFile) {
const { data: infoFromPullRequest } = await axios.get(infoJsonFile.raw_url);

if (infoFromPullRequest && typeof infoFromPullRequest === 'object') {
newOwner = identity ?? '';
}
async function getAccountOwner(): Promise<string> {
if (!identity) {
return '';
}
const account = identity;

let apiUrl = 'https://next-api.multiversx.com';
if (network === 'devnet') {
Expand All @@ -102,25 +95,14 @@ export const robot = (app: Probot) => {
apiUrl = 'https://testnet-api.multiversx.com';
}

const allOwners: string[] = [];
let allOwnersToCheck: string[] = [];
if (newOwner) {
allOwnersToCheck = [...allOwnersToCheck, newOwner];
}
if (originalOwner) {
allOwnersToCheck = [...allOwnersToCheck, originalOwner];
}

for (const owner of allOwnersToCheck) {
if (new Address(owner).isContractAddress()) {
const ownerResult = await axios.get(`${apiUrl}/accounts/${owner}?extract=ownerAddress`);
allOwners.push(ownerResult.data);
} else {
allOwners.push(owner);
}
const ownerResult = await axios.get(`${apiUrl}/accounts/${account}?extract=ownerAddress`);
const accountOwner = ownerResult.data;
if (new Address(accountOwner).isContractAddress()) {
const ownerResult = await axios.get(`${apiUrl}/tokens/${accountOwner}?extract=ownerAddress`);
return ownerResult.data;
}

return [...new Set(allOwners)];
return accountOwner;
}

async function getTokenOwner(): Promise<string> {
Expand Down Expand Up @@ -351,14 +333,15 @@ export const robot = (app: Probot) => {

const bodies = [...comments.data.map(x => x.body || ''), body];

const adminAddress = process.env.ADMIN_ADDRESS;
let adminAddress = process.env.ADMIN_ADDRESS;
if (!adminAddress) {
adminAddress = 'erd1cevsw7mq5uvqymjqzwqvpqtdrhckehwfz99n7praty3y7q2j7yps842mqh';
}

if (adminAddress) {
const invalidAddresses = await multiVerify(bodies, [adminAddress], commitShas);
if (invalidAddresses && invalidAddresses.length === 0) {
await createComment(`Signature OK. Verified that the latest commit hash \`${lastCommitSha}\` was signed using the admin wallet address`);
return;
}
const invalidAddressesForAdminChecks = await multiVerify(bodies, [adminAddress], commitShas);
if (invalidAddressesForAdminChecks && invalidAddressesForAdminChecks.length === 0) {
await createComment(`Signature OK. Verified that the latest commit hash \`${lastCommitSha}\` was signed using the admin wallet address`);
return;
}

if (distinctIdentities.length > 1) {
Expand All @@ -380,7 +363,7 @@ export const robot = (app: Probot) => {
owners = await getIdentityOwners(changedFiles);
break;
case 'account':
owners = await getAccountOwner(changedFiles);
owners = [...await getAccountOwner()];
break;
case 'token':
owners = [...await getTokenOwner()];
Expand Down

0 comments on commit 0f97ab2

Please sign in to comment.