Skip to content

Commit

Permalink
Enhancement: Merge develop to feature/box-storage (#379)
Browse files Browse the repository at this point in the history
* add check to desc so we dont output null if undefined (#368)

* Bumped version to v1.16.1

* Enhancement: Trim the indexer images and use the sandbox instead of custom dockers (#367)

Co-authored-by: algochoi <[email protected]>
Co-authored-by: Michael Diamant <[email protected]>

* Bug-fix: Pass verbosity through to testing harness (#373)

* Enhancement: Add State Proof support (#370)

* add stateproof support

* Enhancement: Deprecating use of langspec  (#371)

* Bumped version to v1.17.0

* Update README.md

Co-authored-by: Zeph Grunschlag <[email protected]>

* Mergeback: Release v1.17.0b1 (#378)

* Bumped version
* Update README.md

* bumped version to v1.17.0

Co-authored-by: Ben Guidarelli <[email protected]>
Co-authored-by: Barbara Poon <[email protected]>
Co-authored-by: Zeph Grunschlag <[email protected]>
Co-authored-by: algochoi <[email protected]>
Co-authored-by: Michael Diamant <[email protected]>
Co-authored-by: shiqizng <[email protected]>
Co-authored-by: Jack Smith <[email protected]>
Co-authored-by: Jack <[email protected]>
Co-authored-by: Lucky Baar <[email protected]>
  • Loading branch information
10 people authored Sep 2, 2022
1 parent c83d813 commit 9ea8676
Show file tree
Hide file tree
Showing 14 changed files with 567 additions and 15 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@

- `class StateSchema`'s method `undictify()` now returns a `StateSchema` object instead of a python `dict`

# v1.17.0
## What's Changed
### Bugfixes
* Bug-fix: Pass verbosity through to testing harness by @tzaffi in https://github.com/algorand/py-algorand-sdk/pull/373
### Enhancements
* Enhancement: Trim the indexer images and use the sandbox instead of custom dockers by @tzaffi in https://github.com/algorand/py-algorand-sdk/pull/367
* Enhancement: Add State Proof support by @shiqizng in https://github.com/algorand/py-algorand-sdk/pull/370
* Enhancement: Deprecating use of langspec by @ahangsu in https://github.com/algorand/py-algorand-sdk/pull/371

## New Contributors
* @ahangsu made their first contribution in https://github.com/algorand/py-algorand-sdk/pull/371

**Full Changelog**: https://github.com/algorand/py-algorand-sdk/compare/v1.16.1...v1.17.0


# v1.17.0b1
## What's Changed
### Bugfixes
* Bug-fix: Pass verbosity through to testing harness by @tzaffi in https://github.com/algorand/py-algorand-sdk/pull/373
### Enhancements
* Enhancement: Trim the indexer images and use the sandbox instead of custom dockers by @tzaffi in https://github.com/algorand/py-algorand-sdk/pull/367
* Enhancement: Add State Proof support by @shiqizng in https://github.com/algorand/py-algorand-sdk/pull/370
* Enhancement: Deprecating use of langspec by @ahangsu in https://github.com/algorand/py-algorand-sdk/pull/371

## New Contributors
* @ahangsu made their first contribution in https://github.com/algorand/py-algorand-sdk/pull/371

**Full Changelog**: https://github.com/algorand/py-algorand-sdk/compare/v1.16.1...v1.17.0b1


# v1.16.1
### Bugfixes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Install dependencies

Run tests

* `make harness`
* `make docker-test`

Set up the Algorand Sandbox based test-harness without running the tests

* `make docker-test`
* `make harness`

Format code:

Expand Down
3 changes: 3 additions & 0 deletions algosdk/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"""str: indicates an asset transfer transaction"""
APPCALL_TXN = "appl"
"""str: indicates an app call transaction, allows creating, deleting, and interacting with an application"""
STATEPROOF_TXN = "stpf"
"""str: indicates an state proof transaction"""

# note field types
NOTE_FIELD_TYPE_DEPOSIT = "d"
Expand Down Expand Up @@ -134,3 +136,4 @@
logic_sig_max_cost = LOGIC_SIG_MAX_COST
logic_sig_max_size = LOGIC_SIG_MAX_SIZE
app_page_max_size = APP_PAGE_MAX_SIZE
stateproof_txn = STATEPROOF_TXN
131 changes: 128 additions & 3 deletions algosdk/future/transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
from collections import OrderedDict
import binascii
from enum import IntEnum
from typing import List, Union

Expand Down Expand Up @@ -257,6 +258,11 @@ def undictify(d):
elif txn_type == constants.appcall_txn:
args.update(ApplicationCallTxn._undictify(d))
txn = ApplicationCallTxn(**args)
elif txn_type == constants.stateproof_txn:
# a state proof txn does not have these fields
args.pop("note"), args.pop("rekey_to"), args.pop("lease")
args.update(StateProofTxn._undictify(d))
txn = StateProofTxn(**args)
if "grp" in d:
txn.group = d["grp"]
return txn
Expand Down Expand Up @@ -2520,13 +2526,54 @@ class LogicSig:
"""

def __init__(self, program, args=None):
if not program or not logic.check_program(program, args):
raise error.InvalidProgram()
self._sanity_check_program(program)
self.logic = program
self.args = args
self.sig = None
self.msig = None

@staticmethod
def _sanity_check_program(program):
"""
Performs heuristic program validation:
check if passed in bytes are Algorand address, or they are B64 encoded, rather than Teal bytes
Args:
program (bytes): compiled program
"""

def is_ascii_printable(program_bytes):
return all(
map(
lambda x: x == ord("\n") or (ord(" ") <= x <= ord("~")),
program_bytes,
)
)

if not program:
raise error.InvalidProgram("empty program")

if is_ascii_printable(program):
try:
encoding.decode_address(program.decode("utf-8"))
raise error.InvalidProgram(
"requesting program bytes, get Algorand address"
)
except error.WrongChecksumError:
pass
except error.WrongKeyLengthError:
pass

try:
base64.b64decode(program.decode("utf-8"))
raise error.InvalidProgram("program should not be b64 encoded")
except binascii.Error:
pass

raise error.InvalidProgram(
"program bytes are all ASCII printable characters, not looking like Teal byte code"
)

def dictify(self):
od = OrderedDict()
if self.args:
Expand Down Expand Up @@ -2563,7 +2610,7 @@ def verify(self, public_key):
return False

try:
logic.check_program(self.logic, self.args)
self._sanity_check_program(self.logic)
except error.InvalidProgram:
return False

Expand Down Expand Up @@ -2921,6 +2968,84 @@ def __eq__(self, other):
return False


class StateProofTxn(Transaction):
"""
Represents a state proof transaction
Arguments:
sender (str): address of the sender
state_proof (dict(), optional)
state_proof_message (dict(), optional)
state_proof_type (str, optional): state proof type
sp (SuggestedParams): suggested params from algod
Attributes:
sender (str)
sprf (dict())
sprfmsg (dict())
sprf_type (str)
first_valid_round (int)
last_valid_round (int)
genesis_id (str)
genesis_hash (str)
type (str)
"""

def __init__(
self,
sender,
sp,
state_proof=None,
state_proof_message=None,
state_proof_type=None,
):
Transaction.__init__(
self, sender, sp, None, None, constants.stateproof_txn, None
)

self.sprf_type = state_proof_type
self.sprf = state_proof
self.sprfmsg = state_proof_message

def dictify(self):
d = dict()
if self.sprf_type:
d["sptype"] = self.sprf_type
if self.sprfmsg:
d["spmsg"] = self.sprfmsg
if self.sprf:
d["sp"] = self.sprf
d.update(super(StateProofTxn, self).dictify())
od = OrderedDict(sorted(d.items()))

return od

@staticmethod
def _undictify(d):
args = {}
if "sptype" in d:
args["state_proof_type"] = d["sptype"]
if "sp" in d:
args["state_proof"] = d["sp"]
if "spmsg" in d:
args["state_proof_message"] = d["spmsg"]

return args

def __eq__(self, other):
if not isinstance(other, StateProofTxn):
return False
return (
super(StateProofTxn, self).__eq__(other)
and self.sprf_type == other.sprf_type
and self.sprf == other.sprf
and self.sprfmsg == other.sprfmsg
)

return False


def write_to_file(txns, path, overwrite=True):
"""
Write signed or unsigned transactions to a file.
Expand Down
Loading

0 comments on commit 9ea8676

Please sign in to comment.