restake 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +17 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -57,13 +57,13 @@ async function validatePrivateKeys() {
57
57
  }
58
58
  function runLoop() {
59
59
  cafe_utility_1.System.forever(async () => {
60
- const port = BASE_PORT + cafe_utility_1.Random.intBetween(0, n - 1);
61
- const bee = new bee_js_1.Bee(`http://localhost:${port}`);
62
- const wallet = await bee.getWalletBalance();
63
- if (wallet.bzzBalance.lt(bzz)) {
64
- console.log(`:${port} balance is ${wallet.bzzBalance.toDecimalString()} BZZ, skipping`);
60
+ const eligiblePorts = await findEligiblePorts();
61
+ if (eligiblePorts.length === 0) {
62
+ console.log('no eligible nodes found, skipping');
65
63
  return;
66
64
  }
65
+ const port = cafe_utility_1.Arrays.pick(eligiblePorts);
66
+ const bee = new bee_js_1.Bee(`http://localhost:${port}`);
67
67
  if (cafe_utility_1.Random.chance(1 / 4)) {
68
68
  await runAction(port, `stake ${bzz.toDecimalString()} BZZ`, () => stake(bee, port));
69
69
  }
@@ -78,6 +78,18 @@ function runLoop() {
78
78
  }
79
79
  }, sleep, console.error);
80
80
  }
81
+ async function findEligiblePorts() {
82
+ const eligible = [];
83
+ for (let i = 0; i < n; i++) {
84
+ const port = BASE_PORT + i;
85
+ const bee = new bee_js_1.Bee(`http://localhost:${port}`);
86
+ const [wallet, redistribution] = await Promise.all([bee.getWalletBalance(), bee.getRedistributionState()]);
87
+ if (!redistribution.isFrozen && wallet.bzzBalance.gte(bzz)) {
88
+ eligible.push(port);
89
+ }
90
+ }
91
+ return eligible;
92
+ }
81
93
  async function runAction(port, description, action) {
82
94
  try {
83
95
  await action();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "restake",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "restake": "./dist/index.js"