Post #366
795
Небольшая статейка для тех, кто использует Lokalise API - в ней я показываю разные примеры на TS, Ruby, Python https://lokalise.com/blog/lokalise-apiv2-in-practice/
- 👍 5
DE @dev_in_ruby_colors
Showing posts older than #367 · Back to latest
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Parent1 {
uint public parentInt1 = 45;
uint public parentInt2 = 55;
}
contract Parent2 is Parent1 {
uint public parentInt3 = 65;
uint public parentInt4 = 75;
}
contract Parent4 {
uint public parentInt5 = 100;
uint public parentInt6 = 101;
}
contract Parent3 is Parent4 {
uint public parentInt7 = 102;
uint public parentInt8 = 103;
}
contract Demo is Parent2, Parent3 {
uint public demoInt = 76;
function readSlot(uint _n) external view returns (uint data) {
assembly {
data := sload(_n)
}
}
}
"test(uint256)".abi.encodeWithSignature("test(uint256)", 42)bytes4(keccak256(bytes("test(uint256)")))test, принимающая uint256, то в ABI вы увидите что-то вроде:"test(uint256)": "29e99f07"
function test(uint a) external view returns(bytes4) {
return bytes4(msg.data[0:4]);
} function test(uint a) external view returns(bytes4) {
bytes32 temp;
assembly {
temp := calldataload(0)
}
return bytes4(temp);
}0x29e99f07. После первых 4 байт будут идти уже сами аргументы, которые передаются в функцию. function test(uint a) external view returns(bytes4, bytes32) {
bytes32 temp;
bytes32 _arg1;
assembly {
temp := calldataload(0)
_arg1 := calldataload(4)
}
return (bytes4(temp), _arg1);
}test с аргументом 1 вернётся0:
bytes4: 0x29e99f07
1:
bytes32: 0x0000000000000000000000000000000000000000000000000000000000000001
function test(uint[] memory a) и мы вызываем её с аргументом [1,2] то в msg.data будет нечто странное:0xca1606840000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002
function test(uint[] memory a) external view returns(bytes4, bytes32, bytes32, bytes32, bytes32, bytes memory) {
bytes32 temp;
bytes32 _startIn;
bytes32 _elCount;
bytes32 _firstEl;
bytes32 _secondEl;
assembly {
temp := calldataload(0)
_startIn := calldataload(4)
_elCount := calldataload(36)
_firstEl := calldataload(68)
_secondEl := calldataload(100)
}
return (bytes4(temp), _startIn, _elCount, _firstEl, _secondEl, msg.data);
}.vodka, причём по вполне сходной цене 😂 https://www.namecheap.com/domains/registration/gtld/vodka/internal, а не private:contract C1{
uint test = 42;
}
contract C2 is C1 {
function demo() external view returns(uint) {
return test; // вот тут test виден!
}
}
Прошу прощения.DEV: Рубиновые тона Ещё немного вас повеселю. Какое-то время назад я всё-таки подумал, что надо бы почитать книги об известном герое, а потом сел писать на него жалобу. Вышло примерно на сто страниц текста (может и больше, уже не помню), так что всё это оформлено в виде вот такого…
abstract class Parent {
constructor(params: any) {
for (const key of Object.keys(params)) {
(<any>this)[key] = params[key];
}
}
}
class Child extends Parent {
test!: number;
}
const c = new Child({
test: 1
});
console.log(c);test всегда оказывается пустым.declare:class Parent {
constructor(params: any) {
for (const key of Object.keys(params)) {
(<any>this)[key] = params[key];
}
}
}
class Child extends Parent {
declare test: number;
}