-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
338 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,15 @@ | ||
[package] | ||
name = "erc20-relay" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
erc20-relay-app.workspace = true | ||
|
||
[build-dependencies] | ||
erc20-relay-app.workspace = true | ||
sails-rs = { version = "0.4.0", features = ["wasm-builder"] } | ||
sails-idl-gen = "0.4.0" | ||
|
||
[features] | ||
wasm-binary = [] |
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,8 @@ | ||
## The **erc20-relay** program | ||
|
||
The program workspace includes the following packages: | ||
- `erc20-relay` is the package allowing to build WASM binary for the program and IDL file for it. | ||
- `erc20-relay-app` is the package containing business logic for the program represented by the `Erc20RelayService` structure. | ||
- `erc20-relay-client` is the package containing the client for the program allowing to interact with it from another program, tests, or | ||
off-chain client. | ||
|
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 @@ | ||
[package] | ||
name = "erc20-relay-app" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
sails-rs = "0.4.0" | ||
ethereum-common.workspace = true | ||
|
||
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] | ||
getrandom = { version = "0.2", default-features = false, features = ["custom"] } | ||
lazy_static = { version = "1.1", features = ["spin_no_std"] } |
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,68 @@ | ||
#![no_std] | ||
|
||
use cell::RefCell; | ||
use sails_rs::prelude::*; | ||
use ethereum_common:: | ||
beacon::{ | ||
light::Block as LightBeaconBlock, BlockHeader as BeaconBlockHeader, | ||
}; | ||
|
||
const CAPACITY: usize = 500_000; | ||
|
||
#[derive(Clone, Debug, Decode, TypeInfo)] | ||
#[codec(crate = sails_rs::scale_codec)] | ||
#[scale_info(crate = sails_rs::scale_info)] | ||
pub struct BlockInclusionProof { | ||
pub block: LightBeaconBlock, | ||
pub headers: Vec<BeaconBlockHeader>, | ||
} | ||
|
||
#[derive(Clone, Debug, Decode, TypeInfo)] | ||
#[codec(crate = sails_rs::scale_codec)] | ||
#[scale_info(crate = sails_rs::scale_info)] | ||
pub struct EthToVaraEvent { | ||
pub proof_block: BlockInclusionProof, | ||
pub proof: Vec<Vec<u8>>, | ||
pub transaction_index: u64, | ||
pub receipt_rlp: Vec<u8>, | ||
} | ||
|
||
struct State { | ||
checkpoints: ActorId, | ||
Check failure on line 31 in gear-programs/erc20-relay/app/src/lib.rs
|
||
vft: ActorId, | ||
// (slot, transaction_index) | ||
transactions: Vec<(u64, u64)>, | ||
} | ||
|
||
struct Erc20RelayService<'a>(&'a RefCell<State>); | ||
Check failure on line 37 in gear-programs/erc20-relay/app/src/lib.rs
|
||
|
||
#[sails_rs::service] | ||
impl<'a> Erc20RelayService<'a> { | ||
pub fn new(state: &'a RefCell<State>) -> Self { | ||
Self(state) | ||
} | ||
|
||
pub fn relay(&mut self, message: EthToVaraEvent) -> String { | ||
Check failure on line 45 in gear-programs/erc20-relay/app/src/lib.rs
|
||
"Hello from Erc20Relay!".to_string() | ||
} | ||
} | ||
|
||
pub struct Erc20RelayProgram(RefCell<State>); | ||
|
||
#[sails_rs::program] | ||
impl Erc20RelayProgram { | ||
pub fn new( | ||
checkpoints: ActorId, | ||
vft: ActorId, | ||
) -> Self { | ||
Self(RefCell::new(State { | ||
checkpoints, | ||
vft, | ||
transactions: Vec::with_capacity(CAPACITY), | ||
})) | ||
} | ||
|
||
pub fn erc20_relay(&self) -> Erc20RelayService { | ||
Erc20RelayService::new(&self.0) | ||
} | ||
} |
Oops, something went wrong.