Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Tools: Source map decoder #353

Merged
merged 38 commits into from
Jul 13, 2022
Merged
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
240759e
Merge branch 'release/v1.10.0b1'
algobarb Feb 15, 2022
9d5ec1b
Merge branch 'release/v1.10.0'
onetechnical Mar 2, 2022
23354e9
Merge branch 'release/v1.11.0b1'
onetechnical Mar 18, 2022
51e0364
Merge branch 'release/v1.11.0'
algobarb Mar 23, 2022
e6f5aa9
Merge branch 'release/v1.12.0'
algojack Apr 21, 2022
896d2aa
Merge branch 'release/v1.13.0'
onetechnical May 2, 2022
de80435
Merge branch 'release/v1.13.1'
onetechnical May 4, 2022
760d892
Merge branch 'release/v1.14.0'
onetechnical Jun 2, 2022
671aeb6
Merge branch 'release/v1.15.0'
algojack Jun 16, 2022
c03a53d
adding src map decoder
barnjamin Jun 20, 2022
cb7a735
fmt
barnjamin Jun 20, 2022
5a1bf5d
reorg, fmt, add comments
barnjamin Jun 20, 2022
5ca54c6
Merge branch 'src-map-decoder' into develop
barnjamin Jun 20, 2022
5bc92ab
remove comments from src map
barnjamin Jun 23, 2022
f547df8
move SourceMap to its own file, add source_map arg in client for requ…
barnjamin Jun 24, 2022
a617d2c
adding tests for parsing source map from file
barnjamin Jun 24, 2022
abbf604
Merge branch 'develop' of github.com:algorand/py-algorand-sdk into de…
barnjamin Jun 24, 2022
58e60f0
Merge branch 'develop' into src-map-decoder
barnjamin Jun 24, 2022
a968807
fmt
barnjamin Jun 24, 2022
92d197c
implement new test
barnjamin Jun 24, 2022
d4618d6
fmt
barnjamin Jun 24, 2022
d0ec5c1
cr
barnjamin Jun 24, 2022
90333ca
cr
barnjamin Jun 24, 2022
c217a96
Merge branch 'src-map-decoder' of github.com:algorand/py-algorand-sdk…
barnjamin Jun 24, 2022
fe2aef6
cr changes, mostly naming fixes
barnjamin Jun 27, 2022
1d4c007
removing delimited, adding exception if version != 3, checking for ma…
barnjamin Jun 28, 2022
8ed7979
updating to new format
barnjamin Jul 1, 2022
94b59c0
remove initialized 0s
barnjamin Jul 1, 2022
be41089
fmt
barnjamin Jul 1, 2022
14b6658
Update algosdk/source_map.py
barnjamin Jul 1, 2022
7c4309c
use on dict lookup, returning None if not set
barnjamin Jul 11, 2022
ab087ff
Merge branch 'src-map-decoder' of github.com:algorand/py-algorand-sdk…
barnjamin Jul 11, 2022
ece278c
adding commments about None line and tweaking logic to append to the …
barnjamin Jul 11, 2022
689ad74
Update algosdk/source_map.py
barnjamin Jul 11, 2022
5a72f99
adding new tests
barnjamin Jul 12, 2022
e5a3ee8
Merge branch 'src-map-decoder' of github.com:algorand/py-algorand-sdk…
barnjamin Jul 12, 2022
0339df9
fmt
barnjamin Jul 12, 2022
c7cd30a
revert to master
barnjamin Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions algosdk/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import os

michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved
from typing import Tuple, Dict, List, Any
barnjamin marked this conversation as resolved.
Show resolved Hide resolved

from . import constants
from . import error
from . import encoding
Expand Down Expand Up @@ -287,3 +289,82 @@ def get_application_address(appID: int) -> str:
to_sign = constants.APPID_PREFIX + appID.to_bytes(8, "big")
checksum = encoding.checksum(to_sign)
return encoding.encode_address(checksum)


class SourceMap:
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, map: Dict[str, Any], delimiter: str = ";"):
self.delimter = delimiter

self.version: int = map["version"]
self.sources: List[str] = map["sources"]
self.mapping: str = map["mapping"]

pc_list = [
_decode_int_value(raw_val)
for raw_val in self.mapping.split(delimiter)
]

self.pc_to_line: Dict[int, int] = {}
self.line_to_pc: Dict[int, List[int]] = {}
last_line = 0
for index, line_num in enumerate(pc_list):
if line_num is not None: # be careful for '0' checks!
if line_num not in self.line_to_pc:
self.line_to_pc[line_num] = []
self.line_to_pc[line_num].append(index)
last_line = line_num

self.pc_to_line[index] = last_line

def get_line_for_pc(self, pc: int) -> int:
return self.pc_to_line[pc]

def get_pcs_for_line(self, line: int) -> List[int]:
return self.line_to_pc[line]


def _decode_int_value(value: str) -> int:
decoded_value = base64vlq_decode(value)
return decoded_value[2] if decoded_value else None


_b64chars = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
_b64table = [None] * (max(_b64chars) + 1)
for i, b in enumerate(_b64chars):
_b64table[b] = i

_shiftsize, _flag, _mask = 5, 1 << 5, (1 << 5) - 1


def base64vlq_decode(vlqval: str) -> Tuple[int]:
"""Decode Base64 VLQ value"""
results = []
add = results.append
shiftsize, flag, mask = _shiftsize, _flag, _mask
shift = value = 0
# use byte values and a table to go from base64 characters to integers
for v in map(_b64table.__getitem__, vlqval.encode("ascii")):
value += (v & mask) << shift
if v & flag:
shift += shiftsize
continue
# determine sign and add to results
add((value >> 1) * (-1 if value & 1 else 1))
shift = value = 0
return results


def base64vlq_encode(*values: int) -> str:
"""Encode integers to a VLQ value"""
results = []
add = results.append
shiftsize, flag, mask = _shiftsize, _flag, _mask
for v in values:
# add sign bit
v = (abs(v) << 1) | int(v < 0)
while True:
toencode, v = v & mask, v >> shiftsize
add(toencode | (v and flag))
if not v:
break
return bytes(map(_b64chars.__getitem__, results)).decode()