Skip to content

Commit

Permalink
Merge pull request #50 from maestro-org/feat/new-handlers
Browse files Browse the repository at this point in the history
feat: latest block handler
  • Loading branch information
Vardominator authored Dec 13, 2024
2 parents 9b6deef + 2ca68c5 commit 76f911f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
10 changes: 10 additions & 0 deletions examples/examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MaestroClient, Configuration } from '../dist';

let maestroClient = new MaestroClient(
new Configuration({
apiKey: '<PROJECT_API_KEY>',
network: 'Preprod',
}),
);

maestroClient.blocks.blockLatest().then((x) => console.log(x.data));
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maestro-org/typescript-sdk",
"version": "1.6.2",
"version": "1.6.3",
"description": "TypeScript SDK for the Maestro Dapp Platform",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -50,4 +50,3 @@
]
}
}

5 changes: 1 addition & 4 deletions src/api/assets/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,7 @@ export const AssetsApiAxiosParamCreator = (configuration: Configuration) => ({
): RequestArgs => {
// verify required parameter 'policy' is not null or undefined
assertParamExists('policyUtxos', 'policy', policy);
const localVarPath = `/policy/{policy}/utxos`.replace(
`{${'policy'}}`,
encodeURIComponent(String(policy)),
);
const localVarPath = `/policy/{policy}/utxos`.replace(`{${'policy'}}`, encodeURIComponent(String(policy)));
// 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
43 changes: 43 additions & 0 deletions src/api/blocks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,39 @@ export const BlocksApiAxiosParamCreator = (configuration: Configuration) => ({
options: localVarRequestOptions,
};
},

/**
* Returns information about the latest block
* @summary Latest block
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
blockLatest: (options: AxiosRequestConfig = {}): RequestArgs => {
const localVarPath = `/blocks/latest`;
// 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: 'GET', ...baseOptions, ...options };
const localVarHeaderParameter = {} as Record<string, string>;
const localVarQueryParameter = {} as Record<string, string>;

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

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

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
});

/**
Expand All @@ -74,5 +107,15 @@ export const BlocksApiFp = (configuration: Configuration) => {
const localVarAxiosArgs = localVarAxiosParamCreator.blockInfo(hashOrHeight, options);
return createRequestFunction(localVarAxiosArgs, configuration);
},
/**
* Returns information about the latest block
* @summary Latest block
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
blockLatest(options?: AxiosRequestConfig): () => Promise<TimestampedBlockInfo> {
const localVarAxiosArgs = localVarAxiosParamCreator.blockLatest(options);
return createRequestFunction(localVarAxiosArgs, configuration);
},
};
};
11 changes: 11 additions & 0 deletions src/api/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ export class BlocksApi extends BaseAPI {
public blockInfo(hashOrHeight: string, options?: AxiosRequestConfig) {
return BlocksApiFp(this.configuration).blockInfo(hashOrHeight, options)();
}

/**
* Returns information about the latest block
* @summary Latest block
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof BlocksApi
*/
public blockLatest(options?: AxiosRequestConfig) {
return BlocksApiFp(this.configuration).blockLatest(options)();
}
}

0 comments on commit 76f911f

Please sign in to comment.