Skip to content

Commit

Permalink
Deprecation: Add deprecation warnings on v1 algod API and old transac…
Browse files Browse the repository at this point in the history
…tion format (algorand#381)

* Add deprecation warnings to old transaction uses

* Add deprecation warning to v1 algod apis

* Format template.py

* Add deprecation warning between old transaction format

* Remove version references

* Reduce warnings on old transaction so only constructors and top level functions have it
  • Loading branch information
algochoi authored Sep 16, 2022
1 parent 5860971 commit b53a53d
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 45 deletions.
26 changes: 17 additions & 9 deletions algosdk/algod.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from urllib.request import Request, urlopen
from urllib import parse
import urllib.error
import json
import base64
import json
import urllib.error
import warnings
from urllib import parse
from urllib.request import Request, urlopen

import msgpack
from . import error
from . import encoding
from . import constants
from . import transaction
from . import future

from . import constants, encoding, error, future
from .v2client.algod import _specify_round_string

api_version_path_prefix = "/v1"


class AlgodClient:
"""
NOTE: This class is deprecated:
v1 algod APIs are deprecated.
Please use the v2 equivalent in `v2client.algod` instead.
Client class for kmd. Handles all algod requests.
Args:
Expand All @@ -30,6 +33,11 @@ class AlgodClient:
"""

def __init__(self, algod_token, algod_address, headers=None):
warnings.warn(
"`AlgodClient` is a part of v1 algod APIs that is deprecated. "
"Please use the v2 equivalent in `v2client.algod` instead.",
DeprecationWarning,
)
self.algod_token = algod_token
self.algod_address = algod_address
self.headers = headers
Expand Down
15 changes: 13 additions & 2 deletions algosdk/encoding.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import base64
import msgpack
import warnings
from collections import OrderedDict

import msgpack
from Cryptodome.Hash import SHA512
from . import transaction, error, auction, constants, future

from . import auction, constants, error, future, transaction


def msgpack_encode(obj):
Expand Down Expand Up @@ -94,6 +97,9 @@ def future_msgpack_decode(enc):

def msgpack_decode(enc):
"""
NOTE: This method is deprecated:
Please use `future_msgpack_decode` instead.
Decode a msgpack encoded object from a string.
Args:
Expand All @@ -103,6 +109,11 @@ def msgpack_decode(enc):
Transaction, SignedTransaction, Multisig, Bid, or SignedBid:\
decoded object
"""
warnings.warn(
"`msgpack_decode` is being deprecated. "
"Please use `future_msgpack_decode` instead.",
DeprecationWarning,
)
decoded = enc
if not isinstance(enc, dict):
decoded = msgpack.unpackb(base64.b64decode(enc), raw=False)
Expand Down
25 changes: 15 additions & 10 deletions algosdk/future/transaction.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from typing import List, Union
import base64
import binascii
import warnings
from collections import OrderedDict
from enum import IntEnum
from typing import List, Union

import msgpack
from collections import OrderedDict
from .. import account
from .. import constants
from .. import encoding
from .. import error
from .. import logic
from .. import transaction
from ..v2client import algod, models
from nacl.signing import SigningKey, VerifyKey
from nacl.exceptions import BadSignatureError
from nacl.signing import SigningKey, VerifyKey

from .. import account, constants, encoding, error, logic, transaction
from ..v2client import algod, models


class SuggestedParams:
Expand Down Expand Up @@ -273,6 +271,13 @@ def undictify(d):
def __eq__(self, other):
if not isinstance(other, (Transaction, transaction.Transaction)):
return False
if isinstance(other, transaction.Transaction):
warnings.warn(
"You are trying to check equality of an older `transaction` "
" format that is being deprecated. "
"Please use the v2 equivalent in `future.transaction` instead.",
DeprecationWarning,
)
return (
self.sender == other.sender
and self.fee == other.fee
Expand Down
16 changes: 7 additions & 9 deletions algosdk/kmd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from urllib.request import Request, urlopen
from urllib import parse
import urllib.error
import json
import base64
from . import encoding
from . import error
from . import transaction
from . import constants
import json
import urllib.error
from urllib import parse
from urllib.request import Request, urlopen

from . import constants, encoding, error, future

api_version_path_prefix = "/v1"

Expand Down Expand Up @@ -383,7 +381,7 @@ def export_multisig(self, handle, address):
result = self.kmd_request("POST", req, data=query)
pks = result["pks"]
pks = [encoding.encode_address(base64.b64decode(p)) for p in pks]
msig = transaction.Multisig(
msig = future.transaction.Multisig(
result["multisig_version"], result["threshold"], pks
)
return msig
Expand Down
12 changes: 12 additions & 0 deletions algosdk/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@


class Template:
"""
NOTE: This class is deprecated
"""

def get_address(self):
"""
Return the address of the contract.
Expand All @@ -18,6 +22,8 @@ def get_program(self):

class Split(Template):
"""
NOTE: This class is deprecated
Split allows locking algos in an account which allows transfering to two
predefined addresses in a specified ratio such that for the given ratn and
ratd parameters we have:
Expand Down Expand Up @@ -164,6 +170,8 @@ def get_split_funds_transaction(

class HTLC(Template):
"""
NOTE: This class is deprecated
Hash Time Locked Contract allows a user to recieve the Algo prior to a
deadline (in terms of a round) by proving knowledge of a special value
or to forfeit the ability to claim, returning it to the payer.
Expand Down Expand Up @@ -433,6 +441,8 @@ def sign_dynamic_fee(self, private_key, gh):

class PeriodicPayment(Template):
"""
NOTE: This class is deprecated
PeriodicPayment contract enables creating an account which allows the
withdrawal of a fixed amount of assets every fixed number of rounds to a
specific Algrorand Address. In addition, the contract allows to add
Expand Down Expand Up @@ -543,6 +553,8 @@ def get_withdrawal_transaction(contract, first_valid, gh, fee):

class LimitOrder(Template):
"""
NOTE: This class is deprecated
Limit Order allows to trade Algos for other assets given a specific ratio;
for N Algos, swap for Rate * N Assets.
Expand Down
Loading

0 comments on commit b53a53d

Please sign in to comment.