Omni Layer
Table of Contents
1. Omni Layer 简介
Omni Layer 是 BTC 上的二层协议,可以基于这个协议发行代币,其中最有名的是 USDT,它是编号为 31 的 Omni Token。
Omni Layer 规定了三类交易:
Class A : payload stored in fake Bitcoin address
Class B : payload stored in redeemable multisignature output
Class C : payload stored in OP_RETURN output
我们只关注 Class C,也就是 把交易元数据附带到 OP_RETURN 中。
Omni Layer 上的交易需要使用专门的浏览器才能查看,如:https://omniexplorer.info/
2. 转账实例
下面以 USDT 转账 Tx dbefea564ea13abe519554882b8ea70996c95dc7a8116e8f8579019aafee82fd 为例介绍一下 Omni Layer。
2.1. OP_RETURN 元数据
我们在 Omni 浏览器上打开这个 Tx,可以得到如表 1 所示信息。
Simple Send dbefea564ea13abe519554882b8ea70996c95dc7a8116e8f8579019aafee82fd | |
---|---|
Amount | 150,000.00 |
Property | TetherUS (#31) |
Sender | 1MjsAPNHugmDfbyCPT3f5KaLT3edXVLNiF |
Recipient | 1L26MQMD1Nk9DdsHA9ueNGS8HS1zzKnx7p |
Date/Time | 9/30/2019 2:29:26 PM |
In Block | 597223 |
Status | CONFIRMED |
Bitcoin Fees | 0.00087737 BTC |
Omni Layer Fees | 0.00 OMNI |
Type/Version | Type 0, Version 0 |
可知它是从 1MjsAPNHugmDfbyCPT3f5KaLT3edXVLNiF 到 1L26MQMD1Nk9DdsHA9ueNGS8HS1zzKnx7p 的转账,金额为 150,000.00 USDT。
如果我们使用普通的 BTC 区块浏览器打开这个 Tx,如 https://www.blockchain.com/btc/tx/dbefea564ea13abe519554882b8ea70996c95dc7a8116e8f8579019aafee82fd ,则可以看到它就是一个普通的 BTC 转账,只是 Output 中多了一个 OP_RETURN 6f6d6e69000000000000001f00000da475abf000
。
6f6d6e69000000000000001f00000da475abf000 各个字节的含义如下:
6f6d6e69: omni 4 个字母的 16 进制 00: Transaction version 00: Transaction type. 如 0 表示 Simple Send 0000001f: Currency Identifier,从 16 进制转换为 10 进制就是 31 00000da475abf000: 从 16 进制转换为 10 进制是 15000000000000,去掉 8 位小数就是 150,000
其中 Transaction type 如表 2 所示(参考 https://github.com/OmniLayer/spec/blob/master/OmniSpecification-v0.6.adoc#7918-field-transaction-type )。
Transaction type | Meaning |
---|---|
0 | Simple Send |
3 | Send To Owners |
20 | Sell Coins for Bitcoins (currency trade offer) |
21 | Offer/Accept Omni Protocol Coins for Another Omni Protocol Currency (currency trade offer) |
22 | Purchase Coins with Bitcoins (accept currency trade offer) |
50 | Create a Property with fixed number of tokens |
51 | Create a Property via Crowdsale with Variable number of Tokens |
52 | Promote a Property |
53 | Close a Crowdsale Manually |
54 | Create a Managed Property with Grants and Revocations |
55 | Grant Property Tokens |
56 | Revoke Property Tokens |
70 | Change Property Issuer on Record |
2.2. 发送地址和接收地址
上面介绍的 OP_RETURN 中包含了转账 USDT 的数量,还剩下一个问题:怎么决定发送地址(sender)和接收地址(receiver)呢?
对于 Class C(也就是元数据在 OP_RETURN 上)的交易,确定发送地址和接收地址的规则如下:
- Tx 的 Inputs 中,首个 Input 对应地址是发送地址。
- Tx 的 Outputs 中,检查最后一个 Output 对应地址,如果它不是 sender,则它就是接收地址;如果是 sender,则倒数第二个 Output 对应地址就是接收地址。之所以这么做,是为了去掉找零地址,如:
Tx1(最后一个 Output 对应地址不是 sender): In[0]: A [< sender] Out[0]: Payload Out[1]: A Out[2]: B Out[3]: C [< receiver] Tx2(最后一个 Output 对应地址恰好是 sender): In[0]: A [< sender] Out[0]: Payload Out[1]: C Out[2]: B [< receiver] Out[3]: A Tx3(最后一个 Output 对应地址恰好是 sender,倒数第二个地址也是 sender): In[0]: A [< sender] Out[0]: Payload Out[1]: B Out[2]: A [< receiver] Out[3]: A
参考:
https://github.com/OmniLayer/omnicore/issues/836#issuecomment-474434143
https://github.com/OmniLayer/spec/blob/master/OmniSpecification-v0.6.adoc#transfer-coins-simple-send