Repository navigation
Expand file tree
/
Copy pathprecompile.sol
More file actions
73 lines (64 loc) · 2.59 KB
/
Copy pathprecompile.sol
File metadata and controls
73 lines (64 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract ContractA {
address precomplieContarct = 0x0000000000000000000000000000000000000100;
uint256 public number;
event pushLog(string data);
function callWasm(string memory wasmAddr, string memory msgData,bool requireASuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = precomplieContarct.call{value: msg.value} (
abi.encodeWithSignature("callToWasm(string,string)", wasmAddr,msgData)
);
if (requireASuccess) {
require(success);
string memory res = abi.decode(data,(string));
emit pushLog(res);
}
number = number + 1;
return data;
}
function queryWasm(string memory msgData,bool requireASuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = precomplieContarct.call{value: msg.value} (
abi.encodeWithSignature("queryToWasm(string)",msgData)
);
if (requireASuccess) {
require(success);
string memory res = abi.decode(data,(string));
emit pushLog(res);
}
number = number + 1;
return data;
}
function callToWasm(string memory wasmAddr, string memory data) public payable returns (string memory response) {
return "";
}
function queryToWasm(string memory data) public view returns (string memory response) {
return "";
}
}
contract ContractB {
uint256 public number;
function callWasm(address contractA ,string memory wasmAddr, string memory msgData, bool requireASuccess,bool requireBSuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = contractA.call{value: msg.value} (
abi.encodeWithSignature("callWasm(string,string,bool)", wasmAddr,msgData,requireASuccess)
);
number = number + 1;
if (requireBSuccess) {
require(success);
}
return data;
}
function queryWasm(address contractA , string memory msgData, bool requireASuccess,bool requireBSuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = contractA.call{value: msg.value} (
abi.encodeWithSignature("queryWasm(string,bool)",msgData,requireASuccess)
);
number = number + 1;
if (requireBSuccess) {
require(success);
}
return data;
}
}