Skip to content

Commit

Permalink
EvalDeltas should be done.
Browse files Browse the repository at this point in the history
Not tested enough, especially on handling shared account modifications.
  • Loading branch information
jannotti committed Jan 22, 2024
1 parent 3ed1d11 commit 7e6f3d7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 49 deletions.
54 changes: 14 additions & 40 deletions algosdk/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ def undictify(d):
)

def __str__(self):
return (
"{"
+ ", ".join(
[
str(key) + ": " + str(value)
for key, value in self.__dict__.items()
]
)
+ "}"
)
return ostr(self)


class Block:
Expand Down Expand Up @@ -124,16 +115,7 @@ def undictify(d):
)

def __str__(self):
return (
"{"
+ ", ".join(
[
str(key) + ": " + str(value)
for key, value in self.__dict__.items()
]
)
+ "}"
)
return ostr(self)


class Cert:
Expand All @@ -159,16 +141,7 @@ def undictify(d):
)

def __str__(self):
return (
"{"
+ ", ".join(
[
str(key) + ": " + str(value)
for key, value in self.__dict__.items()
]
)
+ "}"
)
return ostr(self)


class ProposalValue:
Expand All @@ -184,19 +157,20 @@ def __init__(
def undictify(d):
return ProposalValue(
original_period=d.get("oper", 0),
original_proposer=d.get("oprop"),
original_proposer=encoding.encode_address(d.get("oprop")),
block_digest=d.get("dig"),
encoding_digest=d.get("encdig"),
)

def __str__(self):
return (
"{"
+ ", ".join(
[
str(key) + ": " + str(value)
for key, value in self.__dict__.items()
]
)
+ "}"
return ostr(self)


def ostr(o):
return (
"{"
+ ", ".join(
[str(key) + ": " + str(value) for key, value in o.__dict__.items()]
)
+ "}"
)
75 changes: 68 additions & 7 deletions algosdk/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ def __init__(self, stxn: SignedTransaction, apply_data):
@staticmethod
def undictify(d):
stxn = SignedTransaction.undictify(d)
ad = ApplyData.undictify(d)
ad = ApplyData.undictify(d, stxn.transaction)
return SignedTxnWithAD(stxn, ad)


Expand All @@ -2214,26 +2214,77 @@ def __init__(
self.application_id = application_id

@staticmethod
def undictify(d):
def undictify(d, txn):
return ApplyData(
d.get("ca", 0),
d.get("aca", 0),
d.get("rs", 0),
d.get("rr", 0),
d.get("rc", 0),
EvalDelta.undictify(d.get("dt", {})),
EvalDelta.undictify(d.get("dt"), txn),
d.get("caid", 0),
d.get("apid", 0),
)

def __str__(self):
return ostr(self)


class EvalDelta:
def __init__(self, gd):
self.global_delta = gd
def __init__(self, globals, locals, shared, logs, inners):
self.global_delta = globals
self.local_deltas = locals
self.shared_accounts = shared
self.logs = logs
self.inner_transactions = inners

@classmethod
def undictify(cls, d, txn):
if d is None:
return None
locals = {
i: EvalDelta.values(sd) for (i, sd) in d.get("ld", {}).items()
}
shared = d.get("sa", [])
if txn is not None:
locals = {
cls.resolve(i, txn, shared): sd for (i, sd) in locals.items()
}
return EvalDelta(
EvalDelta.values(d.get("gd", {})),
locals,
shared,
d.get("logs", []),
[SignedTxnWithAD.undictify(i) for i in d.get("itxn", [])],
)

@staticmethod
def undictify(d):
return EvalDelta(d.get("gd"))
def resolve(i, txn, shared):
if i == 0:
return txn.sender
i -= 1
if i < len(txn.accounts):
return txn.accounts[i]
i -= len(txn.accounts)
return shared[i]

@classmethod
def values(cls, d):
return {k: cls.value(v) for (k, v) in d.items()}

@classmethod
def value(cls, v):
match v[b"at"]:
case 1:
return v[b"bs"]
case 2:
return v[b"ui"]
case 3:
return None
exit(1)

def __str__(self):
return ostr(self)


class MultisigTransaction:
Expand Down Expand Up @@ -3404,3 +3455,13 @@ def decode_programs(app):
app["params"]["clear-state-program"]
)
return app


def ostr(o):
return (
"{"
+ ", ".join(
[str(key) + ": " + str(value) for key, value in o.__dict__.items()]
)
+ "}"
)
4 changes: 2 additions & 2 deletions algosdk/v2client/algod.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from urllib import parse
from urllib.request import Request, urlopen

from algosdk import constants, encoding, error, transaction, util
from algosdk import block, constants, encoding, error, transaction, util
from algosdk.v2client import models

AlgodResponseType = Union[Dict[str, Any], bytes]
Expand Down Expand Up @@ -288,7 +288,7 @@ def block(
round: int | str,
**kwargs: Any,
) -> "block.BlockInfo":
msgp = self.block_info(round, "msgpack")
msgp = self.block_info(int(round), "msgpack")
d = encoding.algo_msgp_decode(msgp)
return encoding.undictify(d)

Expand Down

0 comments on commit 7e6f3d7

Please sign in to comment.