UNPKG

rosetta-sdk-typescript

Version:

Typescript SDK to create and interact with Rosetta API implementations.

151 lines (150 loc) 11.7 kB
"use strict"; /* 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. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlockApi = exports.BlockApiController = void 0; const models_1 = require("../models"); const runtime = __importStar(require("../runtime")); /** * BlockApi - controller interface for the server side implementation. * * @export * @interface BlockApiController */ class BlockApiController { /** * * @param service - The service that implements */ constructor(service) { this.service = service; } /** * 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) { return this.service.block(models_1.BlockRequestFromJSON(req.body)).then(models_1.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) { return this.service.blockTransaction(models_1.BlockTransactionRequestFromJSON(req.body)).then(models_1.BlockTransactionResponseToJSON); } } exports.BlockApiController = BlockApiController; /** * */ class BlockApi extends runtime.BaseAPI { /** * 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 */ blockRaw(requestParameters, initOverrides) { return __awaiter(this, void 0, void 0, function* () { 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 = {}; const headerParameters = {}; headerParameters['Content-Type'] = 'application/json'; const response = yield this.request({ path: `/block`, method: 'POST', headers: headerParameters, query: queryParameters, body: models_1.BlockRequestToJSON(requestParameters.blockRequest), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => models_1.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 */ block(requestParameters, initOverrides) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.blockRaw(requestParameters, initOverrides); return yield 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 */ blockTransactionRaw(requestParameters, initOverrides) { return __awaiter(this, void 0, void 0, function* () { 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 = {}; const headerParameters = {}; headerParameters['Content-Type'] = 'application/json'; const response = yield this.request({ path: `/block/transaction`, method: 'POST', headers: headerParameters, query: queryParameters, body: models_1.BlockTransactionRequestToJSON(requestParameters.blockTransactionRequest), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => models_1.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 */ blockTransaction(requestParameters, initOverrides) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.blockTransactionRaw(requestParameters, initOverrides); return yield response.value(); }); } } exports.BlockApi = BlockApi;