我想在 RSK 和以太坊中构建一个每年支付股息的 Solidity 智能合约。假设 RSK 和以太坊当前的平均块间时间,我应该使用块时间还是可以依赖块编号?
我尝试构建示例文件夹通过 cmake 在此项目中但这里有一些错误称为:
\ncmake .-- Configuring done\nCMake Error at CMakeLists.txt:23 (add_executable):\n Target "evmc-example" links to target "evmc::evmc_cpp" but the target was\n not found. Perhaps a find_package() call is missing for an IMPORTED\n target, or an ALIAS target is missing?\n\n\nCMake Error at CMakeLists.txt:23 (add_executable):\n Target "evmc-example" links to target "evmc::loader" but the target was not\n found. Perhaps a find_package() call is missing for an IMPORTED target, or\n …Run Code Online (Sandbox Code Playgroud) 我有这样的 Solidity 智能合约,pragma solidity >=0.7.0 <0.9.0;即使 0.8+ 不需要它,我仍然可以导入 SafeMath 吗?由于 SafeMath 使用的是 0.7,但我的合同指定它接受 0.7.0 至低于 0.9.0,在这种情况下 SafeMath 会做什么。
使用debug_traceCall时,我可以获得执行期间所有操作码和状态更改的低级 EVM 跟踪。这实在是太详细了。当我使用 default 时callTracer,我可以获得更好的调用树。但是,无论哪种方式,我似乎都无法从跟踪中提取发出的事件。我可以在跟踪(LOG*操作码)中看到它们,但是没有简单的方法可以将它们实际解析为“可读”的东西(以及值和原始地址)必须有一种方法来获取日志 - 有什么想法吗?
例如。这是 Etherscan 显示的https://etherscan.io/tx-decoder?tx=0x3e3ad35fda1fddd9e154b3860b50371a1acd2fdb4f27f897e234846522bde732(请参阅“发出的事件”部分)
contract Sharer {
function sendHalf(address payable addr) public payable returns (uint balance) {
require(msg.value % 2 == 0, "Even value required.");
uint balanceBeforeTransfer = address(this).balance;
addr.transfer(msg.value / 2);
// Since transfer throws an exception on failure and
// cannot call back here, there should be no way for us to
// still have half of the money.
assert(address(this).balance == balanceBeforeTransfer - msg.value / 2);
return address(this).balance;
}
}
Run Code Online (Sandbox Code Playgroud)
对于上述合约,在什么情况下断言失败/address(this).balance 不会减少 (msg.value / 2)?为什么我们需要在这里断言?
我正在学习 Solidity Assembly,但我对某些事情感到困惑。我正在查看这个名为 Seriality 的库。具体来说,这个函数:https : //github.com/pouladzade/Seriality/blob/master/src/TypesToBytes.sol#L21
function bytes32ToBytes(uint _offst, bytes32 _input, bytes memory _output) internal pure {
assembly {
mstore(add(_output, _offst), _input)
mstore(add(add(_output, _offst),32), add(_input,32))
}
}
Run Code Online (Sandbox Code Playgroud)
该函数 bytes32ToBytes 接受一个 bytes32 变量并将其存储在动态大小的字节数组中,从传入的偏移量开始。
让我困惑的是它使用了 mstore 函数两次。但是mstore函数存储了一个词,是32个字节,对吧?既然输入是 32 个字节,那么为什么它会被调用两次呢?不会调用它两次存储 2 个字,即 64 个字节?
谢谢!
在向运行时添加模块之后,我尝试为Dothereum 运行时实现Parity Substrate 特征。paint-evm
EVM模块特征定义如下:
pub trait Trait: Trait + Trait {
type FeeCalculator: FeeCalculator;
type ConvertAccountId: ConvertAccountId<Self::AccountId>;
type Currency: Currency<Self::AccountId>;
type Event: From<Event> + Into<Self::Event>;
type Precompiles: Precompiles;
}
Run Code Online (Sandbox Code Playgroud)
然而,这里添加模块的教程有点含糊,鼓励人们:
“.. 如果事情没有意义,请探索 [..] 模块的源代码 ..”
虽然 EVM 模块代码看起来不太复杂,但我无法理解如何为我的运行时实现 EVM 特征:
impl evm::Trait for Runtime {
type FeeCalculator = ();
type ConvertAccountId = ();
type Currency = Balances;
type Event = Event;
type Precompiles = ();
}
Run Code Online (Sandbox Code Playgroud)
这里有什么类型的人FeeCalculator以及ConvertAccountId期望什么类型的人?
我想在我的合约中包含一个内部方法,该方法允许在由参数命名的存储中创建一个新的 uint256。就像是:
function createUint (string memory _name) internal {
/*
* creates a new uint256 named _name in storage
*/
}
Run Code Online (Sandbox Code Playgroud)
我的猜测是它需要内联汇编,但我不知道如何
我正在用 Solidity 编写代理合约。为了在我的后备函数中转发传入呼叫,我使用内联汇编代码。我是一名学生,下面的代码是我的老师在教程中编写的代码。
不过,我的代码收到以下错误:
必须调用内置函数“gas”。
我假设自本教程制作以来 Solidity 已经不断发展,但我在网上找不到任何东西(谷歌或文档)。
这是代码:
assembly {
let result := delegatecall(gas, implementation, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 {revert(ptr, size)}
default{return(ptr, size)}
}
Run Code Online (Sandbox Code Playgroud)
该错误是指第 2 行中带有红色下划线的单词“gas”。
有什么改变吗?