MetaID website building tutorial: how to build MetaProtocols.com

MetaProtocols.com is a website that records the protocols related to metaid. This website is convenient for users to search and view existing agreements. You can also publish new agreements and edit your own agreements on this website.

1.MetaProtocols.com

MetaProtocols.com development goals

  • Show that the development model based on MetaID can quickly develop an application

  • How to create a MetaID+ShowMeta/MetaSV to implement a Serverless website (only the first version, in the long run, it still needs a simple background to manage, such as blacklist, sensitive word filtering, etc.)

  • Developers can easily browse the release agreement on this website

Expected development time

If the following conditions are met, the development time should be completed within 48 hours

  • Middleware can quickly return data as required;

  • The design draft is completed.

  • showmoney third-party login/registration is relatively complete

  • The relevant agreement is established.

2. Login/Register

Login/register uses ShowMoney's third-party authorized login and registration functions;

Insert picture description here

After the user logs in, he can use the following main functions of the website:

  • Release agreement
  • Edit agreement
  • Like the agreement
  • Comment Agreement

3. Publication Agreement

After the user enters the release agreement page, the agreement can be released. The protocol release adopts the 9.1 release meta protocol protocol. The user interface is as follows:

Insert picture description here

After the user fills out the form, the metaProtocols protocol is used to construct such a json object

metaProtocolData:

{
"protocolTitle":表单上协议名称,
"protocolAuthors":"这是记录协议作者",
"protocolIdentifier":表单上的协议标识,
"protocolHASHID":这是12位哈希值,采用BRFCID生成方式,根据protocolTitle、protocolAuthors、版本号来生成,
"protocolType":从协议类型选择选择,
"protocolEncoding":从协议编码框选择,
"protocolContent":表单上的协议内容,
"protocolDescription":表单上的协议说明,
"protocolImages":暂为空
}

Then construct the following transaction:

OP_0 OP_RETURN meta <address> <MetaProtocols TxID> MetaID <address> <metaProtocolData> 0 <表单上的版本号> applicaiton/json UTF-8 

If the user does not have a MetaProtocols node under the Protocols node, you need to create a new node MetaProtocols:

OP_0 OP_RETURN meta <address> <Protocols TxID> MetaID MetaProtocols <protocolHASHID> 0 1 NULL NULL 

After submitting the transaction, it will be published successfully.

4. Home page agreement list

Make the following similar queries to the data service provider

查询
"find":{
"parentNode":"MetaProtocols",
"isValid":true, //是否可用的
"isNew":true //最新版本
}

The user obtains the metaprotocol submitted by the metaaid users of the entire network.

Then a set of protocol arrays can be obtained from the data service provider. The array elements should contain at least the following information:

The data part of the protocol should be the complete json format data (see 9.1 Publishing Protocol Protocol)

Protocol version number, protocol creation time

metaid, user name, user avatar, txid, etc.

As shown:
Insert picture description here

5. Personal Center

Click on the user's avatar or your own avatar to enter the personal center page.

The personal center mainly displays the agreement and some simple information released by the user. The final display effect is as follows:

Insert picture description here

It should be noted that if you enter your personal center page, the "New Version" button in the agreement is available to you, otherwise the button will not be displayed.

Obtaining the agreement issued by the specified user is very simple, just request a similar query from the data service provider:

查询
"find":{
"parentNode":"MetaProtocols",
"metaID":"{用户的metaID}"
"isValid":true, //是否可用的
"isNew":true //最新版本
}

After the data is obtained, the data can be processed by asynchronously obtaining the number of likes like the homepage, and the page can be rendered.

Acquisition of total revenue

The total revenue is the total revenue from all the user's published agreements. Similar queries can be requested from the data service provider:

查询
"find":{
"parentNode":"ShowLike",
"data.payTo":"{用户的metaID}"
"data.payTO":{"$in":[所有的out地址]} //payTo地址和真实打款地址一致
"data.Pay":{"$in":[所有的out地址的输出金额]}//pay金额和打款金额一致
”data.toTx“:{"$in":[所有MetaProtocols下的本人交易]} //只统计协议部分的点赞,不统计其他应用的点赞。
"isValid":true, //是否可用的
"isNew":true //最新版本
}

Total number of agreements

To obtain your total number of agreements, you can request similar queries from the data service provider:

查询
"find":{
"parentNode":"MetaProtocols",
"MetaID":"{用户的metaID}"
"isValid":true, //是否可用的
"isNew":true //最新版本
}

Get the length of the returned result.

New version/editing interface

When users enter their personal center page, they should be able to see the "Add Version" button in each agreement. After the user clicks, it will enter the protocol editing interface. The editing interface is consistent with the new agreement, except that the content of the form will be copied from the latest version of the agreement. And the version number is automatically increased by one. And start the new protocol of the modification mode of metanet:

  • Do not detect the same protocolIndentifier
  • Update related version and agreement content
  • The address after op_return is constructed is the same as the last latest protocol address.

6. Agreement details

The user clicks on the agreement to enter the agreement details page according to the agreement tx.

Obtaining protocol details is very simple, you can directly query tx with the service provider, such as:

"find":{
"tx":"{需查询协议tx}"
}

Then, according to the feedback result, interpret the data content according to the specified protocol, that is, the protocol format of the 9.1 Publication Protocol Protocol, and then the relevant data can be obtained and rendered into the following page.

Insert picture description here

7. Like processing

Likes uses the 9.2 simple like protocol. After the user clicks the like, a SimpleLike protocol is constructed. The reference is as follows:

{
"isLike":"1",
"toTx":协议的txID,
"pay":5000
”payTo":协议创建者rootAddress
}

After the user confirms, construct a transaction similar to the following

OP_0 OP_RETURN meta <address> <parennt TxID> MetaID <address> {"isLike":"1","toTx":协议的txID,"pay":5000”payTo":协议创建者rootAddress} 0 1 application/json UTF-8

其中一个out的地址和金额应该和payTo和pay中的值一致

In this application, the like rules are:

  • payTo: the metaID of the creator of the agreement;
  • pay: Like at least once, no less than 5000 Satoshi

8. View historical version

There is a historical version view button under each agreement details page. After clicking, the user can view all historical versions of the agreement. The reference design drawing is as follows:

Insert picture description here

You can get similar queries from the data service

查询
"find":{
"parentNode":"MetaProtocols",
"data.protocolIdentifier":"{协议的标识ID}",
"metaID":"{用户的metaID}"
"isValid":true, //是否可用的
}

The key point is to remove the filter conditions for obtaining the current version to view all historical versions.

9. Related agreements

9.1 Publishing agreement agreement

Agreement name: metaprotocols release agreement

Agreement On: MetaID Team

Protocol ID: MetaProtocols

Protocol format and encoding: application/json, UTF-8

Agreement

{
"protocolTitle":"{这是协议标题,如一个xx协议}",
"protocolAuthors":"{这是记录协议作者}",
"protocolIdentifier":"{这是协议标识,如xxProtocol}",
"protocolHASHID":"{这是12位哈希值,和protocolIdentifier一起构成唯一协议名}",
"protocolType":"{协议格式,例如applicaiton/json代表json格式}",
"protocolEncoding":"{协议编码,例如UTF-8}",
"protocolContent":"{协议内容实例,一般放示例性例子内容,例如本段文字,}",
"ProtocolContentType":{协议内容的文本格式",如text/plain"},
"protocolDescription":"{协议的详细说明,例如下面这段文字}",
"ProtocolDescriptionType":{协议描述的文本格式,如"text/plain"},
"protocolImages":['采用B协议的图片tx地址','存放和协议相关的说明性图片']
}

Protocol description:

protocolEncoding,为协议编码,参考https://www.iana.org/assignments/character-sets/character-sets.xhtml
ProtocolContentType和ProtocolDescriptionType可接受的格式:
text/plain,text/html,text

9.2 Payment Like Agreement

Agreement name: simple like agreement

Agreement ID: PayLike

Protocol format and encoding: application/json, UTF-8

Agreement:

{
"isLike":"{1为点赞,-1为反对,其他不处理}",
"toTx":"{点赞的交易ID}",
"pay":"{向payTo指定用户支付的金额,默认为2000聪}"
”payTo":"{支付对象的地址}"
}

9.3 Payment Review Agreement

**Chinese Agreement Name: **Payment Review Agreement

Agreement ID: PayComment

Protocol format: Applicaiton/json

Protocol instance:

{
	"createTime":"{创建时间}",
	"content":"{内容}",
	"contentType":"内容格式,默认text/plain",
	"commentTo":"评论是针对某tx或URL",
	"pay":"{向payTo指定用户支付的金额,默认为5000聪}"
	"payTo":"{支付对象的metaid}"
}

Guess you like

Origin blog.csdn.net/percyWangcn/article/details/107206384