Machine learning is one of artificial intelligence technologies.It realizes autonomous learning and prediction of machines through data learning algorithm,and can realize intelligent control,prediction and optimization in industrial production process.For example,machines on the production line can predict equipment failures by learning historical data,repair them in advance,and avoid losses caused by production line downtime.
5G技术可以为智慧物流提供高速、低延迟的数据传输和通信服务,实现物流的实时监控和管理。例如,在物流配送中,使用5G技术可以实现对货物的实时跟踪和配送调度,提高物流效率和准确性。
tokenToEthSwapInput和tokenToEthTransferInput都调用了函数tokenToEthInput进行ETH的兑换,区别是ETH的接收者不同,tokenToEthSwapOutput和tokenToEthTransferOutput的结构与前两者类似,不同的是输入换成了eth_bought,也就是想要兑换的ETH的目标数量,并且调用的函数是tokenToEthOutput。
因此接下来我们需要分析tokenToEthInput和tokenToEthOutput。
private
def tokenToEthInput(tokens_sold:uint256,min_eth:uint256(wei),deadline:timestamp,buyer:address,recipient:address)->uint256(wei):
#判断输入数据的合理性,且当前时间还没超过限定的时间戳
assert deadline>=block.timestamp and(tokens_sold>0 and min_eth>0)
#获取当前兑换合约对应代币的储备量
token_reserve:uint256=self.token.balanceOf(self)
#调用getInputPrice函数获取可以兑换到的eth数量(as_unitless_number用于去除wei单位)
eth_bought:uint256=self.getInputPrice(tokens_sold,token_reserve,as_unitless_number(self.balance))
#调用as_wei_value函数将单位转换成wei
wei_bought:uint256(wei)=as_wei_value(eth_bought,'wei')
assert wei_bought>=min_eth#兑换的eth不能低于设定最小值
send(recipient,wei_bought)#调用send函数向recipient转移兑换得到的eth
#调用代币合约的transferFrom函数从购买者收取应当支付的代币
assert self.token.transferFrom(buyer,self,tokens_sold)
log.EthPurchase(buyer,tokens_sold,wei_bought)#日志