rosetta-sdk-typescript
Version:
Typescript SDK to create and interact with Rosetta API implementations.
233 lines (206 loc) • 18.4 kB
text/typescript
/* tslint:disable */
/* eslint-disable */
/**
* Rosetta
* Build Once. Integrate Your Blockchain Everywhere.
*
* The version of the OpenAPI document: 1.4.10
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import {
BlockRequest,
BlockRequestFromJSON,
BlockRequestToJSON,
BlockResponse,
BlockResponseFromJSON,
BlockResponseToJSON,
BlockTransactionRequest,
BlockTransactionRequestFromJSON,
BlockTransactionRequestToJSON,
BlockTransactionResponse,
BlockTransactionResponseFromJSON,
BlockTransactionResponseToJSON,
} from '../models';
import * as runtime from '../runtime';
export interface BlockOperationRequest {
blockRequest: BlockRequest;
}
export interface BlockTransactionOperationRequest {
blockTransactionRequest: BlockTransactionRequest;
}
/**
* BlockApi - controller interface for the server side implementation.
*
* @export
* @interface BlockApiController
*/
export class BlockApiController<Req extends { body: any } = { body: any }> {
/**
*
* @param service - The service that implements
*/
constructor(private readonly service: BlockApiService) {}
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* Get a Block
*
* @param req - The request object, where the body is a BlockRequest
*/
block(req: Req): Promise<any> {
return this.service.block(BlockRequestFromJSON(req.body)).then(BlockResponseToJSON);
}
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* Get a Block Transaction
*
* @param req - The request object, where the body is a BlockTransactionRequest
*/
blockTransaction(req: Req): Promise<any> {
return this.service.blockTransaction(BlockTransactionRequestFromJSON(req.body)).then(BlockTransactionResponseToJSON);
}
}
/**
* BlockApi - service interface for the server side implementation.
*
*
* @export
* @interface BlockApiService
*/
export interface BlockApiService {
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* Get a Block
*
* requestParameters - the body of the RPC style request.
*/
block(requestParameters: BlockRequest): Promise<BlockResponse>;
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* Get a Block Transaction
*
* requestParameters - the body of the RPC style request.
*/
blockTransaction(requestParameters: BlockTransactionRequest): Promise<BlockTransactionResponse>;
}
/**
* BlockApi - interface
*
* @export
* @interface BlockApiInterface
*/
export interface BlockApiInterface {
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* @summary Get a Block
* @param {BlockRequest} blockRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof BlockApiInterface
*/
blockRaw(requestParameters: BlockOperationRequest, initOverrides?: RequestInit): Promise<runtime.ApiResponse<BlockResponse>>;
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* Get a Block
*/
block(requestParameters: BlockOperationRequest, initOverrides?: RequestInit): Promise<BlockResponse>;
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* @summary Get a Block Transaction
* @param {BlockTransactionRequest} blockTransactionRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof BlockApiInterface
*/
blockTransactionRaw(
requestParameters: BlockTransactionOperationRequest,
initOverrides?: RequestInit,
): Promise<runtime.ApiResponse<BlockTransactionResponse>>;
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* Get a Block Transaction
*/
blockTransaction(requestParameters: BlockTransactionOperationRequest, initOverrides?: RequestInit): Promise<BlockTransactionResponse>;
}
/**
*
*/
export class BlockApi extends runtime.BaseAPI implements BlockApiInterface {
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* Get a Block
*/
async blockRaw(requestParameters: BlockOperationRequest, initOverrides?: RequestInit): Promise<runtime.ApiResponse<BlockResponse>> {
if (requestParameters.blockRequest === null || requestParameters.blockRequest === undefined) {
throw new runtime.RequiredError(
'blockRequest',
'Required parameter requestParameters.blockRequest was null or undefined when calling block.',
);
}
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
headerParameters['Content-Type'] = 'application/json';
const response = await this.request(
{
path: `/block`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: BlockRequestToJSON(requestParameters.blockRequest),
},
initOverrides,
);
return new runtime.JSONApiResponse(response, (jsonValue) => BlockResponseFromJSON(jsonValue));
}
/**
* Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information. When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents. No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one.
* Get a Block
*/
async block(requestParameters: BlockOperationRequest, initOverrides?: RequestInit): Promise<BlockResponse> {
const response = await this.blockRaw(requestParameters, initOverrides);
return await response.value();
}
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* Get a Block Transaction
*/
async blockTransactionRaw(
requestParameters: BlockTransactionOperationRequest,
initOverrides?: RequestInit,
): Promise<runtime.ApiResponse<BlockTransactionResponse>> {
if (requestParameters.blockTransactionRequest === null || requestParameters.blockTransactionRequest === undefined) {
throw new runtime.RequiredError(
'blockTransactionRequest',
'Required parameter requestParameters.blockTransactionRequest was null or undefined when calling blockTransaction.',
);
}
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
headerParameters['Content-Type'] = 'application/json';
const response = await this.request(
{
path: `/block/transaction`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: BlockTransactionRequestToJSON(requestParameters.blockTransactionRequest),
},
initOverrides,
);
return new runtime.JSONApiResponse(response, (jsonValue) => BlockTransactionResponseFromJSON(jsonValue));
}
/**
* Get a transaction in a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it. All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section). This method can be used to let consumers to paginate results when the block trasactions count is too big to be returned in a single BlockResponse. Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org). Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node).
* Get a Block Transaction
*/
async blockTransaction(
requestParameters: BlockTransactionOperationRequest,
initOverrides?: RequestInit,
): Promise<BlockTransactionResponse> {
const response = await this.blockTransactionRaw(requestParameters, initOverrides);
return await response.value();
}
}