-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #86 - contract.py does way too much, refactor it
- Loading branch information
Showing
32 changed files
with
735 additions
and
730 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
class DataNft: | ||
def __init__(self, config: Web3Config, address: str): | ||
self.contract_address = config.w3.to_checksum_address(address) | ||
self.contract_instance = config.w3.eth.contract( | ||
address=config.w3.to_checksum_address(address), | ||
abi=get_contract_abi("ERC721Template"), | ||
) | ||
self.config = config | ||
|
||
def set_data(self, field_label, field_value, wait_for_receipt=True): | ||
"""Set key/value data via ERC725, with strings for key/value""" | ||
field_label_hash = Web3.keccak(text=field_label) # to keccak256 hash | ||
field_value_bytes = field_value.encode() # to array of bytes | ||
# gasPrice = self.config.w3.eth.gas_price | ||
call_params = { | ||
"from": self.config.owner, | ||
"gasPrice": 100000000000, | ||
"gas": 100000, | ||
} | ||
tx = self.contract_instance.functions.setNewData( | ||
field_label_hash, field_value_bytes | ||
).transact(call_params) | ||
if wait_for_receipt: | ||
self.config.w3.eth.wait_for_transaction_receipt(tx) | ||
return tx | ||
|
||
def add_erc20_deployer(self, address, wait_for_receipt=True): | ||
# gasPrice = self.config.w3.eth.gas_price | ||
call_params = { | ||
"from": self.config.owner, | ||
"gasPrice": 100000000000, | ||
} | ||
tx = self.contract_instance.functions.addToCreateERC20List( | ||
self.config.w3.to_checksum_address(address) | ||
).transact(call_params) | ||
if wait_for_receipt: | ||
self.config.w3.eth.wait_for_transaction_receipt(tx) | ||
return tx | ||
|
||
def set_ddo(self, ddo, wait_for_receipt=True): | ||
# gasPrice = self.config.w3.eth.gas_price | ||
call_params = { | ||
"from": self.config.owner, | ||
"gasPrice": 100000000000, | ||
} | ||
js = json.dumps(ddo) | ||
stored_ddo = Web3.to_bytes(text=js) | ||
tx = self.contract_instance.functions.setMetaData( | ||
1, | ||
"", | ||
str(self.config.owner), | ||
bytes([0]), | ||
stored_ddo, | ||
Web3.to_bytes(hexstr=hashlib.sha256(js.encode("utf-8")).hexdigest()), | ||
[], | ||
).transact(call_params) | ||
if wait_for_receipt: | ||
self.config.w3.eth.wait_for_transaction_receipt(tx) | ||
return tx | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
class ERC721Factory: | ||
def __init__(self, config: Web3Config, chain_id=None): | ||
if not chain_id: | ||
chain_id = config.w3.eth.chain_id | ||
address = get_address(chain_id, "ERC721Factory") | ||
if not address: | ||
raise ValueError("Cannot figure out ERC721Factory address") | ||
self.contract_address = config.w3.to_checksum_address(address) | ||
self.contract_instance = config.w3.eth.contract( | ||
address=config.w3.to_checksum_address(address), | ||
abi=get_contract_abi("ERC721Factory"), | ||
) | ||
self.config = config | ||
|
||
def createNftWithErc20WithFixedRate(self, NftCreateData, ErcCreateData, FixedData): | ||
# gasPrice = self.config.w3.eth.gas_price | ||
call_params = { | ||
"from": self.config.owner, | ||
"gasPrice": 100000000000, | ||
} | ||
|
||
tx = self.contract_instance.functions.createNftWithErc20WithFixedRate( | ||
NftCreateData, ErcCreateData, FixedData | ||
).transact(call_params) | ||
receipt = self.config.w3.eth.wait_for_transaction_receipt(tx) | ||
if receipt["status"] != 1: | ||
raise ValueError(f"createNftWithErc20WithFixedRate failed in {tx.hex()}") | ||
# print(receipt) | ||
logs_nft = self.contract_instance.events.NFTCreated().process_receipt( | ||
receipt, errors=DISCARD | ||
) | ||
logs_erc = self.contract_instance.events.TokenCreated().process_receipt( | ||
receipt, errors=DISCARD | ||
) | ||
return logs_nft[0]["args"], logs_erc[0]["args"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
class FixedRate: | ||
def __init__(self, config: Web3Config, address: str): | ||
self.contract_address = config.w3.to_checksum_address(address) | ||
self.contract_instance = config.w3.eth.contract( | ||
address=config.w3.to_checksum_address(address), | ||
abi=get_contract_abi("FixedRateExchange"), | ||
) | ||
self.config = config | ||
|
||
def get_dt_price(self, exchangeId): | ||
return self.contract_instance.functions.calcBaseInGivenOutDT( | ||
exchangeId, self.config.w3.to_wei("1", "ether"), 0 | ||
).call() |
Oops, something went wrong.