Skip to content

Instantly share code, notes, and snippets.

@m-kus
Created August 27, 2019 12:39
Show Gist options
  • Save m-kus/c500e6e735bbc480a9b4c47d776f908e to your computer and use it in GitHub Desktop.
Save m-kus/c500e6e735bbc480a9b4c47d776f908e 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": [
"import os\n",
"from hashlib import sha256\n",
"from pytezos import pytezos\n",
"from datetime import datetime, timedelta\n",
"from decimal import Decimal"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"b'\\xbf\\xbb\\xb1o\\xdd\\x0f\\x82,\\x82\\xe4\\x90\\xe1\\x04\\xc2d\\x1b\\x7f\\x96|j\\x87\\x05\\xba=\\xbf\\x15.\\x9d7G\\x13\\x17'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"secret = os.urandom(32)\n",
"secret"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'12f64fbad3843c5803aab31f8030304e4ba7688e5b56d39dc6abe8bb3a25254e'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"secret_hash = sha256(sha256(secret).digest()).hexdigest()\n",
"secret_hash"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"ci = pytezos.contract('KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pytezos.michelson.interface.ContractEntrypoint object at 0x7ff3e64d6eb8>\n",
"\n",
"Properties\n",
".key # tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm\n",
".shell # https://tezos-dev.cryptonomic-infra.tech/ (alphanet)\n",
".address # KT1WhouvVKZFH94VXj9pa8v4szvfrBwXoBUj\n",
"\n",
"$kwargs:\n",
"\t{\n",
"\t \"participant\": $address,\n",
"\t \"settings\": $settings\n",
"\t}\n",
"\n",
"$settings:\n",
"\t{\n",
"\t \"hashed_secret\": $bytes,\n",
"\t \"refund_time\": $timestamp,\n",
"\t \"payoff\": $mutez\n",
"\t}\n",
"\n",
"$mutez:\n",
"\tint /* Amount in `utz` (10^-6) */ ||\n",
"\tDecimal /* Amount in `tz` */\n",
"\n",
"$address:\n",
"\tstring /* Base58 encoded `tz` or `KT` address */\n",
"\n",
"$bytes:\n",
"\tstring /* Hex string */ ||\n",
"\tbytes /* Python byte string */\n",
"\n",
"$timestamp:\n",
"\tint /* Unix time in seconds */ ||\n",
"\tstring /* Formatted datetime `%Y-%m-%dT%H:%M:%SZ` */"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ci.ll"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"initiate = ci.ll(\n",
" participant=pytezos.key.public_key_hash(),\n",
" settings=dict(\n",
" hashed_secret=secret_hash,\n",
" refund_time=int((datetime.utcnow() + timedelta(6)).timestamp()),\n",
" payoff=Decimal('0.01')\n",
" )\n",
").with_amount(Decimal('1'))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"initiate.result().big_map_diff"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ookSqpsFiHKwjFzfD9VP5zreQ7PWBREcNwkUpmd5eWRjHGwRpQ8'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"initiate.inject()"
]
}
],
"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