{"swagger":"2.0","info":{"description":"send, manage and share your blog\n","version":"1.0.0","title":"A Blog System","license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}},"tags":[{"name":"Blog","description":"Operations about blog"},{"name":"User","description":"Operations about user"},{"name":"Comment","description":"Operations about comment"},{"name":"Tag","description":"Operations about tags"}],"paths":{"/comment/{BlogID}":{"post":{"tags":["Comment"],"summary":"Post some comments","operationId":"postComment","produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog id to addTag","required":true,"type":"string"},{"in":"body","name":"body","description":"Create a new comment","required":true,"schema":{"type":"object","properties":{"ownName":{"type":"string","example":"pmlpml"},"content":{"type":"string","example":"Thanks"}}}}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}},"security":[{"token":[]}]},"get":{"tags":["Comment"],"summary":"Get the comment by its BlogID","operationId":"getCommentByBlogId","consumes":["application/x-www-form-urlencoded"],"produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog's ID to get comment","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"type":"boolean"},"response":{"type":"array","items":{"$ref":"#/definitions/Comment"}}}}}}}},"/tag/{BlogID}":{"get":{"tags":["Tag"],"summary":"Get the tag by its BlogID","operationId":"getTagByBlogId","consumes":["application/x-www-form-urlencoded"],"produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog's ID","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"type":"boolean"},"response":{"type":"string","example":"study life"}}}}}},"post":{"tags":["Tag"],"summary":"Post some tags","operationId":"postTag","produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog id to addTag","required":true,"type":"string"},{"in":"body","name":"body","description":"The tag to add","required":true,"schema":{"type":"object","properties":{"content":{"description":"POST tags","type":"string","example":"study"}}}}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}},"security":[{"token":[]}]}},"/user/signup":{"post":{"tags":["User"],"summary":"Create user","operationId":"createUser","produces":["application/json"],"parameters":[{"in":"body","name":"body","description":"Created user object","required":true,"schema":{"type":"object","properties":{"ID":{"type":"string","example":"32183921@qq.com"},"Name":{"type":"string","example":"PmlPml"},"Password":{"type":"string","example":"123456加密后的密文"}}}}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}}}},"/user/login":{"post":{"tags":["User"],"summary":"Logs user into the system","operationId":"loginUser","produces":["application/json"],"parameters":[{"in":"body","name":"body","description":"identification","required":true,"schema":{"type":"object","properties":{"ID":{"type":"string","example":"32183921@qq.com"},"Password":{"type":"string","example":"123456加密后的密文"}}}}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Responseforlogin"}}}}},"/user/logout":{"get":{"tags":["User"],"summary":"Logs out current logged in user session","operationId":"logoutUser","produces":["application/json"],"parameters":[],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}}}},"/user/{ID}/info":{"get":{"tags":["User"],"summary":"Get user by user ID","operationId":"getUserByID","produces":["application/json","application/xml"],"parameters":[{"name":"ID","in":"path","description":"The name that needs to be fetched. Use user1 for testing.","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"description":"true for success and false for failure","type":"boolean"},"response":{"$ref":"#/definitions/UserInfo"}}}}}}},"/blog":{"post":{"tags":["Blog"],"summary":"Add a new blog","operationId":"addBlog","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"body","required":true,"schema":{"type":"object","properties":{"Title":{"type":"string","example":"这是一篇博客"},"Abstract":{"type":"string","example":"这是博客的摘要"},"Content":{"type":"string","example":"这是博客的内容"}}}}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}},"security":[{"token":[]}]}},"/blogs":{"get":{"tags":["Blog"],"summary":"Get all public blogs","operationId":"getBlogs","produces":["application/json"],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"type":"boolean"},"response":{"type":"array","items":{"$ref":"#/definitions/Blog"}}}}}}}},"/blogs/{UserID}":{"get":{"tags":["Blog"],"summary":"Get all blogs of someone","operationId":"getBlogsByID","produces":["application/json"],"parameters":[{"name":"UserID","in":"path","description":"UserID","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"type":"boolean"},"response":{"type":"array","items":{"$ref":"#/definitions/Blog"}}}}}}}},"/blog/{BlogID}":{"get":{"tags":["Blog"],"summary":"Get the blog by its BlogID","operationId":"getBlogByBlogID","consumes":["application/x-www-form-urlencoded"],"produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog's ID","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","properties":{"state":{"type":"boolean"},"response":{"type":"array","items":{"$ref":"#/definitions/Blog"}}}}}}},"delete":{"tags":["Blog"],"summary":"Delete a Blog","operationId":"deleteBlog","produces":["application/json"],"parameters":[{"name":"BlogID","in":"path","description":"Blog id to delete","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"$ref":"#/definitions/Response"}}},"security":[{"token":[]}]}}},"securityDefinitions":{"token":{"type":"apiKey","name":"token","in":"header"}},"definitions":{"Tag":{"type":"object","properties":{"BlogID":{"description":"The ID of the Blog","type":"string","example":"c113456181"},"content":{"description":"all of the tags","type":"string","example":"study life math"}}},"Comment":{"type":"object","properties":{"BlogId":{"description":"The ID of the Blog","type":"string","example":"c113456181"},"ownName":{"description":"The name of the one who comments","type":"string","example":"pmlpml"},"commentTime":{"description":"The time of the comment","type":"number","example":1608107600},"content":{"description":"The content of the comment","type":"string","example":"Thanks!"}}},"Response":{"type":"object","properties":{"state":{"description":"true for success and false for failure","type":"boolean","example":true},"response":{"description":"the return message of the interfaces","type":"string","example":"success"}}},"Responseforlogin":{"type":"object","properties":{"state":{"description":"true for success and false for failure","type":"boolean","example":true},"response":{"description":"the token for signup","type":"string","example":"321141312"}}},"UserInfo":{"type":"object","properties":{"ID":{"type":"string","example":"32183921@qq.com"},"Name":{"type":"string","example":"PmlPml"},"Bio":{"type":"string","example":"好好学习天天向上"},"Level":{"type":"number","example":1}}},"Blog":{"type":"object","required":["title"],"properties":{"BlogID":{"type":"string","example":"231326"},"AuthorID":{"type":"string","example":"u010389391"},"AuthorName":{"type":"string","example":"链圈社区技术博客"},"CreateTime":{"type":"number","example":1608107600},"Title":{"type":"string","example":"雷电网络（一）：厘清雷电网络的原理"},"Abstract":{"type":"string","example":"以太坊也有自己的“闪电网络”，它的名字叫雷电网络"},"Content":{"type":"string","example":"闪电网络为解决比特币拥堵而生，当然也可以用于其他区块链项目，比如我们上篇说的OMG。不过，以太坊也有自己的“闪电网络”，它的名字叫雷电网络。甚至，以太坊除了雷电网络，还有其他类似的技术。我们可以把闪电网络、雷电网络及其他类似技术，统称为“状态通道技术”。 我们回顾下闪电网络的原理就知道，双方构建一条通道，然后双方的状态（在比特币里，仅为账户余额）在通道里刷新，通道关闭后，再将最终状态记录到区块链上。所以，状态通道这个名字还是挺贴切的。从这里可以看出，所有的状态通道技术，仅仅是把区块链当做最后的记录手段，而在平时尽量避免“上链”。继闪电网络后，今天我们稍微来了解下以太坊的雷电网络。在比特币那里，闪电网络只是一个单纯的技术，但以太坊的雷电网络是一个有自己代币（RDN）的ICO项目。从技术上来说，发不发代币并无区别，所以V神也曾质疑过RDN的必要性。不过从通证经济的角度来看，也许有妙用。不过，咱们这里仅了解其技术。因为以太坊是一个图灵完备的智能合约平台，很多复杂的工作以太坊在底层就已完成了，所以雷电网络的实现其实比闪电网络更简单。雷电网络不像闪电网络，必须依赖多重签名地址予以实现，而是直接靠以太坊的智能合约来实现。第一步：在以太坊上布署一个智能合约，理论上来说，既可以每建一个通道，就布署一个合约，也可以为一种代币布署一个合约。前者实现比较简单，但耗费gas太多，后者实现起来复杂一点，但便宜一些。第二步：通道双方将一定量的代币发送到合约地址进行锁定，构建资金池，在闪电网络那，由多重签名地址代持代币，而在雷电网络，则由合约地址代持。同时，双方会向合约发送一条双方签名的报文，这条报文的作用是向全网公示，通道双方各自锁定了多少代币。到此时为止，通道便建立起来了。第三步：通道建立后，双方所有的交易都可以在链下进行。举个例子：比如A和B建立了雷电通道，双方最初各自锁定了10个以太币，现在A要转1个以太币给B，那么双方一起签名一条新的信息：A减去1个以太币，B增加1个以太币（闪电通道的是记录余额，雷电通道的是记录净增减，比如A再发1个以太币给B，闪电通道会记录A还有8个，B有12个，但雷电通道会记录A减少2个，B增加2个）。这条信息不需要发到区块链上，只需A和B保留就行。第四步：A和B之间在链下的每一次双方签名的转账信息，都有一个序列号，比如第一次是1，第二次是2，如果要结束通道（假如A发起），A可以将最新的，也就是序列号最大的那个信息发送到智能合约，同时提供一个锁定时间。如果在锁定时间到期前，B提供了一个更新的信息，那说明A作弊（比如，A在倒数第二条信息时收到了B的1个以太币，在最后一条信息发给B两个以太币，但A结束通道时，只提交倒数第二条信息），合约会将锁定的币全部给B，用以惩罚A，如果到期时对方没有异议，合约根据最后这条信息的净增减额计算双方的最终余额并发还给他们。以上就是雷电网络的简单原理，下篇我们了解下它的一些特点。"}}}},"externalDocs":{"description":"Find out more about Swagger","url":"http://swagger.io"},"host":"virtserver.swaggerhub.com","basePath":"/CSBlog/a-blog_system/1.0.0","schemes":["https"]}