Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eth-rpc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abi/*
evm/*
pvm/*
!.gitkeep
src/samples

# Editor directories and files
.vscode/*
Expand Down
13 changes: 6 additions & 7 deletions eth-rpc/contracts/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.0;

contract Errors {
bool public state;
bool public state;

// Payable function that can be used to test insufficient funds errors
// Payable function that can be used to test insufficient funds errors
function valueMatch(uint256 value) public payable {
require(msg.value == value , "msg.value does not match value");
require(msg.value == value, 'msg.value does not match value');
}

function setState(bool newState) public {
Expand All @@ -15,7 +15,7 @@ contract Errors {

// Trigger a require statement failure with a custom error message
function triggerRequireError() public pure {
require(false, "This is a require error");
require(false, 'This is a require error');
}

// Trigger an assert statement failure
Expand All @@ -25,7 +25,7 @@ contract Errors {

// Trigger a revert statement with a custom error message
function triggerRevertError() public pure {
revert("This is a revert error");
revert('This is a revert error');
}

// Trigger a division by zero error
Expand All @@ -45,7 +45,6 @@ contract Errors {
error CustomError(string message);

function triggerCustomError() public pure {
revert CustomError("This is a custom error");
revert CustomError('This is a custom error');
}
}

3 changes: 1 addition & 2 deletions eth-rpc/contracts/Event.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ contract EventExample {

function triggerEvent() public {
uint256 value = 12345;
string memory message = "Hello world";
string memory message = 'Hello world';
emit ExampleEvent(msg.sender, value, message);
}
}

1 change: 0 additions & 1 deletion eth-rpc/contracts/Flipper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ contract FlipperCaller {
return Flipper(flipperAddress).getValue();
}
}

12 changes: 6 additions & 6 deletions eth-rpc/contracts/PiggyBank.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.0;

contract PiggyBank {

uint256 private balance;
address public owner;

Expand All @@ -20,13 +19,14 @@ contract PiggyBank {
return balance;
}

function withdraw(uint256 withdrawAmount) public returns (uint256 remainingBal) {
require(msg.sender == owner, "You are not the owner");
function withdraw(
uint256 withdrawAmount
) public returns (uint256 remainingBal) {
require(msg.sender == owner, 'You are not the owner');
balance -= withdrawAmount;
(bool success, ) = payable(msg.sender).call{value: withdrawAmount}("");
require(success, "Transfer failed");
(bool success, ) = payable(msg.sender).call{value: withdrawAmount}('');
require(success, 'Transfer failed');

return balance;
}
}

69 changes: 69 additions & 0 deletions eth-rpc/contracts/Pretrace.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title PretraceFixture
/// @notice A simple contract to exercise storage, balance, and nonce changes
contract PretraceFixture {
uint256 public value;
mapping(address => uint256) public balances;

constructor() payable {
balances[msg.sender] = msg.value;
value = 42;
}

function writeStorage(uint256 _value) external {
value = _value;
}

function readStorage() external view returns (uint256) {
return value;
}

function deposit() external payable {
balances[msg.sender] += msg.value;
}

function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount, 'Insufficient balance');
balances[msg.sender] -= amount;
(bool sent, ) = msg.sender.call{value: amount}('');
require(sent, 'Transfer failed');
}

function getContractBalance() external view returns (uint256) {
return address(this).balance;
}

function getExternalBalance(
address account
) external view returns (uint256) {
return account.balance;
}

function createChild() external returns (address) {
PretraceFixtureChild c = new PretraceFixtureChild();
return address(c);
}

function callContract(address childAddr) external {
PretraceFixtureChild(childAddr).increment();
}

function delegatecallContract(address childAddr) external {
(bool success, ) = childAddr.delegatecall(
abi.encodeWithSelector(PretraceFixtureChild.increment.selector)
);
require(success, "Delegatecall failed");
}}

/// @title Child
/// @notice A disposable child contract used to test contract deployment and calls
contract PretraceFixtureChild {
uint256 public value = 1;

function increment() external {
value += 1;
}

}
29 changes: 17 additions & 12 deletions eth-rpc/contracts/Redstone.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

pragma solidity ^0.8.4;

import "@redstone-finance/evm-connector/contracts/data-services/RapidDemoConsumerBase.sol";
// TODO restore once https://github.com/paritytech/revive/pull/343 is released
// import '@redstone-finance/evm-connector/contracts/data-services/PrimaryProdDataServiceConsumerBase.sol';
import './node_modules/@redstone-finance/evm-connector/contracts/data-services/PrimaryProdDataServiceConsumerBase.sol';

contract ExampleRedstoneShowroom is RapidDemoConsumerBase {
function getPrices() public view returns(uint256[] memory) {
bytes32[] memory dataFeedIds = new bytes32[](6);
dataFeedIds[0] = bytes32("BTC");
dataFeedIds[1] = bytes32("ETH");
dataFeedIds[2] = bytes32("BNB");
dataFeedIds[3] = bytes32("AR");
dataFeedIds[4] = bytes32("AVAX");
dataFeedIds[5] = bytes32("CELO");
return getOracleNumericValuesFromTxMsg(dataFeedIds);
}
contract ExampleRedstoneShowroom is PrimaryProdDataServiceConsumerBase {
function getPrices() public view returns (uint256[] memory) {
bytes32[] memory dataFeedIds = new bytes32[](6);
dataFeedIds[0] = bytes32('BTC');
dataFeedIds[1] = bytes32('ETH');
dataFeedIds[2] = bytes32('BNB');
dataFeedIds[3] = bytes32('AR');
dataFeedIds[4] = bytes32('AVAX');
dataFeedIds[5] = bytes32('CELO');
return getOracleNumericValuesFromTxMsg(dataFeedIds);
}
}



30 changes: 30 additions & 0 deletions eth-rpc/contracts/Storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;

/**
* @title Storage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract Storage {
uint256 public n1;
uint256 public n2;

constructor() {
n1 = 42;
n2 = 100;
}

/**
* @dev Store value in variable
* @param num value to store
*/
function write_n1_read_n2(uint256 num) public {
n1 = num + n2;
}

function write_n2(uint256 num) public {
n2 = num;
}
}
4 changes: 1 addition & 3 deletions eth-rpc/contracts/Tester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Tester {
constructor() payable {
emit TesterDeployed(msg.sender);
value = 42;
name = "Hello world";
name = 'Hello world';
}

function setValue(uint256 v) external {
Expand All @@ -21,6 +21,4 @@ contract Tester {
function setName(string memory v) external {
name = v;
}

}

44 changes: 27 additions & 17 deletions eth-rpc/contracts/Tracing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,61 @@
pragma solidity ^0.8.0;

contract TracingCaller {
event TraceEvent(uint256 value, string message);
event TraceEvent(uint256 value, string message);
address payable public callee;

constructor(address payable _callee) payable {
require(_callee != address(0), "Callee address cannot be zero");
constructor(address payable _callee) payable {
require(_callee != address(0), 'Callee address cannot be zero');
callee = _callee;
}

function start(uint256 counter) external {
if (counter == 0) {
return;
return;
}

uint256 paymentAmount = 0.01 ether;
callee.transfer(paymentAmount);

emit TraceEvent(counter, "before");
TracingCallee(callee).consumeGas(counter);
emit TraceEvent(counter, "after");
emit TraceEvent(counter, 'before');
TracingCallee(callee).consumeGas(counter);
emit TraceEvent(counter, 'after');

try TracingCallee(callee).failingFunction{value: paymentAmount}() {
} catch {
}
try
TracingCallee(callee).failingFunction{value: paymentAmount}()
{} catch {}

this.start(counter - 1);
}

this.start(counter - 1);
function create() external returns (address) {
TracingCallee newCallee = new TracingCallee();
return address(newCallee);
}

function create2() external returns (address) {
bytes32 salt = bytes32(uint256(0x42));
TracingCallee newCallee = new TracingCallee{salt: salt}();
return address(newCallee);
}
}

contract TracingCallee {
event CalleeCalled(uint256 counter);

function consumeGas(uint256 counter) external {
// burn some gas
// burn some gas
for (uint256 i = 0; i < 10; i++) {
uint256(keccak256(abi.encodePacked(i)));
uint256(keccak256(abi.encodePacked(i)));
}

emit CalleeCalled(counter);
}

function failingFunction() external payable {
require(false, "This function always fails");
function failingFunction() external payable {
require(false, 'This function always fails');
}

// Enable contract to receive Ether
// Enable contract to receive Ether
receive() external payable {}
}

Loading