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

Deprecation: Add deprecation warnings on v1 algod API and old transaction format #381

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
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,
)
Comment on lines +112 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much objection here, just a minor question: since encode-decode is coupled, do we want to mark encode as deprecated? Or it is because of Transaction had a structural change (i.e., some new fields)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serializing into msgpack is okay - the old Transaction and new Transaction can both be serialized into msgpack as long as the fields are ordered and can be represented by a key-value map/dict. Decoding msgpack into the old Transaction does not seem preferable, so marked it with the deprecation warning here.

decoded = enc
if not isinstance(enc, dict):
decoded = msgpack.unpackb(base64.b64decode(enc), raw=False)
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old and new Multisig should be the same - changed to used the new class in future here.

result["multisig_version"], result["threshold"], pks
)
return msig
Expand Down
11 changes: 11 additions & 0 deletions algosdk/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@


class Template:
"""
NOTE: This class is deprecated
Copy link
Contributor Author

@algochoi algochoi Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: future.template already has a deprecation warning in the comments.

"""
def get_address(self):
"""
Return the address of the contract.
Expand All @@ -18,6 +21,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 +169,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 +440,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 +552,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