Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use objects in API

Shulou Source: shulou.com Published: 2022-06-01 08:06:47 10月01日 Update

This article focuses on "how to use objects in API". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use objects in API.

1. JSON coding of API request / response data

The access request and response of API are encoded by JSON. Here are some common objects in API.

1.1 Channel / Channel

An example of a channel object is as follows:

{"channel_identifier": 21, "token_network_identifier": "0x2a65Aca4D5fC5B5C859090a6c34d164135398226", "partner_address": "0x61C808D82A3Ac53231750daDc13c777b59310bD9", "token_address": "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8", "balance": 25000000, "total_deposit": 35000000, "state": "opened", "settle_timeout": 500,500, "reveal_timeout": 40}

The channel object contains the following fields:

Channel_identifier: identification of the channel, integer

Partner_address: address of the other party, an address string encoded by EIP55, used to open a channel

Token_address: token address, EIP555-encoded token address string, used for transactions on the channel

Token_network_identifier: token network identifier, EIP55-encoded token network identifier

Balance: available token balance, integer

Total_deposit: the amount that has been deposited into the channel contract, integer

State: the current state of the channel, string. Possible values include: opened-Channel is open closed-Channel is closed settled-Channel is closed and cleared

Settle_timeout: number of timeout blocks for channel clearing, integer

Reveal_timeout: maximum number of blocks allowed to reveal timeout, integer

1.2 Channel event / Event

The channel event is also encoded as a JSON object, and the parameters of the event are used as properties of the event object. To make it easier to distinguish between different types of events, additional event_type and block_number attributes have been added to the event object.

2. API error message

For unsuccessful API requests, the corresponding http status code will be returned, such as 409 conflicts or 400 error requests, and an errors field will be attached to the returned json object, which you can use to get more information about the error. However, it is important to note that if Raiden cannot process the received request and throws an exception, the http status code will be returned, and instead of the json object, a string message Internal server error will be returned. This is because we rely on other development libraries to implement API, and we cannot properly handle the response message when an exception occurs.

In any case, we think the 500th error is the bug of Raiden. If you encounter this phenomenon, please give us your feedback.

At this point, I believe you have a deeper understanding of "how to use objects in API". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Channels objects events codes integers tokens addresses characters strings errors identifiers status information content blocks fields attributes identifiers messages networks Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info OPPO Reno Microsoft Shulou Information