Skip to content

Commit

Permalink
Added an example how to unpack KYC payload in Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Mar 14, 2018
1 parent 017ee10 commit 43f22c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/interact.rst
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,4 @@ Example:
# Get a Dayta payload for calling a contract function refund()
sig_data = contract._prepare_transaction(function)
print("Data payload for {}() is {}".format(function, sig_data["data"]))
33 changes: 33 additions & 0 deletions ico/kyc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""AML data passing helpers."""
from binascii import hexlify
from uuid import UUID

from eth_utils import is_checksum_address
Expand Down Expand Up @@ -61,3 +62,35 @@ def pack_kyc_pricing_dataframe(whitelisted_address: str, customer_id: UUID, min_
data = addr_b + customer_b + min_b + max_b + pricing_data
assert len(data) == 76, "Got length: {}".format(len(data))
return data


def unpack_kyc_pricing_dataframe(b: bytes) -> dict:
"""Unpack a KYC payloda for diagnostics purposes.
Useful to troubleshoot live transactions. Grab the transaction hex data from Etherscan, starting on [5], make it a single string and use this function to see what parameters where given to the user.
Example::
import binascii
from ico.kyc import unpack_kyc_pricing_dataframe
h = "83dcb...40000000000000000000000000000000000000000000000000000000000000001"
b = binascii.unhexlify(h)
unpack_kyc_pricing_dataframe(b)
"""

assert len(b) == 76, "Got byte array of length: {}".format(len(b))
addr_value = b[0:20]
customer_id = b[20:36]
min_b = b[36:40]
max_b = b[40:44]
pricing_data = b[44:76]

return {
"address": "0x" + hexlify(addr_value).decode("ascii"),
"customer_id": UUID(int=int(hexlify(customer_id), 16)),
"min_payment_eth": int(hexlify(min_b), 16) / 10000.0,
"max_payment_eth": int(hexlify(max_b), 16) / 10000.0,
"pricing_data": int(hexlify(pricing_data), 16),
}

0 comments on commit 43f22c1

Please sign in to comment.