|
2 | 2 | import msgpack |
3 | 3 | from collections import OrderedDict |
4 | 4 | from Cryptodome.Hash import SHA512 |
5 | | -from . import transaction, error, auction, constants |
| 5 | +from . import transaction, error, auction, constants, future |
6 | 6 |
|
7 | 7 |
|
8 | 8 | def msgpack_encode(obj): |
@@ -52,6 +52,43 @@ def _sort_dict(d): |
52 | 52 | return od |
53 | 53 |
|
54 | 54 |
|
| 55 | +def future_msgpack_decode(enc): |
| 56 | + """ |
| 57 | + Decode a msgpack encoded object from a string. |
| 58 | +
|
| 59 | + Args: |
| 60 | + enc (str): string to be decoded |
| 61 | +
|
| 62 | + Returns: |
| 63 | + Transaction, SignedTransaction, Multisig, Bid, or SignedBid:\ |
| 64 | + decoded object |
| 65 | + """ |
| 66 | + decoded = enc |
| 67 | + if not isinstance(enc, dict): |
| 68 | + decoded = msgpack.unpackb(base64.b64decode(enc), raw=False) |
| 69 | + if "type" in decoded: |
| 70 | + return future.transaction.Transaction.undictify(decoded) |
| 71 | + if "l" in decoded: |
| 72 | + return future.transaction.LogicSig.undictify(decoded) |
| 73 | + if "msig" in decoded: |
| 74 | + return future.transaction.MultisigTransaction.undictify(decoded) |
| 75 | + if "lsig" in decoded: |
| 76 | + return future.transaction.LogicSigTransaction.undictify(decoded) |
| 77 | + if "sig" in decoded: |
| 78 | + return future.transaction.SignedTransaction.undictify(decoded) |
| 79 | + if "txn" in decoded: |
| 80 | + return future.transaction.Transaction.undictify(decoded["txn"]) |
| 81 | + if "subsig" in decoded: |
| 82 | + return future.transaction.Multisig.undictify(decoded) |
| 83 | + if "txlist" in decoded: |
| 84 | + return future.transaction.TxGroup.undictify(decoded) |
| 85 | + if "t" in decoded: |
| 86 | + return auction.NoteField.undictify(decoded) |
| 87 | + if "bid" in decoded: |
| 88 | + return auction.SignedBid.undictify(decoded) |
| 89 | + if "auc" in decoded: |
| 90 | + return auction.Bid.undictify(decoded) |
| 91 | + |
55 | 92 | def msgpack_decode(enc): |
56 | 93 | """ |
57 | 94 | Decode a msgpack encoded object from a string. |
|
0 commit comments