New transaction.getInterchain and block.getInterchain call the prime-node
/api/v1/{transaction,block}/{id}/interchain endpoints, returning an
InterchainTrace { blockId, validatorBlocks, interchainTransactions }. Adds
VerificationBlock / InterchainTransaction / InterchainTrace interfaces and
method-existence assertions.
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
/**
|
|
* Transaction module for managing Dragonchain transactions
|
|
*/
|
|
|
|
import { DragonchainClient } from './client';
|
|
import {
|
|
ContentType,
|
|
TransactionCreateRequest,
|
|
TransactionCreateResponse,
|
|
TransactionBulkRequest,
|
|
TransactionBulkResponse,
|
|
Transaction,
|
|
ListTransactionsResponse,
|
|
InterchainTrace,
|
|
} 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}`);
|
|
}
|
|
|
|
/**
|
|
* Traces a transaction to the validator (verification) blocks that validated
|
|
* its prime block and the public-chain interchain anchors those validator
|
|
* blocks were bundled into. If the transaction is still pending (not yet in a
|
|
* block) the trace's arrays are empty.
|
|
*/
|
|
async getInterchain(transactionId: string): Promise<InterchainTrace> {
|
|
return this.client.get<InterchainTrace>(`/api/v1/transaction/${transactionId}/interchain`);
|
|
}
|
|
|
|
/**
|
|
* Lists all transactions
|
|
*/
|
|
async list(): Promise<ListTransactionsResponse> {
|
|
return this.client.get<ListTransactionsResponse>('/api/v1/transaction/');
|
|
}
|
|
}
|