Initial Commit
This commit is contained in:
58
src/transaction.ts
Normal file
58
src/transaction.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Transaction module for managing Dragonchain transactions
|
||||
*/
|
||||
|
||||
import { DragonchainClient } from './client';
|
||||
import {
|
||||
ContentType,
|
||||
TransactionCreateRequest,
|
||||
TransactionCreateResponse,
|
||||
TransactionBulkRequest,
|
||||
TransactionBulkResponse,
|
||||
Transaction,
|
||||
ListTransactionsResponse,
|
||||
} from './types';
|
||||
|
||||
export class TransactionClient {
|
||||
private client: DragonchainClient;
|
||||
|
||||
constructor(client: DragonchainClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new transaction
|
||||
*/
|
||||
async create(request: TransactionCreateRequest): Promise<TransactionCreateResponse> {
|
||||
return this.client.post<TransactionCreateResponse>(
|
||||
'/api/v1/transaction',
|
||||
ContentType.JSON,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates multiple transactions in bulk
|
||||
*/
|
||||
async createBulk(request: TransactionBulkRequest): Promise<TransactionBulkResponse> {
|
||||
return this.client.post<TransactionBulkResponse>(
|
||||
'/api/v1/transaction/bulk',
|
||||
ContentType.JSON,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a transaction by ID
|
||||
*/
|
||||
async get(transactionId: string): Promise<Transaction> {
|
||||
return this.client.get<Transaction>(`/api/v1/transaction/${transactionId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all transactions
|
||||
*/
|
||||
async list(): Promise<ListTransactionsResponse> {
|
||||
return this.client.get<ListTransactionsResponse>('/api/v1/transaction/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user