vapor

社区观点 | 理解比原链MOV链上交换协议

邮差的信 提交于 2019-12-27 18:03:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 去中心化交换协议的发展 从Bitshare,Stellar到以太坊上的Etherdelta,Bancor,0x协议,去中心化交换协议也经过了好几代发展和很多模式的探索,每一代都通过前面的协议的痛点来进行改进和深化, 主要分为: 链上orderbook,链上结算; 链下orderbook,链上结算; 基于智能合约管理的资金池; 链上orderbook,链上结算 最早的 基于以太坊的去中心化交换协议的成功探索非Etherdelta莫属,曾一度占据去中心化交换市场的半壁江山。Etherdelta是较为完全的去中心化模式,用户充值、挂单、吃单、结算及提现全部在链上完成。 具体运行机制如下: Etherdelta的整个运行都在链上完成,用户保管自己的私钥,平台不会触碰用户资产,保证了资产和交换的安全、透明。但其弊病也较为明显: 由于所有的交换环节都在链上完成,且每一个挂单、撤单、吃单等操作都会消耗GAS费用,导致延时高、成本效益低下。 存在矿工非法预先交换的可能。 链下orderbook,链上结算 为了解决纯链上效率低下,且手续费低廉的问题,0x协议引入了relayer(中继)的概念,所有订单都发给relayer,无需上链,只有成交才会上链。 0x的“链下订单中继、链上最终结算”运作模式如下: 0x协议的主要问题在于

如何从Android上的Intent中获取更多数据?

你离开我真会死。 提交于 2019-12-26 13:52:40
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 如何从一个活动(意图)向另一个活动发送数据? 我使用以下代码发送数据: Intent i=new Intent(context,SendMessage.class); i.putExtra("id", user.getUserAccountId()+""); i.putExtra("name", user.getUserFullName()); context.startActivity(i); #1楼 // How to send value using intent from one class to another class // class A(which will send data) Intent theIntent = new Intent(this, B.class); theIntent.putExtra("name", john); startActivity(theIntent); // How to get these values in another class // Class B Intent i= getIntent(); i.getStringExtra("name"); // if you log here i than you will get the value of

Vapor `client.get`, transform and return json

若如初见. 提交于 2019-12-24 09:38:07
问题 I’m trying to GET data from another web service, then transform it and return it. I found a Spotify example in the docs, but I’m not sure how to return a portion of the JSON. drop.get("music") { request in guard let query = request.data["q"]?.string else { throw Abort.badRequest } let result = try drop.client.get( "https://api.spotify.com/v1/search", query: ["type": "artist", "q": query] ) return result.data["artists"]?.array } I'm getting this error when I try to build: error: return

Swift Vapor Leaf deliver html in a variable

你。 提交于 2019-12-23 14:13:34
问题 I need to create a complex html-table inside a Swift Vapor App. Problem is: Leaf doesn't seem to support counting up variables like #(somevar += 1) nor concatenating string variables like #(somevar1 + somevar2) So I decided to create my complex table inside the App and transfer it to the html template inside a variable. (in php I'm used to doing this all the time) In the template I'd call the variable like #(table) but turns out, I'm getting the plain html code as leaf escapes all variables.

How to respond with an image using Vapor?

杀马特。学长 韩版系。学妹 提交于 2019-12-22 09:56:39
问题 I just want to have a controller action that is basically doing the same as accessing an image directly through the Public/ folder. The difference is that the route can be whatever you want and the returned image will be the one that is determined inside of the controller function. But how to create a proper response? My approach looks like this: import Vapor final class ImageController { func read(_ req: Request) throws -> Future<Data> { let directory = DirectoryConfig.detect() let promise =

Doing joins with Fluent in a Vapor application

╄→гoц情女王★ 提交于 2019-12-21 21:34:28
问题 I'm struggling to figure out how to join my two tables together using fluent. In essence I want to run this SQL command: SELECT p.name, o.amount, o.amount * p.amount total FROM "OrderPoints" o INNER JOIN "Points" p ON o.points_id = p.id WHERE order_id = 10831 I've got my two models setup like so: final class OrderPoint: Codable, PostgreSQLModel, Content, Migration { var id: Int? = nil var orderID: Order.ID var pointID: Point.ID var amount: Double = 0 var point: Parent<OrderPoint, Point> {

How do I read this Swift syntax? [duplicate]

喜欢而已 提交于 2019-12-20 05:00:29
问题 This question already has an answer here : Parameters after opening bracket (1 answer) Closed 3 years ago . I am using Vapor and one of the first thing is to use get method which looks like following: drop.get("hello") { request in return "Hello, world!" } Now my understanding was that the closures are like variable of type functions. Correct? Here I see we call a method get on an instance of Droplet class called drop and pass in a string. What is with the closure being called/passed inside

How to send a POST request to Firebase Cloud Messaging API in Vapor

感情迁移 提交于 2019-12-20 02:44:10
问题 I am trying to make a POST request to a Firebase Notifications API using Vapor 1.5 and Firebase Legacy Protocol, but I get failure response. response is JSON(node: Node.Node.object(["multicast_id": Node.Node.number(5936281277445399934), "failure": Node.Node.number(0), "canonical_ids": Node.Node.number(0), "results": Node.Node.array([Node.Node.object(["message_id": Node.Node.string("0:1527074314969790%c7ade8b9f9fd7ecd")])]), "success": Node.Node.number(1)])) EDIT Making the request through

How to use timer in Vapor (server-side Swift)?

梦想与她 提交于 2019-12-19 07:18:08
问题 Can I use timer, such as NSTimer in Vapor (server-side Swift)? I hope my server written in Vapor can do some tasks proactively once in a while. For example, polling some data from the web every 15 mins. How to achieve this with Vapor? 回答1: If you can accept your task timer being re-set whenever the server instance is recreated, and you only have one server instance, then you should consider the excellent Jobs library. If you need your task to run exactly at the same time regardless of the

Vapor MySQL - not showing as an Import value

心不动则不痛 提交于 2019-12-12 17:53:17
问题 This question is about the Swift Web Framework, Vapor. I am trying to import VaporMySQL framework using Swift's Package Manager. I already have the database running locally, the mySQL port is open & working, the mySQL database is working, the Vapor app is working [I have written several GET / POST requests that work]. But I can't Import VaporMySQL. This may be related to my lack of knowledge with Package.swift. let package = Package( name: "HelloWorld", dependencies: [ .Package(url: "https:/