diff --git a/.gitignore b/.gitignore index b7347ec..0b4ca54 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ taptrade-cli-demo/target taptrade-cli-demo/coordinator/target taptrade-cli-demo/coordinator/dbs/* taptrade-cli-demo/trader/target +taptrade-cli-demo/rpc_node/testnet4/testnet4node +taptrade-cli-demo/rpc_node/testnet3/data +taptrade-cli-demo/rpc_node/signet/data \ No newline at end of file diff --git a/docs/TapTrade_obs/.obsidian/workspace.json b/docs/TapTrade_obs/.obsidian/workspace.json index 504a2f6..8d91957 100755 --- a/docs/TapTrade_obs/.obsidian/workspace.json +++ b/docs/TapTrade_obs/.obsidian/workspace.json @@ -11,11 +11,14 @@ "id": "bdb9fd88a01a8909", "type": "leaf", "state": { - "type": "markdown", + "type": "canvas", "state": { - "file": "Research/Bitcoin fundamentals/Knowledge sources.md", - "mode": "source", - "source": false + "file": "Research/Trade Pipelines/new concepts/concept locking script 1.canvas", + "viewState": { + "x": 31, + "y": -44.99563086871524, + "zoom": -0.432684559607355 + } } } } @@ -85,7 +88,7 @@ "state": { "type": "backlink", "state": { - "file": "Research/Bitcoin fundamentals/Knowledge sources.md", + "file": "Research/Trade Pipelines/new concepts/concept locking script 1.canvas", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -102,7 +105,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Research/Bitcoin fundamentals/Knowledge sources.md", + "file": "Research/Trade Pipelines/new concepts/concept locking script 1.canvas", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -125,7 +128,7 @@ "state": { "type": "outline", "state": { - "file": "Research/Bitcoin fundamentals/Knowledge sources.md" + "file": "Research/Trade Pipelines/new concepts/concept locking script 1.canvas" } } } @@ -148,8 +151,8 @@ }, "active": "bdb9fd88a01a8909", "lastOpenFiles": [ - "Research/Trade Pipelines/new concepts/concept locking script 1.canvas", "Research/Trade Pipelines/new concepts/concept pipeline 1.canvas", + "Research/Trade Pipelines/new concepts/concept locking script 1.canvas", "Research/Bitcoin fundamentals/Knowledge sources.md", "assets/ptlc2.png", "assets/ptlc.png", diff --git a/docs/TapTrade_obs/Research/Trade Pipelines/new concepts/concept pipeline 1.canvas b/docs/TapTrade_obs/Research/Trade Pipelines/new concepts/concept pipeline 1.canvas index 32fe7f8..6f6d5ae 100755 --- a/docs/TapTrade_obs/Research/Trade Pipelines/new concepts/concept pipeline 1.canvas +++ b/docs/TapTrade_obs/Research/Trade Pipelines/new concepts/concept pipeline 1.canvas @@ -21,7 +21,7 @@ {"id":"9b054e655a321517","type":"text","text":"PSBT of contract\nMaker adds escrow input sig\n\nMaker only gets PSBT without the Sig of the Taker, so he can't maliciously hold the tx and publish it at a later point in time.","x":-345,"y":980,"width":295,"height":210}, {"id":"345fbda43e40d028","type":"text","text":"Research/use PTLC","x":580,"y":41,"width":250,"height":50,"color":"2"}, {"id":"7916e1f2236a38b6","type":"text","text":"Look into DLC negotiation procedure\nhttps://github.com/discreetlogcontracts/dlcspecs/blob/9cd9148938c616690c79d99ec6f330e213c246c5/Protocol.md","x":5,"y":500,"width":515,"height":140,"color":"4"}, - {"id":"5e3c3c0695787e9a","type":"text","text":"User (Tor)Browser (Wasm)","x":-720,"y":-69,"width":305,"height":60,"color":"3"}, + {"id":"5e3c3c0695787e9a","type":"text","text":"User (Tor)Browser (Wasm)","x":-720,"y":-69,"width":305,"height":69,"color":"3"}, {"id":"483fbdbcc5ea8501","type":"text","text":"I think there could be an advanced mode / external wallet mode where this could be done directly from an external Wallet e.g. Hardware wallet with Sparrow. But it would require lot of copy pasting (signed txs, psbts, addresses). Also there is secret state needed to be saved for MuSig2, this could be downloaded as file or stored encrypted on the coordinator. \n\nFor easy use there would need to be a wallet in RoboSats (BDK) but UI wise this would be either a challenge or a privacy reduction (if you use the same wallet but different Robot). It's also possible to limit the Wallet to one robot so the user must withdraw the sats after the trade (can't import wallet into robosats, only export). I think wallet could also be stored encrypted on coordinator or exported as file/seed.","x":55,"y":-549,"width":660,"height":338}, {"id":"f3b7288289dc8954","type":"text","text":"Backend","x":195,"y":-172,"width":250,"height":60,"color":"3"}, {"id":"93c73227c82f1a81","type":"text","text":"**Coordinator**\n\nwatches Mempool and Chain, could publish the bond TX. Essentially just to prevent orderbook spam / for skin in the game.\n\n*SIGHASH_ALL | ANYONECANPAY* could make it possible for the coordinator to add inputs up to the height of the bond to push the TX fees without losing capital itself. \nAlso out of band mining would cause a cost for the Maker so there is always a price to being unreliable. \n\nThe Maker could be required to use Inputs at least the value of the trade amount to proof that he owns enough sats to fulfill the trade. Maybe lock the time to invalidate the bond after a certain amount of time.","x":80,"y":-98,"width":500,"height":418}, diff --git a/taptrade-cli-demo/bitcoin-testnet4-node/docker-compose.yml b/taptrade-cli-demo/bitcoin-testnet4-node/docker-compose.yml deleted file mode 100755 index 5bc7e44..0000000 --- a/taptrade-cli-demo/bitcoin-testnet4-node/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -services: - bitcoind: - image: mocacinno/btc_testnet4:latest - privileged: true - container_name: bitcoind - volumes: - - ./bitcoin_data:/root/.bitcoin/ - command: ["bitcoind", "-testnet4"] - ports: - - "18332:18332" - - "8333:8333" - - "48332:48332" - -# https://bitcointalk.org/index.php?topic=5496494 diff --git a/taptrade-cli-demo/coordinator/.env b/taptrade-cli-demo/coordinator/.env index adf371c..f2deecf 100644 --- a/taptrade-cli-demo/coordinator/.env +++ b/taptrade-cli-demo/coordinator/.env @@ -1,5 +1,5 @@ -BITCOIN_RPC_ADDRESS_PORT="127.0.0.1:18332" -BITCOIN_RPC_COOKIE_FILE_PATH="~/.bitcoin/.cookie" # path to the cookie file for the bitcoind RPC +BITCOIN_RPC_ADDRESS_PORT="127.0.0.1:8332" +BITCOIN_RPC_COOKIE_FILE_PATH="./.cookie" # path to the cookie file for the bitcoind RPC BITCOIN_RPC_WALLET_NAME="coordinator_wallet" # not used yet DATABASE_PATH="./dbs/trades.db" # path to the coordinator sqlite database storing the trades BDK_DB_PATH="./dbs/bdk-wallet" # Path to the BDK Sled database (no .db postfix) diff --git a/taptrade-cli-demo/coordinator/src/coordinator/mod.rs b/taptrade-cli-demo/coordinator/src/coordinator/mod.rs index b049b1a..ab90781 100755 --- a/taptrade-cli-demo/coordinator/src/coordinator/mod.rs +++ b/taptrade-cli-demo/coordinator/src/coordinator/mod.rs @@ -1,4 +1,4 @@ pub mod monitoring; -pub mod create_taproot; // commented out for testing +// pub mod create_taproot; // commented out for testing use super::*; diff --git a/taptrade-cli-demo/coordinator/src/wallet/mod.rs b/taptrade-cli-demo/coordinator/src/wallet/mod.rs index b9680f8..a43eb93 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/mod.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/mod.rs @@ -40,7 +40,7 @@ pub fn init_coordinator_wallet() -> Result> { auth: Auth::Cookie { file: env::var("BITCOIN_RPC_COOKIE_FILE_PATH")?.into(), }, - network: bdk::bitcoin::Network::Testnet, + network: bdk::bitcoin::Network::Signet, wallet_name: env::var("BITCOIN_RPC_WALLET_NAME")?, sync_params: None, }; @@ -51,13 +51,13 @@ pub fn init_coordinator_wallet() -> Result> { let wallet = Wallet::new( Bip86(wallet_xprv, KeychainKind::External), Some(Bip86(wallet_xprv, KeychainKind::Internal)), - bitcoin::Network::Testnet, + bitcoin::Network::Signet, sled_db, )?; - wallet - .sync(&backend, SyncOptions::default()) - .context("Connection to electrum server failed.")?; // we could also use Esplora to make this async + // wallet + // .sync(&backend, SyncOptions::default()) + // .context("Connection to electrum server failed.")?; // we could also use Esplora to make this async dbg!(wallet.get_balance()?); Ok(CoordinatorWallet { wallet: Arc::new(Mutex::new(wallet)), @@ -266,7 +266,7 @@ mod tests { auth: Auth::Cookie { file: env::var("BITCOIN_RPC_COOKIE_FILE_PATH").unwrap().into(), }, - network: bdk::bitcoin::Network::Testnet, + network: bdk::bitcoin::Network::Signet, wallet_name: env::var("BITCOIN_RPC_WALLET_NAME").unwrap(), sync_params: None, }; @@ -277,7 +277,7 @@ mod tests { let wallet = Wallet::new( Bip86(wallet_xprv, KeychainKind::External), Some(Bip86(wallet_xprv, KeychainKind::Internal)), - Network::Testnet, + Network::Signet, MemoryDatabase::new(), ) .unwrap(); diff --git a/taptrade-cli-demo/coordinator/src/wallet/utils.rs b/taptrade-cli-demo/coordinator/src/wallet/utils.rs index e516545..3118f5d 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/utils.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/utils.rs @@ -41,7 +41,7 @@ impl BondTx for Transaction { fn bond_output_sum(&self, bond_address: &str) -> Result { let bond_script = Address::from_str(bond_address)? - .require_network(Network::Testnet)? + .require_network(Network::Signet)? .script_pubkey(); for output in self.output.iter() { diff --git a/taptrade-cli-demo/bitcoin-testnet4-node/bitcoin_data/bitcoin.conf b/taptrade-cli-demo/rpc_node/signet/bitcoin.conf similarity index 57% rename from taptrade-cli-demo/bitcoin-testnet4-node/bitcoin_data/bitcoin.conf rename to taptrade-cli-demo/rpc_node/signet/bitcoin.conf index f7aaf31..243f9c3 100644 --- a/taptrade-cli-demo/bitcoin-testnet4-node/bitcoin_data/bitcoin.conf +++ b/taptrade-cli-demo/rpc_node/signet/bitcoin.conf @@ -1,15 +1,18 @@ -[testnet4] server=1 txindex=1 -rpcbind=127.0.0.1 -rpcallowip=127.0.0.1 -rpcport=18332 + # Authentication -rpcauth= +rpcauth=XXX:1234 # generator: https://jlopp.github.io/bitcoin-core-rpc-auth-generator/ # Cookie file authentication -rpccookiefile=/home/user/.bitcoin/.cookie +rpccookiefile=/home/bitcoin/.bitcoin/.cookie # Increase the number of connections maxconnections=15 # Set the maximum number of transactions to keep in the memory pool maxmempool=300 +# Run this node on the Bitcoin Test Network. Equivalent to -chain=test +signet=1 +[signet] +rpcbind=0.0.0.0 +rpcallowip=0.0.0.0/0 +rpcport=8332 \ No newline at end of file diff --git a/taptrade-cli-demo/rpc_node/signet/docker-compose.yml b/taptrade-cli-demo/rpc_node/signet/docker-compose.yml new file mode 100644 index 0000000..d635c79 --- /dev/null +++ b/taptrade-cli-demo/rpc_node/signet/docker-compose.yml @@ -0,0 +1,10 @@ +services: + bitcoin: + container_name: bitcoin + image: dobtc/bitcoin + ports: + - 8332:8332 + volumes: + - ./bitcoin.conf:/home/bitcoin/.bitcoin/bitcoin.conf + - ./data/:/home/bitcoin/.bitcoin + diff --git a/taptrade-cli-demo/trader/maker.env b/taptrade-cli-demo/trader/maker.env index 4979e18..30e24f1 100644 --- a/taptrade-cli-demo/trader/maker.env +++ b/taptrade-cli-demo/trader/maker.env @@ -1,4 +1,4 @@ -ELECTRUM_ENDPOINT="ssl://mempool.space:40002" # testnet 4 electrum server +ELECTRUM_ENDPOINT="ssl://mempool.space:60602" # signet electrum server COORDINATOR_ENDPOINT="http://127.0.0.1:9999" ROBOHASH_HEX="26ee3dee4815655d223c3505162fd4610294a9542f89bb3d3e9748f534ac10ae" # sha256 of "robot21" TRADE_TYPE="buy" diff --git a/taptrade-cli-demo/trader/src/wallet/bond.rs b/taptrade-cli-demo/trader/src/wallet/bond.rs index c37dd8a..60432f8 100644 --- a/taptrade-cli-demo/trader/src/wallet/bond.rs +++ b/taptrade-cli-demo/trader/src/wallet/bond.rs @@ -33,7 +33,7 @@ impl Bond { debug!("Assembling bond transaction"); // parse bond locking address as Address struct and verify network is testnet let address: Address = - Address::from_str(&bond_target.bond_address)?.require_network(Network::Testnet)?; + Address::from_str(&bond_target.bond_address)?.require_network(Network::Signet)?; // build bond locking transaction. Use coin selection to add at least enough outputs // to have the full trading sum as change as evidence for the coordinator that the maker owns @@ -53,10 +53,10 @@ impl Bond { builder.finish()? }; debug!("Signing bond transaction."); - // let finalized = wallet.sign(&mut psbt, SignOptions::default())?; // deactivated to test bond validation - // if !finalized { - // return Err(anyhow!("Transaction could not be finalized")); - // }; + let finalized = wallet.sign(&mut psbt, SignOptions::default())?; // deactivated to test bond validation + if !finalized { + return Err(anyhow!("Transaction could not be finalized")); + }; Ok(psbt) } } @@ -84,7 +84,7 @@ mod tests { let wallet = Wallet::new( Bip86(wallet_xprv, KeychainKind::External), Some(Bip86(wallet_xprv, KeychainKind::Internal)), - Network::Testnet, + Network::Signet, MemoryDatabase::default(), ) .unwrap(); diff --git a/taptrade-cli-demo/trader/src/wallet/mod.rs b/taptrade-cli-demo/trader/src/wallet/mod.rs index 92202a3..4dcaff0 100644 --- a/taptrade-cli-demo/trader/src/wallet/mod.rs +++ b/taptrade-cli-demo/trader/src/wallet/mod.rs @@ -27,7 +27,7 @@ pub struct TradingWallet { pub fn get_wallet_xprv(xprv_input: Option) -> Result { let xprv: ExtendedPrivKey; - let network: Network = Network::Testnet; + let network: Network = Network::Signet; if let Some(xprv_i) = xprv_input { xprv = ExtendedPrivKey::from_str(&xprv_i)?; @@ -45,7 +45,7 @@ impl TradingWallet { let wallet = Wallet::new( Bip86(trader_config.wallet_xprv, KeychainKind::External), Some(Bip86(trader_config.wallet_xprv, KeychainKind::Internal)), - bitcoin::Network::Testnet, + bitcoin::Network::Signet, MemoryDatabase::default(), // non-permanent storage )?; diff --git a/taptrade-cli-demo/trader/taker.env b/taptrade-cli-demo/trader/taker.env index 2c3f756..48a0a57 100644 --- a/taptrade-cli-demo/trader/taker.env +++ b/taptrade-cli-demo/trader/taker.env @@ -1,8 +1,8 @@ -ELECTRUM_ENDPOINT="ssl://mempool.space:40002" # testnet 4 electrum server +ELECTRUM_ENDPOINT="ssl://mempool.space:60602" # signet electrum server COORDINATOR_ENDPOINT="http://127.0.0.1:9999" ROBOHASH_HEX="169b6049cf865eba7d01e1ad26975f1d5ff29d570297ff18d40a53c8281dff5d" # sha256 of "robot22" TRADE_TYPE="sell" -PAYOUT_ADDRESS="tb1p37qg73t5y0l4un3q5dknzl8fgfhemghaap67wns45pzgrw2tasrq6kesxm" +PAYOUT_ADDRESS="tb1pca4thykxsj4ura8h2pj3zx7v9hzlcvlw9k32u8m0vqs6mxp02c9qr9eup6" BOND_RATIO=5 XPRV="tprv8ZgxMBicQKsPdHuCSjhQuSZP1h6ZTeiRqREYS5guGPdtL7D1uNLpnJmb2oJep99Esq1NbNZKVJBNnD2ZhuXSK7G5eFmmcx73gsoa65e2U32" # wallet xprv OFFER_DURATION_HOURS=48