Skip to content

Commit

Permalink
Merge commit '4b1455160a92181c304e87395cf94328aa611a7b'
Browse files Browse the repository at this point in the history
* commit '4b1455160a92181c304e87395cf94328aa611a7b':
  [Testing] moveos_stdlib::account_storage (rooch-network#355)
  add release workflow (rooch-network#343)
  [cli] return a string for init command. (rooch-network#347)
  Feature owen eth rooch address mapping (rooch-network#348)
  Fix the issue of illegal invocation of private_generics in the module without throwing an error. (rooch-network#345)
  • Loading branch information
wubuku committed Jun 26, 2023
2 parents 5703c51 + 4b14551 commit fa5419d
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 52 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/release_asset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release asset bot

on:
workflow_dispatch:
release:
types: [published]
jobs:
build:
name: Build release asset
continue-on-error: true
strategy:
fail-fast: false
matrix:
platform:
- ubuntu-latest
- ubuntu-18.04
- ubuntu-22.04
- macos-latest
- windows-latest
runs-on: ${{matrix.platform}}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install LLVM and Clang # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797
uses: KyleMayes/install-llvm-action@v1
if: matrix.platform == 'windows-latest'
with:
version: "11.0"
directory: ${{ runner.temp }}/llvm
- name: Set LIBCLANG_PATH
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
if: matrix.platform == 'windows-latest'
- name: build for ${{ matrix.platform }}
uses: actions-rs/cargo@v1
with:
command: build
args: --release

- name: build rooch release asset
run: bash ./scripts/release.sh ${{ matrix.platform }}

- name: upload artifact asset
uses: actions/upload-artifact@v2
if: ${{ github.event_name != 'release'}}
with:
name: rooch-${{ matrix.platform }}.zip
path: ./rooch-${{ matrix.platform }}.zip

- name: upload rooch release asset
if: ${{ github.event_name == 'release'}}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./rooch-${{ matrix.platform }}.zip
asset_name: rooch-${{ matrix.platform }}.zip
asset_content_type: application/zip
34 changes: 28 additions & 6 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

use super::messages::{
AnnotatedStatesMessage, ExecuteTransactionMessage, ExecuteTransactionResult,
ExecuteViewFunctionMessage, GetEventsByEventHandleMessage, GetEventsMessage, StatesMessage,
ValidateTransactionMessage,
ExecuteViewFunctionMessage, GetEventsByEventHandleMessage, GetEventsMessage, ResolveMessage,
StatesMessage, ValidateTransactionMessage,
};
use crate::actor::messages::{GetTransactionInfosByTxHashMessage, GetTxSeqMappingByTxOrderMessage};
use anyhow::bail;
use anyhow::Result;
use async_trait::async_trait;
use coerce::actor::{context::ActorContext, message::Handler, Actor};
use move_core_types::account_address::AccountAddress;
use move_resource_viewer::MoveValueAnnotator;
use moveos::moveos::MoveOS;
use moveos_common::accumulator::InMemoryAccumulator;
Expand All @@ -28,6 +29,7 @@ use rooch_framework::bindings::address_mapping::AddressMapping;
use rooch_framework::bindings::transaction_validator::TransactionValidator;
use rooch_genesis::RoochGenesis;
use rooch_store::RoochDB;
use rooch_types::address::MultiChainAddress;
use rooch_types::transaction::{AbstractTransaction, TransactionSequenceMapping};

pub struct ExecutorActor {
Expand All @@ -47,9 +49,10 @@ impl ExecutorActor {
Ok(Self { moveos, rooch_db })
}

pub fn validate<T: AbstractTransaction>(&self, tx: T) -> Result<VerifiedMoveOSTransaction> {
let multi_chain_address_sender = tx.sender();

pub fn resolve_address(
&self,
multi_chain_address_sender: MultiChainAddress,
) -> Result<AccountAddress> {
let resolved_sender = {
let address_mapping = self.moveos.as_module_bundle::<AddressMapping>();
address_mapping
Expand All @@ -61,9 +64,17 @@ impl ExecutorActor {
)
})?
};

Ok(resolved_sender)
}

pub fn validate<T: AbstractTransaction>(&self, tx: T) -> Result<VerifiedMoveOSTransaction> {
let multi_chain_address_sender = tx.sender();

let resolved_sender = self.resolve_address(multi_chain_address_sender.clone());
let authenticator = tx.authenticator_info();

let mut moveos_tx = tx.construct_moveos_transaction(resolved_sender)?;
let mut moveos_tx = tx.construct_moveos_transaction(resolved_sender?)?;

let result = {
let tx_validator = self.moveos.as_module_bundle::<TransactionValidator>();
Expand Down Expand Up @@ -159,6 +170,17 @@ impl Handler<ExecuteViewFunctionMessage> for ExecutorActor {
}
}

#[async_trait]
impl Handler<ResolveMessage> for ExecutorActor {
async fn handle(
&mut self,
msg: ResolveMessage,
_ctx: &mut ActorContext,
) -> Result<AccountAddress, anyhow::Error> {
self.resolve_address(msg.address)
}
}

#[async_trait]
impl Handler<StatesMessage> for ExecutorActor {
async fn handle(
Expand Down
11 changes: 11 additions & 0 deletions crates/rooch-executor/src/actor/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use anyhow::Result;
use coerce::actor::message::Message;
use move_core_types::account_address::AccountAddress;
use move_core_types::language_storage::StructTag;
use moveos_types::access_path::AccessPath;
use moveos_types::event::AnnotatedMoveOSEvent;
Expand All @@ -14,6 +15,7 @@ use moveos_types::transaction::FunctionCall;
use moveos_types::transaction::TransactionExecutionInfo;
use moveos_types::transaction::TransactionOutput;
use moveos_types::transaction::VerifiedMoveOSTransaction;
use rooch_types::address::MultiChainAddress;
use rooch_types::transaction::{AbstractTransaction, TransactionSequenceMapping};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -61,6 +63,15 @@ impl Message for StatesMessage {
type Result = Result<Vec<Option<State>>>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ResolveMessage {
pub address: MultiChainAddress,
}

impl Message for ResolveMessage {
type Result = Result<AccountAddress>;
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AnnotatedStatesMessage {
pub access_path: AccessPath,
Expand Down
8 changes: 7 additions & 1 deletion crates/rooch-executor/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use crate::actor::{
executor::ExecutorActor,
messages::{
AnnotatedStatesMessage, ExecuteViewFunctionMessage, GetEventsByEventHandleMessage,
GetEventsMessage, StatesMessage, ValidateTransactionMessage,
GetEventsMessage, ResolveMessage, StatesMessage, ValidateTransactionMessage,
},
};
use anyhow::Result;
use coerce::actor::ActorRef;
use move_core_types::account_address::AccountAddress;
use move_core_types::language_storage::StructTag;
use moveos_types::h256::H256;
use moveos_types::transaction::FunctionCall;
Expand All @@ -25,6 +26,7 @@ use moveos_types::{
event_filter::EventFilter,
state::{AnnotatedState, State},
};
use rooch_types::address::MultiChainAddress;
use rooch_types::transaction::{AbstractTransaction, TransactionSequenceMapping};

#[derive(Clone)]
Expand Down Expand Up @@ -67,6 +69,10 @@ impl ExecutorProxy {
self.actor.send(StatesMessage { access_path }).await?
}

pub async fn resolve_address(&self, mca: MultiChainAddress) -> Result<AccountAddress> {
self.actor.send(ResolveMessage { address: mca }).await?
}

pub async fn get_annotated_states(
&self,
access_path: AccessPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
processed 2 tasks

task 1 'publish'. lines 3-12:
error: type `test::Foo` is not supported as a parameter type
Error: error: type `test::Foo` is not supported as a parameter type
┌─ /tmp/tempfile:8:5
8 │ ╭ entry public fun test_entry_function_invalid_struct( _foo: Foo ){
9 │ │ }
│ ╰─────^

status EXECUTED

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
processed 2 tasks

task 1 'publish'. lines 3-33:
error: type `&mut signer` is not supported as a parameter type
Error: error: type `&mut signer` is not supported as a parameter type
┌─ /tmp/tempfile:9:5
9 │ ╭ entry public fun test_entry_function_valid_reference_mut_signer( _: &mut signer ){
10 │ │ }
│ ╰─────^

status EXECUTED

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
processed 2 tasks

task 1 'publish'. lines 3-54:
error: entry function cannot return values
Error: error: entry function cannot return values
┌─ /tmp/tempfile:26:5
26 │ ╭ entry public fun test_entry_function_return_value_String():std::string::String{
Expand Down Expand Up @@ -81,4 +81,4 @@ error: entry function cannot return values
7 │ │ }
│ ╰─────^

status EXECUTED

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ task 1 'publish'. lines 3-21:
status EXECUTED

task 2 'run'. lines 22-38:
error: resource type "TestObject" in function "0x2::object::new" not defined in current module or not allowed
Error: error: resource type "TestObject" in function "0x2::object::new" not defined in current module or not allowed
┌─ /tmp/tempfile:31:19
31 │ let obj = object::new<TestObject>(storage_context::tx_context_mut(ctx), sender_addr, object);
Expand All @@ -22,4 +22,4 @@ error: resource type "TestObject" in function "0x2::object::unpack" not defined
33 │ let (_id, _owner, test_object) = object::unpack(obj);
│ ^^^^^^^^^^^^^^^^^^^

status EXECUTED

3 changes: 2 additions & 1 deletion crates/rooch-framework/doc/address_mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<b>use</b> <a href="">0x2::table</a>;
<b>use</b> <a href="">0x2::tx_context</a>;
<b>use</b> <a href="core_addresses.md#0x3_core_addresses">0x3::core_addresses</a>;
<b>use</b> <a href="rooch_hash.md#0x3_rooch_hash">0x3::rooch_hash</a>;
</code></pre>


Expand Down Expand Up @@ -168,7 +169,7 @@ Resolve a multi-chain address to a rooch address
<b>let</b> addr = <a href="_borrow">table::borrow</a>(&am.mapping, maddress);
<a href="_some">option::some</a>(*addr)
}<b>else</b>{
<a href="_none">option::none</a>&lt;<b>address</b>&gt;()
<a href="address_mapping.md#0x3_address_mapping_default_rooch_address">default_rooch_address</a>(maddress)
}
}
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-framework/sources/account.move
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ module rooch_framework::account{

#[test(sender=@0x0)]
#[expected_failure(abort_code = 0x10005, location = Self)]
fun test_failur_entry_account_creation_reserved(sender: address){
fun test_failure_entry_account_creation_reserved(sender: address){
let ctx = storage_context::new_test_context(sender);
create_account_entry(&mut ctx, sender);
storage_context::drop_test_context(ctx);
Expand Down
8 changes: 7 additions & 1 deletion crates/rooch-framework/sources/address_mapping.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module rooch_framework::address_mapping{
use moveos_std::storage_context::{Self, StorageContext};
use moveos_std::table::{Self, Table};
use moveos_std::account_storage;
use rooch_framework::rooch_hash::{blake2b256};

friend rooch_framework::transaction_validator;

Expand Down Expand Up @@ -46,10 +47,15 @@ module rooch_framework::address_mapping{
let addr = table::borrow(&am.mapping, maddress);
option::some(*addr)
}else{
option::none<address>()
default_rooch_address(maddress)
}
}

fun default_rooch_address(maddress: MultiChainAddress): Option<address> {
let hash = blake2b256(&maddress.raw_address);
option::some(moveos_std::bcd::to_address(hash))
}

/// Check if a multi-chain address is bound to a rooch address
public fun exists_mapping(ctx: &StorageContext, maddress: MultiChainAddress): bool {
if (is_rooch_address(&maddress)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ task 1 'publish'. lines 3-8:
status EXECUTED

task 2 'publish'. lines 10-48:
error: resource type "KeyStruct" in function "0x2::object_storage::remove" not defined in current module or not allowed
Error: error: resource type "KeyStruct" in function "0x2::object_storage::remove" not defined in current module or not allowed
┌─ /tmp/tempfile:37:19
37 │ let obj = object_storage::remove<KeyStruct>(object_storage, object_id);
Expand All @@ -22,4 +22,4 @@ error: resource type "KeyStruct" in function "0x2::account_storage::global_move_
40 │ account_storage::global_move_to(ctx, &sender, value);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

status EXECUTED

19 changes: 18 additions & 1 deletion crates/rooch-server/src/api/eth_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

use crate::jsonrpc_types::eth::{CallRequest, EthFeeHistory};
use ethers::types::{
Block, BlockNumber, Bytes, Transaction, TransactionRequest, TxHash, H160, U256,
Block, BlockNumber, Bytes, Transaction, TransactionReceipt, TransactionRequest, TxHash, H160,
U256,
};
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
Expand Down Expand Up @@ -87,4 +88,20 @@ pub trait EthAPI {
/// Sends signed transaction, returning its hash.
#[method(name = "eth_sendRawTransaction")]
async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<H256>;

/// Returns transaction receipt by transaction hash.
#[method(name = "eth_getTransactionReceipt")]
async fn transaction_receipt(&self, hash: H256) -> RpcResult<Option<TransactionReceipt>>;

/// Get transaction by its hash.
#[method(name = "eth_getTransactionByHash")]
async fn transaction_by_hash(&self, hash: H256) -> RpcResult<Option<Transaction>>;

/// Returns block with given hash.
#[method(name = "eth_getBlockByHash")]
async fn block_by_hash(
&self,
hash: H256,
include_txs: bool,
) -> RpcResult<Block<TransactionType>>;
}
Loading

0 comments on commit fa5419d

Please sign in to comment.