mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 10:01:01 +00:00
implement self balance
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Generated
+349
-347
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -66,7 +66,7 @@ log = { version = "0.4" }
|
|||||||
# polkadot-sdk and friends
|
# polkadot-sdk and friends
|
||||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||||
scale-info = { version = "2.11.1", default-features = false }
|
scale-info = { version = "2.11.1", default-features = false }
|
||||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "d7b575338b2c647e04fc48bfbe00ea8f492fb580" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "868a36bd186f3ef9535ebf7deceac1b2fab19fcb" }
|
||||||
|
|
||||||
# llvm
|
# llvm
|
||||||
[workspace.dependencies.inkwell]
|
[workspace.dependencies.inkwell]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pragma solidity ^0.8;
|
|||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"Instantiate": {
|
"Instantiate": {
|
||||||
|
"value": 1024,
|
||||||
"code": {
|
"code": {
|
||||||
"Solidity": {
|
"Solidity": {
|
||||||
"contract": "Value"
|
"contract": "Value"
|
||||||
@@ -22,16 +23,30 @@ pragma solidity ^0.8;
|
|||||||
"value": 123,
|
"value": 123,
|
||||||
"data": "3fa4f245"
|
"data": "3fa4f245"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Call": {
|
||||||
|
"dest": {
|
||||||
|
"Instantiated": 0
|
||||||
|
},
|
||||||
|
"data": "52da5fa0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
contract Value {
|
contract Value {
|
||||||
|
constructor() payable {}
|
||||||
|
|
||||||
function value() public payable returns (uint ret) {
|
function value() public payable returns (uint ret) {
|
||||||
ret = msg.value;
|
ret = msg.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function balance_self() public view returns (uint ret) {
|
||||||
|
ret = address(this).balance;
|
||||||
|
}
|
||||||
|
|
||||||
function balance_of(address _address) public view returns (uint ret) {
|
function balance_of(address _address) public view returns (uint ret) {
|
||||||
ret = _address.balance;
|
ret = _address.balance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,9 +209,11 @@ case!("Call.sol", "Call", vec![], call_constructor);
|
|||||||
sol!(
|
sol!(
|
||||||
contract Value {
|
contract Value {
|
||||||
function balance_of(address _address) public view returns (uint ret);
|
function balance_of(address _address) public view returns (uint ret);
|
||||||
|
function balance_self() public view returns (uint ret);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
case!("Value.sol", Value, balance_ofCall, value_balance_of, address: Address);
|
case!("Value.sol", Value, balance_ofCall, value_balance_of, address: Address);
|
||||||
|
case!("Value.sol", Value, balance_selfCall, value_balance_self,);
|
||||||
|
|
||||||
sol!(
|
sol!(
|
||||||
contract Bitwise {
|
contract Bitwise {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ test_spec!(hash_keccak_256, "TestSha3", "Crypto.sol");
|
|||||||
test_spec!(erc20, "ERC20", "ERC20.sol");
|
test_spec!(erc20, "ERC20", "ERC20.sol");
|
||||||
test_spec!(computation, "Computation", "Computation.sol");
|
test_spec!(computation, "Computation", "Computation.sol");
|
||||||
test_spec!(msize, "MSize", "MSize.sol");
|
test_spec!(msize, "MSize", "MSize.sol");
|
||||||
test_spec!(transferred_value, "Value", "Value.sol");
|
|
||||||
test_spec!(sha1, "SHA1", "SHA1.sol");
|
test_spec!(sha1, "SHA1", "SHA1.sol");
|
||||||
test_spec!(block, "Block", "Block.sol");
|
test_spec!(block, "Block", "Block.sol");
|
||||||
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
test_spec!(mcopy, "MCopy", "MCopy.sol");
|
||||||
@@ -34,6 +33,7 @@ test_spec!(events, "Events", "Events.sol");
|
|||||||
test_spec!(storage, "Storage", "Storage.sol");
|
test_spec!(storage, "Storage", "Storage.sol");
|
||||||
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
test_spec!(mstore8, "MStore8", "MStore8.sol");
|
||||||
test_spec!(address, "Context", "Context.sol");
|
test_spec!(address, "Context", "Context.sol");
|
||||||
|
test_spec!(balance, "Value", "Value.sol");
|
||||||
|
|
||||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||||
vec![Instantiate {
|
vec![Instantiate {
|
||||||
|
|||||||
@@ -56,16 +56,32 @@ where
|
|||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
"balance",
|
"balance",
|
||||||
)?;
|
)?;
|
||||||
let address = context.builder().build_ptr_to_int(
|
let _address = context.builder().build_ptr_to_int(
|
||||||
address_pointer.value,
|
address_pointer.value,
|
||||||
context.xlen_type(),
|
context.xlen_type(),
|
||||||
"address",
|
"address",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
|
||||||
runtime_api::imports::BALANCE,
|
|
||||||
&[address.into(), balance.into()],
|
context.build_load(balance_pointer, "balance")
|
||||||
);
|
}
|
||||||
|
|
||||||
|
/// Translates the `selfbalance` instructions.
|
||||||
|
pub fn self_balance<'ctx, D>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
|
||||||
|
let balance = context.builder().build_ptr_to_int(
|
||||||
|
balance_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"balance",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
|
||||||
|
|
||||||
context.build_load(balance_pointer, "balance")
|
context.build_load(balance_pointer, "balance")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ impl pallet_revive::Config for Runtime {
|
|||||||
type UnsafeUnstableInterface = UnstableInterface;
|
type UnsafeUnstableInterface = UnstableInterface;
|
||||||
type UploadOrigin = EnsureSigned<AccountId32>;
|
type UploadOrigin = EnsureSigned<AccountId32>;
|
||||||
type InstantiateOrigin = EnsureSigned<AccountId32>;
|
type InstantiateOrigin = EnsureSigned<AccountId32>;
|
||||||
type Migrations = ();
|
|
||||||
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
|
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
|
||||||
type Debug = ();
|
type Debug = ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint32_t, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, gas_left, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, gas_left, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, balance, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, balance, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, now, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, now, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
|||||||
@@ -1159,7 +1159,9 @@ where
|
|||||||
let address = arguments[0].into_int_value();
|
let address = arguments[0].into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::SELFBALANCE => todo!(),
|
InstructionName::SELFBALANCE => {
|
||||||
|
revive_llvm_context::polkavm_evm_ether_gas::self_balance(context).map(Some)
|
||||||
|
}
|
||||||
|
|
||||||
InstructionName::GASLIMIT => {
|
InstructionName::GASLIMIT => {
|
||||||
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
||||||
|
|||||||
@@ -912,7 +912,9 @@ impl FunctionCall {
|
|||||||
let address = arguments[0].into_int_value();
|
let address = arguments[0].into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
revive_llvm_context::polkavm_evm_ether_gas::balance(context, address).map(Some)
|
||||||
}
|
}
|
||||||
Name::SelfBalance => todo!(),
|
Name::SelfBalance => {
|
||||||
|
revive_llvm_context::polkavm_evm_ether_gas::self_balance(context).map(Some)
|
||||||
|
}
|
||||||
|
|
||||||
Name::GasLimit => {
|
Name::GasLimit => {
|
||||||
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
revive_llvm_context::polkavm_evm_contract_context::gas_limit(context).map(Some)
|
||||||
|
|||||||
Reference in New Issue
Block a user