Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TXO 2.0 #3

Open
unwriter opened this issue Feb 3, 2020 · 0 comments
Open

TXO 2.0 #3

unwriter opened this issue Feb 3, 2020 · 0 comments

Comments

@unwriter
Copy link
Contributor

unwriter commented Feb 3, 2020

TXO 2.0 is mostly backwards compatible with TXO 1.0, with several additions.

What's New

  1. "b" is for base64: Now the b attribute is ONLY used for base64. Previously, the b attributes had somewhat of an ambiguous meaning: it could be a base64 representation, but could also mean an Opcode. Now b attributes are only used for base64. This brings up a question: How do we represent opcodes?
  2. "o" is for opcode: The Genesis update will remove all opcode usage limitations. This means there will be an explosion of different bitcoin transaction types, and being able to query based on opcodes will become very important going forward. We need an easy, human readable way to filter by opcode patterns. Therefore it is best to use human readable opcode names instead of numbers. This means, instead of indexing { "b0": { "op": 106 } } we use { "o0": "OP_RETURN" } for example.
  3. "len" is for script sequence size: Each input or output script is a sequence of chunks (either a buffer chunk or an opcode chunk). There has been no native way to get how many chunks are in a script. With TXO2.0, now we have a len attribute.
  4. "seq" is for nSequence: Enabled with the Genesis update.
  5. "lock" is for nLocktime: Enabled with the Genesis update.
  6. "str" removed: The "str" attribute was simply an ASM representation of a Bitcoin script. Technically this was a redundant feature and waste of storage space, because everything in the "str" attribute was already supported by other attributes such as "b", "h", and "s" attributes. But many people have been using "str" just to get opcode names because previously the "o" attribute didn't exist. Now you can use the "o" attribute for this purpose.

Example

Here's an example of the V2.0 TXO format. See Schema for the actual specification.

{
  "tx": {
    "h": "153d56a57db213777d3dac3459a40fe62036b762163f2563066f8a67a3cba014"
  },
  "blk": {
  	"i": 620415,
  	"h": "0000000000000000025a5aeaed281a198979f44c1492432505858c7603b33133",
  	"t": 1580715685
  },
  "in": [
    {
      "i": 0,
      "seq": 4294967295,
      "e": {
        "h": "f51596ab84f5219d470b3e73229533997c4ffd32579bb7c350bf235b57aac063",
        "i": 1,
        "a": "184UFRtgg8BR2Uebt3BVBvqBLoj81ZwDK1"
      },
      "s0": "0E\u0002!\u0000��(�su�\u0014�\u0018AU���=ܦE�\u0003��P(7к��{\u0002 /�\u0007�O�30_ټ�J�\t\u0003�O�ް��\u001c�\u0015Ղg���A",
      "b0": "MEUCIQCbxSiAc3XurhTDGEFVwOvWPdymRcUDj5pQKDfQuuCMewIgL/oH10/pMzBf2bzSSo0JA+xPyt6wtKgciRXVgmeFjfJB",
      "h0": "30450221009bc528807375eeae14c3184155c0ebd63ddca645c5038f9a502837d0bae08c7b02202ffa07d74fe933305fd9bcd24a8d0903ec4fcadeb0b4a81c8915d58267858df241",
      "s1": "\u0003�;�d\f�G��/T��0\u001b�<��w5���y�\u0003��\\ I",
      "b1": "A/w7smQM2Ee18i9U2cYwG+48vKt3NfmWv3nkA6TcXCBJ",
      "h1": "03fc3bb2640cd847b5f22f54d9c6301bee3cbcab7735f996bf79e403a4dc5c2049",
      "len": 2
    }
  ],
  "out": [
    {
      "i": 0,
      "e": {
        "v": 0,
        "i": 0,
        "a": "false"
      },
      "o0": "OP_RETURN",
      "s1": "19dbzMDDg4jZ4pvYzLb291nT8uCqDa61zH",
      "b1": "MTlkYnpNRERnNGpaNHB2WXpMYjI5MW5UOHVDcURhNjF6SA==",
      "h1": "313964627a4d444467346a5a347076597a4c623239316e5438754371446136317a48",
      "s2": "\u0001",
      "b2": "AQ==",
      "h2": "01",
      "s3": "{\"bitvavo\":{\"l\":256.96,\"v\":62906}}",
      "b3": "eyJiaXR2YXZvIjp7ImwiOjI1Ni45NiwidiI6NjI5MDZ9fQ==",
      "h3": "7b226269747661766f223a7b226c223a3235362e39362c2276223a36323930367d7d",
      "s4": "184UFRtgg8BR2Uebt3BVBvqBLoj81ZwDK1",
      "b4": "MTg0VUZSdGdnOEJSMlVlYnQzQlZCdnFCTG9qODFad0RLMQ==",
      "h4": "3138345546527467673842523255656274334256427671424c6f6a38315a77444b31",
      "s5": "1580715600",
      "b5": "MTU4MDcxNTYwMA==",
      "h5": "31353830373135363030",
      "len": 6
    },
    {
      "i": 1,
      "e": {
        "v": 606891,
        "i": 1,
        "a": "184UFRtgg8BR2Uebt3BVBvqBLoj81ZwDK1"
      },
      "o0": "OP_DUP",
      "o1": "OP_HASH160",
      "s2": "Mp�߫W��2w�|�r刂��\u0012",
      "b2": "TXDf36tXmocyd9x893LliIK4ihI=",
      "h2": "4d70dfdfab579a873277dc7cf772e58882b88a12",
      "o3": "OP_EQUALVERIFY",
      "o4": "OP_CHECKSIG",
      "len": 5
    }
  ],
  "lock": 0,
  "timestamp": 1580715617612
}

Schema

Level 0: Transacton Level

{
  "tx": {
    "h": <Transaction ID>
  },
  "blk": {
    "i": <Block Height (Index)>,
    "h": <Block Hash>,
    "t": <Block Time in Unix Time>
  },
  "in": [ <Input>, <Input>, ..., <Input> ],
  "out": [ <Output>, ..., <Output> ],
  "lock": <nLocktime>,
  "timestamp": <The timestamp at which the transaction was stored (optional)>
}

Level 1: Script Level

The in and out attributes are arrays of input scripts and output scripts.

A script is a sequence of chunks made up of opcodes or data buffers.

1. Input Script

{
  "i": <Input script index within the transaction>,
  "seq": <nSquence>,
  "e": {
    "h": <Previous Transaction ID>,
    "i": <Previous Output Index>,
    "a": <Sender Address (P2PKH)>
  },
  "s0": <Data buffer chunk at index 0, in UTF8>,
  "b0": <Data buffer chunk at index 0, in Base64>,
  "h0": <Data buffer chunk at index 0, in Hex>,
  "s1": <Data buffer chunk at index 1, in UTF8>,
  "b1": <Data buffer chunk at index 1, in Base64>,
  "h1": <Data buffer chunk at index 1, in Hex>,
  ...
  "len": <Total chunk length>
}

Here's an example:

{
  "i": 0,
  "seq": 4294967295,
  "e": {
    "h": "4b26303480086fc0b949c99c1698f012675d361daa759cb4a3d010bab65e259e",
    "i": 1,
    "a": "1H4t15RUz2A1XqPK9jZisgbbs7ewREVzHf"
  },
  "s0": "0E\u0002!\u0000��T�\t�0���$�I��n\u000b�ʆ�?��)�\fߞ�#�\u0002 {p�Q���z�\u0007�=\u0011\t�Z\u0010���\u0016��sʶ�U���\u0002A",
  "b0": "MEUCIQD5tlSlCeQw1Pi5JPFJz+xuC+fKhpk/0uApkgzfntgjkAIge3D9Udn8yXrMB7w9EQmmWhDzzsIWqM1zyrbnVfbpwwJB",
  "h0": "3045022100f9b654a509e430d4f8b924f149cfec6e0be7ca86993fd2e029920cdf9ed8239002207b70fd51d9fcc97acc07bc3d1109a65a10f3cec216a8cd73cab6e755f6e9c30241",
  "s1": "\u0003��\u001e�$5�����|�)�O�\u0012f\n�\u0019�c��)�ڷ�",
  "b1": "A/P0HrskNbSdv7PWfOKDKb1PkxJmCvoZumPL+CmV2rek",
  "h1": "03f3f41ebb2435b49dbfb3d67ce28329bd4f9312660afa19ba63cbf82995dab7a4",
  "len": 2
}

2. Output Script

{
  "i": <Input index within the transaction>,
  "e": {
    "v": <Transferred amount in Satoshis>,
    "i": <Output index>,
    "a": <Receiver address (P2PKH)>
  },
  "o0": <Opcode chunk at index 0>,
  "s1": <Data buffer chunk at index 1, in UTF8>,
  "b1": <Data buffer chunk at index 1, in Base64>,
  "h1": <Data buffer chunk at index 1, in Hex>,
  "s2": <Data buffer chunk at index 2, in UTF8>,
  "b2": <Data buffer chunk at index 0, in Base64>,
  "h2": <Data buffer chunk at index 0, in Hex>,
  ...
  "len": <Total chunk length>
}

Here's an example:

{
  "i": 0,
  "e": {
    "v": 0,
    "i": 0,
    "a": "false"
  },
  "o0": "OP_RETURN",
  "s1": "19dbzMDDg4jZ4pvYzLb291nT8uCqDa61zH",
  "b1": "MTlkYnpNRERnNGpaNHB2WXpMYjI5MW5UOHVDcURhNjF6SA==",
  "h1": "313964627a4d444467346a5a347076597a4c623239316e5438754371446136317a48",
  "s2": "\u0001",
  "b2": "AQ==",
  "h2": "01",
  "s3": "{\"bitvavo\":{\"l\":256.96,\"v\":62906}}",
  "b3": "eyJiaXR2YXZvIjp7ImwiOjI1Ni45NiwidiI6NjI5MDZ9fQ==",
  "h3": "7b226269747661766f223a7b226c223a3235362e39362c2276223a36323930367d7d",
  "s4": "184UFRtgg8BR2Uebt3BVBvqBLoj81ZwDK1",
  "b4": "MTg0VUZSdGdnOEJSMlVlYnQzQlZCdnFCTG9qODFad0RLMQ==",
  "h4": "3138345546527467673842523255656274334256427671424c6f6a38315a77444b31",
  "s5": "1580715600",
  "b5": "MTU4MDcxNTYwMA==",
  "h5": "31353830373135363030",
  "len": 6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant