From fcdf41f838d380ef833cdef04bd9aa47fdf7c5e9 Mon Sep 17 00:00:00 2001 From: Armando Dutra Date: Wed, 11 Jan 2023 22:49:21 -0300 Subject: [PATCH] allow many transfers by cli --- cli/src/command.rs | 47 +++++++----- cli/src/opts.rs | 25 +++---- rpc/src/client.rs | 29 +------- rpc/src/lib.rs | 6 +- rpc/src/messages.rs | 25 ------- rpc/src/{reveal.rs => structs.rs} | 82 +++++++++++++++++++++ shell/_rgb-cli | 8 +-- shell/_rgb-cli.ps1 | 2 - shell/rgb-cli.bash | 10 +-- src/bucketd/processor.rs | 42 +---------- src/bucketd/service.rs | 114 +----------------------------- src/bus/ctl.rs | 15 ---- src/bus/mod.rs | 4 +- src/rgbd/service.rs | 43 +---------- 14 files changed, 138 insertions(+), 314 deletions(-) rename rpc/src/{reveal.rs => structs.rs} (58%) diff --git a/cli/src/command.rs b/cli/src/command.rs index 6ee77a5..6f4f4e3 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -8,9 +8,11 @@ // You should have received a copy of the MIT License along with this software. // If not, see . -use std::collections::BTreeSet; +use std::collections::{BTreeMap, BTreeSet}; use std::{fs, io}; +use crate::opts::{ContractCommand, OutpointCommand, TransferCommand}; +use crate::{Command, Opts}; use amplify::IoError; use bitcoin::consensus; use bitcoin::psbt::serialize::{Deserialize, Serialize}; @@ -20,13 +22,10 @@ use microservices::shell::Exec; use psbt::Psbt; use rgb::blank::BlankBundle; use rgb::psbt::{RgbExt, RgbInExt}; -use rgb::{Node, StateTransfer, Transition, TransitionBundle}; +use rgb::{Node, SealEndpoint, StateTransfer, Transition, TransitionBundle}; use rgb_rpc::{Client, ContractValidity}; use strict_encoding::{StrictDecode, StrictEncode}; -use crate::opts::{ContractCommand, OutpointCommand, TransferCommand}; -use crate::{Command, Opts}; - #[derive(Debug, Display, Error, From)] #[display(inner)] pub enum Error { @@ -93,10 +92,7 @@ impl TransferCommand { format!("Composing consignment for state transfer for contract {}", contract_id) } Self::Combine { .. } => s!("Preparing PSBT for the state transfer"), - Self::Finalize { - send: Some(addr), .. - } => format!("Finalizing state transfer and sending it to {}", addr), - Self::Finalize { send: None, .. } => s!("Finalizing state transfer"), + Self::Finalize { .. } => s!("Finalizing state transfers"), Self::Consume { .. } => s!("Verifying and consuming state transfer"), } } @@ -261,23 +257,36 @@ impl Exec for Opts { } TransferCommand::Finalize { + endseal, psbt: psbt_in, - consignment_in, - consignment_out, - endseals, - send, psbt_out, } => { let psbt_bytes = fs::read(&psbt_in)?; let psbt = Psbt::deserialize(&psbt_bytes)?; - let consignment = StateTransfer::strict_file_load(&consignment_in)?; - let transfer = client.transfer(consignment, endseals, psbt, send, progress)?; - transfer - .consignment - .strict_file_save(consignment_out.unwrap_or(consignment_in))?; + let mut consig_paths = BTreeMap::new(); + let transfers: Vec<(StateTransfer, Vec)> = endseal + .into_iter() + .map(|b| -> (StateTransfer, Vec) { + let consignment = + StateTransfer::strict_file_load(b.consignment.clone()) + .expect("Valid consignment file"); + consig_paths.insert(consignment.contract_id(), b.consignment); + (consignment, b.endseals) + }) + .collect(); + + let transfers = client.finalize_transfers(transfers, psbt, progress)?; + for transfer in transfers.consignments { + if consig_paths.contains_key(&transfer.contract_id()) { + let path = consig_paths + .get(&transfer.contract_id()) + .expect("Invalid consignment path"); + let _ = transfer.strict_file_save(path); + } + } - let psbt_bytes = transfer.psbt.serialize(); + let psbt_bytes = transfers.psbt.serialize(); fs::write(psbt_out.unwrap_or(psbt_in), psbt_bytes)?; } diff --git a/cli/src/opts.rs b/cli/src/opts.rs index d82ef53..f38790b 100644 --- a/cli/src/opts.rs +++ b/cli/src/opts.rs @@ -11,11 +11,11 @@ use std::path::PathBuf; use bitcoin::OutPoint; -use internet2::addr::{NodeAddr, ServiceAddr}; +use internet2::addr::ServiceAddr; use lnpbp::chain::Chain; use rgb::schema::TransitionType; -use rgb::{Contract, ContractId, SealEndpoint}; -use rgb_rpc::{Reveal, RGB_NODE_RPC_ENDPOINT}; +use rgb::{Contract, ContractId}; +use rgb_rpc::{NewTransfer, Reveal, RGB_NODE_RPC_ENDPOINT}; /// Command-line tool for working with RGB node #[derive(Parser, Clone, PartialEq, Eq, Debug)] @@ -151,14 +151,10 @@ pub enum TransferCommand { /// (LNP Node). #[display("finalize ...")] Finalize { - /// Bifrost server to send state transfer to - #[clap(short, long)] - send: Option, - /// Beneficiary blinded TXO seal - or witness transaction output numbers /// containing allocations for the beneficiary. #[clap(short, long = "endseal", required = true)] - endseals: Vec, + endseal: Vec, /// The final PSBT (not modified). psbt: PathBuf, @@ -167,13 +163,12 @@ pub enum TransferCommand { /// information. If not given, the source PSBT file is overwritten. #[clap(short = 'o', long = "out")] psbt_out: Option, + // /// State transfer consignment draft file prepared with `compose` command. + // consignment_in: PathBuf, - /// State transfer consignment draft file prepared with `compose` command. - consignment_in: PathBuf, - - /// Output file to save the final consignment. If not given, the source - /// consignment file is overwritten. - consignment_out: Option, + // /// Output file to save the final consignment. If not given, the source + // /// consignment file is overwritten. + // consignment_out: Option, }, /// Validate incoming transfer consignment and consume it into the stash. @@ -194,7 +189,7 @@ pub enum TransferCommand { /// Examples: /// /// tapret1st@# - /// opret1st@# + /// opret1st@# #[clap(short, long)] reveal: Option, }, diff --git a/rpc/src/client.rs b/rpc/src/client.rs index 634fc45..2787164 100644 --- a/rpc/src/client.rs +++ b/rpc/src/client.rs @@ -13,7 +13,7 @@ use std::thread::sleep; use std::time::Duration; use bitcoin::{OutPoint, Txid}; -use internet2::addr::{NodeAddr, ServiceAddr}; +use internet2::addr::ServiceAddr; use internet2::ZmqSocketType; use lnpbp::chain::Chain; use microservices::esb::{self, BusId, ClientId}; @@ -22,10 +22,10 @@ use psbt::Psbt; use rgb::schema::TransitionType; use rgb::{Contract, ContractId, ContractState, ContractStateMap, SealEndpoint, StateTransfer}; -use crate::messages::{FinalizeTransfersRes, HelloReq, TransferFinalize, TransfersReq}; +use crate::messages::{FinalizeTransfersRes, HelloReq, TransfersReq}; use crate::{ AcceptReq, BusMsg, ComposeReq, ContractValidity, Error, FailureCode, OutpointFilter, Reveal, - RpcMsg, ServiceId, TransferReq, + RpcMsg, ServiceId, }; // We have just a single service bus (RPC), so we can use any id @@ -218,29 +218,6 @@ impl Client { } } - pub fn transfer( - &mut self, - consignment: StateTransfer, - endseals: Vec, - psbt: Psbt, - beneficiary: Option, - progress: impl Fn(String), - ) -> Result { - self.request(RpcMsg::Transfer(TransferReq { - consignment, - endseals, - psbt, - beneficiary, - }))?; - loop { - match self.response()?.failure_to_error()? { - RpcMsg::StateTransferFinalize(transfer) => return Ok(transfer), - RpcMsg::Progress(info) => progress(info), - _ => return Err(Error::UnexpectedServerResponse), - } - } - } - pub fn finalize_transfers( &mut self, transfers: Vec<(StateTransfer, Vec)>, diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index ebe346f..0a2ed14 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -36,16 +36,16 @@ pub mod client; mod error; mod messages; mod service_id; -mod reveal; +mod structs; pub use client::Client; pub use error::{Error, FailureCode}; pub(crate) use messages::BusMsg; pub use messages::{ AcceptReq, ComposeReq, ContractValidity, FinalizeTransfersRes, HelloReq, OutpointFilter, - RpcMsg, TransferFinalize, TransferReq, TransfersReq, + RpcMsg, TransfersReq, }; -pub use reveal::Reveal; pub use service_id::ServiceId; +pub use structs::{NewTransfer, Reveal}; pub const RGB_NODE_RPC_ENDPOINT: &str = "0.0.0.0:63963"; diff --git a/rpc/src/messages.rs b/rpc/src/messages.rs index 1aa6c7e..bc230cc 100644 --- a/rpc/src/messages.rs +++ b/rpc/src/messages.rs @@ -11,7 +11,6 @@ use std::collections::BTreeSet; use bitcoin::{OutPoint, Txid}; -use internet2::addr::NodeAddr; use internet2::presentation; use lnpbp::chain::Chain; use microservices::rpc; @@ -71,9 +70,6 @@ pub enum RpcMsg { #[display("process_disclosure({0})")] ProcessDisclosure(Txid), - #[display(inner)] - Transfer(TransferReq), - #[display(inner)] FinalizeTransfers(TransfersReq), @@ -97,9 +93,6 @@ pub enum RpcMsg { #[display("state_transfer(...)")] StateTransfer(StateTransfer), - #[display("state_transfer_finalize(...)")] - StateTransferFinalize(TransferFinalize), - #[display("state_transfer_finalize(...)")] FinalizedTransfers(FinalizeTransfersRes), @@ -190,24 +183,6 @@ pub struct ComposeReq { pub outpoints: OutpointFilter, } -#[derive(Clone, PartialEq, Eq, Debug, Display)] -#[derive(NetworkEncode, NetworkDecode)] -#[display("transfer(...)")] -pub struct TransferReq { - pub consignment: StateTransfer, - pub endseals: Vec, - pub psbt: Psbt, - pub beneficiary: Option, -} - -#[derive(Clone, PartialEq, Eq, Debug, Display)] -#[derive(NetworkEncode, NetworkDecode)] -#[display("transfer_complete(...)")] -pub struct TransferFinalize { - pub consignment: StateTransfer, - pub psbt: Psbt, -} - #[derive(Clone, PartialEq, Eq, Debug, Display)] #[derive(NetworkEncode, NetworkDecode)] #[display("transfers_req(...)")] diff --git a/rpc/src/reveal.rs b/rpc/src/structs.rs similarity index 58% rename from rpc/src/reveal.rs rename to rpc/src/structs.rs index 63ba25b..ac2ac88 100644 --- a/rpc/src/reveal.rs +++ b/rpc/src/structs.rs @@ -10,6 +10,7 @@ use bitcoin::OutPoint; use bp::seals::txout::CloseMethod; +use rgb::SealEndpoint; #[derive(From, PartialEq, Eq, Debug, Clone, StrictEncode, StrictDecode)] pub struct Reveal { @@ -115,3 +116,84 @@ impl ::std::error::Error for ParseRevealError { } } } + +#[derive(From, PartialEq, Eq, Debug, Clone, StrictEncode, StrictDecode)] +pub struct NewTransfer { + /// Beneficiary blinded TXO seal - or witness transaction output numbers + /// containing allocations for the beneficiary. + pub endseals: Vec, + + /// State transfer consignment draft file prepared with `compose` command. + pub consignment: String, +} + +/// An error in parsing an OutPoint. +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum ParseNewTransferError { + /// Error in seal endpoint part. + SealEndpoint, + /// Error in consignment part. + Consignment, + /// Error in general format. + Format, +} + +impl std::fmt::Display for ParseNewTransferError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match *self { + ParseNewTransferError::SealEndpoint => write!(f, "error parsing SealEndpoint"), + ParseNewTransferError::Consignment => write!(f, "error parsing Consignment"), + ParseNewTransferError::Format => todo!(), + } + } +} + +impl std::fmt::Display for NewTransfer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let endseals: Vec = + self.endseals.clone().into_iter().map(|e| e.to_string()).collect(); + let endseals = endseals.join(","); + write!(f, "{}:{}", endseals, self.consignment) + } +} + +impl ::core::str::FromStr for NewTransfer { + type Err = ParseNewTransferError; + + fn from_str(s: &str) -> Result { + let find_consig = s.find(':'); + let index_consig = match find_consig { + Some(index) => index, + _ => return Err(ParseNewTransferError::Format), + }; + + println!("{}", "passou aqui"); + if index_consig == 0 || index_consig == s.len() - 1 { + return Err(ParseNewTransferError::Format); + } + + let find_endseals = s.find(','); + let endseals = match find_endseals { + Some(_) => s[..index_consig] + .split(',') + .into_iter() + .map(|e| SealEndpoint::from_str(e).expect("Error in SealEndpoint part")) + .collect(), + _ => { + vec![SealEndpoint::from_str(&s[..index_consig]).expect("Error in SealEndpoint part")] + } + }; + + Ok(NewTransfer { + endseals, + consignment: match String::try_from(&s[index_consig + 1..]) { + Ok(it) => it, + Err(_) => return Err(ParseNewTransferError::Consignment), + }, + }) + } +} + +impl ::std::error::Error for ParseNewTransferError { + fn cause(&self) -> Option<&dyn ::std::error::Error> { None } +} diff --git a/shell/_rgb-cli b/shell/_rgb-cli index 55ee5d8..83cafc3 100644 --- a/shell/_rgb-cli +++ b/shell/_rgb-cli @@ -247,10 +247,8 @@ _arguments "${_arguments_options[@]}" \ ;; (finalize) _arguments "${_arguments_options[@]}" \ -'-s+[Bifrost server to send state transfer to]:SEND: ' \ -'--send=[Bifrost server to send state transfer to]:SEND: ' \ -'*-e+[Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary]:ENDSEALS: ' \ -'*--endseal=[Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary]:ENDSEALS: ' \ +'*-e+[Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary]:ENDSEAL: ' \ +'*--endseal=[Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary]:ENDSEAL: ' \ '-o+[Output file to save the PSBT updated with state transition(s) information. If not given, the source PSBT file is overwritten]:PSBT_OUT: ' \ '--out=[Output file to save the PSBT updated with state transition(s) information. If not given, the source PSBT file is overwritten]:PSBT_OUT: ' \ '-R+[ZMQ socket for connecting daemon RPC interface]:CONNECT: ' \ @@ -262,8 +260,6 @@ _arguments "${_arguments_options[@]}" \ '*-v[Set verbosity level]' \ '*--verbose[Set verbosity level]' \ ':psbt -- The final PSBT (not modified):' \ -':consignment-in -- State transfer consignment draft file prepared with `compose` command:' \ -'::consignment-out -- Output file to save the final consignment. If not given, the source consignment file is overwritten:' \ && ret=0 ;; (consume) diff --git a/shell/_rgb-cli.ps1 b/shell/_rgb-cli.ps1 index 44c65e4..7b88138 100644 --- a/shell/_rgb-cli.ps1 +++ b/shell/_rgb-cli.ps1 @@ -203,8 +203,6 @@ Register-ArgumentCompleter -Native -CommandName 'rgb-cli' -ScriptBlock { break } 'rgb-cli;transfer;finalize' { - [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Bifrost server to send state transfer to') - [CompletionResult]::new('--send', 'send', [CompletionResultType]::ParameterName, 'Bifrost server to send state transfer to') [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary') [CompletionResult]::new('--endseal', 'endseal', [CompletionResultType]::ParameterName, 'Beneficiary blinded TXO seal - or witness transaction output numbers containing allocations for the beneficiary') [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Output file to save the PSBT updated with state transition(s) information. If not given, the source PSBT file is overwritten') diff --git a/shell/rgb-cli.bash b/shell/rgb-cli.bash index eb6cdb8..7d8f48e 100644 --- a/shell/rgb-cli.bash +++ b/shell/rgb-cli.bash @@ -594,20 +594,12 @@ _rgb-cli() { return 0 ;; rgb__cli__transfer__finalize) - opts="-s -e -o -h -R -n -v --send --endseal --out --help --rpc --chain --verbose " + opts="-e -o -h -R -n -v --endseal --out --help --rpc --chain --verbose " if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi case "${prev}" in - --send) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - -s) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; --endseal) COMPREPLY=($(compgen -f "${cur}")) return 0 diff --git a/src/bucketd/processor.rs b/src/bucketd/processor.rs index 8d918bf..e2ad531 100644 --- a/src/bucketd/processor.rs +++ b/src/bucketd/processor.rs @@ -24,7 +24,7 @@ use rgb::{ InmemConsignment, Node, NodeId, OwnedRights, PedersenStrategy, Schema, SchemaId, SealEndpoint, StateTransfer, Transition, TransitionBundle, TypedAssignments, Validator, Validity, }; -use rgb_rpc::{FinalizeTransfersRes, OutpointFilter, Reveal, TransferFinalize}; +use rgb_rpc::{FinalizeTransfersRes, OutpointFilter, Reveal}; use storm::chunk::ChunkIdExt; use storm::{ChunkId, Container, ContainerId}; use strict_encoding::StrictDecode; @@ -564,46 +564,6 @@ impl Runtime { Ok(res) } - pub(super) fn finalize_transfer( - &mut self, - mut consignment: StateTransfer, - endseals: Vec, - mut psbt: Psbt, - ) -> Result { - let contract_id = consignment.contract_id(); - info!("Finalizing transfer for {}", contract_id); - - // 1. Pack LNPBP-4 and anchor information. - let mut bundles = psbt.rgb_bundles()?; - debug!("Found {} bundles", bundles.len()); - trace!("Bundles: {:?}", bundles); - - let anchor = Anchor::commit(&mut psbt)?; - trace!("Anchor: {:?}", anchor); - - // 2. Extract contract-related state transition from PSBT and put it - // into consignment. - let bundle = bundles.remove(&contract_id).ok_or(FinalizeError::ContractBundleMissed)?; - let bundle_id = bundle.bundle_id(); - consignment.push_anchored_bundle(anchor.to_merkle_proof(contract_id)?, bundle)?; - - // 3. Add seal endpoints. - for endseal in endseals { - consignment.push_seal_endpoint(bundle_id, endseal); - } - - // 4. Conceal all the state not related to the transfer. - // TODO: Conceal all the amounts except the last transition - // TODO: Conceal all seals outside of the paths from the endpoint to genesis - - // 5. Construct and store disclosure for the blank transfers. - let txid = anchor.txid; - let disclosure = Disclosure::with(anchor, bundles, None); - self.store.store_sten(db::DISCLOSURES, txid, &disclosure)?; - - Ok(TransferFinalize { consignment, psbt }) - } - pub(super) fn finalize_transfers( &mut self, transfers: Vec<(StateTransfer, Vec)>, diff --git a/src/bucketd/service.rs b/src/bucketd/service.rs index 1553be5..898a6f1 100644 --- a/src/bucketd/service.rs +++ b/src/bucketd/service.rs @@ -9,16 +9,13 @@ // If not, see . use std::collections::BTreeSet; -use std::str::FromStr; use std::thread; use std::time::Duration; -use amplify::num::u24; use bitcoin::secp256k1::rand::random; use bitcoin::{OutPoint, Txid}; use commit_verify::ConsensusCommit; use electrum_client::{Client as ElectrumClient, ConfigBuilder}; -use internet2::addr::NodeAddr; use internet2::ZmqSocketType; use microservices::error::BootstrapError; use microservices::esb; @@ -31,18 +28,11 @@ use rgb::{ StateTransfer, TransferConsignment, Validity, }; use rgb_rpc::{OutpointFilter, Reveal, RpcMsg}; -use stens::AsciiString; -use storm::{ - Chunk, Container, ContainerFullId, ContainerHeader, ContainerId, ContainerInfo, MesgId, -}; -use storm_ext::ExtMsg as StormMsg; -use storm_rpc::AddressedMsg; -use strict_encoding::{MediumVec, StrictEncode}; +use storm::ContainerId; use crate::bus::{ - BusMsg, ConsignReq, CtlMsg, DaemonId, Endpoints, FinalizeTransferReq, FinalizeTransfersReq, - OutpointStateReq, ProcessDisclosureReq, ProcessReq, Responder, ServiceBus, ServiceId, - ValidityResp, + BusMsg, ConsignReq, CtlMsg, DaemonId, Endpoints, FinalizeTransfersReq, OutpointStateReq, + ProcessDisclosureReq, ProcessReq, Responder, ServiceBus, ServiceId, ValidityResp, }; use crate::{Config, DaemonError, LaunchError}; @@ -236,23 +226,6 @@ impl Runtime { self.handle_outpoint_state(endpoints, client_id, outpoints)?; } - CtlMsg::FinalizeTransfer(FinalizeTransferReq { - client_id, - consignment, - endseals, - psbt, - beneficiary, - }) => { - self.handle_finalize_transfer( - endpoints, - client_id, - consignment, - endseals, - psbt, - beneficiary, - )?; - } - CtlMsg::FinalizeTransfers(FinalizeTransfersReq { client_id, transfers, @@ -416,87 +389,6 @@ impl Runtime { Ok(()) } - fn handle_finalize_transfer( - &mut self, - endpoints: &mut Endpoints, - client_id: ClientId, - consignment: StateTransfer, - endseals: Vec, - psbt: Psbt, - beneficiary: Option, - ) -> Result<(), DaemonError> { - match self.finalize_transfer(consignment, endseals, psbt) { - Err(err) => { - let _ = self.send_rpc(endpoints, client_id, err); - self.send_ctl(endpoints, ServiceId::rgbd(), CtlMsg::ProcessingFailed)? - } - Ok(transfer) => { - if let Some(beneficiary) = beneficiary { - // 1. Containerize consignment - // TODO: Make consignment containerization part of the RGB stdlib; use logical, - // not a size-chunking - let data = transfer.consignment.strict_serialize()?; - let mut chunk_ids = MediumVec::new(); - let size = data.len() as u64; - for piece in data.chunks(u24::MAX.into_usize()) { - let chunk = Chunk::try_from(piece)?; - let chunk_id = chunk.chunk_id(); - self.store.store(storm_rpc::DB_TABLE_CHUNKS, chunk_id, &chunk)?; - chunk_ids.push(chunk_id)?; - } - - let header = ContainerHeader { - version: 0, - mime: AsciiString::from_str("application/vnd.lnpbp.rgb.consignment") - .expect("hardcoded MIME type"), - info: empty!(), - size, - }; - let header_chunk = Chunk::try_from(header.strict_serialize()?)?; - let container = Container { - header: header.clone(), - chunks: chunk_ids, - }; - let container_chunk = Chunk::try_from(container.strict_serialize()?)?; - - // 2. Upload container to stored database - let container_id = container.container_id(); - self.store.store( - storm_rpc::DB_TABLE_CONTAINER_HEADERS, - container_id, - &header_chunk, - )?; - self.store.store( - storm_rpc::DB_TABLE_CONTAINERS, - container_id, - &container_chunk, - )?; - - // 3. Instruct storm to send the consignment to the remote peer - // TODO: Ensure we are connected to the beneficiary - let container_full_id = ContainerFullId { - // TODO: Change to use message-wrapped container announcements - message_id: MesgId::default(), - container_id, - }; - let addressed_msg = AddressedMsg { - remote_id: beneficiary.id, - data: ContainerInfo { - id: container_full_id, - header, - }, - }; - - self.send_storm(endpoints, StormMsg::ContainerAnnouncement(addressed_msg))?; - } - let _ = - self.send_rpc(endpoints, client_id, RpcMsg::StateTransferFinalize(transfer)); - self.send_ctl(endpoints, ServiceId::rgbd(), CtlMsg::ProcessingComplete)?; - } - } - Ok(()) - } - fn handle_finalize_transfers( &mut self, endpoints: &mut Endpoints, diff --git a/src/bus/ctl.rs b/src/bus/ctl.rs index 06c8790..8bf1682 100644 --- a/src/bus/ctl.rs +++ b/src/bus/ctl.rs @@ -11,7 +11,6 @@ use std::collections::BTreeSet; use bitcoin::{OutPoint, Txid}; -use internet2::addr::NodeAddr; use microservices::esb::ClientId; use psbt::Psbt; use rgb::schema::TransitionType; @@ -51,9 +50,6 @@ pub enum CtlMsg { #[display(inner)] OutpointState(OutpointStateReq), - #[display(inner)] - FinalizeTransfer(FinalizeTransferReq), - #[display(inner)] FinalizeTransfers(FinalizeTransfersReq), @@ -110,17 +106,6 @@ pub struct OutpointStateReq { pub outpoints: BTreeSet, } -#[derive(Clone, PartialEq, Eq, Debug, Display)] -#[derive(NetworkEncode, NetworkDecode)] -#[display("finalize_transfer({client_id}, ...)")] -pub struct FinalizeTransferReq { - pub client_id: ClientId, - pub consignment: StateTransfer, - pub endseals: Vec, - pub psbt: Psbt, - pub beneficiary: Option, -} - #[derive(Clone, PartialEq, Eq, Debug, Display)] #[derive(NetworkEncode, NetworkDecode)] #[display("finalize_transfers({client_id}, ...)")] diff --git a/src/bus/mod.rs b/src/bus/mod.rs index 15c49d9..1000797 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -16,8 +16,8 @@ use rgb_rpc::RpcMsg; use storm_ext::ExtMsg as StormMsg; pub use self::ctl::{ - ConsignReq, CtlMsg, FinalizeTransferReq, FinalizeTransfersReq, OutpointStateReq, - ProcessDisclosureReq, ProcessReq, ValidityResp, + ConsignReq, CtlMsg, FinalizeTransfersReq, OutpointStateReq, ProcessDisclosureReq, ProcessReq, + ValidityResp, }; pub use self::services::{DaemonId, ServiceId}; pub(crate) use self::services::{Endpoints, Responder, ServiceBus}; diff --git a/src/rgbd/service.rs b/src/rgbd/service.rs index d62d9a1..1c01abb 100644 --- a/src/rgbd/service.rs +++ b/src/rgbd/service.rs @@ -13,7 +13,6 @@ use std::collections::{BTreeSet, VecDeque}; use amplify::Wrapper; use bitcoin::hashes::Hash; use bitcoin::{OutPoint, Txid}; -use internet2::addr::NodeAddr; use internet2::ZmqSocketType; use lnpbp::chain::Chain; use microservices::cli::LogStyle; @@ -27,8 +26,7 @@ use rgb::{ Contract, ContractConsignment, ContractId, SealEndpoint, StateTransfer, TransferConsignment, }; use rgb_rpc::{ - AcceptReq, ComposeReq, FailureCode, HelloReq, OutpointFilter, Reveal, RpcMsg, TransferReq, - TransfersReq, + AcceptReq, ComposeReq, FailureCode, HelloReq, OutpointFilter, Reveal, RpcMsg, TransfersReq, }; use storm::ContainerId; use storm_ext::ExtMsg as StormMsg; @@ -36,8 +34,8 @@ use storm_rpc::AddressedMsg; use crate::bucketd::StashError; use crate::bus::{ - BusMsg, ConsignReq, CtlMsg, DaemonId, Endpoints, FinalizeTransferReq, FinalizeTransfersReq, - OutpointStateReq, ProcessDisclosureReq, ProcessReq, Responder, ServiceBus, ServiceId, + BusMsg, ConsignReq, CtlMsg, DaemonId, Endpoints, FinalizeTransfersReq, OutpointStateReq, + ProcessDisclosureReq, ProcessReq, Responder, ServiceBus, ServiceId, }; use crate::db::ChunkHolder; use crate::rgbd::daemons::Daemon; @@ -263,22 +261,6 @@ impl Runtime { self.process_disclosure(endpoints, client_id, txid)?; } - RpcMsg::Transfer(TransferReq { - consignment, - endseals, - psbt, - beneficiary, - }) => { - self.complete_transfer( - endpoints, - client_id, - consignment, - endseals, - psbt, - beneficiary, - )?; - } - RpcMsg::FinalizeTransfers(TransfersReq { transfers, psbt }) => { self.complete_transfers(endpoints, client_id, transfers, psbt)?; } @@ -546,25 +528,6 @@ impl Runtime { Ok(()) } - fn complete_transfer( - &mut self, - endpoints: &mut Endpoints, - client_id: ClientId, - consignment: StateTransfer, - endseals: Vec, - psbt: Psbt, - beneficiary: Option, - ) -> Result<(), DaemonError> { - self.ctl_queue.push_back(CtlMsg::FinalizeTransfer(FinalizeTransferReq { - client_id, - consignment, - endseals, - psbt, - beneficiary, - })); - self.pick_or_start(endpoints, client_id) - } - fn complete_transfers( &mut self, endpoints: &mut Endpoints,