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

chore: add validators #181

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 28 additions & 12 deletions bin/commands/set-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ exports.builder = yargs => {
.option('nodes', {
describe: 'JSON file path which has nodes list'
})
.option('action', {
describe: 'The nodes operation to take: add, update or remove',
choices: ['add', 'update', 'remove']
})
};

exports.handler = async function (argv) {
Expand All @@ -28,6 +32,12 @@ exports.handler = async function (argv) {
const file = fs.readFileSync(filename);
const nodes = JSON.parse(file.toString());

const action = argv.action;
const actions = {};
for (let a of ['add', 'update', 'remove']) {
actions[a] = !action || action === a;
}

const near = await init(argv.network);
const signer = await near.account(argv.signer);
const contract = await near.account(address);
Expand Down Expand Up @@ -59,14 +69,20 @@ exports.handler = async function (argv) {
});
}

console.log('Nodes to add:');
console.log(nodesToAdd);
if (actions['add']) {
console.log('Nodes to add:');
console.log(nodesToAdd);
}

console.log('Nodes to update:');
console.log(nodesToUpdate);
if (actions['update']) {
console.log('Nodes to update:');
console.log(nodesToUpdate);
}

console.log('Nodes to remove:');
console.log(nodesToRemove);
if (actions['remove']) {
console.log('Nodes to remove:');
console.log(nodesToRemove);
}

const res = await prompts({
type: 'confirm',
Expand All @@ -77,7 +93,7 @@ exports.handler = async function (argv) {

// Add
// in case the list is too long, we cut it into chunks
if (nodesToAdd.length > 0) {
if (actions['add'] && nodesToAdd.length > 0) {
const chunks = chunkList(nodesToAdd, 5);
for (const chunkNodes of chunks) {
await signer.functionCall({
Expand All @@ -91,11 +107,11 @@ exports.handler = async function (argv) {
});
console.log(`added ${chunkNodes.length} nodes`);
}
console.log(`Added ${nodesToAdd.length} nodes in total`);
}
console.log(`Added ${nodesToAdd.length} nodes in total`);

// Update
if (nodesToUpdate.length > 0) {
if (actions['update'] && nodesToUpdate.length > 0) {
await signer.functionCall({
contractId: address,
methodName: 'update_weights',
Expand All @@ -105,12 +121,12 @@ exports.handler = async function (argv) {
},
gas: Gas.parse('300 Tgas')
});
console.log(`Weights updated for ${nodesToUpdate.length} nodes`);
}
console.log(`Weights updated for ${nodesToUpdate.length} nodes`);

// Remove
// set weight to zero instead of remove it
if (nodesToRemove.length > 0) {
if (actions['remove'] && nodesToRemove.length > 0) {
await signer.functionCall({
contractId: address,
methodName: 'update_weights',
Expand All @@ -120,8 +136,8 @@ exports.handler = async function (argv) {
},
gas: Gas.parse('300 Tgas')
});
console.log(`Weights set to 0 for ${nodesToRemove.length} nodes`);
}
console.log(`Weights set to 0 for ${nodesToRemove.length} nodes`);

console.log('done.');
}
Expand Down
8 changes: 8 additions & 0 deletions nodes-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -878,5 +878,13 @@
{
"id": "cryptotribe.poolv1.near",
"weight": 0
},
{
"id": "colossus.poolv1.near",
"weight": 0
},
{
"id": "fialka.poolv1.near",
"weight": 0
}
]
8 changes: 8 additions & 0 deletions nodes-stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -882,5 +882,13 @@
{
"id": "cryptotribe.poolv1.near",
"weight": 0
},
{
"id": "colossus.poolv1.near",
"weight": 0
},
{
"id": "fialka.poolv1.near",
"weight": 0
}
]