Skip to content

Commit

Permalink
Merge pull request #26 from vespr-wallet/alex/datum
Browse files Browse the repository at this point in the history
Alex/datum
  • Loading branch information
Vardominator authored Dec 4, 2023
2 parents aecd8c0 + 51756b8 commit de2dbf9
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 11 deletions.
57 changes: 55 additions & 2 deletions src/api/datum/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
setSearchParams,
toPathString,
createRequestFunction,
serializeDataIfNeeded,
} from '../../common';
import { Configuration } from '../../configuration';
import { TimestampedDatum } from '../type';
import { TimestampedDatum, TimestampedDatums } from '../type';

/**
* DatumApi - axios parameter creator
Expand All @@ -27,7 +28,7 @@ export const DatumApiAxiosParamCreator = function (configuration: Configuration)
lookupDatum: async (datumHash: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'datumHash' is not null or undefined
assertParamExists('lookupDatum', 'datumHash', datumHash);
const localVarPath = `/datum/{datum_hash}`.replace(
const localVarPath = `/datums/{datum_hash}`.replace(
`{${'datum_hash'}}`,
encodeURIComponent(String(datumHash)),
);
Expand All @@ -50,6 +51,44 @@ export const DatumApiAxiosParamCreator = function (configuration: Configuration)
...options.headers,
};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Returns the datums corresponding to the specified datum hashes, for the datums which have been seen on-chain
* @summary Datums by datum hashes
* @param {Array<string>} requestBody Array of hex encoded datum hashes
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
lookupDatums: async (requestBody: Array<string>, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'requestBody' is not null or undefined
assertParamExists('lookupDatums', 'requestBody', requestBody);
const localVarPath = `/datums`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
const { baseOptions } = configuration;

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication api-key required
setApiKeyToObject(localVarHeaderParameter, 'api-key', configuration);

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
};
localVarRequestOptions.data = serializeDataIfNeeded(requestBody, localVarRequestOptions, configuration);

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
Expand Down Expand Up @@ -79,6 +118,20 @@ export const DatumApiFp = function (configuration: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.lookupDatum(datumHash, options);
return createRequestFunction(localVarAxiosArgs, configuration);
},
/**
* Returns the datums corresponding to the specified datum hashes, for the datums which have been seen on-chain
* @summary Datums by datum hashes
* @param {Array<string>} requestBody Array of hex encoded datum hashes
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async lookupDatums(
requestBody: Array<string>,
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<TimestampedDatums>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.lookupDatums(requestBody, options);
return createRequestFunction(localVarAxiosArgs, configuration);
},
};
};

Expand Down
20 changes: 16 additions & 4 deletions src/api/datum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ export class DatumApi extends BaseAPI {
* @throws {RequiredError}
* @memberof DatumApi
*/
public lookupDatum(datumHash: string, options?: AxiosRequestConfig) {
return DatumApiFp(this.configuration)
.lookupDatum(datumHash, options)
.then((request) => request());
public async lookupDatum(datumHash: string, options?: AxiosRequestConfig) {
const request = await DatumApiFp(this.configuration).lookupDatum(datumHash, options);
return request();
}

/**
* Returns the datums corresponding to the specified datum hashes, for the datums which have been seen on-chain
* @summary Datums by datum hashes
* @param {Array<string>} requestBody Array of hex encoded datum hashes
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DatumApi
*/
public async lookupDatums(requestBody: Array<string>, options?: AxiosRequestConfig) {
const request = await DatumApiFp(this.configuration).lookupDatums(requestBody, options);
return request();
}
}
5 changes: 1 addition & 4 deletions src/api/epochs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ export const EpochsApiAxiosParamCreator = function (configuration: Configuration
epochInfo: async (epochNo: number, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'epochNo' is not null or undefined
assertParamExists('epochInfo', 'epochNo', epochNo);
const localVarPath = `/epochs/{epoch_no}/info`.replace(
`{${'epoch_no'}}`,
encodeURIComponent(String(epochNo)),
);
const localVarPath = `/epochs/{epoch_no}`.replace(`{${'epoch_no'}}`, encodeURIComponent(String(epochNo)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
const { baseOptions } = configuration;
Expand Down
31 changes: 31 additions & 0 deletions src/api/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ export interface DelegatorInfo {
* @interface EpochInfo
*/
export interface EpochInfo {
/**
* Total active stake in the epoch
* @type {number}
* @memberof EpochInfo
*/
active_stake?: string | null;
/**
* Average reward in the epoch
* @type {number}
* @memberof EpochInfo
*/
average_reward?: string | null;
/**
* Total blocks in the epoch
* @type {number}
Expand Down Expand Up @@ -3213,6 +3225,25 @@ export interface TimestampedDatum {
*/
last_updated: LastUpdated;
}
/**
* Timestamped response. Returns the endpoint response data along with the chain-tip of the indexer, which details at which point in the chain\'s history the data was correct as-of.
* @export
* @interface TimestampedDatums
*/
export interface TimestampedDatums {
/**
* Record of Datum by datum hash
* @type {Record<string, Datum | undefined>}
* @memberof TimestampedDatum
*/
data: Record<string, Datum | undefined>;
/**
*
* @type {LastUpdated}
* @memberof TimestampedDatum
*/
last_updated: LastUpdated;
}
/**
* Timestamped response. Returns the endpoint response data along with the chain-tip of the indexer, which details at which point in the chain\'s history the data was correct as-of.
* @export
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DUMMY_BASE_URL = 'https://example.com';
* @export
*/
export const HEADER_AMOUNTS_AS_STRING = {
'amounts-as-string': 'true',
'amounts-as-strings': 'true',
};

/**
Expand Down

0 comments on commit de2dbf9

Please sign in to comment.