You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/index.md
+12-12
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,21 @@
4
4
5
5
The WindingTree Market Protocol facilitates coordination and deal management for buyers and sellers. This SDK provides essential software tools to configure and construct the protocol actors, streamlining the implementation of its workflow. For a comprehensive understanding of the protocol's operation, explore the detailed documentation available at this [link](/docs/protocol.md).
- Market: [0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57](https://explorer.public.zkevm-test.net/address/0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57/read-proxy#address-tabs) - Protocol entry point
14
-
- LIF: [0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8](https://explorer.public.zkevm-test.net/address/0x4d60F4483BaA654CdAF1c5734D9E6B16735efCF8/read-proxy#address-tabs) - Test version of LIF token
11
+
- Config ([0x4556d5C1486d799f67FA96c84F1d0552486CAAF4](https://gnosis-chiado.blockscout.com/address/0x4556d5C1486d799f67FA96c84F1d0552486CAAF4?tab=read_proxy)): the protocol configuration smart contract
12
+
- EntitiesRegistry ([0x4EcB659060Da61D795D777bb21BAe3599b301C66](https://gnosis-chiado.blockscout.com/address/0x4EcB659060Da61D795D777bb21BAe3599b301C66?tab=read_proxy)): the protocol identity management
13
+
- Market ([0xF54784206A53EF19fd3024D8cdc7A6251A4A0d67](https://gnosis-chiado.blockscout.com/address/0xF54784206A53EF19fd3024D8cdc7A6251A4A0d67?tab=read_proxy)): the protocol entry point
14
+
- LIF ([0x8CB96383609C56af1Fe44DB7591F94AEE2fa43b2](https://gnosis-chiado.blockscout.com/address/0x8CB96383609C56af1Fe44DB7591F94AEE2fa43b2?tab=read_proxy)): Test version of LIF token
15
15
16
-
### Testing Tokens
16
+
####Testing tokens
17
17
18
-
-`STABLE6`: [ERC20, 6 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x8CB96383609C56af1Fe44DB7591F94AEE2fa43b2/read-proxy#address-tabs)
19
-
-`STABLE6PERMIT`: [ERC20, 6 decimals, with permit](https://explorer.public.zkevm-test.net/address/0x4556d5C1486d799f67FA96c84F1d0552486CAAF4/read-proxy#address-tabs)
20
-
-`STABLE18`: [ERC20, 18 decimals, no permit](https://explorer.public.zkevm-test.net/address/0x4EcB659060Da61D795D777bb21BAe3599b301C66/read-proxy#address-tabs)
21
-
-`STABLE18PERMIT`: [ERC20, 18 decimals, with permit](https://explorer.public.zkevm-test.net/address/0xF54784206A53EF19fd3024D8cdc7A6251A4A0d67/read-proxy#address-tabs)
18
+
-`STABLE6`: [ERC20, 6 decimals, no permit](https://gnosis-chiado.blockscout.com/address/0xcC28A4e6DEF318A1b88CF34c4F2Eeb2489995513?tab=read_proxy)
19
+
-`STABLE6PERMIT`: [ERC20, 6 decimals, with permit](https://gnosis-chiado.blockscout.com/address/0x78F924A7C70213D502E6110567AC556c2EFBBF73?tab=read_proxy)
20
+
-`STABLE18`: [ERC20, 18 decimals, no permit](https://gnosis-chiado.blockscout.com/address/0x7067fC74fFCf4096796454747461D098E6bF7241?tab=read_proxy)
21
+
-`STABLE18PERMIT`: [ERC20, 18 decimals, with permit](https://gnosis-chiado.blockscout.com/address/0x44947d69A9F06EF48170BD41Da9B27E74ecd0891?tab=read_proxy)
22
22
23
23
## Protocol Addresses
24
24
@@ -53,10 +53,10 @@ Once you have generated a peer key for your server, you can create a server addr
53
53
To generate a server address, use the following script:
Copy file name to clipboardexpand all lines: docs/nodes.md
+121
Original file line number
Diff line number
Diff line change
@@ -322,6 +322,29 @@ With the `ProtocolContracts` utility, you have a powerful tool to work with the
322
322
323
323
Tasks for checking deal state changes can be implemented in the same way as monitoring the creation of deals (requests processing). For more details, refer to the previous section on "Requests Processing."
324
324
325
+
Also, monitoring the status of deals can be performed using the `subscribeMarket` method of the `ProtocolContracts` class. Here is a brief example:
const { offerId, status } =log.argsasStatusEventLog;
340
+
// ...
341
+
});
342
+
// Save `maxBlockNumber` for later use eq re-subscription
343
+
},
344
+
blockNumber, // Block number to listen from (0 by default)
345
+
);
346
+
```
347
+
325
348
With this information, you have a better understanding of how to configure the supplier node, manage incoming requests, build and publish offers, and handle deal state changes.
326
349
327
350
## The Node Management API
@@ -370,6 +393,104 @@ const apiServer = new NodeApiServer({
370
393
apiServer.start(appRouter);
371
394
```
372
395
396
+
### Extending the Node API
397
+
398
+
You can add your custom routes to the Node API. When creating API routes for your application, following specific guidelines can facilitate the development, maintenance, and use of your API. Below a guide for creating API routes:
399
+
400
+
#### 1. **Structure of Routes**
401
+
402
+
-**Naming**: Name your routes in a way that clearly reflects the actions they perform and the resources they handle. For example, use `add`, `update`, `delete`, `get`, and `getAll` for operations related to airplanes.
403
+
-**Grouping**: Organize routes into logical groups. In the example, all routes are grouped under `airplanesRouter`, which simplifies understanding their purpose.
404
+
405
+
```typescript
406
+
exportconst airplanesRouter =router({
407
+
add: authAdminProcedure
408
+
// Implementation...
409
+
update: authAdminProcedure
410
+
// Implementation...
411
+
delete: authAdminProcedure
412
+
// Implementation...
413
+
get: authProcedure
414
+
// Implementation...
415
+
getAll: authProcedure
416
+
// Implementation...
417
+
});
418
+
```
419
+
420
+
#### 2. **Authentication and Authorization**
421
+
422
+
- Differentiate access levels for different operations. In the example, `authProcedure` is used for basic authentication and `authAdminProcedure` for operations requiring admin rights.
423
+
- Explicitly specify authentication and authorization requirements for each route.
424
+
425
+
#### 3. **Input Validation**
426
+
427
+
- Use validation libraries, such as `zod`, to ensure inputs match expected types and formats. This helps prevent errors and vulnerabilities.
428
+
- Define schemas for input data, like `AirplaneInputSchema` and `AirplaneUpdateSchema`, and use them in route procedures.
429
+
430
+
```typescript
431
+
.add: authAdminProcedure
432
+
.input(AirplaneInputSchema)
433
+
.mutation(async ({ input, ctx }) => {
434
+
// Implementation...
435
+
}),
436
+
```
437
+
438
+
#### 4. **Error Handling**
439
+
440
+
- Handle exceptions and errors within each route to return understandable error messages.
441
+
- Use standardized HTTP error codes, such as `BAD_REQUEST` for validation errors and `NOT_FOUND` for missing resources.
442
+
443
+
```typescript
444
+
.mutation(async ({ input, ctx }) => {
445
+
try {
446
+
// Operation...
447
+
} catch (error) {
448
+
thrownewTRPCError({
449
+
code: 'BAD_REQUEST',
450
+
message: (errorasError).message,
451
+
});
452
+
}
453
+
}),
454
+
```
455
+
456
+
#### 5. **Logging**
457
+
458
+
- Log key operations and errors. This facilitates debugging and monitoring your API.
459
+
- Use a created logger, such as `logger`, to record events.
460
+
461
+
```typescript
462
+
logger.trace(`Airplane ${input.name} registered with id ${id}`);
463
+
```
464
+
465
+
#### Integrate Your Custom Route Into the Node API
466
+
467
+
The following code snippet demonstrates how to set up and start a Node API server using the `@windingtree/sdk-node-api/server` package, integrating multiple routers for different parts of an application. It includes default routers like `adminRouter`, `dealsRouter`, `serviceRouter`, and `userRouter` provided by the `@windingtree/sdk-node-api/router` package, **along with a custom router defined by the developer (`customRouter`)**. The code creates a combined router that aggregates these individual routers under specific namespaces, making it easier to manage and organize routes according to their functionality. Finally, the code initializes a `NodeApiServer` instance with optional server configuration (`apiServerConfig`) and starts the server with the combined router, making the API ready to handle requests. This approach facilitates the modular development of API services, allowing for scalability and ease of maintenance.
0 commit comments