-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add mainnet-local-v decorator * Fix nix hash * fix decorator Co-authored-by: Javier Viola <javier@parity.io> * Update javascript/packages/orchestrator/src/chain-decorators/index.ts * lint --------- Co-authored-by: valentinfernandez1 <valentinfernandez1@users.noreply.github.com> Co-authored-by: Javier Viola <javier@parity.io> Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
- Loading branch information
1 parent
7563e5c
commit 19a02a1
Showing
3 changed files
with
97 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
84 changes: 84 additions & 0 deletions
84
javascript/packages/orchestrator/src/chain-decorators/mainnet-local-v.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,84 @@ | ||
import { Keyring } from "@polkadot/api"; | ||
import { u8aToHex } from "@polkadot/util"; | ||
import { cryptoWaitReady } from "@polkadot/util-crypto"; | ||
import { CreateLogTable, decorators } from "@zombienet/utils"; | ||
import { | ||
GenesisNodeKey, | ||
getRuntimeConfig, | ||
readAndParseChainSpec, | ||
writeChainSpec, | ||
} from "../chainSpec"; | ||
import { generateKeyForNode as _generateKeyForNode } from "../keys"; | ||
import { Node } from "../sharedTypes"; | ||
|
||
async function generateKeyForNode(nodeName?: string): Promise<any> { | ||
const keys = await _generateKeyForNode(nodeName); | ||
|
||
await cryptoWaitReady(); | ||
|
||
const eth_keyring = new Keyring({ type: "ethereum" }); | ||
const eth_account = eth_keyring.createFromUri( | ||
`${keys.mnemonic}/m/44'/60'/0'/0/0`, | ||
); | ||
|
||
keys.eth_account = { | ||
address: eth_account.address, | ||
publicKey: u8aToHex(eth_account.publicKey), | ||
}; | ||
|
||
return keys; | ||
} | ||
|
||
export function getNodeKey(node: Node): GenesisNodeKey { | ||
try { | ||
const { sr_account, eth_account } = node.accounts; | ||
|
||
const key: GenesisNodeKey = [ | ||
eth_account.address, | ||
eth_account.address, | ||
{ | ||
aura: sr_account.address, | ||
}, | ||
]; | ||
|
||
return key; | ||
} catch (err) { | ||
console.error( | ||
`\n${decorators.red(`Fail to generate key for node: ${node}`)}`, | ||
); | ||
throw err; | ||
} | ||
} | ||
|
||
export async function addCollatorSelection(specPath: string, node: Node) { | ||
try { | ||
const chainSpec = readAndParseChainSpec(specPath); | ||
const runtimeConfig = getRuntimeConfig(chainSpec); | ||
if (!runtimeConfig?.collatorSelection?.invulnerables) return; | ||
|
||
const { eth_account } = node.accounts; | ||
|
||
runtimeConfig.collatorSelection.invulnerables.push(eth_account.address); | ||
|
||
new CreateLogTable({ | ||
colWidths: [30, 20, 70], | ||
}).pushToPrint([ | ||
[ | ||
decorators.cyan("👤 Added CollatorSelection "), | ||
decorators.green(node.name), | ||
decorators.magenta(eth_account.address), | ||
], | ||
]); | ||
|
||
writeChainSpec(specPath, chainSpec); | ||
} catch (err) { | ||
console.error(`\n${decorators.red(`Fail to add collator: ${node}`)}`); | ||
throw err; | ||
} | ||
} | ||
|
||
export default { | ||
getNodeKey, | ||
generateKeyForNode, | ||
addCollatorSelection, | ||
}; |