Skip to content

Commit

Permalink
api: update NEP-11 wrappers (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored Sep 16, 2024
1 parent 7a71114 commit a4cf6e8
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions neo3/api/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]:
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a4cf6e8

Please sign in to comment.