mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: Adding mainFn helpers
This commit is contained in:
38
lib/mainFn/NetworkInterfaceBuilder.ts
Normal file
38
lib/mainFn/NetworkInterfaceBuilder.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Effects } from "../types";
|
||||
import { AddressReceipt } from "./AddressReceipt";
|
||||
import { Origin } from "./Origin";
|
||||
|
||||
export class NetworkInterfaceBuilder {
|
||||
constructor(
|
||||
readonly options: {
|
||||
effects: Effects;
|
||||
name: string;
|
||||
id: string;
|
||||
description: string;
|
||||
ui: boolean;
|
||||
basic?: null | { password: string; username: string };
|
||||
path?: string;
|
||||
search?: Record<string, string>;
|
||||
}
|
||||
) {}
|
||||
|
||||
async exportAddresses(addresses: Iterable<Origin>) {
|
||||
const { name, description, id, ui, path, search } = this.options;
|
||||
// prettier-ignore
|
||||
const urlAuth = !!(this.options?.basic) ? `${this.options.basic.username}:${this.options.basic.password}@` :
|
||||
'';
|
||||
for (const origin of addresses) {
|
||||
const address = `${origin.protocol}://${urlAuth}${origin.address}`;
|
||||
await this.options.effects.exportAddress({
|
||||
name,
|
||||
description,
|
||||
address,
|
||||
id,
|
||||
ui,
|
||||
path,
|
||||
search,
|
||||
});
|
||||
}
|
||||
return {} as AddressReceipt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user