From a4cf6e8f228519f55c80a65387a5d6af9745ab91 Mon Sep 17 00:00:00 2001 From: ixje Date: Mon, 16 Sep 2024 16:09:07 +0200 Subject: [PATCH] api: update NEP-11 wrappers (#312) --- neo3/api/wrappers.py | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/neo3/api/wrappers.py b/neo3/api/wrappers.py index 3066cba..0688314 100644 --- a/neo3/api/wrappers.py +++ b/neo3/api/wrappers.py @@ -25,6 +25,7 @@ from __future__ import annotations from typing import Callable, Any, TypeVar, Optional, cast, Generic, TypeAlias +from typing_extensions import deprecated from collections.abc import Sequence import asyncio from enum import IntEnum @@ -1164,23 +1165,6 @@ def decimals(self) -> ContractMethodResult[int]: """ return super(_NEP11Contract, self).decimals() - def total_owned_by( - self, owner: types.UInt160 | NeoAddress - ) -> ContractMethodResult[int]: - """ - Get the total amount of NFTs owned for the given account. - - Raises: - ValueError: if `owner` is an invalid NeoAddress format. - """ - owner = _check_address_and_convert(owner) - script = ( - vm.ScriptBuilder() - .emit_contract_call_with_args(self.hash, "balanceOf", [owner]) - .to_array() - ) - return ContractMethodResult(script, unwrap.as_int) - def token_ids_owned_by( self, owner: types.UInt160 | NeoAddress ) -> ContractMethodResult[list[bytes]]: @@ -1309,8 +1293,14 @@ def process(res: noderpc.ExecutionResult, _: int = 0) -> list[types.UInt160]: return ContractMethodResult(sb.to_array(), process) + @deprecated("use total_owned_by", category=DeprecationWarning, stacklevel=2) def balance_of( self, owner: types.UInt160 | NeoAddress, token_id: bytes + ) -> ContractMethodResult[int]: + return self.total_owned_by(owner, token_id) + + def total_owned_by( + self, owner: types.UInt160 | NeoAddress, token_id: bytes ) -> ContractMethodResult[int]: """ Get the token balance for the given owner. @@ -1324,8 +1314,16 @@ def balance_of( ) return ContractMethodResult(sb.to_array(), unwrap.as_int) + @deprecated( + "use total_owned_by_friendly", category=DeprecationWarning, stacklevel=2 + ) def balance_of_friendly( self, owner: types.UInt160 | NeoAddress, token_id: bytes + ) -> ContractMethodResult[float]: + return self.total_owned_by_friendly(owner, token_id) + + def total_owned_by_friendly( + self, owner: types.UInt160 | NeoAddress, token_id: bytes ) -> ContractMethodResult[float]: """ Get the balance for the given account and convert the result into the user representation. @@ -1355,6 +1353,23 @@ def process(res: noderpc.ExecutionResult, _: int = 0) -> float: class NEP11NonDivisibleContract(_NEP11Contract): """Base class for non-divisible NFTs.""" + def total_owned_by( + self, owner: types.UInt160 | NeoAddress + ) -> ContractMethodResult[int]: + """ + Get the total amount of NFTs owned for the given account. + + Raises: + ValueError: if `owner` is an invalid NeoAddress format. + """ + owner = _check_address_and_convert(owner) + script = ( + vm.ScriptBuilder() + .emit_contract_call_with_args(self.hash, "balanceOf", [owner]) + .to_array() + ) + return ContractMethodResult(script, unwrap.as_int) + def transfer( self, destination: types.UInt160 | NeoAddress,