craft-nft

A standalone NFT implementation for real-world arts and crafts assets
Log | Files | Refs | README

commit 9ae9b02d083d81ea8baf36868c50a24d5f292de0
parent d3059fc6c4768a35ff367db8b2bcf16771de9c0a
Author: lash <dev@holbrook.no>
Date:   Wed, 15 Feb 2023 04:54:35 +0000

Implement chainlib-gen

Diffstat:
Mpython/CHANGELOG | 4++++
Mpython/craft_nft/__init__.py | 5+++++
Apython/craft_nft/data/.chainlib | 0
Mpython/craft_nft/nft.py | 37+++++++++++++++++++++++++++++--------
Mpython/setup.cfg | 2+-
5 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -1,3 +1,7 @@ +- 0.0.3 + * Implement chainlib-gen + * Apply fully qualified URL for tokenUri, with mutable base url + * Include toURI method for hash uri generation - 0.0.2 * Add allocate and mint CLI tools - 0.0.1 diff --git a/python/craft_nft/__init__.py b/python/craft_nft/__init__.py @@ -1,2 +1,7 @@ # local imports from .nft import CraftNFT +from .nft import create +from .nft import bytecode +from .nft import args + + diff --git a/python/craft_nft/data/.chainlib b/python/craft_nft/data/.chainlib diff --git a/python/craft_nft/nft.py b/python/craft_nft/nft.py @@ -92,7 +92,7 @@ class CraftNFT(ERC721): @staticmethod - def bytecode(): + def bytecode(version=None): if CraftNFT.__bytecode == None: f = open(os.path.join(datadir, 'CraftNFT.bin')) CraftNFT.__bytecode = f.read() @@ -104,19 +104,24 @@ class CraftNFT(ERC721): def gas(code=None): return 4000000 - - def constructor(self, sender_address, name, symbol, declaration=None, tx_format=TxFormat.JSONRPC): - if declaration == None: - declaration = strip_0x(ZERO_CONTENT) + + def constructor(self, sender_address, name, symbol, declaration=ZERO_ADDRESS, tx_format=TxFormat.JSONRPC, version=None): + code = self.cargs(name, symbol, declaration, version=version) + tx = self.template(sender_address, None, use_nonce=True) + tx = self.set_code(tx, code) + return self.finalize(tx, tx_format) + + + @staticmethod + def cargs(name, symbol, declaration, version=None): + declaration = strip_0x(declaration) code = CraftNFT.bytecode() enc = ABIContractEncoder() enc.string(name) enc.string(symbol) enc.bytes32(declaration) code += enc.get() - tx = self.template(sender_address, None, use_nonce=True) - tx = self.set_code(tx, code) - return self.finalize(tx, tx_format) + return code def allocate(self, contract_address, sender_address, token_id, amount=0, tx_format=TxFormat.JSONRPC): @@ -359,3 +364,19 @@ class CraftNFT(ERC721): def parse_uri(self, v): r = abi_decode_single(ABIContractType.STRING, v) return r + + +def bytecode(**kwargs): + return CraftNFT.bytecode(version=kwargs.get('version')) + + +def create(**kwargs): + return CraftNFT.cargs(kwargs['name'], kwargs['symbol'], kwargs['declaration'], version=kwargs.get('version')) + + +def args(v): + if v == 'create': + return (['name', 'symbol', 'declaration'], ['version'],) + elif v == 'default' or v == 'bytecode': + return ([], ['version'],) + raise ValueError('unknown command: ' + v) diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = craft-nft -version = 0.0.2 +version = 0.0.3 description = A standalone NFT implementation for real-world arts and crafts assets author = Louis Holbrook author_email = dev@holbrook.no