Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pallet-revive] use evm decimals in call host fn #6466

Merged
merged 17 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 12 additions & 0 deletions prdoc/pr_6466.prdoc
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
34 changes: 34 additions & 0 deletions substrate/frame/revive/rpc/examples/js/abi/event.json
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"
}
]
65 changes: 65 additions & 0 deletions substrate/frame/revive/rpc/examples/js/abi/piggyBank.json
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"
}
]
14 changes: 14 additions & 0 deletions substrate/frame/revive/rpc/examples/js/abi/revert.json
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 modified substrate/frame/revive/rpc/examples/js/bun.lockb
Binary file not shown.
28 changes: 28 additions & 0 deletions substrate/frame/revive/rpc/examples/js/contracts/PiggyBank.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 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;
}
}

56 changes: 0 additions & 56 deletions substrate/frame/revive/rpc/examples/js/evm-contracts.json

This file was deleted.

53 changes: 31 additions & 22 deletions substrate/frame/revive/rpc/examples/js/index.html
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>
Loading
Loading