mirror of
https://github.com/conduition/dlctix.git
synced 2026-01-30 13:15:11 +01:00
add bitcoin core client into global state
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -253,6 +253,7 @@ name = "mm_server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
"common",
|
||||
"dlctix",
|
||||
"hex",
|
||||
|
||||
@@ -15,3 +15,4 @@ hex = "0.4.3"
|
||||
serdect = "0.2.0"
|
||||
serde = "1.0.197"
|
||||
serde_json = "1.0.114"
|
||||
bitcoincore-rpc = "0.18.0"
|
||||
|
||||
@@ -34,6 +34,7 @@ pub(crate) enum Stage {
|
||||
pub(crate) struct GlobalState {
|
||||
pub(crate) event: EventAnnouncement,
|
||||
pub(crate) odds: OutcomeOdds,
|
||||
pub(crate) bitcoind: bitcoincore_rpc::Client,
|
||||
pub(crate) market_maker_seckey: Scalar,
|
||||
pub(crate) market_maker_pubkey: Point,
|
||||
pub(crate) registrations: HashMap<PlayerID, PlayerRegistration>,
|
||||
|
||||
@@ -3,6 +3,8 @@ mod global_state;
|
||||
mod payouts;
|
||||
mod server;
|
||||
|
||||
use bitcoincore_rpc::RpcApi;
|
||||
|
||||
use crate::global_state::{GlobalState, Stage};
|
||||
use common::OutcomeOdds;
|
||||
use dlctix::secp::Scalar;
|
||||
@@ -28,11 +30,23 @@ fn run_server() -> Result<(), Box<dyn Error>> {
|
||||
let odds: OutcomeOdds =
|
||||
serde_cbor::from_slice(&hex::decode(env::var("DLC_EVENT_ODDS_CBOR")?)?)?;
|
||||
|
||||
let bitcoind = {
|
||||
let bitcoind_rpc_url = std::env::var("BITCOIND_RPC_URL")?;
|
||||
let bitcoind_auth_username = std::env::var("BITCOIND_RPC_AUTH_USERNAME")?;
|
||||
let bitcoind_auth_password = std::env::var("BITCOIND_RPC_AUTH_PASSWORD")?;
|
||||
let auth = bitcoincore_rpc::Auth::UserPass(bitcoind_auth_username, bitcoind_auth_password);
|
||||
bitcoincore_rpc::Client::new(&bitcoind_rpc_url, auth)?
|
||||
};
|
||||
|
||||
// Check that a wallet is loaded
|
||||
let _ = bitcoind.get_wallet_info()?;
|
||||
|
||||
let global_state = Arc::new(RwLock::new(GlobalState {
|
||||
event,
|
||||
odds,
|
||||
market_maker_seckey,
|
||||
market_maker_pubkey,
|
||||
bitcoind,
|
||||
registrations: HashMap::new(),
|
||||
stage: Stage::IntentRegistry,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user