Skip to content

Instantly share code, notes, and snippets.

@m-kus
Created August 27, 2019 12:54
Show Gist options
  • Save m-kus/c284b9704a236a1c464d008fe9776b5f to your computer and use it in GitHub Desktop.
Save m-kus/c284b9704a236a1c464d008fe9776b5f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from conseil import conseil\n",
"from pytezos import pytezos\n",
"from datetime import datetime, timedelta"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Path\n",
"metadata/tezos/alphanet/operations/attributes\n",
"\n",
"Attributes\n",
".operation_group_hash\n",
".kind\n",
".level\n",
".delegate\n",
".slots\n",
".nonce\n",
".pkh\n",
".secret\n",
".source\n",
".fee\n",
".counter\n",
".gas_limit\n",
".storage_limit\n",
".public_key\n",
".amount\n",
".destination\n",
".parameters\n",
".manager_pubkey\n",
".balance\n",
".spendable\n",
".delegatable\n",
".script\n",
".storage\n",
".status\n",
".consumed_gas\n",
".storage_size\n",
".paid_storage_size_diff\n",
".originated_contracts\n",
".block_hash\n",
".block_level\n",
".timestamp\n",
".internal"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Operation = conseil.tezos.alphanet.operations\n",
"Operation"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"txs = Operation.query(Operation.block_level, Operation.operation_group_hash) \\\n",
" .filter(Operation.destination == 'KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj',\n",
" Operation.status == 'applied',\n",
" Operation.timestamp > 1000 * int((datetime.utcnow() - timedelta(3)).timestamp())) \\\n",
" .order_by(Operation.timestamp) \\\n",
" .all()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'block_level': 609940,\n",
" 'operation_group_hash': 'ookSqpsFiHKwjFzfD9VP5zreQ7PWBREcNwkUpmd5eWRjHGwRpQ8'}]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"txs"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'protocol': 'Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd',\n",
" 'chain_id': 'NetXgtSLGNJvNye',\n",
" 'hash': 'ookSqpsFiHKwjFzfD9VP5zreQ7PWBREcNwkUpmd5eWRjHGwRpQ8',\n",
" 'branch': 'BKnC1eLAicw5Zfgj48cvrm2P3XQjRu7BrH1tmWCUywuHb28LyuG',\n",
" 'contents': [{'kind': 'transaction',\n",
" 'source': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm',\n",
" 'fee': '7623',\n",
" 'counter': '233596',\n",
" 'gas_limit': '72637',\n",
" 'storage_limit': '0',\n",
" 'amount': '1000000',\n",
" 'destination': 'KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj',\n",
" 'parameters': {'prim': 'Left',\n",
" 'args': [{'prim': 'Left',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'string': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'bytes': '12f64fbad3843c5803aab31f8030304e4ba7688e5b56d39dc6abe8bb3a25254e'},\n",
" {'int': '1567417055'}]},\n",
" {'int': '10000'}]}]}]}]},\n",
" 'metadata': {'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm',\n",
" 'change': '-7623'},\n",
" {'kind': 'freezer',\n",
" 'category': 'fees',\n",
" 'delegate': 'tz3gN8NTLNLJg5KRsUU47NHNVHbdhcFXjjaB',\n",
" 'cycle': 297,\n",
" 'change': '7623'}],\n",
" 'operation_result': {'status': 'applied',\n",
" 'storage': {'prim': 'Pair', 'args': [[], {'prim': 'Unit'}]},\n",
" 'big_map_diff': [{'key_hash': 'exprvN5C4dTXtaq5JRb3g8NBUHssLjSAJRQx6Pb8vHLQVNyLnSaCb8',\n",
" 'key': {'bytes': '12f64fbad3843c5803aab31f8030304e4ba7688e5b56d39dc6abe8bb3a25254e'},\n",
" 'value': {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'bytes': '0000e8b36c80efb51ec85a14562426049aa182a3ce38'},\n",
" {'bytes': '0000e8b36c80efb51ec85a14562426049aa182a3ce38'}]},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair',\n",
" 'args': [{'int': '990000'}, {'int': '1567417055'}]},\n",
" {'int': '10000'}]}]}}],\n",
" 'balance_updates': [{'kind': 'contract',\n",
" 'contract': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm',\n",
" 'change': '-1000000'},\n",
" {'kind': 'contract',\n",
" 'contract': 'KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj',\n",
" 'change': '1000000'}],\n",
" 'consumed_gas': '72537',\n",
" 'storage_size': '3315'}}}],\n",
" 'signature': 'sigZU1K4hW5KVC2cpxmQHcwa3qLvihcnUNb1XvAte6yipxhrY6YJNvZcrBPbGAyusfngvEob4LDt5SDPsmV1Qu7BkKThhgGQ'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"op = pytezos.shell.blocks[txs[0]['block_level']].operations[txs[0]['operation_group_hash']]()\n",
"op"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"ci = pytezos.contract('KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'12f64fbad3843c5803aab31f8030304e4ba7688e5b56d39dc6abe8bb3a25254e': {'recipients': {'initiator': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm',\n",
" 'participant': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm'},\n",
" 'settings': {'amount': Decimal('0.99'),\n",
" 'refund_time': 1567417055,\n",
" 'payoff': Decimal('0.01')}}}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ci.operation_result(op).big_map_diff"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"big_map = dict()\n",
"for tx in txs:\n",
" opg = pytezos.shell.blocks[tx['block_level']].operations[tx['operation_group_hash']]()\n",
" for k, v in ci.operation_result(opg).big_map_diff.items():\n",
" if v and v['settings']['payoff'] > 0:\n",
" big_map[k] = v"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'12f64fbad3843c5803aab31f8030304e4ba7688e5b56d39dc6abe8bb3a25254e': {'recipients': {'initiator': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm',\n",
" 'participant': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm'},\n",
" 'settings': {'amount': Decimal('0.99'),\n",
" 'refund_time': 1567417055,\n",
" 'payoff': Decimal('0.01')}}}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"big_map"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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