EOS WiKi Bilingual News & Info Of EOS, Vote for us: eosdotwikibp

EOSfinex:采用去中心化链上交易模式的WebSockets/EOSfinex: WebSockets for a decentralised, on-chain exchange

E

译文/Translated:

EOSfinex启动在即,在这里我们先一睹为快,端看技术为交易赋能。

This image has an empty alt attribute; its file name is 1*pK3AbzHt5KUXmM48Iyt9xg.png

EOSfinex是一款构建于EOSIO之上的高效去中心化交易所,采用纯链上模式,其EOS合约包含抵押、订货薄及匹配引擎等内容。EOSfinex预计将于2019年第一季度全面启动。

我们将于以下文章中探讨我们向交易商提供的传统WebSocket协议,以及端口的使用情况。

WebSockets上的EOS

通常EOS合约提供以HTTP为基础的API,该端口在EOSfinex上为单边交易。此外,我们也将提供低延迟的WebSockets。WebSockets让用户能对巨大的市场变动做出快速反应,同时它也作为web标准而存在。

EOSfinex的WebSocket协议以目前在Bitfinex上使用的第二版协议为基础。为了让交易能在去中心化环境中完成,我们增添了一些改变。

我们在端口上采用了高性能设计,并且让Bitfinex现有用户能够轻松使用。

以下部分将展示EOSfinex WebSocket端口传送的交易更新信息。

它看起来很像我们API第二版信息,不是吗?

[ ‘0’, 
  ‘tu’,
  [ ’10’, 
    ‘EOS.USD’, 
    1549888790502, 
    ‘26195’, 
    -10.99, 
    3, 
    ‘LIMIT’, 
    0, 
    6594000, 
    ‘USD’, 
    15498887884290, 
    1 ] ]

Auth&提前签署

为了能通过WebSockets 完成交易,我们必须连接WebSocket端口。该端口本身作为EOS原生插件,在紧邻合约的EOS节点之上运行。交易商在将其发送给端口前,提前用私钥完成订单签署。

端口随后将其用于合约之上。由此,私钥不会脱离交易商的掌控。

我们的WebSocket库目前支持以私钥为基础的签署和Scatter。未来,我们将添加硬件钱包的功能支持。

以下是一段从客户处发送至端口的信息示例,这是一份交易提交信息:

[0,”on”,null,{“meta”:{“expiration”:”2019-02-11T13:59:55″,”ref_block_num”:53303,”ref_block_prefix”:3288141905,”max_net_usage_words”:0,”max_cpu_usage_ms”:0,”delay_sec”:0,”context_free_actions”:[],”actions”:[{“account”:”exchgcntract”,”name”:”place”,”authorization”:[{“actor”:”testuser4321″,”permission”:”active”}],”data”:”10c42057619db1ca620c6d9e180e000000003020610d305510270000000000004cad01000000000000″}],”transaction_extensions”:[],”signatures”:[“SIG_K1_KfW7wg125Rc9Jt7HWTu3gzfXZqw24PjE4boTvYHuu1u3CTLeQGnz2xv2LLcWvBD1Paff7mV8qFUpnN4ttyp2jCpUGT8LaF”]}}]

当然,所有更新对于链上交易都是公开的。但用户如何判断哪一段交易更新信息是属于自己的?这是将正确的信息发送给各自接口所需解决的重要问题。

因此,我们在合约中添加了特殊的终点。该EOS操作的名称已经生效。Sunbeam,我们的WebSocket库将其作为auth过程的一部分使用。

通过调用auth(),Sunbeam向websocket端口发送一份本地签署信息。被送以认证的信息本身为空信息,并不会引发任何操作。

端口通过将签署的信息与各自链上的公钥进行对比,仅将其用于用户验证。auth成功后,我们将收到“私有”钱包的信息,以及交易和订单更新。

以下您将看到一份有关Scatter的简短演示:

若您想知道Sunbeam如何发挥作用,请参阅以下内容。该内容对Apache License 2.0完全公开。

bitfinexcom/sunbeam
Contribute to bitfinexcom/sunbeam development by creating an account on GitHub.github.com

希望您在此快速预览中有所收获,并且与我们一样期待即将发布的EOSfinex。

原文/Original:

With the launch of EOSfinex right around the corner, we’re here to give a sneak peek into the mechanics powering the exchange.

EOSfinex is a high-performance decentralised exchange built on EOSIO which will run fully on-chain — custody, order book, and matching engine are all part of the EOS contracts. EOSfinex is set for full launch in Q1 of 2019.

In the below article, we will take a look at the additional WebSocket protocols which we are offering to traders, as well as using the gateway in practise.

EOS On WebSockets

Usually, EOS contracts offer an HTTP-based API, which will be one way of trading on EOSfinex. In addition to this, we will also support low latency WebSockets. WebSockets allow users to react quickly to drastic market movements and are at the same time a web standard.

The WebSocket protocol for EOSfinex is based on the v2 protocol that is in use at Bitfinex. To make trading in the decentralised environment possible, we added a few changes.

We’ve designed the gateway to be capable of high-performance, and to make it simple for existing Bitfinex users to use it.

The following section shows a trade update message from the EOSfinex WebSocket gateway.

Looks pretty familiar to our API v2 messages, doesn’t it?

[ '0', 
'tu',
[ '10',
'EOS.USD',
1549888790502,
'26195',
-10.99,
3,
'LIMIT',
0,
6594000,
'USD',
15498887884290,
1 ] ]

Auth & Pre-Signing

To be able to trade via WebSockets, we have to connect to the WebSocket gateway. The gateway itself runs as a native EOS plugin, on an EOS node next to the contract. The trader presigns the orders with their private key before sending it to the gateway.

The gateway then applies it to the contract. This way, no private keys ever leave the traders machine.

Our WebSocket library currently supports private key based signing and Scatter. In the future, we will add hardware wallet support.

Below is a sample message, sent from the client to the gateway, which would submit a trade:

[0,"on",null,{"meta":{"expiration":"2019-02-11T13:59:55","ref_block_num":53303,"ref_block_prefix":3288141905,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"exchgcntract","name":"place","authorization":[{"actor":"testuser4321","permission":"active"}],"data":"10c42057619db1ca620c6d9e180e000000003020610d305510270000000000004cad01000000000000"}],"transaction_extensions":[],"signatures":["SIG_K1_KfW7wg125Rc9Jt7HWTu3gzfXZqw24PjE4boTvYHuu1u3CTLeQGnz2xv2LLcWvBD1Paff7mV8qFUpnN4ttyp2jCpUGT8LaF"]}}]

By nature, all updates are public for an on-chain exchange. But how can one decide which trade update message belongs to the right user? This is an important question required for sending the right message to their socket.

For this reason we have added a special endpoint to our contract. The name of the EOS action is validateSunbeam, our WebSocket library uses it as part of an auth process.

By calling auth(), Sunbeam sends a locally signed message to the websocket gateway. The message sent to the validate action itself is empty and does not trigger anything.

The gateway only uses it to verify the user by comparing the signed message with their public keys on-chain. With an successful auth, we receive “private” wallet messages, trades and order updates.


Below you will find a brief demonstration of Scatter:


If you are curious as to how Sunbeam functions, feel free to take a look below. It is fully open-sourced under Apache License 2.0.bitfinexcom/sunbeam
Contribute to bitfinexcom/sunbeam development by creating an account on GitHub.github.com


We hope you enjoyed this quick preview and are excited as us about the upcoming launch of EOSfinex.


原文链接/Original URL:

https://medium.com/bitfinex/eosfinex-websockets-for-a-decentralised-on-chain-exchange-e02a1d572d04

About the author

By user
EOS WiKi Bilingual News & Info Of EOS, Vote for us: eosdotwikibp

Recent Posts