-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
755 additions
and
9,756 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
cache |
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,25 @@ | ||
# Evolve Many | ||
|
||
Sometimes, you will have multiple HollowDB contracts and you would like to evolve all of them to a newer version. Doing this via the CLI in HollowDB may be cumbersome, especially for a large number of contracts. | ||
|
||
## Installation | ||
|
||
This script only makes use Warp and Chalk (for nice outputs), install them via: | ||
|
||
```sh | ||
yarn install | ||
``` | ||
|
||
## Usage | ||
|
||
The main script is `index.js`, to configure the script you must: | ||
|
||
- Specify the contracts to be evolved as an array within [contract.js](./contracts.js) | ||
- Provide the source txID for the new contract source code, within [index.js](./index.js) | ||
- Provide a path to the wallet that is the owner of all these contracts, again within [index.js](./index.js) | ||
|
||
With these configured, simply: | ||
|
||
```sh | ||
yarn evolve | ||
``` |
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,3 @@ | ||
export const contractTxIds = [ | ||
/** your list of contracts here */ | ||
]; |
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,42 @@ | ||
import {readFileSync} from 'fs'; | ||
import {LoggerFactory, WarpFactory, sleep} from 'warp-contracts'; | ||
import {contractTxIds} from './contracts.js'; | ||
import chalk from 'chalk'; | ||
|
||
// new source txId for evolve | ||
const srcTxId = 'your-txid-here'; | ||
|
||
// your wallet should be the contract owner for evolve to happen | ||
const walletPath = '/path/to/wallet.json'; | ||
const owner = JSON.parse(readFileSync(walletPath, 'utf-8')); | ||
|
||
// create warp instance | ||
const warp = WarpFactory.forMainnet(); | ||
|
||
// `none` hides Warp logs, can be a different level if you want | ||
LoggerFactory.INST.logLevel('none'); | ||
|
||
// each evolve takes around 200-300ms to finish | ||
// if you want to start from a later index, just change the `i` below | ||
// to something like `i = startIdx` | ||
for (let i = 0; i < contractTxIds.length; i++) { | ||
try { | ||
const idxStr = chalk.yellow(`[${i.toString().padEnd(5, '')}]`); | ||
const contractTxId = contractTxIds[i]; | ||
console.log(`${idxStr} ${contractTxId} beginning to evolve.`); | ||
const msg = chalk.green(`${idxStr} ${contractTxId} evolved`); | ||
|
||
// the main evolve logic | ||
console.time(msg); | ||
const contract = warp.contract(contractTxId).connect(owner); | ||
await contract.evolve(srcTxId); | ||
console.timeEnd(msg); | ||
|
||
// sleep a bit to avoid rate-limiting | ||
await sleep(1000); | ||
} catch { | ||
// timed-out, try again after a long sleep | ||
i--; | ||
await sleep(7000); | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"name": "evolve-many", | ||
"version": "0.1.0", | ||
"private": true, | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"evolve": "node index.js" | ||
}, | ||
"dependencies": { | ||
"chalk": "^5.3.0", | ||
"warp-contracts": "^1.4.36" | ||
} | ||
} |
Oops, something went wrong.