Skip to content

Commit

Permalink
Merge pull request #19 from willemolding/willem/github-actions
Browse files Browse the repository at this point in the history
Add github actions to check Rust code
  • Loading branch information
willemolding authored Apr 9, 2024
2 parents af584bb + 7665d29 commit e0c104f
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 60 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Rust

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup protoc
uses: arduino/setup-protoc@v1.1.2
- uses: actions-rs/cargo@v1
with:
command: check
args: --all
lints:
name: fmt check
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup protoc
uses: arduino/setup-protoc@v1.1.2
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ members = [ "cartezcash-lightwalletd", "tiny-cash", "tower-cartesi"]
[workspace.dependencies]

# patched zebra crates to support TinyCash network and expose things we need
# zebra-consensus = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false }
# zebra-state = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false }
# zebra-test = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false }
# zebra-chain = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false }
zebra-consensus = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false }
zebra-state = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false }
zebra-test = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false }
zebra-chain = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false }

zebra-consensus = { path = "../zebra/zebra-consensus", default-features = false }
zebra-state = { path = "../zebra/zebra-state", default-features = false }
zebra-test = { path = "../zebra/zebra-test", default-features = false }
zebra-chain = { path = "../zebra/zebra-chain", default-features = false }
# uncomment for local dev when modifying zebra
# zebra-consensus = { path = "../zebra/zebra-consensus", default-features = false }
# zebra-state = { path = "../zebra/zebra-state", default-features = false }
# zebra-test = { path = "../zebra/zebra-test", default-features = false }
# zebra-chain = { path = "../zebra/zebra-chain", default-features = false }


[patch.crates-io]
Expand Down
10 changes: 6 additions & 4 deletions cartezcash-lightwalletd/src/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use crate::proto::compact_formats::*;
use crate::proto::service::compact_tx_streamer_server::CompactTxStreamer;
use crate::proto::service::*;

use ethers::middleware::SignerMiddleware;
use ethers::prelude::abigen;
use ethers::providers::{Http, Provider};
use ethers::signers::{LocalWallet, Signer};
use ethers::types::{Address, Bytes};
use ethers::middleware::SignerMiddleware;

abigen!(
IInputBox,
Expand Down Expand Up @@ -57,13 +57,15 @@ where
) -> std::result::Result<tonic::Response<SendResponse>, tonic::Status> {
tracing::info!("send_transaction called. Fowarding to InputBox contract");

let provider =
Provider::<Http>::try_from("http://127.0.0.1:8545").unwrap();
let provider = Provider::<Http>::try_from("http://127.0.0.1:8545").unwrap();
let wallet: LocalWallet =
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
.parse()
.unwrap();
let client = std::sync::Arc::new(SignerMiddleware::new(provider, wallet.with_chain_id(31337_u64)));
let client = std::sync::Arc::new(SignerMiddleware::new(
provider,
wallet.with_chain_id(31337_u64),
));

// Instantiate the contract
let contract = IInputBox::new(
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.76.0"
23 changes: 11 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ async fn main() -> Result<(), anyhow::Error> {

let network = Network::Mainnet;

println!("Withdraw address is: {}", UnifiedAddress::from_receivers(Some(tiny_cash::mt_doom_address()), None).unwrap().encode(&MAIN_NETWORK));
println!(
"Withdraw address is: {}",
UnifiedAddress::from_receivers(Some(tiny_cash::mt_doom_address()), None)
.unwrap()
.encode(&MAIN_NETWORK)
);

// TODO: Enable this when not debugging
// tracing::info!("Initializing Halo2 verifier key");
Expand All @@ -59,8 +64,7 @@ async fn main() -> Result<(), anyhow::Error> {
let state_service = Buffer::new(state_service, 30);
let state_read_service = Buffer::new(state_read_service.boxed(), 30);

let mut cartezcash_app =
CarteZcashApp::new(network, state_service).await;
let mut cartezcash_app = CarteZcashApp::new(network, state_service).await;

let svc = CompactTxStreamerServer::new(CompactTxStreamerImpl { state_read_service });
let addr = grpc_addr.parse()?;
Expand All @@ -79,14 +83,12 @@ async fn main() -> Result<(), anyhow::Error> {
}

struct CarteZcashApp {
cartezcash: Buffer<BoxService<Request, service::Response, Box<dyn Error + Sync + Send>>, Request>,
cartezcash:
Buffer<BoxService<Request, service::Response, Box<dyn Error + Sync + Send>>, Request>,
}

impl CarteZcashApp {
pub async fn new(
network: Network,
state_service: StateService,
) -> Self {
pub async fn new(network: Network, state_service: StateService) -> Self {
// set up the services needed to run the rollup
let verifier_service = tx::Verifier::new(network, state_service.clone());
let mut tinycash = Buffer::new(
Expand All @@ -100,10 +102,7 @@ impl CarteZcashApp {
initialize_network(&mut tinycash).await.unwrap();

Self {
cartezcash: Buffer::new(
BoxService::new(CarteZcashService::new(tinycash)),
10,
),
cartezcash: Buffer::new(BoxService::new(CarteZcashService::new(tinycash)), 10),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use futures_util::future::FutureExt;
use std::future::Future;
use std::pin::Pin;
use tower::{BoxError, Service, ServiceExt};
use zebra_chain::amount::{Amount, NonNegative};

pub use request::Request;

Expand Down
22 changes: 6 additions & 16 deletions src/service/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ impl TryFrom<(tower_cartesi::AdvanceStateMetadata, Vec<u8>)> for Request {
transaction bytes // arbitrary size
*/

let txn = zebra_chain::transaction::Transaction::zcash_deserialize(payload.as_slice())?;
let txn =
zebra_chain::transaction::Transaction::zcash_deserialize(payload.as_slice())?;

tracing::info!(
"Received transaction request {}",
txn.hash()
);
tracing::info!("Received transaction request {}", txn.hash());

Ok(Request::Transact {
txn,
})
Ok(Request::Transact { txn })
}
_ => anyhow::bail!("unrecognised sender {}", metadata.msg_sender.to_string()),
}
Expand All @@ -88,14 +84,8 @@ impl std::fmt::Debug for Request {
Request::Deposit { amount, to } => {
write!(f, "Deposit {} to {}", amount, to)
}
Request::Transact {
txn,
} => {
write!(
f,
"Transact hash {}",
txn.hash(),
)
Request::Transact { txn } => {
write!(f, "Transact hash {}", txn.hash(),)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions tiny-cash/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
};
use tower::{Service, ServiceExt};

use zebra_chain::{transaction::{Memo, Transaction}, transparent::Script};
use zebra_chain::transparent;
use zebra_chain::{
amount::{Amount, NonNegative},
Expand All @@ -18,6 +17,10 @@ use zebra_chain::{
work::{difficulty::CompactDifficulty, equihash::Solution},
};
use zebra_chain::{block, serialization::ZcashDeserialize};
use zebra_chain::{
transaction::{Memo, Transaction},
transparent::Script,
};
use zebra_consensus::transaction as tx;

use crate::extract_burn_info;
Expand Down Expand Up @@ -253,9 +256,5 @@ fn mint_coinbase_txn(
}

fn empty_coinbase_txn(height: Height) -> Transaction {
mint_coinbase_txn(
Amount::zero(),
&Script::new(&[0x0; 32]),
height,
)
mint_coinbase_txn(Amount::zero(), &Script::new(&[0x0; 32]), height)
}
22 changes: 10 additions & 12 deletions tower-cartesi/examples/echo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use futures_util::FutureExt;
use std::env;
use std::future::Future;
use std::error::Error;
use std::future::Future;
use std::pin::Pin;
use std::task::{Poll, Context};
use futures_util::FutureExt;
use std::task::{Context, Poll};

use tower_service::Service;
use tower_cartesi::{listen_http, Request, Response};
use tower_service::Service;

type BoxError = Box<dyn Error + Send + Sync>;

Expand Down Expand Up @@ -35,24 +35,22 @@ impl Service<Request> for EchoApp {
type Error = Box<dyn Error + Send + Sync>;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;

fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

fn call(&mut self, req: Request) -> Self::Future {
match req {
Request::AdvanceState { metadata, payload } => {
println!("Received advance state request {:?} \npayload {:?}:", metadata, payload);
println!(
"Received advance state request {:?} \npayload {:?}:",
metadata, payload
);
}
Request::InspectState { payload } => {
println!("Received inspect state request {:?}", payload);
}
}
async {
Ok(tower_cartesi::Response::empty_accept())
}.boxed()
async { Ok(tower_cartesi::Response::empty_accept()) }.boxed()
}
}
5 changes: 4 additions & 1 deletion tower-cartesi/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ impl Response {
}

pub fn add_voucher(&mut self, destination: ethereum_types::Address, payload: &[u8]) {
self.outputs.push(Output::Voucher{destination, payload: payload.to_vec() });
self.outputs.push(Output::Voucher {
destination,
payload: payload.to_vec(),
});
}

pub fn finish_message(&self) -> Finish {
Expand Down

0 comments on commit e0c104f

Please sign in to comment.