Skip to content

Commit 205557c

Browse files
committed
Add noteWitness and feeRate endpoints
1 parent afce928 commit 205557c

File tree

5 files changed

+2242
-1854
lines changed

5 files changed

+2242
-1854
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"levelup": "^5.1.1",
5454
"dotenv": "^16.3.1",
5555
"leveldown": "^6.1.1",
56-
"@ironfish/sdk": "^2.1.0",
56+
"@ironfish/sdk": "2.5.0",
5757
"@aws-sdk/client-s3": "3",
5858
"express": "^4.18.3",
5959
"ts-proto": "1.155.1",

src/controllers/block.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ export class BlockController {
2929
};
3030
}
3131

32+
/**
33+
* Creates a note witness for the given note index. Note witnesses are used to create a spend for the
34+
* note at that index.
35+
* @param index The index of the note to create a witness for
36+
* @param confirmations Number of blocks back from the head block to set the tree size.
37+
*/
38+
@Get("note-witness")
39+
public async noteWitness(
40+
@Query() index: number,
41+
@Query() confirmations?: number,
42+
) {
43+
const rpcClient = await ifClient.getClient();
44+
const response = await rpcClient.chain.getNoteWitness({
45+
index,
46+
confirmations,
47+
});
48+
49+
return {
50+
authPath: response.content.authPath,
51+
rootHash: response.content.rootHash,
52+
treeSize: response.content.treeSize,
53+
};
54+
}
55+
56+
/**
57+
* Returns estimated fee rates for the network.
58+
*/
59+
@Get("fee-rates")
60+
public async feeRates() {
61+
const rpcClient = await ifClient.getClient();
62+
const response = await rpcClient.chain.estimateFeeRates();
63+
64+
return {
65+
slow: response.content.slow,
66+
average: response.content.average,
67+
fast: response.content.fast,
68+
};
69+
}
70+
3271
/**
3372
* Broadcasts a transaction to the network. Input is a hex encoded string of the `Transaction` to broadcast.
3473
* @param transaction The hex encoded string `Transaction` to broadcast
@@ -45,10 +84,11 @@ export class BlockController {
4584
transaction,
4685
});
4786
if (!response.content) {
48-
return err(400, { reason: "Either hash or sequence must be provided" });
87+
return err(400, { reason: "Broadcast failed" });
4988
}
5089
return {
5190
accepted: response.content.accepted,
91+
broadcasted: response.content.broadcasted,
5292
hash: response.content.hash,
5393
};
5494
}

src/routes/routes.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ export function RegisterRoutes(app: Router) {
4141
// NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look
4242
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
4343
// ###########################################################################################################
44+
4445
app.get(
4546
"/latest-block",
4647
...fetchMiddlewares<RequestHandler>(BlockController),
4748
...fetchMiddlewares<RequestHandler>(
4849
BlockController.prototype.getLatestBlock,
4950
),
5051

51-
function BlockController_getLatestBlock(
52+
async function BlockController_getLatestBlock(
5253
request: ExRequest,
5354
response: ExResponse,
5455
next: any,
@@ -67,7 +68,7 @@ export function RegisterRoutes(app: Router) {
6768

6869
const controller = new BlockController();
6970

70-
templateService.apiHandler({
71+
await templateService.apiHandler({
7172
methodName: "getLatestBlock",
7273
controller,
7374
response,
@@ -81,14 +82,64 @@ export function RegisterRoutes(app: Router) {
8182
},
8283
);
8384
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
85+
app.get(
86+
"/note-witness",
87+
...fetchMiddlewares<RequestHandler>(BlockController),
88+
...fetchMiddlewares<RequestHandler>(BlockController.prototype.noteWitness),
89+
90+
async function BlockController_noteWitness(
91+
request: ExRequest,
92+
response: ExResponse,
93+
next: any,
94+
) {
95+
const args: Record<string, TsoaRoute.ParameterSchema> = {
96+
index: {
97+
in: "query",
98+
name: "index",
99+
required: true,
100+
dataType: "double",
101+
},
102+
confirmations: {
103+
in: "query",
104+
name: "confirmations",
105+
dataType: "double",
106+
},
107+
};
108+
109+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
110+
111+
let validatedArgs: any[] = [];
112+
try {
113+
validatedArgs = templateService.getValidatedArgs({
114+
args,
115+
request,
116+
response,
117+
});
118+
119+
const controller = new BlockController();
120+
121+
await templateService.apiHandler({
122+
methodName: "noteWitness",
123+
controller,
124+
response,
125+
next,
126+
validatedArgs,
127+
successStatus: undefined,
128+
});
129+
} catch (err) {
130+
return next(err);
131+
}
132+
},
133+
);
134+
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
84135
app.post(
85136
"/transaction",
86137
...fetchMiddlewares<RequestHandler>(BlockController),
87138
...fetchMiddlewares<RequestHandler>(
88139
BlockController.prototype.broadcastTransaction,
89140
),
90141

91-
function BlockController_broadcastTransaction(
142+
async function BlockController_broadcastTransaction(
92143
request: ExRequest,
93144
response: ExResponse,
94145
next: any,
@@ -121,7 +172,7 @@ export function RegisterRoutes(app: Router) {
121172

122173
const controller = new BlockController();
123174

124-
templateService.apiHandler({
175+
await templateService.apiHandler({
125176
methodName: "broadcastTransaction",
126177
controller,
127178
response,
@@ -140,7 +191,7 @@ export function RegisterRoutes(app: Router) {
140191
...fetchMiddlewares<RequestHandler>(BlockController),
141192
...fetchMiddlewares<RequestHandler>(BlockController.prototype.getBlock),
142193

143-
function BlockController_getBlock(
194+
async function BlockController_getBlock(
144195
request: ExRequest,
145196
response: ExResponse,
146197
next: any,
@@ -176,7 +227,7 @@ export function RegisterRoutes(app: Router) {
176227

177228
const controller = new BlockController();
178229

179-
templateService.apiHandler({
230+
await templateService.apiHandler({
180231
methodName: "getBlock",
181232
controller,
182233
response,
@@ -197,7 +248,7 @@ export function RegisterRoutes(app: Router) {
197248
BlockController.prototype.getBlockRange,
198249
),
199250

200-
function BlockController_getBlockRange(
251+
async function BlockController_getBlockRange(
201252
request: ExRequest,
202253
response: ExResponse,
203254
next: any,
@@ -238,7 +289,7 @@ export function RegisterRoutes(app: Router) {
238289

239290
const controller = new BlockController();
240291

241-
templateService.apiHandler({
292+
await templateService.apiHandler({
242293
methodName: "getBlockRange",
243294
controller,
244295
response,
@@ -259,7 +310,7 @@ export function RegisterRoutes(app: Router) {
259310
BlockController.prototype.getServerInfo,
260311
),
261312

262-
function BlockController_getServerInfo(
313+
async function BlockController_getServerInfo(
263314
request: ExRequest,
264315
response: ExResponse,
265316
next: any,
@@ -278,7 +329,7 @@ export function RegisterRoutes(app: Router) {
278329

279330
const controller = new BlockController();
280331

281-
templateService.apiHandler({
332+
await templateService.apiHandler({
282333
methodName: "getServerInfo",
283334
controller,
284335
response,

src/swagger/swagger.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,86 @@
7979
"parameters": []
8080
}
8181
},
82+
"/note-witness": {
83+
"get": {
84+
"operationId": "NoteWitness",
85+
"responses": {
86+
"200": {
87+
"description": "Ok",
88+
"content": {
89+
"application/json": {
90+
"schema": {
91+
"properties": {
92+
"treeSize": {
93+
"type": "number",
94+
"format": "double"
95+
},
96+
"rootHash": {
97+
"type": "string"
98+
},
99+
"authPath": {
100+
"items": {
101+
"properties": {
102+
"hashOfSibling": {
103+
"type": "string"
104+
},
105+
"side": {
106+
"type": "string",
107+
"enum": [
108+
"Left",
109+
"Right"
110+
]
111+
}
112+
},
113+
"required": [
114+
"hashOfSibling",
115+
"side"
116+
],
117+
"type": "object"
118+
},
119+
"type": "array"
120+
}
121+
},
122+
"required": [
123+
"treeSize",
124+
"rootHash",
125+
"authPath"
126+
],
127+
"type": "object"
128+
}
129+
}
130+
}
131+
}
132+
},
133+
"description": "Creates a note witness for the given note index. Note witnesses are used to create a spend for the\nnote at that index.",
134+
"tags": [
135+
"Block Controller"
136+
],
137+
"security": [],
138+
"parameters": [
139+
{
140+
"description": "The index of the note to create a witness for",
141+
"in": "query",
142+
"name": "index",
143+
"required": true,
144+
"schema": {
145+
"format": "double",
146+
"type": "number"
147+
}
148+
},
149+
{
150+
"description": "Number of blocks back from the head block to set the tree size.",
151+
"in": "query",
152+
"name": "confirmations",
153+
"required": false,
154+
"schema": {
155+
"format": "double",
156+
"type": "number"
157+
}
158+
}
159+
]
160+
}
161+
},
82162
"/transaction": {
83163
"post": {
84164
"operationId": "BroadcastTransaction",

0 commit comments

Comments
 (0)