mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
service/eth: Restore missing functions after halo2-integration merge.
This commit is contained in:
@@ -14,7 +14,7 @@ use serde_json::{json, Value};
|
||||
use super::bridge::{NetworkClient, TokenNotification, TokenSubscribtion};
|
||||
use crate::{
|
||||
rpc::{jsonrpc, jsonrpc::JsonResult},
|
||||
serial::{deserialize, serialize},
|
||||
serial::{deserialize, serialize, Decodable, Encodable},
|
||||
types::*,
|
||||
util::{generate_id, parse::truncate, NetworkName},
|
||||
Error, Result,
|
||||
@@ -22,6 +22,27 @@ use crate::{
|
||||
|
||||
pub const ETH_NATIVE_TOKEN_ID: &str = "0x0000000000000000000000000000000000000000";
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Keypair {
|
||||
pub private_key: String,
|
||||
pub public_key: String,
|
||||
}
|
||||
|
||||
impl Encodable for Keypair {
|
||||
fn encode<S: std::io::Write>(&self, mut s: S) -> Result<usize> {
|
||||
let mut len = 0;
|
||||
len += self.private_key.encode(&mut s)?;
|
||||
len += self.public_key.encode(&mut s)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Keypair {
|
||||
fn decode<D: std::io::Read>(mut d: D) -> Result<Self> {
|
||||
Ok(Self { private_key: Decodable::decode(&mut d)?, public_key: Decodable::decode(&mut d)? })
|
||||
}
|
||||
}
|
||||
|
||||
// An ERC-20 token transfer transaction's data is as follows:
|
||||
//
|
||||
// 1. The first 4 bytes of the keccak256 hash of "transfer(address,uint256)".
|
||||
@@ -167,8 +188,7 @@ impl EthTx {
|
||||
// INFO [10-25|19:47:32.845] IPC endpoint opened: url=/home/x/.ethereum/ropsten/geth.ipc
|
||||
//
|
||||
pub struct EthClient {
|
||||
// main_keypair (private, public)
|
||||
main_keypair: (String, String),
|
||||
main_keypair: Keypair,
|
||||
passphrase: String,
|
||||
socket_path: String,
|
||||
subscriptions: Arc<Mutex<Vec<String>>>,
|
||||
@@ -177,20 +197,28 @@ pub struct EthClient {
|
||||
}
|
||||
|
||||
impl EthClient {
|
||||
pub fn new(
|
||||
socket_path: String,
|
||||
passphrase: String,
|
||||
main_keypair: (String, String),
|
||||
) -> Arc<Self> {
|
||||
pub fn new(socket_path: String, passphrase: String) -> Self {
|
||||
let notify_channel = async_channel::unbounded();
|
||||
let subscriptions = Arc::new(Mutex::new(Vec::new()));
|
||||
Arc::new(Self { main_keypair, passphrase, socket_path, subscriptions, notify_channel })
|
||||
Self {
|
||||
// This must be set by the cashier
|
||||
main_keypair: Keypair { private_key: String::new(), public_key: String::new() },
|
||||
passphrase,
|
||||
socket_path,
|
||||
subscriptions,
|
||||
notify_channel,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_main_keypair(&mut self, keypair: &Keypair) {
|
||||
self.main_keypair = keypair.clone();
|
||||
}
|
||||
|
||||
async fn send_eth_to_main_wallet(&self, acc: &str, amount: BigUint) -> Result<()> {
|
||||
debug!(target: "ETH BRIDGE", "Send eth to main wallet");
|
||||
|
||||
let tx = EthTx::new(acc, &self.main_keypair.1, None, None, Some(amount), None, None);
|
||||
let tx =
|
||||
EthTx::new(acc, &self.main_keypair.public_key, None, None, Some(amount), None, None);
|
||||
|
||||
self.send_transaction(&tx, &self.passphrase).await?;
|
||||
|
||||
@@ -424,7 +452,7 @@ impl NetworkClient for EthClient {
|
||||
let amount = truncate(amount, decimals as u16, 8)?;
|
||||
|
||||
let tx = EthTx::new(
|
||||
&self.main_keypair.1,
|
||||
&self.main_keypair.public_key,
|
||||
&dest,
|
||||
None,
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user