From 0e113bcd22b2543dcc9871d26ec90e1ba58ca332 Mon Sep 17 00:00:00 2001 From: mpsc0x Date: Mon, 14 Oct 2024 16:50:25 +0300 Subject: [PATCH] feat: added network parsing --- src/clients/aptosProvider.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/clients/aptosProvider.ts b/src/clients/aptosProvider.ts index 1f36a8e..52a5d98 100644 --- a/src/clients/aptosProvider.ts +++ b/src/clients/aptosProvider.ts @@ -30,6 +30,7 @@ export interface AptosProviderConfig { } export interface AptosAccountConfig { + network: string; private_key: string; public_key: string; account: string; @@ -135,6 +136,31 @@ export class AptosProvider { const parsedYaml = YAML.parse(aptosConfigData); for (const profile of Object.keys(parsedYaml.profiles)) { const profileConfig = parsedYaml.profiles[profile] as AptosAccountConfig; + + // extract network + switch (profileConfig.network.toLowerCase()) { + case "testnet": { + aptosProvider.setNetwork(Network.TESTNET); + break; + } + case "devnet": { + aptosProvider.setNetwork(Network.DEVNET); + break; + } + case "mainnet": { + aptosProvider.setNetwork(Network.MAINNET); + break; + } + case "local": { + aptosProvider.setNetwork(Network.LOCAL); + break; + } + default: + throw new Error( + `Unknown network ${profileConfig.network ? profileConfig.network : "undefined"}`, + ); + } + const aptosPrivateKey = new Ed25519PrivateKey(profileConfig.private_key); aptosProvider.addProfileAccount(profile, aptosPrivateKey); const profileAccount = Account.fromPrivateKey({