简体   繁体   English

如何自动执行 ChainLink 作业以调用智能合约 function,要求调用者是给定的管理员地址?

[英]How to automate a ChainLink Job to call a smart-contract function that requires the caller to be a given admin address?

ChainLink automation enables conditional execution of smart contracts functions. ChainLink 自动化支持有条件地执行智能合约功能。 However, when calling function from the smart contract, it is the ChainLink registry contract that calls the function, and not the address that registered the UpKeep.但是,当从智能合约调用 function 时,调用 function 的是 ChainLink 注册合约,而不是注册 UpKeep 的地址。

Therefore, it is likely that the call will fail if the function to call has a require that forces the caller (msg.sender) to be a given address (admin address for example).因此,如果要调用的 function 具有强制调用者 (msg.sender) 为给定地址(例如管理地址)的要求,则调用很可能会失败。

Is it possible to automate such kind of functions (with msg.sender set to a needed address) with ChainLink Automation?是否可以使用 ChainLink Automation 自动执行此类功能(将 msg.sender 设置为所需地址)?

As an example:举个例子:

mapping() private _balance;
address public admin;

constructor {
    admin = msg.sender;
}

modifier onlyAdmin {
    require(msg.sender == admin, "Only admin");
    _;
}

function pay(address _account, uint256 _amount) public onlyAdmin {
    _balance[_account] += _amount; 
}

function getBalance(address _account) public view returns(uint256) {
    return _balance[_account];
}

update a balance through Chainlink automation.通过 Chainlink 自动化更新余额。 I expect the balance of _account to update to its previous value + _amount.我希望 _account 的余额更新为之前的值 + _amount。

_balance[account] = _balance[account] + _amount;

As you said transaction sent by Chainlink automation is signed with Chainlink Registry contract, and as far as I know it is impossible to replace the signature with consumer contract's owner's signature.正如您所说,Chainlink 自动化发送的交易是与 Chainlink Registry 合约签署的,据我所知,不可能用消费者合约所有者的签名替换签名。

I think the better way to do this is to modify the modifier onlyAdmin to add address of registry contract.我认为更好的方法是修改修饰符onlyAdmin以添加注册表合约的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM