-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pallet-revive] use evm decimals in call host fn (#6466)
This PR update the pallet to use the EVM 18 decimal balance in contracts call and host functions instead of the native balance. It also updates the js example to add the piggy-bank solidity contract that expose the problem --------- Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
5bc571b
commit 39eba14
Showing
42 changed files
with
1,537 additions
and
770 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
title: '[pallet-revive] add piggy-bank sol example' | ||
doc: | ||
- audience: Runtime Dev | ||
description: |- | ||
This PR update the pallet to use the EVM 18 decimal balance in contracts call and host functions instead of the native balance. | ||
|
||
It also updates the js example to add the piggy-bank solidity contract that expose the problem | ||
crates: | ||
- name: pallet-revive-eth-rpc | ||
bump: minor | ||
- name: pallet-revive | ||
bump: minor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "sender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "string", | ||
"name": "message", | ||
"type": "string" | ||
} | ||
], | ||
"name": "ExampleEvent", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "triggerEvent", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "deposit", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getDeposit", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "withdrawAmount", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "withdraw", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "remainingBal", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "doRevert", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
Binary file not shown.
32 changes: 32 additions & 0 deletions
32
substrate/frame/revive/rpc/examples/js/contracts/PiggyBank.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract PiggyBank { | ||
|
||
uint private balance; | ||
address public owner; | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
balance = 0; | ||
} | ||
|
||
function deposit() public payable returns (uint) { | ||
balance += msg.value; | ||
return balance; | ||
} | ||
|
||
function getDeposit() public view returns (uint) { | ||
return balance; | ||
} | ||
|
||
function withdraw(uint withdrawAmount) public returns (uint remainingBal) { | ||
require(msg.sender == owner); | ||
balance -= withdrawAmount; | ||
(bool success, ) = payable(msg.sender).call{value: withdrawAmount}(""); | ||
require(success, "Transfer failed"); | ||
|
||
return balance; | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="https://polkadot.com/favicon.ico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>MetaMask Playground</title> | ||
<style> | ||
input { width: 300px; margin-right: 10px; } | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="https://polkadot.com/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>MetaMask Playground</title> | ||
<style> | ||
input { | ||
width: 300px; | ||
margin-right: 10px; | ||
} | ||
|
||
button { | ||
display: block; | ||
margin-bottom: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<input id="transferInput" type="text" style="float: left" placeholder="Destination address" value="0x3cd0a705a2dc65e5b1e1205896baa2be8a07c6e0" /> | ||
<button id="transferButton">Transfer coins</button> | ||
button { | ||
display: block; | ||
margin-bottom: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<input | ||
id="transferInput" | ||
type="text" | ||
style="float: left" | ||
placeholder="Destination address" | ||
value="0x3cd0a705a2dc65e5b1e1205896baa2be8a07c6e0" | ||
/> | ||
<button id="transferButton">Transfer coins</button> | ||
|
||
<button id="deployButton">Deploy Contract</button> | ||
<button id="deployButton">Deploy Contract</button> | ||
|
||
<input id="callInput" type="text" style="float: left" placeholder="Contract address" /> | ||
<button id="callButton">Call Contract</button> | ||
<input id="callInput" type="text" style="float: left" placeholder="Contract address" /> | ||
<button id="callButton">Call Contract</button> | ||
|
||
<button id="deployAndCallButton">Deploy and Call Contract</button> | ||
<script type="module" src="src/web.ts"></script> | ||
</body> | ||
<button id="deployAndCallButton">Deploy and Call Contract</button> | ||
<script type="module" src="src/web.ts"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.