add bitcoin core client into global state

This commit is contained in:
conduition
2024-03-18 18:39:12 +00:00
parent c953c40e04
commit a4206b2e22
4 changed files with 17 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -253,6 +253,7 @@ name = "mm_server"
version = "0.1.0"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
"common",
"dlctix",
"hex",

View File

@@ -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"

View File

@@ -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>,

View File

@@ -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,
}));