Skip to content

Commit 76f911f

Browse files
authored
Merge pull request #50 from maestro-org/feat/new-handlers
feat: latest block handler
2 parents 9b6deef + 2ca68c5 commit 76f911f

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

examples/examples.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { MaestroClient, Configuration } from '../dist';
2+
3+
let maestroClient = new MaestroClient(
4+
new Configuration({
5+
apiKey: '<PROJECT_API_KEY>',
6+
network: 'Preprod',
7+
}),
8+
);
9+
10+
maestroClient.blocks.blockLatest().then((x) => console.log(x.data));

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@maestro-org/typescript-sdk",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "TypeScript SDK for the Maestro Dapp Platform",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -50,4 +50,3 @@
5050
]
5151
}
5252
}
53-

src/api/assets/helpers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,7 @@ export const AssetsApiAxiosParamCreator = (configuration: Configuration) => ({
446446
): RequestArgs => {
447447
// verify required parameter 'policy' is not null or undefined
448448
assertParamExists('policyUtxos', 'policy', policy);
449-
const localVarPath = `/policy/{policy}/utxos`.replace(
450-
`{${'policy'}}`,
451-
encodeURIComponent(String(policy)),
452-
);
449+
const localVarPath = `/policy/{policy}/utxos`.replace(`{${'policy'}}`, encodeURIComponent(String(policy)));
453450
// use dummy base URL string because the URL constructor only accepts absolute URLs.
454451
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
455452
const { baseOptions } = configuration;

src/api/blocks/helpers.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,39 @@ export const BlocksApiAxiosParamCreator = (configuration: Configuration) => ({
5454
options: localVarRequestOptions,
5555
};
5656
},
57+
58+
/**
59+
* Returns information about the latest block
60+
* @summary Latest block
61+
* @param {*} [options] Override http request option.
62+
* @throws {RequiredError}
63+
*/
64+
blockLatest: (options: AxiosRequestConfig = {}): RequestArgs => {
65+
const localVarPath = `/blocks/latest`;
66+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
67+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
68+
const { baseOptions } = configuration;
69+
70+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
71+
const localVarHeaderParameter = {} as Record<string, string>;
72+
const localVarQueryParameter = {} as Record<string, string>;
73+
74+
// authentication api-key required
75+
setApiKeyToObject(localVarHeaderParameter, 'api-key', configuration);
76+
77+
setSearchParams(localVarUrlObj, localVarQueryParameter);
78+
const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
79+
localVarRequestOptions.headers = {
80+
...localVarHeaderParameter,
81+
...headersFromBaseOptions,
82+
...options.headers,
83+
};
84+
85+
return {
86+
url: toPathString(localVarUrlObj),
87+
options: localVarRequestOptions,
88+
};
89+
},
5790
});
5891

5992
/**
@@ -74,5 +107,15 @@ export const BlocksApiFp = (configuration: Configuration) => {
74107
const localVarAxiosArgs = localVarAxiosParamCreator.blockInfo(hashOrHeight, options);
75108
return createRequestFunction(localVarAxiosArgs, configuration);
76109
},
110+
/**
111+
* Returns information about the latest block
112+
* @summary Latest block
113+
* @param {*} [options] Override http request option.
114+
* @throws {RequiredError}
115+
*/
116+
blockLatest(options?: AxiosRequestConfig): () => Promise<TimestampedBlockInfo> {
117+
const localVarAxiosArgs = localVarAxiosParamCreator.blockLatest(options);
118+
return createRequestFunction(localVarAxiosArgs, configuration);
119+
},
77120
};
78121
};

src/api/blocks/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@ export class BlocksApi extends BaseAPI {
2020
public blockInfo(hashOrHeight: string, options?: AxiosRequestConfig) {
2121
return BlocksApiFp(this.configuration).blockInfo(hashOrHeight, options)();
2222
}
23+
24+
/**
25+
* Returns information about the latest block
26+
* @summary Latest block
27+
* @param {*} [options] Override http request option.
28+
* @throws {RequiredError}
29+
* @memberof BlocksApi
30+
*/
31+
public blockLatest(options?: AxiosRequestConfig) {
32+
return BlocksApiFp(this.configuration).blockLatest(options)();
33+
}
2334
}

0 commit comments

Comments
 (0)