TypeError:类型非类型的参数在Python中是无法的

发布于 2025-01-18 05:31:22 字数 2606 浏览 1 评论 0原文

我目前有一个函数,可以迭代合约地址字典,然后将它们添加到 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() 函数中。这是获取合同的代码:(可能,可能与此无关)

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

感谢您的帮助,如果这令人困惑或措辞不佳,我一定会快速回复任何问题。谢谢!

I currently have a function that iterates through a dictionary of contract addresses and then adds them into the allowedTokens and then set their price feed.

I set the values of the dictionary in a function, then call another function to iterate through it:

..........

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

Here is the 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

Maybe the problem is something in the get_contract() function when setting the dictionary values. Here is the code for the get contract: (may, may not be related to this)

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

I am getting this error in my console:

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

Thanks for the help, if this is confusing or worded poorly I will be sure to be quick to respond with any questions. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹梦 2025-01-25 05:31:22

更新:花了我几个小时,但问题是我的 Brownie-config.yaml 中有空白空间,花了

3 小时修复了 5 秒的错误:)

Update: Took me hours but the problem was I had empty spaces in my brownie-config.yaml

A 3 hour bug for a 5 second fix :)

屋檐 2025-01-25 05:31:22
dependencies:
  # - <organization/repo>@<version>
  - smartcontractkit/[email protected]
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/[email protected]"
dotenv: .env
networks:
  rinkeby:
    eth_usd_price_feed: "0x035dCD3b056BdDbf82273A1b93c7B8cd25614995"
  kovan:
  mainnet:
wallets:
  from_key: ${PRIVATE_KEY}

我只需要删除Kovan和Mainnet,然后开始工作!

dependencies:
  # - <organization/repo>@<version>
  - smartcontractkit/[email protected]
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/[email protected]"
dotenv: .env
networks:
  rinkeby:
    eth_usd_price_feed: "0x035dCD3b056BdDbf82273A1b93c7B8cd25614995"
  kovan:
  mainnet:
wallets:
  from_key: ${PRIVATE_KEY}

I just needed to remove the kovan and mainnet and then it started working!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文