@@ -52,9 +52,9 @@ use rgb_lib::{
5252 } ,
5353 AssetCFA as RgbLibAssetCFA , AssetNIA as RgbLibAssetNIA , AssetUDA as RgbLibAssetUDA ,
5454 Balance as RgbLibBalance , EmbeddedMedia as RgbLibEmbeddedMedia , Invoice as RgbLibInvoice ,
55- Media as RgbLibMedia , ProofOfReserves as RgbLibProofOfReserves , Recipient , RecipientInfo ,
56- RecipientType as RgbLibRecipientType , Token as RgbLibToken , TokenLight as RgbLibTokenLight ,
57- WitnessData as RgbLibWitnessData ,
55+ Media as RgbLibMedia , ProofOfReserves as RgbLibProofOfReserves ,
56+ Recipient as RgbLibRecipient , RecipientInfo , RecipientType as RgbLibRecipientType ,
57+ Token as RgbLibToken , TokenLight as RgbLibTokenLight , WitnessData as RgbLibWitnessData ,
5858 } ,
5959 AssetSchema as RgbLibAssetSchema , Assignment as RgbLibAssignment ,
6060 BitcoinNetwork as RgbLibNetwork , ContractId , RgbTransport ,
@@ -918,6 +918,25 @@ pub(crate) struct RevokeTokenRequest {
918918 pub ( crate ) token : String ,
919919}
920920
921+ #[ derive( Deserialize , Serialize ) ]
922+ pub ( crate ) struct Recipient {
923+ pub ( crate ) recipient_id : String ,
924+ pub ( crate ) witness_data : Option < WitnessData > ,
925+ pub ( crate ) assignment : Assignment ,
926+ pub ( crate ) transport_endpoints : Vec < String > ,
927+ }
928+
929+ impl From < Recipient > for RgbLibRecipient {
930+ fn from ( value : Recipient ) -> Self {
931+ Self {
932+ recipient_id : value. recipient_id ,
933+ witness_data : value. witness_data . map ( |w| w. into ( ) ) ,
934+ assignment : value. assignment . into ( ) ,
935+ transport_endpoints : value. transport_endpoints ,
936+ }
937+ }
938+ }
939+
921940#[ derive( Deserialize , Serialize ) ]
922941pub ( crate ) struct RgbAllocation {
923942 pub ( crate ) asset_id : Option < String > ,
@@ -942,24 +961,6 @@ pub(crate) struct RgbInvoiceResponse {
942961 pub ( crate ) batch_transfer_idx : i32 ,
943962}
944963
945- #[ derive( Deserialize , Serialize ) ]
946- pub ( crate ) struct SendAssetRequest {
947- pub ( crate ) asset_id : String ,
948- pub ( crate ) assignment : Assignment ,
949- pub ( crate ) recipient_id : String ,
950- pub ( crate ) witness_data : Option < WitnessData > ,
951- pub ( crate ) donation : bool ,
952- pub ( crate ) fee_rate : u64 ,
953- pub ( crate ) min_confirmations : u8 ,
954- pub ( crate ) transport_endpoints : Vec < String > ,
955- pub ( crate ) skip_sync : bool ,
956- }
957-
958- #[ derive( Deserialize , Serialize ) ]
959- pub ( crate ) struct SendAssetResponse {
960- pub ( crate ) txid : String ,
961- }
962-
963964#[ derive( Deserialize , Serialize ) ]
964965pub ( crate ) struct SendBtcRequest {
965966 pub ( crate ) amount : u64 ,
@@ -994,6 +995,20 @@ pub(crate) struct SendPaymentResponse {
994995 pub ( crate ) status : HTLCStatus ,
995996}
996997
998+ #[ derive( Deserialize , Serialize ) ]
999+ pub ( crate ) struct SendRgbRequest {
1000+ pub ( crate ) donation : bool ,
1001+ pub ( crate ) fee_rate : u64 ,
1002+ pub ( crate ) min_confirmations : u8 ,
1003+ pub ( crate ) recipient_map : HashMap < String , Vec < Recipient > > ,
1004+ pub ( crate ) skip_sync : bool ,
1005+ }
1006+
1007+ #[ derive( Deserialize , Serialize ) ]
1008+ pub ( crate ) struct SendRgbResponse {
1009+ pub ( crate ) txid : String ,
1010+ }
1011+
9971012#[ derive( Deserialize , Serialize ) ]
9981013pub ( crate ) struct SignMessageRequest {
9991014 pub ( crate ) message : String ,
@@ -3112,7 +3127,7 @@ pub(crate) async fn open_channel(
31123127 } ;
31133128
31143129 let recipient_map = map ! {
3115- asset_id => vec![ Recipient {
3130+ asset_id => vec![ RgbLibRecipient {
31163131 recipient_id,
31173132 witness_data: Some ( RgbLibWitnessData {
31183133 amount_sat: payload. capacity_sat,
@@ -3357,48 +3372,6 @@ pub(crate) async fn rgb_invoice(
33573372 . await
33583373}
33593374
3360- pub ( crate ) async fn send_asset (
3361- State ( state) : State < Arc < AppState > > ,
3362- WithRejection ( Json ( payload) , _) : WithRejection < Json < SendAssetRequest > , APIError > ,
3363- ) -> Result < Json < SendAssetResponse > , APIError > {
3364- no_cancel ( async move {
3365- let guard = state. check_unlocked ( ) . await ?;
3366- let unlocked_state = guard. as_ref ( ) . unwrap ( ) ;
3367-
3368- if * unlocked_state. rgb_send_lock . lock ( ) . unwrap ( ) {
3369- return Err ( APIError :: OpenChannelInProgress ) ;
3370- }
3371-
3372- RecipientInfo :: new ( payload. recipient_id . clone ( ) ) ?;
3373- let recipient_map = map ! {
3374- payload. asset_id => vec![ Recipient {
3375- recipient_id: payload. recipient_id,
3376- witness_data: payload. witness_data. map( |w| w. into( ) ) ,
3377- assignment: payload. assignment. into( ) ,
3378- transport_endpoints: payload. transport_endpoints,
3379- } ]
3380- } ;
3381-
3382- let unlocked_state_copy = unlocked_state. clone ( ) ;
3383- let send_result = tokio:: task:: spawn_blocking ( move || {
3384- unlocked_state_copy. rgb_send (
3385- recipient_map,
3386- payload. donation ,
3387- payload. fee_rate ,
3388- payload. min_confirmations ,
3389- payload. skip_sync ,
3390- )
3391- } )
3392- . await
3393- . unwrap ( ) ?;
3394-
3395- Ok ( Json ( SendAssetResponse {
3396- txid : send_result. txid ,
3397- } ) )
3398- } )
3399- . await
3400- }
3401-
34023375pub ( crate ) async fn send_btc (
34033376 State ( state) : State < Arc < AppState > > ,
34043377 WithRejection ( Json ( payload) , _) : WithRejection < Json < SendBtcRequest > , APIError > ,
@@ -3655,6 +3628,46 @@ pub(crate) async fn send_payment(
36553628 . await
36563629}
36573630
3631+ pub ( crate ) async fn send_rgb (
3632+ State ( state) : State < Arc < AppState > > ,
3633+ WithRejection ( Json ( payload) , _) : WithRejection < Json < SendRgbRequest > , APIError > ,
3634+ ) -> Result < Json < SendRgbResponse > , APIError > {
3635+ no_cancel ( async move {
3636+ let guard = state. check_unlocked ( ) . await ?;
3637+ let unlocked_state = guard. as_ref ( ) . unwrap ( ) ;
3638+
3639+ if * unlocked_state. rgb_send_lock . lock ( ) . unwrap ( ) {
3640+ return Err ( APIError :: OpenChannelInProgress ) ;
3641+ }
3642+
3643+ let recipient_map: HashMap < String , Vec < RgbLibRecipient > > = payload
3644+ . recipient_map
3645+ . into_iter ( )
3646+ . map ( |( asset_id, recipients) | {
3647+ ( asset_id, recipients. into_iter ( ) . map ( |r| r. into ( ) ) . collect ( ) )
3648+ } )
3649+ . collect ( ) ;
3650+
3651+ let unlocked_state_copy = unlocked_state. clone ( ) ;
3652+ let send_result = tokio:: task:: spawn_blocking ( move || {
3653+ unlocked_state_copy. rgb_send (
3654+ recipient_map,
3655+ payload. donation ,
3656+ payload. fee_rate ,
3657+ payload. min_confirmations ,
3658+ payload. skip_sync ,
3659+ )
3660+ } )
3661+ . await
3662+ . unwrap ( ) ?;
3663+
3664+ Ok ( Json ( SendRgbResponse {
3665+ txid : send_result. txid ,
3666+ } ) )
3667+ } )
3668+ . await
3669+ }
3670+
36583671pub ( crate ) async fn shutdown (
36593672 State ( state) : State < Arc < AppState > > ,
36603673) -> Result < Json < EmptyResponse > , APIError > {
0 commit comments