{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Writing TZBTC `big_map_diff` parser script in Michelson\n", "### Goal: to create an analogue of `balance_updates` for transfer / mint / burn operations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "TZBTC `big_map_diff` for a transfer operation looks like this:\n", "```\n", "[..., {'action': 'update',\n", " 'big_map': '31',\n", " 'key_hash': 'expruiaeokjY8rPY52YXKZ6zK7oBN9Cx52psQyHtup13vMUmM7e4X2',\n", " 'key': {'bytes': '05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3'},\n", " 'value': {'bytes': '05070700ac9a010200000000'}}, ...]\n", "```\n", "\n", "What we want to get is changed balances with some metadata (for displaying):\n", "```\n", "{'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT': {'balance': 9900,\n", " 'decimals': 8,\n", " 'symbol': 'TZBTC'}}\n", "```" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "parameter (pair %decodeBigMapDiff (bytes %key) (option (bytes %value))) # value can be null, so we made it optional" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "storage (map (address %holder) \n", " (pair (nat %balance) \n", " (pair (nat %decimals) \n", " (string %symbol))))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step-by-step contract development \n", "You can scroll down to the result" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
Pair\n",
       "  (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3\n",
       "        (Some 0x05070700ac9a010200000000))\n",
       "  {}
pair (pair %decodeBigMapDiff (bytes %key) (option (bytes %value)))\n",
       "      (map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol))))
" ], "text/plain": [ "value type\n", "-------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------\n", "Pair pair (pair %decodeBigMapDiff (bytes %key) (option (bytes %value)))\n", " (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol))))\n", " (Some 0x05070700ac9a010200000000))\n", " {}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BEGIN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 \n", " (Some 0x05070700ac9a010200000000)) \n", " {} # empty map" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DUP: push ((b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)), {});\n", "DIP: protect 1 item(s);\n", " CDR: pop ((b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)), {}); push {};\n", " restore 1 item(s);\n", "CAR: pop ((b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)), {}); push (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',));" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3\n",
       "      (Some 0x05070700ac9a010200000000)
pair %decodeBigMapDiff (bytes %key) (option (bytes %value))
@parameter
" ], "text/plain": [ "value type name\n", "----------------------------------------------------------------------------------------- ----------------------------------------------------------- ----------\n", "Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 pair %decodeBigMapDiff (bytes %key) (option (bytes %value)) @parameter\n", " (Some 0x05070700ac9a010200000000)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DUP ; DIP { CDR @storage } ; # save storage on the bottom of the stack\n", "CAR @parameter" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DUP: push (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',));\n", "CAR: pop (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)); push 05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3;" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3
bytes %key
@key
" ], "text/plain": [ "value type name\n", "------------------------------------------------------------------------------------ ---------- ------\n", "0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 bytes %key @key" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DUP ; CAR @key # first let's check the key" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "UNPACK: pop 05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3; push (('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT'),);\n", "IF_NONE: pop (('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT'),); push ('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT');\n", " RENAME: pop ('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT'); push ('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT');" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
Pair \"ledger\" 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3
pair string address
" ], "text/plain": [ "value type\n", "------------------------------------------------------------ -------------------\n", "Pair \"ledger\" 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 pair string address" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "UNPACK (pair string address) ; # trying to unpack big map key (they can be of different types underneath)\n", "ASSERT_SOME" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DUP: push ('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT');\n", "CAR: pop ('ledger', 'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT'); push ledger;" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
\"ledger\"
string
@label
" ], "text/plain": [ "value type name\n", "-------- ------ ------\n", "\"ledger\" string @label" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DUP ; CAR @label" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PUSH: push ledger;\n", "COMPARE: pop ledger, ledger; push 0;\n", "EQ: pop 0; push True;\n", "IF: pop True;" ] } ], "source": [ "PUSH string \"ledger\" ; ASSERT_CMPEQ ; # make sure it's balance data" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
Pair \"ledger\" 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3
pair string address
Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3\n",
       "      (Some 0x05070700ac9a010200000000)
pair %decodeBigMapDiff (bytes %key) (option (bytes %value))
@parameter
{}
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
@storage
" ], "text/plain": [ "value type name\n", "----------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------- ----------\n", "Pair \"ledger\" 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 pair string address\n", "Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 pair %decodeBigMapDiff (bytes %key) (option (bytes %value)) @parameter\n", " (Some 0x05070700ac9a010200000000)\n", "{} map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol))) @storage" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DUMP" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3
address
@holder
" ], "text/plain": [ "value type name\n", "---------------------------------------------- ------- -------\n", "0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 address @holder" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "CDR @holder ;" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SWAP: pop tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT, (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)); push tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT; push (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',));\n", "CDR: pop (b'\\x05\\x07\\x07\\x01\\x00\\x00\\x00\\x06ledger\\n\\x00\\x00\\x00\\x16\\x00\\x00\\x16\\xe6I\\x94\\xc2\\xdd\\xbd)6\\x95\\xb6>L\\xad\\xe0)\\xd3\\xc8\\xb5\\xe3', (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',)); push (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',);\n", "IF_NONE: pop (b'\\x05\\x07\\x07\\x00\\xac\\x9a\\x01\\x02\\x00\\x00\\x00\\x00',); push 05070700ac9a010200000000;\n", " RENAME: pop 05070700ac9a010200000000; push 05070700ac9a010200000000;" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
0x05070700ac9a010200000000
bytes %value
" ], "text/plain": [ "value type\n", "-------------------------- ------------\n", "0x05070700ac9a010200000000 bytes %value" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SWAP ; CDR @value ; \n", "ASSERT_SOME # actually we need to handle cases when a key is removed from big_map, will do later" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "UNPACK: pop 05070700ac9a010200000000; push ((9900, {}),);\n", "IF_NONE: pop ((9900, {}),); push (9900, {});\n", " RENAME: pop (9900, {}); push (9900, {});" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
Pair 9900 {}
pair nat (map address nat)
" ], "text/plain": [ "value type\n", "------------ --------------------------\n", "Pair 9900 {} pair nat (map address nat)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "UNPACK (pair nat (map address nat)) ; \n", "ASSERT_SOME # here we can fail, since we know exactly how data is packed" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
9900
nat
@balance
" ], "text/plain": [ " value type name\n", "------- ------ --------\n", " 9900 nat @balance" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "CAR @balance" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PUSH: push TZBTC;\n", "PUSH: push 8;" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
8
nat
@decimals
" ], "text/plain": [ " value type name\n", "------- ------ ---------\n", " 8 nat @decimals" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PUSH @symbol string \"TZBTC\" ; # adding metadata\n", "PUSH @decimals nat 8 ;" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type name
8
nat
@decimals
\"TZBTC\"
string
@symbol
9900
nat
@balance
0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3
address
{}
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
@storage
" ], "text/plain": [ "value type name\n", "---------------------------------------------- ----------------------------------------------------------------------------------- ---------\n", "8 nat @decimals\n", "\"TZBTC\" string @symbol\n", "9900 nat @balance\n", "0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 address\n", "{} map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol))) @storage" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DUMP" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PAIR: pop 8, TZBTC; push (8, 'TZBTC');\n", "SWAP: pop (8, 'TZBTC'), 9900; push (8, 'TZBTC'); push 9900;\n", "PAIR: pop 9900, (8, 'TZBTC'); push (9900, (8, 'TZBTC'));\n", "SOME: pop (9900, (8, 'TZBTC')); push ((9900, (8, 'TZBTC')),);" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
Some (Pair 9900 (Pair 8 \"TZBTC\"))
option (pair nat (pair nat string))
" ], "text/plain": [ "value type\n", "--------------------------------- -----------------------------------\n", "Some (Pair 9900 (Pair 8 \"TZBTC\")) option (pair nat (pair nat string))" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PAIR ; SWAP ; PAIR ; SOME ;" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SWAP: pop ((9900, (8, 'TZBTC')),), tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT; push ((9900, (8, 'TZBTC')),); push tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT;\n", "UPDATE: pop tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT, ((9900, (8, 'TZBTC')),), {}; push {'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT': (9900, (8, 'TZBTC'))};" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) }
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
" ], "text/plain": [ "value type\n", "----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------\n", "{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) } map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SWAP ; UPDATE # writing to the storage" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NIL: push [];\n", "PAIR: pop [], {'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT': (9900, (8, 'TZBTC'))}; push ([], {'tz1Mj7RzPmMAqDUNFBn5t5VbXmWW4cSUAdtT': (9900, (8, 'TZBTC'))});\n", "COMMIT:" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) }
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
" ], "text/plain": [ "value type\n", "----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------\n", "{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) } map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "NIL operation ; PAIR ; COMMIT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Resulting script\n", "Actually a valid Tezos contract" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "parameter (pair %decodeBigMapDiff (bytes %key) (option (bytes %value)));\n", "storage (map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol))));\n", "code { DUP ; CAR ; DIP { CDR } ; DUP ; CAR ; UNPACK (pair string address) ; { IF_NONE { DROP } { DUP ; CAR ; PUSH string \"ledger\" ; { { COMPARE ; EQ } ; IF { CDR @holder ; SWAP ; CDR ; { IF_NONE { PUSH @balance nat 0 } { UNPACK (pair nat (map address nat)) ; { IF_NONE { { UNIT ; FAILWITH } } { RENAME } } ; CAR @balance } } ; PUSH @symbol string \"TZBTC\" ; PUSH @decimals nat 8 ; PAIR ; SWAP ; PAIR ; SOME ; SWAP ; UPDATE } { DROP 2 } } } } ; NIL operation ; PAIR };" ] } ], "source": [ "parameter (pair %decodeBigMapDiff (bytes %key) (option (bytes %value))) ;\n", "storage (map (address %holder) \n", " (pair (nat %balance) \n", " (pair (nat %decimals) \n", " (string %symbol)))) ;\n", "code {\n", " DUP ; CAR ; DIP { CDR } ;\n", " DUP ; CAR ;\n", " UNPACK (pair string address) ;\n", " IF_SOME { \n", " DUP ; CAR ;\n", " PUSH string \"ledger\" ;\n", " IFCMPEQ { \n", " CDR @holder ; \n", " SWAP ; CDR ;\n", " IF_SOME { \n", " UNPACK (pair nat (map address nat)) ;\n", " ASSERT_SOME ;\n", " CAR @balance ;\n", " } { \n", " PUSH @balance nat 0;\n", " } ;\n", " PUSH @symbol string \"TZBTC\" ;\n", " PUSH @decimals nat 8 ;\n", " PAIR ; SWAP ; PAIR ; SOME ;\n", " SWAP ; UPDATE \n", " } {\n", " DROP 2\n", " } ;\n", " } { \n", " DROP\n", " } ;\n", " NIL operation ; PAIR ;\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's run some tests" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "DEBUG False" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) }
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
" ], "text/plain": [ "value type\n", "----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------\n", "{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 9900 (Pair 8 \"TZBTC\")) } map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RUN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 \n", " (Some 0x05070700ac9a010200000000)) \n", " {}" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 0 (Pair 8 \"TZBTC\")) }
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
" ], "text/plain": [ "value type\n", "-------------------------------------------------------------------------------- -----------------------------------------------------------------------------------\n", "{ Elt 0x000016e64994c2ddbd293695b63e4cade029d3c8b5e3 (Pair 0 (Pair 8 \"TZBTC\")) } map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RUN %decodeBigMapDiff (Pair 0x05070701000000066c65646765720a00000016000016e64994c2ddbd293695b63e4cade029d3c8b5e3 \n", " None) \n", " {}" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
value type
{}
map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))
" ], "text/plain": [ "value type\n", "------- -----------------------------------------------------------------------------------\n", "{} map (address %holder) (pair (nat %balance) (pair (nat %decimals) (string %symbol)))" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RUN %decodeBigMapDiff (Pair 0xdeadbeef None) {}" ] } ], "metadata": { "kernelspec": { "display_name": "Michelson", "language": "michelson", "name": "michelson" }, "language_info": { "codemirror_mode": "michelson", "file_extension": ".tz", "mimetype": "text/x-michelson", "name": "Michelson" } }, "nbformat": 4, "nbformat_minor": 2 }