Skip to content

Instantly share code, notes, and snippets.

@m-kus
Last active February 22, 2023 19:11
Show Gist options
  • Save m-kus/6f17b09ab6bd368b96abeb73476dfdf9 to your computer and use it in GitHub Desktop.
Save m-kus/6f17b09ab6bd368b96abeb73476dfdf9 to your computer and use it in GitHub Desktop.
Inspecting smart contracts with PyTezos
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Searching for origination\n",
"\n",
"As was shown in the previous post, thanks to Tezos statefulness we can rather quickly look for transactions of a special kind. \n",
"First af all let's try to find a smart contract origination."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
]
}
],
"source": [
"from pytezos.rpc import alphanet, mainnet\n",
"from pytezos.rpc.search import SearchChain"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"sc = SearchChain.from_chain(mainnet.main)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will look for one of the TezVote smart contracts. \n",
"The algorithm checks for the contract existence, before the origination RPC query have to return 404."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-03-24 01:57:19.634 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 182605\n",
"2019-03-24 01:57:20.210 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 273907\n",
"2019-03-24 01:57:20.801 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 319558\n",
"2019-03-24 01:57:21.375 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 296732\n",
"2019-03-24 01:57:21.967 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 285319\n",
"2019-03-24 01:57:22.579 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 291025\n",
"2019-03-24 01:57:23.172 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 293878\n",
"2019-03-24 01:57:23.744 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 292451\n",
"2019-03-24 01:57:24.539 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293164\n",
"2019-03-24 01:57:25.306 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 293521\n",
"2019-03-24 01:57:26.076 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293342\n",
"2019-03-24 01:57:26.866 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293431\n",
"2019-03-24 01:57:27.650 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293476\n",
"2019-03-24 01:57:28.412 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 293498\n",
"2019-03-24 01:57:29.209 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293487\n",
"2019-03-24 01:57:29.983 | DEBUG | pytezos.rpc.search:bisect:31 - 0 at level 293492\n",
"2019-03-24 01:57:30.776 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293489\n",
"2019-03-24 01:57:31.557 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293490\n",
"2019-03-24 01:57:32.332 | DEBUG | pytezos.rpc.search:bisect:31 - None at level 293491\n"
]
}
],
"source": [
"origination = sc.find_contract_origination_operation('KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"{'protocol': 'PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP',\n",
" 'chain_id': 'NetXdQprcVkpaWU',\n",
" 'hash': 'ooYyqjxeAcfgQDUfQPZ7rgrdqkGN61J1twQ3TWth3YnTPPgKuii',\n",
" 'branch': 'BM7oCo9haDP4tRxUDECZTWvE1joLoP1xTV5EJSb53PdDkksFokJ',\n",
" 'contents': [{'kind': 'reveal',\n",
" 'source': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'fee': '1259',\n",
" 'counter': '983246',\n",
" 'gas_limit': '10000',\n",
" 'storage_limit': '0',\n",
" 'public_key': 'edpktkZZBRwQk6BKTirT8tP2o2rFivY2cQ3vcZevnzg3SaCZLRqiL1',\n",
" 'metadata': {'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'change': '-1259'},\n",
" {'kind': 'freezer',\n",
" 'category': 'fees',\n",
" 'delegate': 'tz1Ldzz6k1BHdhuKvAtMRX7h5kJSMHESMHLC',\n",
" 'level': 71,\n",
" 'change': '1259'}],\n",
" 'operation_result': {'status': 'applied', 'consumed_gas': '10000'}}},\n",
" {'kind': 'origination',\n",
" 'source': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'fee': '1559',\n",
" 'counter': '983247',\n",
" 'gas_limit': '12997',\n",
" 'storage_limit': '377',\n",
" 'managerPubkey': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'balance': '0',\n",
" 'spendable': False,\n",
" 'delegatable': False,\n",
" 'script': {'code': [{'prim': 'parameter', 'args': [{'prim': 'nat'}]},\n",
" {'prim': 'storage',\n",
" 'args': [{'prim': 'map',\n",
" 'args': [{'prim': 'address'}, {'prim': 'nat'}]}]},\n",
" {'prim': 'code',\n",
" 'args': [[{'prim': 'DUP'},\n",
" {'prim': 'CDR'},\n",
" {'prim': 'SWAP'},\n",
" {'prim': 'CAR'},\n",
" {'prim': 'DUP'},\n",
" {'prim': 'PUSH', 'args': [{'prim': 'nat'}, {'int': '2'}]},\n",
" [[{'prim': 'COMPARE'}, {'prim': 'GE'}],\n",
" {'prim': 'IF',\n",
" 'args': [[], [[{'prim': 'UNIT'}, {'prim': 'FAILWITH'}]]]}],\n",
" {'prim': 'SOME'},\n",
" {'prim': 'SENDER'},\n",
" {'prim': 'UPDATE'},\n",
" {'prim': 'NIL', 'args': [{'prim': 'operation'}]},\n",
" {'prim': 'PAIR'}]]}],\n",
" 'storage': []},\n",
" 'metadata': {'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'change': '-1559'},\n",
" {'kind': 'freezer',\n",
" 'category': 'fees',\n",
" 'delegate': 'tz1Ldzz6k1BHdhuKvAtMRX7h5kJSMHESMHLC',\n",
" 'level': 71,\n",
" 'change': '1559'}],\n",
" 'operation_result': {'status': 'applied',\n",
" 'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'change': '-100000'},\n",
" {'kind': 'contract',\n",
" 'contract': 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM',\n",
" 'change': '-257000'}],\n",
" 'originated_contracts': ['KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY'],\n",
" 'consumed_gas': '12897',\n",
" 'storage_size': '100',\n",
" 'paid_storage_size_diff': '100'}}}],\n",
" 'signature': 'sigbbmyQB1CaZsn91jZeGsUt5io7uxz5n5epnFiix1ef1evt17NHYwzuRxpKnUZhd7efFyHY14wkyfn7mMCxyM3FMKGXVd8Z'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"origination()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finding all storage altering transactions\n",
"\n",
"We can also use step&bisect algo to retrieve all transactions that have changed the SC storage."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-03-24 01:57:36.053 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 364490\n",
"2019-03-24 01:57:36.640 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 363770\n",
"2019-03-24 01:57:37.423 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 363050\n",
"2019-03-24 01:57:38.033 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 362330\n",
"2019-03-24 01:57:38.614 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 361610\n",
"2019-03-24 01:57:39.204 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 360890\n",
"2019-03-24 01:57:39.777 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 360170\n",
"2019-03-24 01:57:40.363 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 359450\n",
"2019-03-24 01:57:40.954 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 358730\n",
"2019-03-24 01:57:41.710 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 358010\n",
"2019-03-24 01:57:42.495 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 357290\n",
"2019-03-24 01:57:43.289 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 356570\n",
"2019-03-24 01:57:44.091 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 355850\n",
"2019-03-24 01:57:44.907 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 355130\n",
"2019-03-24 01:57:45.698 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 354410\n",
"2019-03-24 01:57:46.471 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 353690\n",
"2019-03-24 01:57:47.259 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 352970\n",
"2019-03-24 01:57:48.041 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 352250\n",
"2019-03-24 01:57:48.827 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 351530\n",
"2019-03-24 01:57:49.591 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 350810\n",
"2019-03-24 01:57:50.378 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 350090\n",
"2019-03-24 01:57:51.164 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 349370\n",
"2019-03-24 01:57:51.963 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 348650\n",
"2019-03-24 01:57:52.771 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 347930\n",
"2019-03-24 01:57:53.559 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 347210\n",
"2019-03-24 01:57:54.319 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 346490\n",
"2019-03-24 01:57:54.909 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 345770\n",
"2019-03-24 01:57:55.505 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 345050\n",
"2019-03-24 01:57:56.099 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 344330\n",
"2019-03-24 01:57:56.691 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 343610\n",
"2019-03-24 01:57:57.276 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 342890\n",
"2019-03-24 01:57:57.858 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 342170\n",
"2019-03-24 01:57:58.474 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 341450\n",
"2019-03-24 01:57:59.063 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 340730\n",
"2019-03-24 01:57:59.654 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 340010\n",
"2019-03-24 01:58:00.235 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 339290\n",
"2019-03-24 01:58:00.842 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 338570\n",
"2019-03-24 01:58:01.447 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 337850\n",
"2019-03-24 01:58:02.059 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 337130\n",
"2019-03-24 01:58:02.652 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 336410\n",
"2019-03-24 01:58:03.235 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 335690\n",
"2019-03-24 01:58:03.825 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - 8212527456151390696 at level 334970\n",
"2019-03-24 01:58:04.420 | DEBUG | pytezos.rpc.search:find_state_change_intervals:16 - -5983102954595768091 at level 334250\n",
"2019-03-24 01:58:05.029 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334610\n",
"2019-03-24 01:58:05.621 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334430\n",
"2019-03-24 01:58:06.229 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334340\n",
"2019-03-24 01:58:06.805 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334295\n",
"2019-03-24 01:58:07.404 | DEBUG | pytezos.rpc.search:bisect:31 - -5983102954595768091 at level 334272\n",
"2019-03-24 01:58:07.984 | DEBUG | pytezos.rpc.search:bisect:31 - -5983102954595768091 at level 334283\n",
"2019-03-24 01:58:08.598 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334289\n",
"2019-03-24 01:58:09.201 | DEBUG | pytezos.rpc.search:bisect:31 - -5983102954595768091 at level 334286\n",
"2019-03-24 01:58:09.787 | DEBUG | pytezos.rpc.search:bisect:31 - -5983102954595768091 at level 334287\n",
"2019-03-24 01:58:10.383 | DEBUG | pytezos.rpc.search:bisect:31 - 8212527456151390696 at level 334288\n"
]
}
],
"source": [
"for op in sc.find_storage_change_operations('KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY', origination_level=293492):\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"{'protocol': 'PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP',\n",
" 'chain_id': 'NetXdQprcVkpaWU',\n",
" 'hash': 'ooJo7FLs23FFV6Nh7T9JePESirCSaQDmYKsjwvpWkGxaXdrwo88',\n",
" 'branch': 'BKs7j5NTxaMoqA6oR5z2tGrrGHtVLLGKPamdEkVBt9Ayuh3Brjr',\n",
" 'contents': [{'kind': 'transaction',\n",
" 'source': 'tz1hcHHoeKQCqsXDTmE2WS1B5FGGsbJVsbp7',\n",
" 'fee': '21000',\n",
" 'counter': '875786',\n",
" 'gas_limit': '32811',\n",
" 'storage_limit': '50',\n",
" 'amount': '0',\n",
" 'destination': 'KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY',\n",
" 'parameters': {'int': '2'},\n",
" 'metadata': {'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1hcHHoeKQCqsXDTmE2WS1B5FGGsbJVsbp7',\n",
" 'change': '-21000'},\n",
" {'kind': 'freezer',\n",
" 'category': 'fees',\n",
" 'delegate': 'tz1TDSmoZXwVevLTEvKCTHWpomG76oC9S2fJ',\n",
" 'level': 81,\n",
" 'change': '21000'}],\n",
" 'operation_result': {'status': 'applied',\n",
" 'storage': [{'prim': 'Elt',\n",
" 'args': [{'bytes': '00000a806e3d01d6178278c8120f861126ac5d4e70dd'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '000014c507140f5f3c75052e12b1975e3adfda9ad8d8'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00002accc28c028ee4e68e990d47baa9769cc0f776ea'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00002eeb56bdbbc7ea0b8ce4b8f09c1fec344bcd1151'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00006f256ddef23b26433f970e856c1f9aea1134cee4'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00007173e7d3b20f38a430ef3c2680002f031a3eafc4'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00008fb5cea62d147c696afd9a93dbce962f4c8a9c91'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '000092e4e012a95c52c068d892fbc6b619e17a36c557'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '0000b71bb0a81e36ebe7a8b256006081b593991265ec'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '0000d9a0c60e0b5718b8bab3bf611c0a4fbbab4c1dc4'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '0000f0fe1f03312284630df8f6c3a8ed4ea0c5119f4a'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '0000fed86ac2172e3841bb3da1ee969c4e619163a2ae'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '00016e19cd2d628167c47f74b60c84c01c67b2d7a49a'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '010b32e023ce9c4d2294b215daa1e43561e611aec500'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01704dc19cc2d13d03183557905ce5a362a09f035700'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '0170b2066acd8ce308e94efc3fd9764919f95098c900'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01ab062220312a77f03738c1b2aad1334276c7bfae00'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01c8c724b479e44f5bf1fe5251cd6c0f09879c675300'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01e360a38d47a089dc1da835ce3b2d740483f499cf00'},\n",
" {'int': '1'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01e8d513978c641c795c621a83d2c10a4daaeb397100'},\n",
" {'int': '2'}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'bytes': '01f0fe7d8f70bc9683b92fd17df37346fee4eb142400'},\n",
" {'int': '1'}]}],\n",
" 'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1hcHHoeKQCqsXDTmE2WS1B5FGGsbJVsbp7',\n",
" 'change': '-31000'}],\n",
" 'consumed_gas': '32711',\n",
" 'storage_size': '751',\n",
" 'paid_storage_size_diff': '31'}}}],\n",
" 'signature': 'sigj7qDjuneTzTUzL82ggkr6WzQvpW2kMQtKBPWmDe8iFLJaVtv3AQuDDNmMXBTWPUWMqoC34WqEG72tbCZYKyXUNvHSqzEy'}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"op()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Decoding storage\n",
"\n",
"Allright, now let's view some data, i'll take some random SC from alphanet for demonstration"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Pair',\n",
" 'args': [[{'prim': 'Elt',\n",
" 'args': [{'string': 'tz1PKKC9NTsxxfwYpg1bVAY5k5AKuPYe9gpg'},\n",
" {'string': 'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn'}]}],\n",
" {'prim': 'Pair',\n",
" 'args': [[{'prim': 'Elt',\n",
" 'args': [{'string': 'tz1PKKC9NTsxxfwYpg1bVAY5k5AKuPYe9gpg'},\n",
" {'string': 'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn'}]}],\n",
" [{'prim': 'Elt',\n",
" 'args': [{'string': 'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn'},\n",
" {'int': '1'}]}]]}]}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT19iGCL4YrVpT6ezEzbDH37Yxbas8jWQz4s'].storage()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Pair',\n",
" 'args': [[],\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '1'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '111111111111111110'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '18'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'test1'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'TST'},\n",
" {'string': 'KT1GE2AZhazRxGsAjRVkQccHcB2pvANXQWd7'}]}]}]}]}]}]}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT1VnRY6UuWH89P8DQtC7Sd178jkckff8o8d'].storage()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Pair',\n",
" 'args': [[{'prim': 'Elt',\n",
" 'args': [{'int': '0'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': ''},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': ''},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '0'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'prim': 'True'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': ''}, {'string': ''}]}]},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': '1970-01-01T00:00:00Z'},\n",
" {'string': '1970-01-01T00:00:00Z'}]}]}]}]}]}]}]}]},\n",
" {'prim': 'Elt',\n",
" 'args': [{'int': '1'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': '2035 Moon Lander'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'A shuttle like no other. Experiance a ride to the moon, retro style.'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '1000000'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'tz1KwNFuzryhY7ZFyZVcdnHFEZCT9xgrRmWT'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'prim': 'False'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'Moon Lander was damaged.'},\n",
" {'string': 'nil'}]}]},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': '2019-04-20T04:00:00Z'},\n",
" {'string': '2019-05-20T04:00:00Z'}]}]}]}]}]}]}]}]}],\n",
" {'int': '1'}]}"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT1FEDVALSfQLZwVZbF1hRxJ9c8MTPe7azCZ'].storage()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Okay that won't work, let's do some magic:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'owner_to_proxy': {'tz1PKKC9NTsxxfwYpg1bVAY5k5AKuPYe9gpg': 'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn'},\n",
" 'recovery_to_proxy': {'tz1PKKC9NTsxxfwYpg1bVAY5k5AKuPYe9gpg': 'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn'},\n",
" 'proxy_to_nonce': {'KT1BmGdHyTXaxKzEY55xmQpPspEBvQcgnrKn': 1}}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT19iGCL4YrVpT6ezEzbDH37Yxbas8jWQz4s'].decode_storage()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'accounts': {},\n",
" 'version': 1,\n",
" 'totalSupply': 111111111111111110,\n",
" 'decimals': 18,\n",
" 'name': 'test1',\n",
" 'symbol': 'TST',\n",
" 'owner': 'KT1GE2AZhazRxGsAjRVkQccHcB2pvANXQWd7'}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT1VnRY6UuWH89P8DQtC7Sd178jkckff8o8d'].decode_storage()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"({0: ('',\n",
" '',\n",
" Decimal('0'),\n",
" 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG',\n",
" 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG',\n",
" True,\n",
" '',\n",
" '',\n",
" DateTime(1970, 1, 1, 0, 0, 0, tzinfo=Timezone('+00:00')),\n",
" DateTime(1970, 1, 1, 0, 0, 0, tzinfo=Timezone('+00:00'))),\n",
" 1: ('2035 Moon Lander',\n",
" 'A shuttle like no other. Experiance a ride to the moon, retro style.',\n",
" Decimal('1'),\n",
" 'tz1KwNFuzryhY7ZFyZVcdnHFEZCT9xgrRmWT',\n",
" 'tz1gH29qAVaNfv7imhPthCwpUBcqmMdLWxPG',\n",
" False,\n",
" 'Moon Lander was damaged.',\n",
" 'nil',\n",
" DateTime(2019, 4, 20, 4, 0, 0, tzinfo=Timezone('+00:00')),\n",
" DateTime(2019, 5, 20, 4, 0, 0, tzinfo=Timezone('+00:00')))},\n",
" 1)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alphanet.context.contracts['KT1FEDVALSfQLZwVZbF1hRxJ9c8MTPe7azCZ'].decode_storage()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Oh yeah, much better :) \n",
"Note that we can handle both annotated and not annotated storage."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Encoding storage\n",
"\n",
"We can easily encode storage data back, this functional is quite useful for unit testing."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"contract = alphanet.context.contracts['KT1VnRY6UuWH89P8DQtC7Sd178jkckff8o8d']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at the schema first"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'accounts': {'#address': {'balance': '#nat',\n",
" 'allowances': {'#address': '#nat'}}},\n",
" 'version': '#nat',\n",
" 'totalSupply': '#nat',\n",
" 'decimals': '#nat',\n",
" 'name': '#string',\n",
" 'symbol': '#string',\n",
" 'owner': '#address'}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.storage_schema()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Pair',\n",
" 'args': [[],\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '2'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '100000000'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '8'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'AbcCoin'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'ABC'},\n",
" {'string': 'KT1GE2AZhazRxGsAjRVkQccHcB2pvANXQWd7'}]}]}]}]}]}]}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.encode_storage({\n",
" 'accounts': {},\n",
" 'version': 2,\n",
" 'totalSupply': 100000000,\n",
" 'decimals': 8,\n",
" 'name': 'AbcCoin',\n",
" 'symbol': 'ABC',\n",
" 'owner': 'KT1GE2AZhazRxGsAjRVkQccHcB2pvANXQWd7'\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Decoding transaction parameters\n",
"\n",
"Great! But what about parameters we call smart contracts with? \n",
"Take some complicated example"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"content = alphanet.blocks[216905].operations.managers.contents()[0]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"contract = alphanet.context.contracts['KT1FU74GimCeEVRAEZGURb6TWU8jK1N6zFJy']"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Left',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'int': '200'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'bytes': '8262f06395dbe509f27c1860774637394783df273e7f94ceac5914e2bcbb5faa'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'string': 'tz1ZvVYfqHUzmXNekaZRRGaFucH2DD6Q88Yc'},\n",
" {'prim': 'True'}]}]}]}]}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"content['parameters']"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Initiate': {'iRefTime': 200,\n",
" 'iHSec': '8262f06395dbe509f27c1860774637394783df273e7f94ceac5914e2bcbb5faa',\n",
" 'iPartie': 'tz1ZvVYfqHUzmXNekaZRRGaFucH2DD6Q88Yc',\n",
" 'iMaster': True}}"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.decode_parameters(content['parameters'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, we combine type and field annotations from the code with the transaction data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Encoding transaction parameters\n",
"\n",
"If we do not know exactly the SC interface, we can look at the internal schema representation:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Initiate': {'iRefTime': '#nat',\n",
" 'iHSec': '#bytes',\n",
" 'iPartie': '#address',\n",
" 'iMaster': '#bool'},\n",
" 'Redeem': {'rdHSec': '#bytes', 'rdSec': '#bytes'},\n",
" 'Refund': '#bytes'}"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.parameter_schema()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'prim': 'Right',\n",
" 'args': [{'prim': 'Left',\n",
" 'args': [{'prim': 'Pair', 'args': [{'bytes': '12'}, {'bytes': '34'}]}]}]}"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.encode_parameters({'Redeem': {'rdHSec': '12', 'rdSec': '34'}})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualize storage diff"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM': 1,\n",
" 'tz1Pv7ha8wzAyRHkR9RahWapdopK1tt6nVz1': 1,\n",
" 'tz1Vyuu4EJ5Nym4JcrfRLnp3hpaq1DSEp1Ke': 1,\n",
" 'tz1Z2jXfEXL7dXhs6bsLmyLFLfmAkXBzA9WE': 2,\n",
" 'tz1cLDXASgh48ntYmLqM3cqPEXmUtpJVVPma': 2,\n",
" 'tz1fUjvVhJrHLZCbhPNvDRckxApqbkievJHN': 2,\n",
" 'tz1isXamBXpTUgbByQ6gXgZQg4GWNW7r6rKE': 2,\n",
" 'KT19bywme8Dvown1K4VvbYfBtRZr967VTw93': 1,\n",
" 'KT1JreWebFqXAYLsd7M4PZat8aKMdRQtW9jb': 1,\n",
" 'KT1StPGrbvca76TrwBoJrDZrfTqireXRiKcP': 1,\n",
" 'KT1VK2iu1sMRWZRDrtRVF7rUSRxEfkpRx2Dj': 1,\n",
" 'KT1Vosb5zuhciCCzYxLggdLLFGXKaT47UFwm': 2,\n",
" 'KT1WZ2c7UsvUtrpd9ZZ7En266Cft7Ztdh4N3': 1}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"storage_1 = mainnet.blocks[328451].context.contracts['KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY'].decode_storage()\n",
"storage_1"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'tz1LbZJZ3ZiNCebiDQghuJCyByCmnsvG1RhV': 2,\n",
" 'tz1MXrEgDNnR8PDryN8sq4B2m9Pqcf57wBqM': 1,\n",
" 'tz1PYLN9TsKZHfn2GtrXnxkeGvahmYdBTG5v': 1,\n",
" 'tz1Pv7ha8wzAyRHkR9RahWapdopK1tt6nVz1': 1,\n",
" 'tz1VmiY38m3y95HqQLjMwqnMS7sdMfGomzKi': 1,\n",
" 'tz1Vyuu4EJ5Nym4JcrfRLnp3hpaq1DSEp1Ke': 1,\n",
" 'tz1Yju7jmmsaUiG9qQLoYv35v5pHgnWoLWbt': 2,\n",
" 'tz1Z2jXfEXL7dXhs6bsLmyLFLfmAkXBzA9WE': 2,\n",
" 'tz1cLDXASgh48ntYmLqM3cqPEXmUtpJVVPma': 2,\n",
" 'tz1fUjvVhJrHLZCbhPNvDRckxApqbkievJHN': 2,\n",
" 'tz1hcHHoeKQCqsXDTmE2WS1B5FGGsbJVsbp7': 2,\n",
" 'tz1isXamBXpTUgbByQ6gXgZQg4GWNW7r6rKE': 2,\n",
" 'tz2JMPu9yVKuX2Au8UUbp7YrKBZJSdYhgwwu': 2,\n",
" 'KT19bywme8Dvown1K4VvbYfBtRZr967VTw93': 1,\n",
" 'KT1JpaPrQq7dmFKMhe5S8yrGaJ9pDf8PK8E5': 2,\n",
" 'KT1JreWebFqXAYLsd7M4PZat8aKMdRQtW9jb': 1,\n",
" 'KT1QB4Tib11b8gYrC77Xs9bXU8TGJTXPAK7J': 2,\n",
" 'KT1StPGrbvca76TrwBoJrDZrfTqireXRiKcP': 1,\n",
" 'KT1VK2iu1sMRWZRDrtRVF7rUSRxEfkpRx2Dj': 1,\n",
" 'KT1Vosb5zuhciCCzYxLggdLLFGXKaT47UFwm': 2,\n",
" 'KT1WZ2c7UsvUtrpd9ZZ7En266Cft7Ztdh4N3': 1}"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"storage_2 = mainnet.blocks[334288].context.contracts['KT1ExvG3EjTrvDcAU7EqLNb77agPa5u6KvnY'].decode_storage()\n",
"storage_2"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"from pytezos.tools.diff import generate_jsondiff_html"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"generate_jsondiff_html(storage_1, storage_2, output_path='storage_diff.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[view diff](./storage_diff.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is pretty what we need when analyzing a smart contract behaviour, an input and side effects."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Accessing BigMap"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'initTs': DateTime(2019, 3, 5, 11, 33, 18, tzinfo=Timezone('UTC')),\n",
" 'refTime': 200,\n",
" 'hSec': '52c5bcbf9cb4dcaacd8689b42726c6f11e6eb575ade913923b6b1420b5b65eb9',\n",
" 'sec': '65a032b509811aba58cf788a90a00b24da6886a12008bfa9b13264478eaa42fe',\n",
" 'initor': 'tz1hqnW3wL3AShSAqnHXCJgt25DkEqn7dCqJ',\n",
" 'partie': 'tz1ZvVYfqHUzmXNekaZRRGaFucH2DD6Q88Yc',\n",
" 'value': Decimal('10'),\n",
" 'empt': True,\n",
" 'state': {'Empty': 'Unit'}}"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.big_map_get('52c5bcbf9cb4dcaacd8689b42726c6f11e6eb575ade913923b6b1420b5b65eb9')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also decode big map delta from the transaction"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"[{'key_hash': 'exprv2HiYAKq5BMmad58uDg7DZTavYaRTfEUERXSW9wqun1UgjjgH9',\n",
" 'key': {'bytes': 'd8d9564ad3a56df8b386f00368f43760b3a27893f27fa8cc840af02d751794e3'},\n",
" 'value': {'prim': 'Pair',\n",
" 'args': [{'int': '1551790128'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '200'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'bytes': 'd8d9564ad3a56df8b386f00368f43760b3a27893f27fa8cc840af02d751794e3'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Some',\n",
" 'args': [{'bytes': 'cd45c8d595d6926d339a46df7f69256e13c7f1eb7eef13962ed743029dde726c'}]},\n",
" {'prim': 'Pair',\n",
" 'args': [{'bytes': '0000f38be9b2a1bfb880fb6bf718924ad3275e4be45e'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'bytes': '00009caed54e6489d2efc325d276166bd3a05152782d'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'int': '10000000'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'True'},\n",
" {'prim': 'Left',\n",
" 'args': [{'prim': 'Unit'}]}]}]}]}]}]}]}]}]}}]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"big_map_diff = alphanet.blocks[216895].operations.contents('transaction')[0]['metadata']['operation_result']['big_map_diff']\n",
"big_map_diff"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'d8d9564ad3a56df8b386f00368f43760b3a27893f27fa8cc840af02d751794e3': {'initTs': DateTime(2019, 3, 5, 12, 48, 48, tzinfo=Timezone('UTC')),\n",
" 'refTime': 200,\n",
" 'hSec': 'd8d9564ad3a56df8b386f00368f43760b3a27893f27fa8cc840af02d751794e3',\n",
" 'sec': 'cd45c8d595d6926d339a46df7f69256e13c7f1eb7eef13962ed743029dde726c',\n",
" 'initor': 'tz1hqnW3wL3AShSAqnHXCJgt25DkEqn7dCqJ',\n",
" 'partie': 'tz1ZvVYfqHUzmXNekaZRRGaFucH2DD6Q88Yc',\n",
" 'value': Decimal('10'),\n",
" 'empt': True,\n",
" 'state': {'Empty': 'Unit'}}}"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract.big_map_diff_decode(big_map_diff)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bonus: parsing .tz files\n",
"\n",
"You can also initialize a `Contract` instance from Micheline, Michelson source string or file."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"source = '''\n",
"parameter nat;\n",
"storage (map address nat);\n",
"code { DUP ;\n",
" CDR ;\n",
" SWAP ;\n",
" CAR ;\n",
" DUP ;\n",
" PUSH nat 2 ;\n",
" { { COMPARE ; GE } ; IF {} { { UNIT ; FAILWITH } } } ;\n",
" SOME ;\n",
" SENDER ;\n",
" UPDATE ;\n",
" NIL operation ;\n",
" PAIR }\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"from pytezos.rpc.contract import Contract"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'prim': 'parameter', 'args': [{'prim': 'nat'}]}, {'prim': 'storage', 'args': [{'prim': 'map', 'args': [{'prim': 'address'}, {'prim': 'nat'}]}]}, {'prim': 'code', 'args': [[{'prim': 'DUP'}, {'prim': 'CDR'}, {'prim': 'SWAP'}, {'prim': 'CAR'}, {'prim': 'DUP'}, {'prim': 'PUSH', 'args': [{'prim': 'nat'}, {'int': '2'}]}, [[{'prim': 'COMPARE'}, {'prim': 'GE'}], {'prim': 'IF', 'args': [[], [[{'prim': 'UNIT'}, {'prim': 'FAILWITH'}]]]}], {'prim': 'SOME'}, {'prim': 'SENDER'}, {'prim': 'UPDATE'}, {'prim': 'NIL', 'args': [{'prim': 'operation'}]}, {'prim': 'PAIR'}]]}]"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"contract = Contract.from_string(source)\n",
"contract"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python 3.7",
"language": "python",
"name": "python36"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment