Skip to content

Commit

Permalink
feat: added network parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mpsc0x committed Oct 14, 2024
1 parent d9f9de5 commit 0e113bc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/clients/aptosProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface AptosProviderConfig {
}

export interface AptosAccountConfig {
network: string;
private_key: string;
public_key: string;
account: string;
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 0e113bc

Please sign in to comment.