eth-erc721

ERC-721 'NFT' token interface with example developer badge token contract
Log | Files | Refs | LICENSE

commit facb527d70efd21ea9c65974f5f0c9b61f5b2800
parent 5153a178ce8f3e3a34af43eb4c7c1b6403284c80
Author: nolash <dev@holbrook.no>
Date:   Mon, 28 Jun 2021 10:02:57 +0200

Move to chainlib-eth

Diffstat:
Mpython/CHANGELOG | 2++
Mpython/eth_badgetoken/token.py | 8+++++---
Mpython/eth_erc721/erc721.py | 38+++++++++++++++++++++++++-------------
Mpython/requirements.txt | 6+++---
Apython/run_tests.sh | 12++++++++++++
Mpython/setup.cfg | 2+-
Mpython/test_requirements.txt | 1-
Mpython/tests/test_app.py | 4++--
8 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.2 + * Move to chainlib-eth - 0.0.1 * Add erc721 interface * Add BadgeToken contract diff --git a/python/eth_badgetoken/token.py b/python/eth_badgetoken/token.py @@ -11,7 +11,7 @@ from chainlib.eth.contract import ( ABIContractType, abi_decode_single, ) -from chainlib.jsonrpc import jsonrpc_template +from chainlib.jsonrpc import JSONRPCRequest from chainlib.eth.constant import ZERO_ADDRESS from hexathon import ( add_0x, @@ -79,8 +79,9 @@ class BadgeToken(ERC721): - def minted_at(self, contract_address, token_id, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def minted_at(self, contract_address, token_id, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('mintedAt') @@ -91,6 +92,7 @@ class BadgeToken(ERC721): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o diff --git a/python/eth_erc721/erc721.py b/python/eth_erc721/erc721.py @@ -8,7 +8,7 @@ from chainlib.eth.contract import ( ABIContractType, abi_decode_single, ) -from chainlib.jsonrpc import jsonrpc_template +from chainlib.jsonrpc import JSONRPCRequest from chainlib.eth.constant import ZERO_ADDRESS from hexathon import ( add_0x, @@ -45,8 +45,9 @@ class ERC721(ERC20, EIP173): return self.set_approve_for_all(contract_address, sender_address, operator_address, False, tx_format=tx_format) - def token_by_index(self, contract_address, idx, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def token_by_index(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('tokenByIndex') @@ -57,11 +58,13 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('ownerOf') @@ -72,11 +75,13 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def is_approved_for_all(self, contract_address, holder_address, operator_address, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def is_approved_for_all(self, contract_address, holder_address, operator_address, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('isApprovedForAll') @@ -89,6 +94,7 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o @@ -96,8 +102,9 @@ class ERC721(ERC20, EIP173): return self.is_approved_for_all(contract_address, token_id, operator_address, sender_address=sender_address) - def get_approved(self, contract_address, token_id, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def get_approved(self, contract_address, token_id, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('getApproved') @@ -108,12 +115,14 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def token_of_owner_by_index(self, contract_address, holder_address, idx, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def token_of_owner_by_index(self, contract_address, holder_address, idx, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('tokenOfOwnerByIndex') @@ -126,11 +135,13 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o - def token_uri(self, contract_address, token_id, sender_address=ZERO_ADDRESS): - o = jsonrpc_template() + def token_uri(self, contract_address, token_id, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('tokenURI') @@ -141,6 +152,7 @@ class ERC721(ERC20, EIP173): tx = self.set_code(tx, data) o['params'].append(self.normalize(tx)) o['params'].append('latest') + o = j.finalize(o) return o diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,3 +1,3 @@ -chainlib~=0.0.3a3 -eth-erc20~=0.0.9a2 -eth-owned~=0.0.1a5 +chainlib-eth~=0.0.5a1 +eth-erc20~=0.0.10a1 +eth-owned~=0.0.2a1 diff --git a/python/run_tests.sh b/python/run_tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e +set -x +for f in `ls tests/*.py`; do + python $f + if [ $? -gt 0 ]; then + exit 1 + fi +done +set +x +set +e diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-erc721 -version = 0.0.1a1 +version = 0.0.2a1 description = ERC721 interface and simple contract with deployment script providing arbitrary minting of NFTs with freely settable tokenids author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/test_requirements.txt b/python/test_requirements.txt @@ -1,3 +1,2 @@ eth_tester==0.5.0b3 py-evm==0.3.0a20 -pytest==6.0.1 diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -27,7 +27,7 @@ from hexathon import ( # local imports -from eth_badge_token import BadgeToken +from eth_badgetoken import BadgeToken logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() @@ -253,7 +253,7 @@ class Test(EthTesterCase): o = c.token_uri(self.address, token_id, sender_address=self.accounts[0]) r = self.rpc.do(o) uri = c.parse_token_uri(r) - self.assertEqual(uri, 'sha256://' + token_bytes.hex()) + self.assertEqual(uri, 'sha256:' + token_bytes.hex()) if __name__ == '__main__':