-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #935 from autonomys/feat/convert-genesis-allocatio…
…n-to-db-seeds Add script to convert genesis allocation to SQL seeds
- Loading branch information
Showing
9 changed files
with
217,589 additions
and
1 deletion.
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
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,6 @@ | ||
# DB scripts | ||
|
||
## Genesis allocation to seeds | ||
|
||
[genesis-allocation-to-seeds](./genesis-allocation-to-seeds/README.md) | ||
This script will take the genesis allocation JSON and convert it to seeds. The seeds will be added to the database. |
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 @@ | ||
seeds/ |
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,11 @@ | ||
# Genesis allocation to seeds | ||
|
||
## Description | ||
|
||
This script will take the genesis allocation JSON and convert it to seeds. The seeds will be added to the database. | ||
|
||
## Usage | ||
|
||
```bash | ||
deno run --allow-net --allow-write --allow-read --allow-env ./main.ts | ||
``` |
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,9 @@ | ||
{ | ||
"tasks": { | ||
"dev": "deno run --watch main.ts" | ||
}, | ||
"imports": { | ||
"@autonomys/auto-utils": "npm:@autonomys/auto-utils@^1.0.4", | ||
"@std/uuid": "jsr:@std/uuid@^1.0.4" | ||
} | ||
} |
651 changes: 651 additions & 0 deletions
651
indexers/db/scripts/genisis-allocation-to-seeds/deno.lock
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
import { NAMESPACE_DNS, v1, v5 } from "jsr:@std/uuid"; | ||
import { decode, Keyring } from "npm:@autonomys/auto-utils"; | ||
|
||
// Load the JSON data | ||
const response = await fetch( | ||
"https://raw.githubusercontent.com/autonomys/subspace/refs/heads/main/crates/subspace-node/src/genesis_allocations.json" | ||
); | ||
const data = await response.json(); | ||
|
||
// Ensure the seeds directory exists | ||
await Deno.mkdir("seeds", { recursive: true }); | ||
|
||
// Open a file to write the SQL output | ||
const accountsFile = await Deno.open("seeds/accounts.sql", { | ||
write: true, | ||
create: true, | ||
truncate: true, | ||
}); | ||
const accountHistoriesFile = await Deno.open("seeds/account_histories.sql", { | ||
write: true, | ||
create: true, | ||
truncate: true, | ||
}); | ||
|
||
// Iterate over each entry in the JSON data and generate the insert sql | ||
for (const entry of data) { | ||
const keyring = new Keyring({ type: "sr25519", ss58Format: 42 }); | ||
const accountId = keyring.encodeAddress(entry[0], 6094); | ||
const freeBalance = ( | ||
BigInt(entry[1]) * BigInt(1000000000000000000) | ||
).toString(); // Convert to 10^18 units | ||
const reservedBalance = "0"; | ||
const totalBalance = freeBalance; | ||
const createdAt = 0; | ||
const updatedAt = 0; | ||
const uniqueNamespace = await v1.generate(); | ||
const _id = await v5.generate(uniqueNamespace, accountId); | ||
const _blockRange = "[0,)"; | ||
|
||
await accountsFile.write( | ||
new TextEncoder().encode( | ||
`INSERT INTO consensus.accounts (id, nonce, free, reserved, total, created_at, updated_at, _id, _block_range) VALUES ('${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, ${updatedAt}, '${_id}', '${_blockRange}');\n` | ||
) | ||
); | ||
await accountHistoriesFile.write( | ||
new TextEncoder().encode( | ||
`INSERT INTO consensus.account_histories (id, nonce, free, reserved, total, created_at, updated_at, _id, _block_range) VALUES ('${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, ${updatedAt}, '${_id}', '${_blockRange}');\n` | ||
) | ||
); | ||
} | ||
|
||
// Close the file | ||
accountsFile.close(); | ||
accountHistoriesFile.close(); |
216,854 changes: 216,854 additions & 0 deletions
216,854
indexers/db/seeds/default/genesis_allocation.sql
Large diffs are not rendered by default.
Oops, something went wrong.
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