我目前有一个函数,它遍历合同地址的字典,然后将它们添加到allowedTokens中,然后设置它们的价格提要。
我在一个函数中设置字典的值,然后调用另一个函数对其进行迭代:
..........
dict_of_allowed_tokens = {
dapp_token: get_contract("dai_usd_price_feed"),
fau_token: get_contract("dai_usd_price_feed"),
weth_token: get_contract("eth_usd_price_feed"),
}
add_allowed_tokens(token_farm, dict_of_allowed_tokens, account)
return token_farm, dapp_token
这是add_allowed_tokens
def add_allowed_tokens(token_farm, dict_of_allowed_tokens, account):
for token in dict_of_allowed_tokens:
add_tx = token_farm.addAllowedTokens(token.address, {"from": account})
add_tx.wait(1)
set_tx = token_farm.setPriceFeedContract(
token.address, dict_of_allowed_tokens[token], {"from": account}
)
set_tx.wait(1)
return token_farm
也许问题出在设置字典值时get_contract((函数中。以下是get合同的代码:(可能与此无关(
contract_to_mock = {
"link_token": LinkToken,
"eth_usd_price_feed": MockV3Aggregator,
"dai_usd_price_feed": MockV3Aggregator,
"oracle": MockOracle,
"fau_token": MockFAU,
"weth_token": MockWETH,
}
def get_contract(contract_name):
contract_type = contract_to_mock[contract_name]
if network.show_active() in NON_FORKED_LOCAL_BLOCKCHAIN_ENVIRONMENTS:
if len(contract_type) <= 0:
deploy_mocks()
contract = contract_type[-1]
else:
try:
contract_address = config["networks"][network.show_active()][contract_name]
contract = Contract.from_abi(
contract_type._name, contract_address, contract_type.abi
)
except KeyError:
print(
f"{network.show_active()} address not found, perhaps you should add it to the config or deploy mocks?"
)
print(
f"brownie run scripts/deploy_mocks.py --network {network.show_active()}"
)
return contract
我的控制台中出现以下错误:
Brownie v1.18.1 - Python development framework for Ethereum
File "brownie/_cli/__main__.py", line 64, in main
importlib.import_module(f"brownie._cli.{cmd}").main()
File "brownie/_cli/run.py", line 42, in main
active_project.load_config()
File "brownie/project/main.py", line 462, in load_config
_load_project_config(self._path)
File "brownie/_config.py", line 222, in _load_project_config
and "cmd_settings" in values
TypeError: argument of type 'NoneType' is not iterable
感谢您的帮助,如果这篇文章令人困惑或措辞不当,我一定会很快回答任何问题。谢谢
更新:花了我几个小时,但问题是我的browne-config.yaml 中有空位
一个3小时的错误需要5秒的修复:(
dependencies:
# - <organization/repo>@<version>
- smartcontractkit/chainlink-brownie-contracts@0.2.1
compiler:
solc:
remappings:
- "@chainlink=smartcontractkit/chainlink-brownie-contracts@0.2.1"
dotenv: .env
networks:
rinkeby:
eth_usd_price_feed: "0x035dCD3b056BdDbf82273A1b93c7B8cd25614995"
kovan:
mainnet:
wallets:
from_key: ${PRIVATE_KEY}
我只需要移除科万和主网,然后它就开始工作了!