depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit 0b51ecda47a222c02b66f65d2d55d104ecfab7e4
parent 9efcd48600a6a6d999b372460f568ef7063a6d40
Author: Antoine A <>
Date:   Thu, 17 Feb 2022 00:23:21 +0100

Fix PWD name conflict

Diffstat:
MCargo.lock | 13+++++++------
Mbtc-wire/src/config.rs | 8++++----
Mbtc-wire/src/main.rs | 4++--
Mbtc-wire/src/rpc.rs | 8++++----
Mcommon/src/lib.rs | 6+++---
Meth-wire/src/bin/eth-wire-utils.rs | 13+++++++------
Meth-wire/src/main.rs | 4++--
Mtest/common.sh | 6+++---
8 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" [[package]] name = "cfg-if" @@ -969,9 +969,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.14" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" dependencies = [ "libc", "log", @@ -1721,9 +1721,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.16.1" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", @@ -1731,6 +1731,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", + "socket2", "tokio-macros", "winapi", ] diff --git a/btc-wire/src/config.rs b/btc-wire/src/config.rs @@ -109,13 +109,13 @@ impl BitcoinConfig { ([127, 0, 0, 1], port).into() }; - let auth = if let (Some(login), Some(pwd)) = ( + let auth = if let (Some(login), Some(passwd)) = ( section.and_then(|s| s.get("rpcuser")), section.and_then(|s| s.get("rpcpassword")), ) { - BtcAuth::Auth(format!("{}:{}", login, pwd)) - } else if let (Some(login), Some(pwd)) = (main.get("rpcuser"), main.get("rpcpassword")) { - BtcAuth::Auth(format!("{}:{}", login, pwd)) + BtcAuth::Auth(format!("{}:{}", login, passwd)) + } else if let (Some(login), Some(passwd)) = (main.get("rpcuser"), main.get("rpcpassword")) { + BtcAuth::Auth(format!("{}:{}", login, passwd)) } else { BtcAuth::Cookie }; diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs @@ -128,8 +128,8 @@ fn init(config: Option<PathBuf>, init: Init) { } // Create wallet - let pwd = password(); - let created = match rpc.create_wallet(WIRE_WALLET_NAME, &pwd) { + let passwd = password(); + let created = match rpc.create_wallet(WIRE_WALLET_NAME, &passwd) { Err(rpc::Error::RPC { code, .. }) if code == ErrorCode::RpcWalletError => false, Err(e) => panic!("{}", e), Ok(_) => true, diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs @@ -232,13 +232,13 @@ impl Rpc { } /// Create encrypted native bitcoin wallet - pub fn create_wallet(&mut self, name: &str, pwd: &str) -> Result<Wallet> { - self.call("createwallet", &(name, (), (), pwd, (), true)) + pub fn create_wallet(&mut self, name: &str, passwd: &str) -> Result<Wallet> { + self.call("createwallet", &(name, (), (), passwd, (), true)) } - pub fn unlock_wallet(&mut self, pwd: &str) -> Result<()> { + pub fn unlock_wallet(&mut self, passwd: &str) -> Result<()> { // TODO Capped at 3yrs, is it enough ? - match self.call("walletpassphrase", &(pwd, 100000000)) { + match self.call("walletpassphrase", &(passwd, 100000000)) { Err(Error::Null) => Ok(()), i => i, } diff --git a/common/src/lib.rs b/common/src/lib.rs @@ -55,9 +55,9 @@ where /// Read password from env pub fn password() -> Zeroizing<String> { - let pwd = std::env::var("PWD").unwrap_or_else(|_| { - error!("Missing env var PWD"); + let passwd = std::env::var("PASSWORD").unwrap_or_else(|_| { + error!("Missing env var PASSWORD"); exit(1); }); - Zeroizing::new(pwd) + Zeroizing::new(passwd) } diff --git a/eth-wire/src/bin/eth-wire-utils.rs b/eth-wire/src/bin/eth-wire-utils.rs @@ -23,8 +23,9 @@ use common::{ api_common::Amount, config::{Config, CoreConfig}, log::init, + password, postgres::{Client, NoTls}, - rand_slice, password, + rand_slice, }; use eth_wire::{ rpc::{hex::Hex, Rpc, TransactionRequest}, @@ -108,7 +109,7 @@ fn main() { .and_then(|it| it.data_dir.as_deref()) .or(args.datadir.as_deref()); let mut rpc = Rpc::new(data_dir.unwrap().join("geth.ipc")).unwrap(); - let pwd = password(); + let passwd = password(); match args.cmd { Cmd::Deposit(TransactionCmd { from, @@ -118,7 +119,7 @@ fn main() { }) => { let from = H160::from_str(&from).unwrap(); let to = H160::from_str(&to).unwrap(); - rpc.unlock_account(&from, &pwd).ok(); + rpc.unlock_account(&from, &passwd).ok(); for amount in amounts { let amount = Amount::from_str(&format!("ETH:{}{}", fmt, amount)).unwrap(); let value = taler_to_eth(&amount).unwrap(); @@ -133,7 +134,7 @@ fn main() { }) => { let from = H160::from_str(&from).unwrap(); let to = H160::from_str(&to).unwrap(); - rpc.unlock_account(&from, &pwd).ok(); + rpc.unlock_account(&from, &passwd).ok(); for amount in amounts { let amount = Amount::from_str(&format!("ETH:{}{}", fmt, amount)).unwrap(); let value = taler_to_eth(&amount).unwrap(); @@ -151,7 +152,7 @@ fn main() { } Cmd::Mine { to, mut amount } => { let to = H160::from_str(&to).unwrap(); - rpc.unlock_account(&to, &pwd).ok(); + rpc.unlock_account(&to, &passwd).ok(); let mut notifier = rpc.subscribe_new_head().unwrap(); rpc.miner_start().unwrap(); @@ -206,7 +207,7 @@ fn main() { } Cmd::Abandon { from } => { let from = H160::from_str(&from).unwrap(); - rpc.unlock_account(&from, &pwd).ok(); + rpc.unlock_account(&from, &passwd).ok(); let pending = rpc.pending_transactions().unwrap(); for tx in pending.into_iter().filter(|t| t.from == Some(from)) { // Replace transaction value with 0 diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs @@ -130,8 +130,8 @@ fn init(config: Option<PathBuf>, init: Init) { (H160::from_slice(row.get(0)), false) } else { // Or generate a new one - let pwd = password(); - let new = rpc.new_account(&pwd).expect("Failed creating account"); + let passwd = password(); + let new = rpc.new_account(&passwd).expect("Failed creating account"); db.execute( "INSERT INTO state (name, value) VALUES ('addr', $1)", &[&new.as_bytes()], diff --git a/test/common.sh b/test/common.sh @@ -33,7 +33,7 @@ for log in log/*; do done # Generate random password -PWD=`cat /proc/sys/kernel/random/uuid` +export PASSWORD=`cat /proc/sys/kernel/random/uuid` # Setup command helpers BTC_CLI="bitcoin-cli -datadir=$WIRE_DIR" @@ -231,7 +231,7 @@ function stress_btc_wire() { function init_eth() { # Create wallets for pswd in "reserve" "client"; do - $ETH_CLI account new --password <(echo $PWD) &> /dev/null + $ETH_CLI account new --password <(echo $PASSWORD) &> /dev/null done # Retrieve addresses local ADDR=`$ETH_CLI account list 2> /dev/null | grep -oP '(?<={).*?(?=})'` @@ -277,7 +277,7 @@ function init_eth2() { $ETH_CLI2 --port 30305 --miner.gasprice 0 $* &>> log/node2.log & sleep 1 # Create etherbase account for mining - $ETH_CLI2 account new --password <(echo $PWD) &> /dev/null + $ETH_CLI2 account new --password <(echo $PASSWORD) &> /dev/null # Connect nodes $WIRE_UTILS connect $WIRE_DIR2 }