Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bulk functions #209

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 21 additions & 44 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import {
ContractUploadRequest,
ContractTemplateDto,
PendingTokenLinkDto, Web3ConnectionFeeLevel,
Task, Job, JobCreatedResponse
BatchTask, BatchJob, JobCreatedResponse
} from "./types";
import { AxiosProxyConfig, AxiosResponse } from "axios";
import { PIIEncryption } from "./pii-client";
Expand Down Expand Up @@ -661,19 +661,6 @@ export class FireblocksSDK {
return await this.apiClient.issuePostRequest("/v1/vault/accounts", body, requestOptions);
}

/**
* Creates a new vault account
* @param count Number of new vault accounts requested
* @param requestOptions
*/
public async createVaultAccountBulk(count: number, requestOptions?: RequestOptions): Promise<JobCreatedResponse> {
const body = {
count
};

return await this.apiClient.issuePostRequest("/v1/vault/accounts/bulk", body, requestOptions);
}

/**
* Hides a vault account in Fireblocks console
* @param vaultAccountId The vault account ID
Expand Down Expand Up @@ -707,12 +694,12 @@ export class FireblocksSDK {
* @param vaultAccountId
* @param name A new name for the vault account
*/
public async updateVaultAccount(vaultAccountId: string, name: string): Promise<VaultAccountResponse> {
public async updateVaultAccount(vaultAccountId: string, name: string, requestOptions?: RequestOptions): Promise<VaultAccountResponse> {
const body = {
name: name
};

return await this.apiClient.issuePutRequest(`/v1/vault/accounts/${vaultAccountId}`, body);
return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}`, body, requestOptions);
}

/**
Expand All @@ -725,20 +712,6 @@ export class FireblocksSDK {
return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`, {}, requestOptions);
}

/**
* Creates a new asset within a list of existing vault accounts
* @param assetId The asset to add
* @param vaultAccountIdFrom The first of the account ID range
* @param vaultAccountIdTo The last of the account ID range
* @param requestOptions
*/
public async createVaultAssetBulk(assetId: string, vaultAccountIdFrom: string, vaultAccountIdTo: string, requestOptions?: RequestOptions): Promise<JobCreatedResponse> {
const body = {
assetId, vaultAccountIdFrom, vaultAccountIdTo
};
return await this.apiClient.issuePostRequest(`/v1/vault/assets/bulk`, body, requestOptions);
}

/**
* Retry to create a vault asset for a vault asset that failed
* @param vaultAccountId The vault account ID
Expand Down Expand Up @@ -1851,26 +1824,26 @@ export class FireblocksSDK {

/**
* Get list of jobs for current tenant
* @param fromTime beggining of time range in MS since 1970
* @param toTime ending of time range in MS since 1970
* @param fromTime beggining of time range in Unix Epoch
* @param toTime ending of time range in Unix Epoch
*/
public getJobs(fromTime: number, toTime: number): Promise<Job[]> {
public getJobsForTenant(fromTime: number, toTime: number): Promise<BatchJob[]> {
gadiguy marked this conversation as resolved.
Show resolved Hide resolved
return this.apiClient.issueGetRequest(`/v1/batch/jobs?fromTime=${fromTime}&toTime=${toTime}`);
}

/**
* Get job info by job ID
* @param jobId
*/
public getJob(jobId: string): Promise<Job> {
public getJobById(jobId: string): Promise<BatchJob> {
return this.apiClient.issueGetRequest(`/v1/batch/${jobId}`);
}

/**
* Get tasks belonging to given job
* @param jobId
*/
public getTasks(jobId: string): Promise<Task> {
public getTasksByJobId(jobId: string): Promise<BatchTask> {
return this.apiClient.issueGetRequest(`/v1/batch/${jobId}/tasks`);
}

Expand Down Expand Up @@ -1901,25 +1874,29 @@ export class FireblocksSDK {
/**
* Create multiple vault accounts in one bulk operation
gadiguy marked this conversation as resolved.
Show resolved Hide resolved
* @param count number of vault accounts
* @param assetId optional asset id to create in each new account
* @param requestOptions
*/
public createVaultAccountsBulk(count: number, assetId: string): Promise<JobCreatedResponse> {
public createVaultAccountsBulk(count: number, assetId: string, requestOptions?: RequestOptions): Promise<JobCreatedResponse> {
const body = {
count,
assetId
};
return this.apiClient.issuePostRequest(`/v1/vault/accounts/bulk`, body);
return this.apiClient.issuePostRequest(`/v1/vault/accounts/bulk`, body, requestOptions);
}

/**
* Create multiple vault wallets in one bulk operation
* @param count number of vault accounts
* Creates a new asset within a list of existing vault accounts
* @param assetId The asset to add
* @param vaultAccountIdFrom The first of the account ID range
* @param vaultAccountIdTo The last of the account ID range
* @param requestOptions
*/
public createVaultWalletsBulk(assetId: string, vaultAccountIdFrom: string, vaultAccountIdTo: string): Promise<JobCreatedResponse> {
public async createVaultAssetsBulk(assetId: string, vaultAccountIdFrom: string, vaultAccountIdTo: string, requestOptions?: RequestOptions): Promise<JobCreatedResponse> {
const body = {
assetId,
vaultAccountIdFrom,
vaultAccountIdTo
assetId, vaultAccountIdFrom, vaultAccountIdTo
};
return this.apiClient.issuePostRequest(`/v1/vault/assets/bulk`, body);
return await this.apiClient.issuePostRequest(`/v1/vault/assets/bulk`, body, requestOptions);
}

}
13 changes: 6 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,35 +1516,34 @@ export interface JobCreatedResponse {
jobId: string;
}

export enum Status {
NONE = "NONE",
export enum BatchStatus {
CREATED = "CREATED",
INPROGRESS = "INPROGRESS",
IN_PROGRESS = "INPROGRESS",
DONE = "DONE",
ERROR = "ERROR",
CANCELED = "CANCELED",
PAUSED = "PAUSED"
}

export class Job {
export class BatchJob {
id: string;
tenantId: string;
type: string;
userId: string;
created: number;
updated?: number;
state: Status;
state: BatchJob;
data: string;
}

export class Task {
export class BatchTask {
id: string;
jobId: string;
type: string;
tenantId: string;
created: number;
updated?: number;
state: Status;
state: BatchStatus;
data?: string;
result?: string;
}
Expand Down